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(platform-fastify): add Fastify platform #2925

Open
wants to merge 1 commit into
base: production
Choose a base branch
from

Conversation

Romakita
Copy link
Collaborator

@Romakita Romakita commented Dec 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced the @tsed/platform-fastify package with version 8.2.0.
    • Added the PlatformFastify class for integrating Fastify with the Ts.ED framework.
    • Created a Fastify server configuration with routes and middleware.
    • Added a new HTML page and EJS view for basic web interactions.
    • Introduced a new TypeScript interface PlatformFastifySettings for configuration management.
  • Bug Fixes

    • Enhanced request and response handling in the Fastify integration.
  • Tests

    • Implemented unit tests for PlatformFastify, PlatformFastifyRequest, and PlatformFastifyResponse classes.
    • Established a test suite for the Fastify server configuration.
    • Added tests for the isRawMiddleware method in the PlatformHandlerMetadata class.
  • Documentation

    • Created a README file for the platform-fastify package with installation instructions and community links.
  • Chores

    • Added TypeScript configuration files for the Fastify platform.
    • Updated .npmignore to exclude unnecessary files from the npm package.

Copy link

coderabbitai bot commented Dec 8, 2024

Walkthrough

The changes in this pull request involve the introduction of the @tsed/platform-fastify package, which includes a new package.json file, a README, and various TypeScript files that define the PlatformFastify class and its associated components. Additionally, unit tests for the PlatformFastify and related classes have been created, alongside configuration files for TypeScript and Vitest. The .npmignore file has also been updated to exclude unnecessary files from the npm package. This update establishes a foundational structure for integrating Fastify with the Ts.ED framework.

Changes

File Path Change Summary
packages/platform/platform-fastify/.npmignore Added entries to exclude test, coverage, tsconfig.json, __mock__, .spec.js, and .tsbuildinfo files from the npm package.
packages/platform/platform-fastify/package.json Introduced a new package.json for @tsed/platform-fastify, specifying metadata, entry points, scripts, dependencies, and peer dependencies.
packages/platform/platform-fastify/readme.md Created a new README file detailing the package, installation instructions, and community involvement.
packages/platform/platform-fastify/src/components/PlatformFastify.spec.ts Added unit tests for the PlatformFastify component, testing create() and bootstrap() methods.
packages/platform/platform-fastify/src/components/PlatformFastify.ts Introduced the PlatformFastify class with methods for integrating Fastify with Ts.ED, including create, bootstrap, and middleware handling.
packages/platform/platform-fastify/src/exports.ts Integrated PlatformFastify into PlatformTest and PlatformBuilder classes as their adapter.
packages/platform/platform-fastify/src/index.ts Created an entry point that exports various modules related to the platform-fastify package.
packages/platform/platform-fastify/src/interfaces/PlatformFastifySettings.ts Added a new interface PlatformFastifySettings with a property app.
packages/platform/platform-fastify/src/interfaces/interfaces.ts Introduced new type definitions and extended the TsED namespace to include Fastify settings and plugins.
packages/platform/platform-fastify/src/services/PlatformFastifyRequest.spec.ts Created a test suite for the PlatformFastifyRequest class, validating its functionalities.
packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts Added the PlatformFastifyRequest class, extending PlatformRequest with Fastify-specific properties and methods.
packages/platform/platform-fastify/src/services/PlatformFastifyResponse.spec.ts Introduced a test suite for the PlatformFastifyResponse class, covering various response handling functionalities.
packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts Created the PlatformFastifyResponse class, enhancing response handling for Fastify.
packages/platform/platform-fastify/test/app/Server.ts Defined a Fastify server configuration with the Server class, including various plugins and settings.
packages/platform/platform-fastify/test/app/index.ts Set up a test application with a HelloWorld controller handling GET routes.
packages/platform/platform-fastify/test/app/public/index.html Added a simple HTML file with basic structure.
packages/platform/platform-fastify/test/app/views/view.ejs Updated the EJS template to dynamically display a greeting message.
packages/platform/platform-fastify/test/platform-fastify.spec.ts Introduced a test suite for the PlatformFastify integration, covering various aspects of its functionality.
packages/platform/platform-fastify/tsconfig.esm.json Added a new TypeScript configuration file for ESM, specifying compiler options and project structure.
packages/platform/platform-fastify/tsconfig.json Created a new TypeScript configuration file with references to other configurations.
packages/platform/platform-fastify/tsconfig.spec.json Introduced a TypeScript configuration for testing, including paths for module resolution.
packages/platform/platform-fastify/vitest.config.mts Added a Vitest configuration file with custom coverage thresholds.
packages/platform/platform-router/src/domain/PlatformHandlerMetadata.spec.ts Updated tests to include the new isRawMiddleware() method in the PlatformHandlerMetadata class.
packages/platform/platform-router/src/domain/PlatformHandlerMetadata.ts Added a public method isRawMiddleware to check if a handler is a raw middleware.
tsconfig.json Modified to include a reference to the platform-koa TypeScript configuration.

Possibly related PRs

  • Prepare fastify integration #2922: The changes in this PR focus on preparing the Fastify integration, which is directly related to the modifications made in the main PR that introduces the PlatformFastify class and its associated functionalities.

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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

