@tsed/platform-fulmine 0.0.0-stage → 8.45.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,92 @@
1
+ import Http from "node:http";
2
+ import { getHostInfoFromPort, isFunction } from "@tsed/core";
3
+ import { configuration, constant, injector, logger, ProviderScope } from "@tsed/di";
4
+ import { PlatformExpress, PlatformExpressHandler, PlatformExpressResponse } from "@tsed/platform-express";
5
+ import { adapter, application, PlatformBuilder, PlatformHandler, PlatformResponse } from "@tsed/platform-http";
6
+ import fulmine from "fulmine.js";
7
+ /**
8
+ * Ts.ED on [fulmine.js](https://github.com/nigrosimone/fulmine.js), an Express 5 compatible framework on
9
+ * uWebSockets.js. The Express adapter does the routing; this platform changes what owns the socket: the app
10
+ * listens on uWebSockets.js itself instead of being passed to `http.createServer()`.
11
+ *
12
+ * @platform
13
+ */
14
+ export class PlatformFulmine extends PlatformExpress {
15
+ constructor() {
16
+ super(...arguments);
17
+ // @ts-ignore PlatformExpress types NAME as the literal "express"
18
+ this.NAME = "fulmine";
19
+ }
20
+ static create(module, settings = {}) {
21
+ return new PlatformBuilder({
22
+ httpsPort: false,
23
+ httpPort: false,
24
+ ...PlatformBuilder.options(PlatformFulmine, module, settings)
25
+ });
26
+ }
27
+ static bootstrap(module, settings = {}) {
28
+ return new PlatformBuilder(PlatformBuilder.options(PlatformFulmine, module, settings)).bootstrap();
29
+ }
30
+ createApp() {
31
+ const app = constant("fulmine.app") || fulmine();
32
+ return { app, callback: () => app };
33
+ }
34
+ /**
35
+ * The app is the server: it binds on uWebSockets.js and answers as an `http.Server`. TLS belongs to
36
+ * uWebSockets.js too, see `fulmine({uwsOptions})`.
37
+ */
38
+ getServers() {
39
+ // as createServer() decides it in platform-http: every value but false enables it, 0 included
40
+ if (constant("httpsPort") !== false) {
41
+ throw new Error("PlatformFulmine: set TLS on the fulmine app with fulmine({uwsOptions}) and the fulmine.app setting");
42
+ }
43
+ const app = application().getApp();
44
+ const port = constant("httpPort");
45
+ // useValue as a function: DI calls a function given as useValue, and the fulmine app is one
46
+ injector().add(Http.Server, { scope: ProviderScope.SINGLETON, useValue: () => (port !== false ? app : null) });
47
+ injector().invoke(Http.Server);
48
+ if (port === false) {
49
+ return [];
50
+ }
51
+ return [
52
+ async () => {
53
+ const hostInfo = getHostInfoFromPort("http", port);
54
+ await new Promise((resolve, reject) => {
55
+ app.listen(Number(hostInfo.port), hostInfo.address, (err) => (err ? reject(err) : resolve()));
56
+ });
57
+ hostInfo.port = app.address().port;
58
+ logger().info(`Listen server on ${hostInfo.toString()}`);
59
+ configuration().set("httpPort", `${hostInfo.address}:${hostInfo.port}`);
60
+ return app;
61
+ }
62
+ ];
63
+ }
64
+ statics(_endpoint, options) {
65
+ const { root, ...props } = options;
66
+ const middleware = fulmine.static(root, props);
67
+ return (req, res, next) => (res.headersSent ? next() : middleware(req, res, next));
68
+ }
69
+ bodyParser(type, additionalOptions = {}) {
70
+ // fulmine.bodyParser.<type> is a parser that replaces the fulmine one, or the options of the fulmine one
71
+ const configured = constant(`fulmine.bodyParser.${type}`);
72
+ const parser = isFunction(configured) ? configured : fulmine[type];
73
+ const { verify, ...configuredOptions } = isFunction(configured) ? {} : configured || {};
74
+ const options = type === "urlencoded" ? { extended: true, ...configuredOptions } : configuredOptions;
75
+ if (type === "urlencoded") {
76
+ this.app.getApp().set("query parser", "extended");
77
+ }
78
+ // rawBody is only known once the routes are mapped, so it is read per request, as in PlatformExpress
79
+ options.verify = (req, res, buffer, encoding) => {
80
+ if (constant("rawBody")) {
81
+ req.rawBody = buffer;
82
+ }
83
+ verify?.(req, res, buffer, encoding);
84
+ return true;
85
+ };
86
+ return parser({ ...options, ...additionalOptions });
87
+ }
88
+ }
89
+ adapter(PlatformFulmine, [
90
+ { token: PlatformHandler, useClass: PlatformExpressHandler },
91
+ { token: PlatformResponse, useClass: PlatformExpressResponse }
92
+ ]);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./components/PlatformFulmine.js";
5
+ export * from "./interfaces/interfaces.js";
6
+ export * from "./interfaces/PlatformFulmineSettings.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./PlatformFulmineSettings.js";
@@ -0,0 +1,26 @@
1
+ import { Type } from "@tsed/core";
2
+ import { PlatformExpress } from "@tsed/platform-express";
3
+ import { PlatformBuilder, PlatformStaticsOptions } from "@tsed/platform-http";
4
+ /**
5
+ * Ts.ED on [fulmine.js](https://github.com/nigrosimone/fulmine.js), an Express 5 compatible framework on
6
+ * uWebSockets.js. The Express adapter does the routing; this platform changes what owns the socket: the app
7
+ * listens on uWebSockets.js itself instead of being passed to `http.createServer()`.
8
+ *
9
+ * @platform
10
+ */
11
+ export declare class PlatformFulmine extends PlatformExpress {
12
+ readonly NAME = "fulmine";
13
+ static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<any>;
14
+ static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<any>>;
15
+ createApp(): {
16
+ app: any;
17
+ callback: () => any;
18
+ };
19
+ /**
20
+ * The app is the server: it binds on uWebSockets.js and answers as an `http.Server`. TLS belongs to
21
+ * uWebSockets.js too, see `fulmine({uwsOptions})`.
22
+ */
23
+ getServers(): any[];
24
+ statics(_endpoint: string, options: PlatformStaticsOptions): (req: any, res: any, next: any) => any;
25
+ bodyParser(type: "json" | "text" | "urlencoded", additionalOptions?: any): any;
26
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./components/PlatformFulmine.js";
5
+ export * from "./interfaces/interfaces.js";
6
+ export * from "./interfaces/PlatformFulmineSettings.js";
@@ -0,0 +1,18 @@
1
+ import type { Options, OptionsJson, OptionsText, OptionsUrlencoded } from "body-parser";
2
+ import type { NextHandleFunction } from "connect";
3
+ export interface PlatformFulmineSettings {
4
+ /**
5
+ * The fulmine application to use instead of a new `fulmine()`, to pass options such as
6
+ * `uwsOptions` for TLS.
7
+ */
8
+ app?: any;
9
+ /**
10
+ * body parser configuration, a function given here replaces the fulmine parser
11
+ */
12
+ bodyParser?: {
13
+ json?: ((opts?: OptionsJson) => NextHandleFunction) | OptionsJson;
14
+ text?: ((opts?: OptionsText) => NextHandleFunction) | OptionsText;
15
+ raw?: ((opts?: Options) => NextHandleFunction) | Options;
16
+ urlencoded?: ((opts?: OptionsUrlencoded) => NextHandleFunction) | OptionsUrlencoded;
17
+ };
18
+ }
@@ -0,0 +1,12 @@
1
+ import { PlatformFulmineSettings } from "./PlatformFulmineSettings.js";
2
+ export * from "./PlatformFulmineSettings.js";
3
+ declare global {
4
+ namespace TsED {
5
+ interface Configuration {
6
+ /**
7
+ * Configuration related to the fulmine.js platform application.
8
+ */
9
+ fulmine: PlatformFulmineSettings;
10
+ }
11
+ }
12
+ }
package/package.json CHANGED
@@ -1,6 +1,123 @@
1
1
  {
2
2
  "name": "@tsed/platform-fulmine",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "8.45.2",
4
+ "description": "A TypeScript Framework on top of fulmine.js, the Express 5 API on uWebSockets.js",
5
+ "keywords": [
6
+ "Controller",
7
+ "Decorator",
8
+ "Express",
9
+ "Inject",
10
+ "TypeScript",
11
+ "api",
12
+ "decorator",
13
+ "decorators",
14
+ "di",
15
+ "express",
16
+ "fulmine",
17
+ "ioc",
18
+ "mvc",
19
+ "rest",
20
+ "server",
21
+ "typescript",
22
+ "uWebSockets",
23
+ "uws"
24
+ ],
25
+ "homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-fulmine",
26
+ "bugs": {
27
+ "url": "https://github.com/tsedio/tsed/issues"
28
+ },
29
+ "license": "MIT",
30
+ "author": "Romain Lenzotti",
31
+ "repository": "https://github.com/tsedio/tsed",
32
+ "source": "./src/index.ts",
33
+ "type": "module",
34
+ "main": "./lib/esm/index.js",
35
+ "module": "./lib/esm/index.js",
36
+ "typings": "./lib/types/index.d.ts",
37
+ "exports": {
38
+ ".": {
39
+ "tsed-source": "./src/index.ts",
40
+ "types": "./lib/types/index.d.ts",
41
+ "import": "./lib/esm/index.js",
42
+ "default": "./lib/esm/index.js"
43
+ }
44
+ },
45
+ "scripts": {
46
+ "build": "yarn barrels && yarn build:ts",
47
+ "barrels": "barrels",
48
+ "test": "vitest run",
49
+ "build:ts": "tsc --build tsconfig.esm.json",
50
+ "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
51
+ },
52
+ "dependencies": {
53
+ "tslib": ">=2.7.0"
54
+ },
55
+ "devDependencies": {
56
+ "@tsed/barrels": "8.45.2",
57
+ "@tsed/core": "8.45.2",
58
+ "@tsed/di": "8.45.2",
59
+ "@tsed/platform-express": "8.45.2",
60
+ "@tsed/platform-http": "8.45.2",
61
+ "@tsed/platform-test-sdk": "8.45.2",
62
+ "@tsed/platform-views": "8.45.2",
63
+ "@tsed/typescript": "8.45.2",
64
+ "@types/compression": "1.7.5",
65
+ "@types/cookie-parser": "1.4.7",
66
+ "@types/express": "^5.0.6",
67
+ "@types/express-session": "1.18.1",
68
+ "@types/method-override": "0.0.35",
69
+ "compression": "1.8.0",
70
+ "cookie-parser": "1.4.7",
71
+ "express": "5.2.1",
72
+ "express-session": "1.18.1",
73
+ "fulmine.js": "5.25.7",
74
+ "method-override": "3.0.0",
75
+ "typescript": "6.0.2",
76
+ "vitest": "4.1.4"
77
+ },
78
+ "peerDependencies": {
79
+ "@tsed/core": ">=8.0.0",
80
+ "@tsed/di": ">=8.0.0",
81
+ "@tsed/json-mapper": ">=8.0.0",
82
+ "@tsed/logger": ">=8.0.0",
83
+ "@tsed/openspec": ">=8.0.0",
84
+ "@tsed/platform-express": ">=8.0.0",
85
+ "@tsed/platform-http": ">=8.0.0",
86
+ "@tsed/platform-views": ">=8.0.0",
87
+ "@tsed/schema": ">=8.0.0",
88
+ "express": ">=5.0.0",
89
+ "fulmine.js": "^5.25.7"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "@tsed/core": {
93
+ "optional": false
94
+ },
95
+ "@tsed/di": {
96
+ "optional": false
97
+ },
98
+ "@tsed/json-mapper": {
99
+ "optional": false
100
+ },
101
+ "@tsed/logger": {
102
+ "optional": false
103
+ },
104
+ "@tsed/platform-express": {
105
+ "optional": false
106
+ },
107
+ "@tsed/platform-http": {
108
+ "optional": false
109
+ },
110
+ "@tsed/platform-views": {
111
+ "optional": true
112
+ },
113
+ "@tsed/schema": {
114
+ "optional": false
115
+ },
116
+ "express": {
117
+ "optional": false
118
+ },
119
+ "fulmine.js": {
120
+ "optional": false
121
+ }
122
+ }
6
123
  }
package/readme.md ADDED
@@ -0,0 +1,106 @@
1
+ <p style="text-align: center" align="center">
2
+ <a href="https://tsed.dev" target="_blank"><img src="https://tsed.dev/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
3
+ </p>
4
+
5
+ <div align="center">
6
+ <h1>Platform fulmine.js</h1>
7
+
8
+ [![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)
9
+ [![PR Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/tsedio/tsed/blob/master/CONTRIBUTING.md)
10
+ [![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
11
+ [![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)
12
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
13
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
14
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
15
+
16
+ </div>
17
+
18
+ <div align="center">
19
+ <a href="https://tsed.dev">Website</a>
20
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
21
+ <a href="https://tsed.dev/getting-started/">Getting started</a>
22
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
23
+ <a href="https://slack.tsed.dev">Slack</a>
24
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
25
+ <a href="https://twitter.com/TsED_io">Twitter</a>
26
+ </div>
27
+
28
+ <hr />
29
+
30
+ A package of Ts.ED framework. See website: https://tsed.dev/getting-started/
31
+
32
+ ## Installation
33
+
34
+ Run npm command (or yarn):
35
+
36
+ ```bash
37
+ npm install --save @tsed/platform-fulmine @tsed/platform-express fulmine.js express
38
+ ```
39
+
40
+ [fulmine.js](https://github.com/nigrosimone/fulmine.js) is an Express 5 compatible framework on
41
+ uWebSockets.js. The platform uses the Express adapter for the routing, so the Express middlewares of a Ts.ED
42
+ app stay the same, and the app listens on uWebSockets.js instead of the http server of node. `express` is
43
+ still needed, as a peer of `@tsed/platform-express`.
44
+
45
+ About the install:
46
+
47
+ - fulmine.js depends on `uWebSockets.js` from GitHub (`github:uNetworking/uWebSockets.js#v20.71.0`), not from the npm
48
+ registry, so the install needs access to github.com. Behind a registry mirror or a proxy that only allows npm, it fails.
49
+ - uWebSockets.js is a native addon with prebuilt binaries: Node 22, 24 or 26 on Linux or macOS (x64 or arm64) or
50
+ Windows (x64). Not Alpine (glibc 2.38+ is needed).
51
+ - On Bun and Deno fulmine.js does not load uWebSockets.js and listens with their own `node:http`, plain HTTP only.
52
+
53
+ ## Usage
54
+
55
+ ```typescript
56
+ import {PlatformFulmine} from "@tsed/platform-fulmine";
57
+ import {Server} from "./Server.js";
58
+
59
+ const platform = await PlatformFulmine.bootstrap(Server, {httpPort: 8083});
60
+ await platform.listen();
61
+ ```
62
+
63
+ To pass options to fulmine, such as TLS with `uwsOptions`, give your own app:
64
+
65
+ ```typescript
66
+ import fulmine from "fulmine.js";
67
+
68
+ const platform = await PlatformFulmine.bootstrap(Server, {
69
+ httpPort: 8443,
70
+ fulmine: {
71
+ app: fulmine({uwsOptions: {key_file_name: "key.pem", cert_file_name: "cert.pem"}})
72
+ }
73
+ });
74
+ ```
75
+
76
+ `httpsPort` is not supported: TLS belongs to uWebSockets.js, set it on the fulmine app.
77
+
78
+ See [Ts.ED capabilities](https://tsed.dev/introduction/capabilities.html) for more information.
79
+
80
+ ## Contributors
81
+
82
+ Please read [contributing guidelines here](https://tsed.dev/contributing.html)
83
+
84
+ <a href="https://github.com/tsedio/tsed/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
85
+
86
+ ## Backers
87
+
88
+ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
89
+
90
+ <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
91
+
92
+ ## Sponsors
93
+
94
+ 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)]
95
+
96
+ ## License
97
+
98
+ The MIT License (MIT)
99
+
100
+ Copyright (c) 2016 - 2022 Romain Lenzotti
101
+
102
+ 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:
103
+
104
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
105
+
106
+ 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.
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.