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 5 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/platform/platform-fastify/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test
coverage
tsconfig.json
tsconfig.*.json
__mock__
*.spec.js
*.tsbuildinfo
Comment on lines +1 to +7
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Based on the files found in the package and parent directories, I can now generate the final response:

Add source files and IDE patterns to .npmignore

The current .npmignore should be extended to include:

  • Source TypeScript files since the package should only publish compiled JavaScript
  • IDE configuration files
  • View templates and static files from test directory

Add these patterns:

  • src/
  • .idea
  • .vscode
  • *.ts
  • !*.d.ts
  • test/app/views/
  • test/app/public/
  • vitest.config.mts
🔗 Analysis chain

Verify completeness of ignore patterns

Let's check if there are any additional file types in the codebase that should be ignored.


Let me try another search strategy to find potential files that should be ignored.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find potential files that should be ignored

# Look for common development files/folders that might need to be ignored
echo "Checking for additional file patterns that might need ignoring..."
fd -H -t f ".(git|vscode|idea)" packages/platform/platform-fastify/
fd -t f ".(map|log|env|cache)" packages/platform/platform-fastify/
fd -t d "(logs|temp|cache|build)" packages/platform/platform-fastify/

Length of output: 351


Script:

#!/bin/bash
# Let's check the actual source files in the package to identify patterns
echo "Files in platform-fastify package:"
fd . packages/platform/platform-fastify/ -t f

# Also check if there are any source maps or IDE configs in parent directories
# that might influence what we should ignore
echo -e "\nRelevant files in parent directories:"
fd -t f ".(map|js.map|d.ts.map|vscode|idea|git)" packages/platform/

Length of output: 1818

21 changes: 21 additions & 0 deletions packages/platform/platform-fastify/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"sourceMaps": false,
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"target": "es2022",
"externalHelpers": true,
"keepClassNames": true,
"transform": {
"useDefineForClassFields": false,
"legacyDecorator": true,
"decoratorMetadata": true
}
},
"module": {
"type": "es6"
}
}
121 changes: 121 additions & 0 deletions packages/platform/platform-fastify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"name": "@tsed/platform-fastify",
"type": "module",
"version": "8.2.0",
"description": "Fastify package for Ts.ED framework",
"source": "./src/index.ts",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",
"typings": "./lib/types/index.d.ts",
"exports": {
".": {
"@tsed/source": "./src/index.ts",
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.js",
"default": "./lib/esm/index.js"
}
},
"scripts": {
"build": "yarn barrels && yarn build:ts",
"barrels": "barrels",
"start": "node --import @swc-node/register/esm-register test/app/index.ts",
"test": "vitest run -u",
"build:ts": "tsc --build tsconfig.json",
"test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
},
"keywords": [
"Koa",
"TypeScript",
Comment on lines +27 to +28
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.

"typescript",
"Decorator",
"decorators",
"decorator",
"fastify",
"Controller",
"Inject",
"ioc",
"di",
"mvc",
"swagger",
"swagger ui",
"ES2015",
"ES6",
"server",
"rest",
"api",
"validation"
],
"author": {
"name": "Romain Lenzotti"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/tsedio/tsed/issues"
},
"homepage": "http://tsed.dev/",
"repository": {
"type": "git",
"url": "git+https://github.com/tsedio/tsed.git"
},
"dependencies": {
"@fastify/middie": ">=9.0.2",
"content-disposition": ">=0.5.4",
"tslib": "2.6.1"
},
Comment on lines +60 to +64
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Pin dependency versions for better stability

Using >= for dependencies can lead to unexpected behavior. Consider using exact versions or caret ranges.

  "dependencies": {
-   "@fastify/middie": ">=9.0.2",
+   "@fastify/middie": "^9.0.2",
-   "content-disposition": ">=0.5.4",
+   "content-disposition": "^0.5.4",
    "tslib": "2.6.1"
📝 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
"dependencies": {
"@fastify/middie": ">=9.0.2",
"content-disposition": ">=0.5.4",
"tslib": "2.6.1"
},
"dependencies": {
"@fastify/middie": "^9.0.2",
"content-disposition": "^0.5.4",
"tslib": "2.6.1"
},

"devDependencies": {
"@fastify/accepts": "5.0.2",
"@fastify/cookie": "11.0.1",
"@fastify/formbody": "8.0.1",
"@fastify/session": "11.0.1",
"@tsed/barrels": "workspace:*",
"@tsed/core": "workspace:*",
"@tsed/di": "workspace:*",
"@tsed/platform-http": "workspace:*",
"@tsed/platform-test-sdk": "workspace:*",
"@types/content-disposition": "^0.5.4",
"cross-env": "7.0.3",
"fastify": "5.1.0",
"fastify-raw-body": "5.0.0",
"ts-node": "10.9.2"
},
"peerDependencies": {
"@fastify/accepts": ">=4.3.0",
"@fastify/cookie": ">=9.3.1",
"@fastify/formbody": ">=7.4.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"
},
"peerDependenciesMeta": {
"@tsed/common": {
"optional": false
},
"@tsed/core": {
"optional": false
},
"@tsed/di": {
"optional": false
},
"@tsed/json-mapper": {
"optional": false
},
"@tsed/logger": {
"optional": false
},
"@tsed/openspec": {
"optional": false
},
"@tsed/schema": {
"optional": false
},
"fastify": {
"optional": false
}
}
}
67 changes: 67 additions & 0 deletions packages/platform/platform-fastify/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<p style="text-align: center" align="center">
<a href="https://tsed.io" target="_blank"><img src="https://tsed.io/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
</p>