@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: 38

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 55301a9 and 0c954dd.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (25)
  • packages/platform/platform-fastify/.npmignore (1 hunks)
  • packages/platform/platform-fastify/package.json (1 hunks)
  • packages/platform/platform-fastify/readme.md (1 hunks)
  • packages/platform/platform-fastify/src/components/PlatformFastify.spec.ts (1 hunks)
  • packages/platform/platform-fastify/src/components/PlatformFastify.ts (1 hunks)
  • packages/platform/platform-fastify/src/exports.ts (1 hunks)
  • packages/platform/platform-fastify/src/index.ts (1 hunks)
  • packages/platform/platform-fastify/src/interfaces/PlatformFastifySettings.ts (1 hunks)
  • packages/platform/platform-fastify/src/interfaces/interfaces.ts (1 hunks)
  • packages/platform/platform-fastify/src/services/PlatformFastifyRequest.spec.ts (1 hunks)
  • packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts (1 hunks)
  • packages/platform/platform-fastify/src/services/PlatformFastifyResponse.spec.ts (1 hunks)
  • packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts (1 hunks)
  • packages/platform/platform-fastify/test/app/Server.ts (1 hunks)
  • packages/platform/platform-fastify/test/app/index.ts (1 hunks)
  • packages/platform/platform-fastify/test/app/public/index.html (1 hunks)
  • packages/platform/platform-fastify/test/app/views/view.ejs (1 hunks)
  • packages/platform/platform-fastify/test/platform-fastify.spec.ts (1 hunks)
  • packages/platform/platform-fastify/tsconfig.esm.json (1 hunks)
  • packages/platform/platform-fastify/tsconfig.json (1 hunks)
  • packages/platform/platform-fastify/tsconfig.spec.json (1 hunks)
  • packages/platform/platform-fastify/vitest.config.mts (1 hunks)
  • packages/platform/platform-router/src/domain/PlatformHandlerMetadata.spec.ts (6 hunks)
  • packages/platform/platform-router/src/domain/PlatformHandlerMetadata.ts (1 hunks)
  • tsconfig.json (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/platform/platform-fastify/readme.md

[style] ~49-~49: Using many exclamation marks might seem excessive (in this case: 7 exclamation marks for a text that’s 2441 characters long)
Context: ...## Backers Thank you to all our backers! 🙏 [[Become a backer](https://opencolle...

(EN_EXCESSIVE_EXCLAMATION)


[typographical] ~61-~61: If you want to indicate numerical ranges or time ranges, consider using an en dash.
Context: ...he MIT License (MIT) Copyright (c) 2016 - 2018 Romain Lenzotti Permission is here...

(DASH_RULE)

🪛 Markdownlint (0.35.0)
packages/platform/platform-fastify/readme.md

1-1: Element: p
Inline HTML

(MD033, no-inline-html)


2-2: Element: a
Inline HTML

(MD033, no-inline-html)


2-2: Element: img
Inline HTML

(MD033, no-inline-html)


5-5: Element: div
Inline HTML

(MD033, no-inline-html)


6-6: Element: h1
Inline HTML

(MD033, no-inline-html)


19-19: Element: div
Inline HTML

(MD033, no-inline-html)


20-20: Element: a
Inline HTML

(MD033, no-inline-html)


21-21: Element: span
Inline HTML

(MD033, no-inline-html)


22-22: Element: a
Inline HTML

(MD033, no-inline-html)


23-23: Element: span
Inline HTML

(MD033, no-inline-html)


24-24: Element: a
Inline HTML

(MD033, no-inline-html)


25-25: Element: span
Inline HTML

(MD033, no-inline-html)


26-26: Element: a
Inline HTML

(MD033, no-inline-html)


29-29: Element: hr
Inline HTML

(MD033, no-inline-html)


45-45: Element: a
Inline HTML

(MD033, no-inline-html)


45-45: Element: img
Inline HTML

(MD033, no-inline-html)


51-51: Element: a
Inline HTML

(MD033, no-inline-html)


51-51: Element: img
Inline HTML

(MD033, no-inline-html)


31-31: null
Bare URL used

(MD034, no-bare-urls)


1-1: null
First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)


45-45: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


51-51: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

🪛 Biome (1.9.4)
packages/platform/platform-fastify/src/interfaces/interfaces.ts

[error] 7-7: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts

[error] 4-4: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)

packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts

[error] 3-3: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)

packages/platform/platform-fastify/src/components/PlatformFastify.ts

[error] 24-24: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)


[error] 158-158: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 114-114: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 121-121: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 130-130: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 314-314: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

🔇 Additional comments (14)
packages/platform/platform-fastify/tsconfig.esm.json (2)

1-2: LGTM! Good use of base configuration.

Extending from @tsed/typescript/tsconfig.node.json ensures consistent TypeScript settings across the monorepo and properly configures Node.js-specific settings.


12-25: Verify test helper exclusion and webpack configuration.

The include/exclude patterns look comprehensive, but let's verify two things:

  1. That no test helpers in src are accidentally included
  2. Whether webpack configuration should also exclude .ts variants
✅ Verification successful

Include/exclude patterns in tsconfig.esm.json are correctly configured

The verification shows:

  1. No test helpers were found in the src directory that might be accidentally included
  2. The webpack.config.js exclusion is sufficient as there's no webpack.config.ts in this package

The current configuration correctly excludes test files and build artifacts while including the necessary source files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential test helpers in src directory
echo "Checking for test helpers in src..."
fd -e ts -E "*.spec.ts" . "src" | grep -i "test\|mock\|stub\|fake"

# Check for webpack config variants
echo "Checking for webpack config variants..."
fd "webpack.config" . | grep -v "\.js$"

Length of output: 678


Script:

#!/bin/bash
# Adjust the path to check for test helpers in the correct package directory
echo "Checking for potential test helpers in platform-fastify src..."
fd -e ts -E "*.spec.ts" . "packages/platform/platform-fastify/src" | grep -i "test\|mock\|stub\|fake"

# Check webpack config in the specific package
echo "Checking webpack config in platform-fastify..."
fd "webpack.config" . "packages/platform/platform-fastify"

Length of output: 916

packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts (2)

53-57: ⚠️ Potential issue

Ensure accepts() method is available in Fastify

The this.raw.accepts() method may not be available by default in Fastify. You need to register the @fastify/accepts plugin to provide this functionality.

Run the following script to check if the @fastify/accepts plugin is registered:


45-47: 🧹 Nitpick (assertive)

Simplify header retrieval by using this.raw.headers

Instead of accessing headers via this.raw.raw.headers, you can directly use this.raw.headers, which provides the same header information and improves readability.

Apply this diff to simplify the method:

-return this.raw.raw.headers[name.toLowerCase()];
+return this.raw.headers[name.toLowerCase()];

Likely invalid or redundant comment.

packages/platform/platform-fastify/test/app/views/view.ejs (1)

1-1: LGTM! Template looks good.

The EJS template is properly structured and uses the correct syntax for variable interpolation. The built-in EJS escaping (<%=) provides protection against XSS attacks.

packages/platform/platform-fastify/src/exports.ts (1)

5-6: 🧹 Nitpick (assertive)

Verify platform adapter implementation.

While the adapter assignments are straightforward, it's important to ensure that PlatformFastify properly implements all required platform adapter interfaces.

Additionally, consider making the adapter assignment more explicit and type-safe:

-PlatformTest.adapter = PlatformFastify;
-PlatformBuilder.adapter = PlatformFastify;
+PlatformTest.setAdapter(PlatformFastify);
+PlatformBuilder.setAdapter(PlatformFastify);
✅ Verification successful

Let me generate another script to specifically look for the PlatformFastify class implementation and its inheritance/implementation details:

This will help us verify if PlatformFastify properly implements the required platform adapter interfaces.


Let me search for the base PlatformAdapter class to understand the inheritance structure:


Based on the gathered information, I can now provide the final response:

PlatformFastify correctly implements the platform adapter interface

The code inspection shows that PlatformFastify properly extends the abstract PlatformAdapter class from @tsed/platform-http, which defines the required platform adapter interface. The implementation includes:

  • Proper class inheritance: class PlatformFastify extends PlatformAdapter<FastifyInstance>
  • Required abstract property implementation: readonly NAME = "fastify"
  • Proper provider configuration through the providers property

The static assignments in exports.ts are therefore type-safe and valid.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify PlatformFastify implements required interfaces

# Check for required interface definitions
ast-grep --pattern 'interface $INTERFACE { $$$ }' | grep -i 'platform'

# Check PlatformFastify class implementation
ast-grep --pattern 'class PlatformFastify $EXTENDS implements $IMPLEMENTS { $$$ }'

Length of output: 38331


Script:

#!/bin/bash
# Search for PlatformFastify class definition and its related base classes/interfaces
rg -A 5 "class PlatformFastify" 

# Search for potential platform adapter interfaces
rg -A 3 "interface.*Platform.*Adapter"

Length of output: 1889


Script:

#!/bin/bash
# Search for PlatformAdapter class/interface definition
rg -A 10 "export (abstract )?class PlatformAdapter"

# Also check the imports in PlatformFastify
rg -A 5 "import.*PlatformAdapter"

Length of output: 7760

packages/platform/platform-fastify/src/index.ts (1)

4-9: Verify completeness of Fastify platform exports

The exports look organized, but let's ensure all essential Fastify platform components are covered.

✅ Verification successful

All essential Fastify platform components are properly exported

Based on the verification results:

  • All Fastify-related TypeScript files are properly exported through the barrel file
  • The exports cover all core components: Platform, Settings, Request, Response, and interfaces
  • The exports.ts file correctly sets up platform adapters
  • No Fastify-related components are missing from the exports
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if all essential Fastify components are exported and no files are missed

# Find all .ts files in the src directory
echo "=== TypeScript files in src ==="
fd -e ts . "packages/platform/platform-fastify/src"

# Check for any potential Fastify-related files that might be missing from exports
echo -e "\n=== Potential missing exports ==="
fd -e ts . "packages/platform/platform-fastify/src" -x grep -l "Fastify" {} \; | \
  grep -v -f <(echo -e "PlatformFastify.ts\nPlatformFastifySettings.ts\nPlatformFastifyRequest.ts\nPlatformFastifyResponse.ts")

Length of output: 1160


Script:

#!/bin/bash
# Let's verify the exports more thoroughly

# First, check the content of exports.ts
echo "=== Content of exports.ts ==="
cat "packages/platform/platform-fastify/src/exports.ts"

# Then check for any TypeScript files that contain Fastify-related code
echo -e "\n=== Files containing Fastify references ==="
rg -l "Fastify" "packages/platform/platform-fastify/src"

# Finally, let's check the actual exports from these files
echo -e "\n=== Exports in Fastify-related files ==="
rg "^export " "packages/platform/platform-fastify/src" --type ts

Length of output: 3090

packages/platform/platform-fastify/vitest.config.mts (2)

1-2: 🛠️ Refactor suggestion

Remove @ts-ignore and fix typing issues

Instead of using @ts-ignore, we should properly type the imports.

-// @ts-ignore
-import {presets} from "@tsed/vitest/presets";
+import type {presets} from "@tsed/vitest/presets";

Likely invalid or redundant comment.


9-18: Verify the feasibility of high coverage thresholds

The coverage thresholds are set very high and specific:

  • statements: 99.15%
  • branches: 95.6%
  • functions: 100%
  • lines: 99.15%

While high coverage is good, such specific thresholds might be hard to maintain.

✅ Verification successful

Let me gather more information about the test coverage by examining the actual test file and its contents.

The previous results show that there's a single test file and its corresponding implementation file. Let's analyze their contents to understand if the high coverage thresholds are justified based on the codebase complexity and test coverage.


Based on the analysis of both test and source files, I can now generate the final response:

High coverage thresholds are justified and maintainable

The high coverage thresholds are reasonable because:

  • The test suite is comprehensive, covering all major platform features (24 test suites)
  • The implementation is well-structured and uses a standardized adapter pattern
  • Non-testable features (stream, view, statics, multer) are properly skipped
  • The codebase follows a consistent pattern making it highly testable
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check current test coverage to verify if thresholds are realistic

# Find and analyze test files
echo "=== Test files coverage ==="
fd -e spec.ts -e test.ts . "packages/platform/platform-fastify/test"

# Check if all components have corresponding test files
echo -e "\n=== Components without test files ==="
for f in $(fd -e ts . "packages/platform/platform-fastify/src/components"); do
  base=$(basename $f .ts)
  if ! fd "${base}.spec.ts|${base}.test.ts" "packages/platform/platform-fastify/test" >/dev/null; then
    echo "Missing tests for: $f"
  fi
done

Length of output: 933


Script:

#!/bin/bash
# Check the content and complexity of the test file
echo "=== Test file content ==="
cat packages/platform/platform-fastify/test/platform-fastify.spec.ts

# Check the source file to understand what needs to be tested
echo -e "\n=== Source file content ==="
cat packages/platform/platform-fastify/src/components/PlatformFastify.ts

Length of output: 11726

packages/platform/platform-fastify/test/app/Server.ts (1)

21-32: Consider adding plugin version constraints

Plugin versions should be explicitly specified to prevent breaking changes.

packages/platform/platform-fastify/tsconfig.json (1)

7-7: Verify the empty include array configuration.

An empty include array might unintentionally exclude source files. Consider explicitly including source files:

-  "include": [],
+  "include": ["src/**/*.ts", "src/**/*.tsx"]
✅ Verification successful

Empty include array is correct for this TypeScript configuration

The empty include array in tsconfig.json is intentional and correct for this package because:

  1. The package uses src/index.ts as the source entry point, as defined in package.json
  2. The TypeScript files are properly organized under the src/ directory
  3. The build process is managed through the build:ts script using tsc --build tsconfig.json
  4. The package extends from a base configuration @tsed/typescript/tsconfig.node.json which likely contains the necessary include patterns
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any TypeScript files that might be excluded
fd -e ts -e tsx . src/

Length of output: 116


Script:

#!/bin/bash
# Let's first check the directory structure to understand where the TypeScript files are located
fd --type directory

# Then check for all TypeScript files in the repository
fd -e ts -e tsx

Length of output: 96052


Script:

#!/bin/bash
# Let's check if there are any TypeScript files in the platform-fastify directory
fd -e ts -e tsx . packages/platform/platform-fastify/

# Let's also check the package.json to understand the project structure
cat packages/platform/platform-fastify/package.json

Length of output: 3813

packages/platform/platform-fastify/test/platform-fastify.spec.ts (1)

6-10: Verify test coverage configuration

The test setup uses PlatformTestSdk with PlatformFastify adapter. Let's verify the test coverage settings.

✅ Verification successful

Test coverage thresholds are properly configured

The test coverage configuration is well-defined with high threshold requirements:

  • Statements: 99.15%
  • Branches: 95.6%
  • Functions: 100%
  • Lines: 99.15%

These are robust thresholds that ensure comprehensive test coverage for the platform-fastify package.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for coverage configuration
echo "Checking coverage configuration..."
rg "coverage|threshold" packages/platform/platform-fastify/vitest.config.mts

Length of output: 231


Script:

#!/bin/bash
# Let's check the actual coverage thresholds and configuration
cat packages/platform/platform-fastify/vitest.config.mts