<div align="center">
<h1>Platform Fastify</h1>

[![Build & Release](https://github.com/tsedio/tsed/workflows/Build%20&%20Release/badge.svg)](https://github.com/tsedio/tsed/actions?query=workflow%3A%22Build+%26+Release%22)
[![PR Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/tsedio/tsed/blob/master/CONTRIBUTING.md)
[![Coverage Status](https://coveralls.io/repos/github/tsedio/tsed/badge.svg?branch=production)](https://coveralls.io/github/tsedio/tsed?branch=production)
[![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
[![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)

</div>

<div align="center">
<a href="https://tsed.io/">Website</a>
<span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
<a href="https://tsed.io/getting-started/">Getting started</a>
<span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
<a href="https://api.tsed.io/rest/slack/tsedio/tsed">Slack</a>
<span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
<a href="https://twitter.com/TsED_io">Twitter</a>
</div>

<hr />

A package of Ts.ED framework. See website: https://tsed.io/getting-started/

Comment on lines +31 to +32
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)

## Installation

Run npm command (or yarn):

```bash
npm install --save @tsed/platform-fastify fastify
```
Comment on lines +37 to +39
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


## Contributors

Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)

<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>

## Backers

Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]

<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>

## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]

## License

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)


Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {PlatformBuilder} from "@tsed/platform-http";

import {PlatformFastify} from "./PlatformFastify.js";

class Server {}

describe("PlatformFastify", () => {
describe("create()", () => {
beforeEach(() => {
vi.spyOn(PlatformBuilder, "create").mockReturnValue({});
});
afterEach(() => vi.resetAllMocks());
it("should create platform", () => {
PlatformFastify.create(Server, {});

expect(PlatformBuilder.create).toHaveBeenCalledWith(Server, {
adapter: PlatformFastify
});
});
Comment on lines +13 to +19
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 test coverage with additional assertions and scenarios.

While the basic functionality is tested, consider adding:

  1. Negative test cases (e.g., invalid Server class)
  2. Test cases with different configuration options
  3. Verification of error handling

});
describe("bootstrap()", () => {
beforeEach(() => {
vi.spyOn(PlatformBuilder, "bootstrap").mockReturnValue({});
});
afterEach(() => vi.resetAllMocks());
it("should create platform", async () => {
await PlatformFastify.bootstrap(Server, {});

expect(PlatformBuilder.bootstrap).toHaveBeenCalledWith(Server, {
adapter: PlatformFastify
});
Comment on lines +27 to +31
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add assertions for the returned platform instance

The test only verifies that bootstrap was called but doesn't assert anything about the returned platform instance.

-      await PlatformFastify.bootstrap(Server, {});
+      const platform = await PlatformFastify.bootstrap(Server, {});
 
       expect(PlatformBuilder.bootstrap).toHaveBeenCalledWith(Server, {
         adapter: PlatformFastify
       });
+      expect(platform).toBeDefined();
📝 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
await PlatformFastify.bootstrap(Server, {});
expect(PlatformBuilder.bootstrap).toHaveBeenCalledWith(Server, {
adapter: PlatformFastify
});
const platform = await PlatformFastify.bootstrap(Server, {});
expect(PlatformBuilder.bootstrap).toHaveBeenCalledWith(Server, {
adapter: PlatformFastify
});
expect(platform).toBeDefined();
🧰 Tools
🪛 GitHub Actions: Build & Release

[warning] Warning: Statics middleware is not implemented yet

});
Comment on lines +26 to +32
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 test description and add error scenarios.

The test description "should create platform" is too generic. Consider:

  1. Renaming to "should bootstrap platform with default configuration"
  2. Adding test cases for configuration validation
  3. Testing error handling during bootstrap

});
});
Loading
Loading