Length of output: 456

packages/platform/platform-router/src/domain/PlatformHandlerMetadata.ts (1)

142-144: LGTM! Clean implementation of raw middleware check

The implementation correctly combines the injectable check with raw function type verification, following the existing pattern of handler type checks in the class.

packages/platform/platform-router/src/domain/PlatformHandlerMetadata.spec.ts (1)

37-37: LGTM! Comprehensive test coverage for isRawMiddleware()

The test coverage for the new isRawMiddleware() method is thorough and well-structured, covering all important scenarios:

  • Context handlers (false)
  • Raw functions (true)
  • Raw error functions (true)
  • Endpoint/middleware with injection (false)
  • Error middleware (false)

Also applies to: 54-54, 72-72, 91-91, 124-124, 152-152

Comment on lines +3 to +11
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "./lib/esm",
"declarationDir": "./lib/types",
"declaration": true,
"composite": true,
"noEmit": false
},
Copy link

@coderabbitai coderabbitai bot Dec 8, 2024

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding ESM-specific compiler options.

While the current configuration is good, consider adding these ESM-specific options for better module resolution and debugging support:

 {
   "compilerOptions": {
     "baseUrl": ".",
     "rootDir": "src",
     "outDir": "./lib/esm",
     "declarationDir": "./lib/types",
     "declaration": true,
     "composite": true,
-    "noEmit": false
+    "noEmit": false,
+    "moduleResolution": "node",
+    "sourceMap": true
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "./lib/esm",
"declarationDir": "./lib/types",
"declaration": true,
"composite": true,
"noEmit": false
},
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "./lib/esm",
"declarationDir": "./lib/types",
"declaration": true,
"composite": true,
"noEmit": false,
"moduleResolution": "node",
"sourceMap": true
},

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"@tsed/typescript/tsconfig.node.json" contient déjà ces options. est-ce que c'est nécessaire de les répéter ?

Copy link

Choose a reason for hiding this comment

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

@Romakita Vous avez tout à fait raison, les options "moduleResolution" et "sourceMap" sont déjà définies dans "@tsed/typescript/tsconfig.node.json". Il n'est donc pas nécessaire de les répéter dans "tsconfig.esm.json" à moins de vouloir les remplacer. Désolé pour la confusion.


✏️ Learnings added
Learnt from: Romakita
PR: tsedio/tsed#2925
File: packages/platform/platform-fastify/tsconfig.esm.json:3-11
Timestamp: 2024-12-10T17:46:27.526Z
Learning: Dans le projet Ts.ED, lorsqu'un fichier `tsconfig` comme `packages/platform/platform-fastify/tsconfig.esm.json` étend `"@tsed/typescript/tsconfig.node.json"`, il n'est pas nécessaire de répéter les options du compilateur telles que `"moduleResolution": "node"` et `"sourceMap": true`, car elles sont déjà incluses dans le fichier de configuration étendu.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

} from "@tsed/platform-http";
import {PlatformHandlerMetadata, PlatformHandlerType, PlatformLayer} from "@tsed/platform-router";
import Fastify, {FastifyInstance, FastifyReply, FastifyRequest} from "fastify";
import {IncomingMessage, ServerResponse} from "http";
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use 'node:' protocol when importing Node.js built-in modules

It's recommended to use the 'node:' protocol when importing Node.js built-in modules to make it explicit that the module belongs to Node.js.

Apply this diff to update the import statement:

-import {IncomingMessage, ServerResponse} from "http";
+import {IncomingMessage, ServerResponse} from "node:http";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import {IncomingMessage, ServerResponse} from "http";
import {IncomingMessage, ServerResponse} from "node:http";
🧰 Tools
🪛 Biome (1.9.4)

[error] 24-24: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)

Comment on lines +27 to +28
"Koa",
"TypeScript",
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Remove duplicate keyword "TypeScript"

The keywords array contains both "TypeScript" and "typescript" (case variants).

  "keywords": [
    "Koa",
    "TypeScript",
-   "typescript",
    "Decorator",

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +81 to +95
"peerDependencies": {
"@fastify/accepts": ">=4.3.0",
"@fastify/cookie": ">=9.3.1",
"@fastify/formbody": ">=7.4.0",
"@fastify/session": ">=10.7.0",
"@tsed/core": ">=8.0.0",
"@tsed/di": ">=8.0.0",
"@tsed/json-mapper": ">=8.0.0",
"@tsed/logger": ">=7.0.0",
"@tsed/openspec": ">=8.0.0",
"@tsed/platform-http": ">=8.0.0",
"@tsed/schema": ">=8.0.0",
"fastify": ">=5.1.0",
"fastify-raw-body": ">=5.0.0"
},
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding version upper bounds to peer dependencies

The current peer dependencies use >= which might lead to compatibility issues with future major versions. Consider using caret ranges (^) for better semver compatibility.

  "peerDependencies": {
-   "@fastify/accepts": ">=4.3.0",
+   "@fastify/accepts": "^4.3.0 || ^5.0.0",
-   "@fastify/cookie": ">=9.3.1",
+   "@fastify/cookie": "^9.3.1 || ^10.0.0 || ^11.0.0",
    // ... apply similar pattern to other dependencies

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +37 to +39
```bash
npm install --save @tsed/platform-fastify fastify
```
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Enhance installation instructions

The installation section could be more comprehensive by including peer dependencies and configuration examples.

Consider adding:

  1. Optional dependencies installation
  2. Basic configuration example
  3. Common usage patterns


The MIT License (MIT)

Copyright (c) 2016 - 2018 Romain Lenzotti
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Update copyright year range

The copyright year range (2016 - 2018) appears outdated for this new package.

- Copyright (c) 2016 - 2018 Romain Lenzotti
+ Copyright (c) 2016 - 2024 Romain Lenzotti
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Copyright (c) 2016 - 2018 Romain Lenzotti
Copyright (c) 2016 - 2024 Romain Lenzotti
🧰 Tools
🪛 LanguageTool

[typographical] ~61-~61: If you want to indicate numerical ranges or time ranges, consider using an en dash.
Context: ...he MIT License (MIT) Copyright (c) 2016 - 2018 Romain Lenzotti Permission is here...

(DASH_RULE)

Comment on lines +101 to +103
{
"path": "./packages/platform/platform-koa/tsconfig.json"
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate platform-koa reference and add platform-fastify

There are two issues with the TypeScript project references:

  1. The platform-koa reference appears twice (here and at line 148)
  2. The platform-fastify reference is missing, which should be added as part of this PR

Please apply these changes:

  1. Remove this duplicate entry
  2. Add the platform-fastify reference:
-    {
-      "path": "./packages/platform/platform-koa/tsconfig.json"
-    },
+    {
+      "path": "./packages/platform/platform-fastify/tsconfig.json"
+    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"path": "./packages/platform/platform-koa/tsconfig.json"
},
{
"path": "./packages/platform/platform-fastify/tsconfig.json"
},

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 0c954dd and 786b751.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (27)
  • packages/platform/platform-fastify/.npmignore (1 hunks)
  • packages/platform/platform-fastify/package.json (1 hunks)
  • packages/platform/platform-fastify/readme.md (1 hunks)
  • packages/platform/platform-fastify/src/components/PlatformFastify.spec.ts (1 hunks)
  • packages/platform/platform-fastify/src/components/PlatformFastify.ts (1 hunks)
  • packages/platform/platform-fastify/src/exports.ts (1 hunks)
  • packages/platform/platform-fastify/src/index.ts (1 hunks)
  • packages/platform/platform-fastify/src/interfaces/PlatformFastifySettings.ts (1 hunks)
  • packages/platform/platform-fastify/src/interfaces/interfaces.ts (1 hunks)
  • packages/platform/platform-fastify/src/services/PlatformFastifyRequest.spec.ts (1 hunks)
  • packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts (1 hunks)
  • packages/platform/platform-fastify/src/services/PlatformFastifyResponse.spec.ts (1 hunks)
  • packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts (1 hunks)
  • packages/platform/platform-fastify/test/app/Server.ts (1 hunks)
  • packages/platform/platform-fastify/test/app/index.ts (1 hunks)
  • packages/platform/platform-fastify/test/app/public/index.html (1 hunks)
  • packages/platform/platform-fastify/test/app/views/view.ejs (1 hunks)
  • packages/platform/platform-fastify/test/platform-fastify.spec.ts (1 hunks)
  • packages/platform/platform-fastify/tsconfig.esm.json (1 hunks)
  • packages/platform/platform-fastify/tsconfig.json (1 hunks)
  • packages/platform/platform-fastify/tsconfig.spec.json (1 hunks)
  • packages/platform/platform-fastify/vitest.config.mts (1 hunks)
  • packages/platform/platform-http/src/common/decorators/params/request.spec.ts (1 hunks)
  • packages/platform/platform-http/src/common/decorators/params/request.ts (1 hunks)
  • packages/platform/platform-router/src/domain/PlatformHandlerMetadata.spec.ts (6 hunks)
  • packages/platform/platform-router/src/domain/PlatformHandlerMetadata.ts (1 hunks)
  • tsconfig.json (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/platform/platform-fastify/tsconfig.esm.json (1)
Learnt from: Romakita
PR: tsedio/tsed#2925
File: packages/platform/platform-fastify/tsconfig.esm.json:3-11
Timestamp: 2024-12-10T17:46:27.733Z
Learning: Dans le projet Ts.ED, lorsqu'un fichier `tsconfig` comme `packages/platform/platform-fastify/tsconfig.esm.json` étend `"@tsed/typescript/tsconfig.node.json"`, il n'est pas nécessaire de répéter les options du compilateur telles que `"moduleResolution": "node"` et `"sourceMap": true`, car elles sont déjà incluses dans le fichier de configuration étendu.
🪛 LanguageTool
packages/platform/platform-fastify/readme.md

[style] ~49-~49: Using many exclamation marks might seem excessive (in this case: 7 exclamation marks for a text that’s 2441 characters long)
Context: ...## Backers Thank you to all our backers! 🙏 [[Become a backer](https://opencolle...

(EN_EXCESSIVE_EXCLAMATION)


[typographical] ~61-~61: If you want to indicate numerical ranges or time ranges, consider using an en dash.
Context: ...he MIT License (MIT) Copyright (c) 2016 - 2018 Romain Lenzotti Permission is here...

(DASH_RULE)

🪛 Markdownlint (0.35.0)
packages/platform/platform-fastify/readme.md

1-1: Element: p
Inline HTML

(MD033, no-inline-html)


2-2: Element: a
Inline HTML

(MD033, no-inline-html)


2-2: Element: img
Inline HTML

(MD033, no-inline-html)


5-5: Element: div
Inline HTML

(MD033, no-inline-html)


6-6: Element: h1
Inline HTML

(MD033, no-inline-html)


19-19: Element: div
Inline HTML

(MD033, no-inline-html)


20-20: Element: a
Inline HTML

(MD033, no-inline-html)


21-21: Element: span
Inline HTML

(MD033, no-inline-html)


22-22: Element: a
Inline HTML

(MD033, no-inline-html)


23-23: Element: span
Inline HTML

(MD033, no-inline-html)


24-24: Element: a
Inline HTML

(MD033, no-inline-html)


25-25: Element: span
Inline HTML

(MD033, no-inline-html)


26-26: Element: a
Inline HTML

(MD033, no-inline-html)


29-29: Element: hr
Inline HTML

(MD033, no-inline-html)


45-45: Element: a
Inline HTML

(MD033, no-inline-html)


45-45: Element: img
Inline HTML

(MD033, no-inline-html)


51-51: Element: a
Inline HTML

(MD033, no-inline-html)


51-51: Element: img
Inline HTML

(MD033, no-inline-html)


31-31: null
Bare URL used

(MD034, no-bare-urls)


1-1: null
First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)


45-45: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


51-51: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

🪛 Biome (1.9.4)
packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts

[error] 4-4: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)

packages/platform/platform-fastify/src/components/PlatformFastify.ts

[error] 24-24: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)


[error] 172-172: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 329-329: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

🔇 Additional comments (41)
packages/platform/platform-fastify/tsconfig.esm.json (2)

1-2: LGTM! Proper base configuration.

The configuration correctly extends from @tsed/typescript/tsconfig.node.json, which provides the base TypeScript settings for Node.js projects.


3-11: LGTM! Well-structured compiler options.

The compiler options are properly configured for:

  • ESM output structure (lib/esm and lib/types)
  • Project references (composite project)
  • Type declarations
  • Module resolution
packages/platform/platform-fastify/tsconfig.spec.json (1)

9-30: Consider removing unused module path mappings

Several mapped modules appear to be unused in the test or source files. Consider cleaning up unused mappings to improve maintainability and compilation performance.

Let's verify the current module usage:

#!/bin/bash
# Description: Analyze module usage in test and source files

echo "Analyzing imports in test and source files..."
# Get all TypeScript files
fd -e ts -E "*.d.ts" . packages/platform/platform-fastify/src packages/platform/platform-fastify/test | while read -r file; do
  echo "=== Analyzing $file ==="
  # Extract all imports
  ast-grep --pattern 'import { $$$ } from "$_"' "$file"
  ast-grep --pattern 'import $_' "$file"
done

echo "Checking dynamic imports..."
rg "import\(" -t ts packages/platform/platform-fastify/src packages/platform/platform-fastify/test
packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts (1)

1-59: Code changes look good

The implementation of PlatformFastifyRequest aligns with the expected integration with Fastify. The methods correctly extend and customize the base PlatformRequest functionalities for the Fastify environment.

packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts (1)

4-4: 🧹 Nitpick (assertive)

Use 'node:' protocol when importing Node.js built-in modules

It's recommended to use the 'node:' protocol when importing Node.js built-in modules to explicitly indicate that the module is a built-in Node.js module.

Apply this diff to update the import statement:

-import type {ServerResponse} from "http";
+import type {ServerResponse} from "node:http";
🧰 Tools
🪛 Biome (1.9.4)

[error] 4-4: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)

packages/platform/platform-fastify/src/components/PlatformFastify.ts (2)

24-24: 🧹 Nitpick (assertive)

Use 'node:' protocol when importing Node.js built-in modules

It's recommended to use the 'node:' protocol when importing Node.js built-in modules to explicitly indicate that the module is a built-in Node.js module.

Apply this diff to update the import statement:

-import {IncomingMessage, ServerResponse} from "http";
+import {IncomingMessage, ServerResponse} from "node:http";
🧰 Tools
🪛 Biome (1.9.4)

[error] 24-24: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)


329-329: 🧹 Nitpick (assertive)

Avoid reassigning function parameters

Reassigning a function parameter can lead to confusion and potential bugs. Instead, assign the new value to a new variable to improve code clarity and maintainability.

Apply this diff to avoid reassigning the parameter:

-plugin = {env, use: plugin};
+const resolvedPlugin = {env, use: plugin};

Ensure that subsequent references to plugin are updated to resolvedPlugin.

🧰 Tools
🪛 Biome (1.9.4)

[error] 329-329: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

packages/platform/platform-fastify/test/app/public/index.html (1)

1-5: Enhance HTML structure with proper declarations

The HTML file is missing essential structural elements including DOCTYPE declaration, language attribute, head section, and meta tags.

packages/platform/platform-fastify/.npmignore (1)

1-7: Consider adding more common ignore patterns

The current patterns are good but could be enhanced with additional common patterns.

packages/platform/platform-fastify/src/exports.ts (1)

1-6: LGTM! Clean platform adapter setup

The code correctly sets up the Fastify platform adapter for both testing and building purposes. The implementation is clean and follows the expected pattern.

packages/platform/platform-fastify/src/index.ts (1)

1-9: LGTM! Verify all exported modules

The barrel exports are well-structured and include all necessary platform components. Let's verify that all exported modules exist.

✅ Verification successful

Let me verify the exports.js file which is also mentioned in the barrel file but wasn't included in our first search.


All exported modules verified successfully

All modules referenced in the barrel file exist in their expected locations:

  • components/PlatformFastify.ts
  • exports.ts
  • interfaces/interfaces.ts
  • interfaces/PlatformFastifySettings.ts
  • services/PlatformFastifyRequest.ts
  • services/PlatformFastifyResponse.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all exported modules exist
# Note: Using fd to find files as paths are relative to repo root

echo "Checking for exported modules..."
fd -e ts -e js "PlatformFastify.ts$|interfaces.ts$|PlatformFastifySettings.ts$|PlatformFastifyRequest.ts$|PlatformFastifyResponse.ts$" packages/platform/platform-fastify/src/

Length of output: 610


Script:

#!/bin/bash
# Check if exports.js/ts exists
fd -e ts -e js "^exports\." packages/platform/platform-fastify/src/

Length of output: 119

packages/platform/platform-fastify/src/interfaces/PlatformFastifySettings.ts (2)

1-1: Remove unused import comment

The commented import for Koa router options should be removed as it's not being used.


5-16: 🧹 Nitpick (assertive)

Add JSDoc documentation to enhance code clarity

The interface would benefit from proper documentation to explain its purpose and usage.

+/**
+ * Settings for the Fastify platform integration
+ * @interface PlatformFastifySettings
+ */
 export interface PlatformFastifySettings {
+  /**
+   * Optional Fastify instance for custom configuration
+   * @type {FastifyInstance}
+   */
   app?: FastifyInstance;
 }

Likely invalid or redundant comment.

packages/platform/platform-fastify/vitest.config.mts (2)

1-1: ⚠️ Potential issue

Remove @ts-ignore and fix the type error properly.

Using @ts-ignore masks potential type issues. Please investigate and fix the underlying type error.

Let's check if there are other instances of @ts-ignore:


12-17: Verify the feasibility of high coverage thresholds.

The coverage thresholds are set quite high:

  • Statements: 99.15%
  • Branches: 95.6%
  • Functions: 100%
  • Lines: 99.15%

While high coverage is excellent for quality, let's verify if these thresholds align with the current test coverage.

✅ Verification successful

Since the previous attempt didn't find any coverage files, let's try a different approach to verify the test coverage. We'll check if there are any test files and their content to assess the feasibility of achieving such high coverage thresholds.


Based on the examination of the test files and source code, I can now provide a final response about the coverage thresholds:

The high coverage thresholds are feasible and justified

The codebase demonstrates comprehensive test coverage with:

  • Extensive unit tests for core components (PlatformFastify, PlatformFastifyRequest, PlatformFastifyResponse)
  • Thorough integration tests covering all major platform features
  • Well-structured test cases that cover edge cases and error scenarios
  • Small, focused codebase with clear responsibilities

The high thresholds are supported by:

  • Complete test coverage of all public methods
  • Extensive test scenarios in platform-fastify.spec.ts
  • Proper mocking and isolation in unit tests
  • Clear separation of concerns making the code highly testable
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check current test coverage in the platform-fastify package
fd "coverage-final.json" --exec cat {} | jq '.total'

Length of output: 52


Script:

#!/bin/bash
# Let's try running the tests to generate coverage
cd packages/platform/platform-fastify && npm run test:coverage

Length of output: 401


Script:

#!/bin/bash
# Find test files in the platform-fastify package
fd ".(test|spec).(ts|js|mts|mjs)" packages/platform/platform-fastify

# Count the number of source files to compare with test files
fd ".(ts|js|mts|mjs)$" packages/platform/platform-fastify --exclude ".(test|spec).(ts|js|mts|mjs)$"

Length of output: 1549


Script:

#!/bin/bash
# Let's examine the test files content to assess their coverage
for file in $(fd ".(test|spec).ts" packages/platform/platform-fastify); do
  echo "=== $file ==="
  cat "$file" | grep -E "describe|it\s*\(|test\s*\("
done

# Let's also check the source files to understand their complexity
for file in $(fd ".ts$" packages/platform/platform-fastify --exclude ".(test|spec).ts$" --exclude "interfaces"); do
  echo "=== $file ==="
  cat "$file"
done

Length of output: 31463

packages/platform/platform-fastify/test/app/Server.ts (1)

10-10: Consider making port configurable via environment variables

Hardcoding the port number limits flexibility across different environments.

packages/platform/platform-fastify/test/app/index.ts (2)

32-35: Remove redundant error logging.

The error is being logged twice using both console.error and $log.error.


14-18: 🛠️ Refactor suggestion

Add request parameter validation and error handling.

The route handler should validate the id parameter and return appropriate error responses. Consider using class-validator or a similar validation library.

    @Get("/:id")
+   @Returns(400).Description("Invalid ID provided")
+   @Returns(200).Description("Success")
    getById(@PathParams("id") id: string) {
+     if (!id?.trim()) {
+       throw new BadRequest("Invalid ID provided");
+     }
      return {test: "Hello world", id};
    }

Likely invalid or redundant comment.

packages/platform/platform-fastify/src/components/PlatformFastify.spec.ts (3)

13-19: Enhance test coverage with additional test cases.

The current test only covers the basic happy path. Consider adding:

  1. Test with custom configuration options
  2. Error scenarios (e.g., invalid Server class)
  3. Edge cases with different platform settings

26-32: 🛠️ Refactor suggestion

Improve test description and add async error handling.

The test description "should create platform" is too generic and the async error handling could be improved.

-    it("should create platform", async () => {
+    it("should bootstrap platform with default configuration", async () => {
       try {
         await PlatformFastify.bootstrap(Server, {});
         
         expect(PlatformBuilder.bootstrap).toHaveBeenCalledWith(Server, {
           adapter: PlatformFastify
         });
+      } catch (error) {
+        fail("Bootstrap should not throw an error");
+      }
     });

Likely invalid or redundant comment.


5-5: 🧹 Nitpick (assertive)

Consider using a more realistic test class.

The Server class is empty and might not represent real-world scenarios accurately. Consider adding minimal required methods/properties to better test platform integration.

-class Server {}
+class Server {
+  // Minimum required setup for a Fastify server
+  configure() {}
+  $beforeRoutesInit() {}
+  $afterRoutesInit() {}
+}

Likely invalid or redundant comment.

packages/platform/platform-fastify/src/services/PlatformFastifyRequest.spec.ts (4)

6-16: Extract test utility to a shared location.

The createRequest helper could be useful across multiple test files.


28-35: Enhance secure protocol testing.

The secure protocol test could be more comprehensive.


37-45: Add edge cases for host testing.

The host testing could be more robust.


47-54: Enhance getReq() test coverage.

The getReq() test could be more comprehensive.

packages/platform/platform-http/src/common/decorators/params/request.spec.ts (1)

1-1: LGTM! Using Node.js prefixed imports.

The change to use node:http instead of http follows Node.js best practices for built-in modules. This helps distinguish built-in modules from third-party ones and ensures consistent resolution.

packages/platform/platform-http/src/common/decorators/params/request.ts (1)

1-1: LGTM! Consistent with spec file changes.

The update to use node:http maintains consistency with the corresponding spec file and follows Node.js best practices.

packages/platform/platform-fastify/test/platform-fastify.spec.ts (3)

6-10: LGTM! Well-structured test initialization.

The test setup properly initializes the PlatformTestSdk with the necessary configuration for Fastify integration.


26-28: Document rationale for skipped tests

Several test suites are skipped with the comment "untestable with Fastify". Consider:

  1. Adding detailed comments explaining why these features are untestable
  2. Creating issues to track these limitations
  3. Documenting these limitations in the README

This will help maintainers understand the platform's limitations and potentially find solutions in future versions.

Would you like me to help create GitHub issues to track these limitations?

Also applies to: 85-96


12-99: LGTM! Comprehensive test coverage.

The test suite provides thorough coverage of the Fastify platform integration, including:

  • Core functionality (handlers, controllers, responses)
  • Parameter handling (headers, path, query, body)
  • Session and cookie management
  • Error handling and response filters
  • Authentication and routing
packages/platform/platform-fastify/src/services/PlatformFastifyResponse.spec.ts (3)

5-19: Consider extracting test helper to a shared location

The createResponse helper function could be useful for other test files.


21-68: Add tests for error handling scenarios

The test suite should include additional scenarios for error handling.


78-113: Add security tests for URL handling

The location header tests should include security-related scenarios.

packages/platform/platform-fastify/package.json (3)

60-64: Pin dependency versions for better stability

Using >= for dependencies can lead to unexpected behavior.


81-95: Consider adding version upper bounds to peer dependencies

The current peer dependencies use >= which might lead to compatibility issues.


27-47: 🧹 Nitpick (assertive)

Clean up keywords and add missing metadata

  1. Remove duplicate typescript-related keywords
  2. Consider adding engines field to specify Node.js version requirements
  "keywords": [
    "Koa",
    "TypeScript",
-   "typescript",
    "Decorator",
    // ...
  ],
+  "engines": {
+    "node": ">=16.0.0"
+  },

Likely invalid or redundant comment.

packages/platform/platform-fastify/readme.md (2)

33-39: Enhance installation instructions

The installation section could be more comprehensive.


61-61: Update copyright year range

The copyright year range (2016 - 2018) appears outdated for this new package.

🧰 Tools
🪛 LanguageTool

[typographical] ~61-~61: If you want to indicate numerical ranges or time ranges, consider using an en dash.
Context: ...he MIT License (MIT) Copyright (c) 2016 - 2018 Romain Lenzotti Permission is here...

(DASH_RULE)

packages/platform/platform-router/src/domain/PlatformHandlerMetadata.ts (1)

142-144: LGTM: Well-implemented middleware type check

The implementation correctly combines injectability check with handler type verification to identify raw middleware handlers. The method follows the established patterns in the class and has a clear, single responsibility.

packages/platform/platform-router/src/domain/PlatformHandlerMetadata.spec.ts (1)

37-37: LGTM: Comprehensive test coverage for isRawMiddleware()

The tests thoroughly verify the behavior of isRawMiddleware() across all relevant scenarios:

  • Context handlers (false)
  • Raw functions (true)
  • Raw error functions (true)
  • Endpoint handlers (false)
  • Middleware with injection (false)

Also applies to: 54-54, 72-72, 91-91, 124-124, 152-152

tsconfig.json (1)

101-103: ⚠️ Potential issue

Remove duplicate platform-koa reference and add platform-fastify

This issue was previously identified. The platform-koa reference appears twice, and the platform-fastify reference is missing.

Apply these changes:

-    {
-      "path": "./packages/platform/platform-koa/tsconfig.json"
-    },
+    {
+      "path": "./packages/platform/platform-fastify/tsconfig.json"
+    },

Comment on lines +13 to +25
"exclude": [
"node_modules",
"test",
"lib",
"benchmark",
"coverage",
"spec",
"**/*.benchmark.ts",
"**/*.spec.ts",
"keys",
"**/__mock__/**",
"webpack.config.js"
]
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding more common test and development file patterns.

The exclude patterns are good but could be more comprehensive. Consider adding these common patterns:

  "exclude": [
    "node_modules",
    "test",
    "lib",
    "benchmark",
    "coverage",
    "spec",
    "**/*.benchmark.ts",
    "**/*.spec.ts",
+   "**/*.test.ts",
+   "**/__tests__/**",
+   "**/*.stories.ts",
+   "**/*.config.ts",
    "keys",
    "**/__mock__/**",
    "webpack.config.js"
  ]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"exclude": [
"node_modules",
"test",
"lib",
"benchmark",
"coverage",
"spec",
"**/*.benchmark.ts",
"**/*.spec.ts",
"keys",
"**/__mock__/**",
"webpack.config.js"
]
"exclude": [
"node_modules",
"test",
"lib",
"benchmark",
"coverage",
"spec",
"**/*.benchmark.ts",
"**/*.spec.ts",
"**/*.test.ts",
"**/__tests__/**",
"**/*.stories.ts",
"**/*.config.ts",
"keys",
"**/__mock__/**",
"webpack.config.js"
]

Comment on lines +31 to +34
"types": ["vite/client", "vitest/globals"]
},
"include": ["src/**/*.spec.ts", "test/**/*.spec.ts", "vitest.config.mts"],
"exclude": ["node_modules", "lib", "benchmark", "coverage"]
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider expanding test file patterns

The current include patterns might miss some test-related files. Consider adding patterns for test helpers and utilities.

  "types": ["vite/client", "vitest/globals"],
  "include": [
    "src/**/*.spec.ts",
    "test/**/*.spec.ts",
+   "test/**/*.helper.ts",
+   "test/**/*.fixtures.ts",
+   "test/**/*.utils.ts",
    "vitest.config.mts"
  ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"types": ["vite/client", "vitest/globals"]
},
"include": ["src/**/*.spec.ts", "test/**/*.spec.ts", "vitest.config.mts"],
"exclude": ["node_modules", "lib", "benchmark", "coverage"]
"types": ["vite/client", "vitest/globals"],
"include": [
"src/**/*.spec.ts",
"test/**/*.spec.ts",
"test/**/*.helper.ts",
"test/**/*.fixtures.ts",
"test/**/*.utils.ts",
"vitest.config.mts"
],
"exclude": ["node_modules", "lib", "benchmark", "coverage"]

Comment on lines +4 to +5
"baseUrl": ".",
"rootDir": "../..",
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider using an absolute path for rootDir

The relative path "../.." in rootDir might cause issues if the project structure changes. Consider using an absolute path or a path relative to the project root to make the configuration more robust.

  "compilerOptions": {
    "baseUrl": ".",
-   "rootDir": "../..",
+   "rootDir": "${workspaceRoot}",

Committable suggestion skipped: line range outside the PR's diff.


export * from "./PlatformFastifySettings.js";

export type PlatformFastifyPluginTypes = ((opts?: any) => any) | /*Type<any> |*/ string;
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Improve type safety by specifying concrete types

The use of any in the function signature reduces type safety. Consider specifying more precise types for opts and the return value to enhance code reliability and maintainability.

use: PlatformFastifyPluginTypes;
options?: FastifyRegisterOptions<FastifyPluginOptions>;
};
export type PlatformFastifyPluginSettings = PlatformFastifyPluginTypes | PlatformFastifyPluginLoadingOptions | any;
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Avoid using any in union types

Including any in a union type negates the benefits of strong typing provided by the other types. It's advisable to remove any and define more specific types to improve type safety.

Comment on lines +8 to +57
"references": [
{
"path": "../../third-parties/components-scan/tsconfig.json"
},
{
"path": "../../engines/tsconfig.json"
},
{
"path": "../../core/tsconfig.json"
},
{
"path": "../../di/tsconfig.json"
},
{
"path": "../../specs/exceptions/tsconfig.json"
},
{
"path": "../../specs/json-mapper/tsconfig.json"
},
{
"path": "../platform-exceptions/tsconfig.json"
},
{
"path": "../platform-log-middleware/tsconfig.json"
},
{
"path": "../platform-middlewares/tsconfig.json"
},
{
"path": "../platform-params/tsconfig.json"
},
{
"path": "../platform-response-filter/tsconfig.json"
},
{
"path": "../platform-router/tsconfig.json"
},
{
"path": "../platform-views/tsconfig.json"
},
{
"path": "../../specs/schema/tsconfig.json"
},
{
"path": "./tsconfig.esm.json"
},
{
"path": "./tsconfig.spec.json"
}
]
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider optimizing project references.

The large number of project references might impact build time. Consider:

  1. Grouping related references into workspace projects
  2. Using path aliases for frequently referenced modules

"baseUrl": ".",
"noEmit": true
},
"include": [],
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Specify source files in the include array.

An empty include array might unintentionally exclude source files. Consider adding source paths:

-  "include": [],
+  "include": ["src/**/*.ts", "test/**/*.ts"],

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +18 to +21
describe("PlatformFastifyRequest", () => {
beforeEach(() => PlatformTest.create());
afterEach(() => PlatformTest.reset());

Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider using more specific test lifecycle hooks.

The current setup/teardown is very broad. Consider using more specific hooks:

-  beforeEach(() => PlatformTest.create());
-  afterEach(() => PlatformTest.reset());
+  beforeEach(async () => {
+    await PlatformTest.create({
+      platform: PlatformFastifyRequest
+    });
+  });
+  afterEach(async () => {
+    await PlatformTest.reset();
+    jest.clearAllMocks();
+  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe("PlatformFastifyRequest", () => {
beforeEach(() => PlatformTest.create());
afterEach(() => PlatformTest.reset());
describe("PlatformFastifyRequest", () => {
beforeEach(async () => {
await PlatformTest.create({
platform: PlatformFastifyRequest
});
});
afterEach(async () => {
await PlatformTest.reset();
jest.clearAllMocks();
});

Comment on lines +69 to +77
describe("stream()", () => {
it("should set body", () => {
const {res, response} = createResponse();

response.stream("body");

expect(res.data).toEqual("body");
});
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add stream-specific error scenarios

The stream test cases should include:

  1. Error handling for stream failures
  2. Memory constraints scenarios
  3. Invalid stream input cases

Example test case:

it("should handle stream errors", async () => {
  const { response } = createResponse();
  const errorStream = new Readable({
    read() {
      this.emit('error', new Error('Stream failed'));
    }
  });
  
  await expect(response.stream(errorStream)).rejects.toThrow('Stream failed');
});

Comment on lines +31 to +32
A package of Ts.ED framework. See website: https://tsed.io/getting-started/

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add configuration examples section

Add a new section with:

  1. Basic configuration example
  2. Common use cases
  3. Integration with existing Ts.ED applications

Example content to add:

## Configuration

```typescript
import {Configuration} from "@tsed/common";
import "@tsed/platform-fastify"; // import fastify platform

@Configuration({
  platform: "fastify",
  fastify: {
    // your fastify options
  }
})
export class Server {
}
🧰 Tools
🪛 Markdownlint (0.35.0)

31-31: null
Bare URL used

(MD034, no-bare-urls)

@Romakita Romakita force-pushed the production branch 2 times, most recently from de8df3b to 474e2d8 Compare December 17, 2024 19:04
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.

1 participant