tspace-spear 1.2.2 → 1.2.3

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.
package/README.md CHANGED
@@ -3,8 +3,10 @@
3
3
  [![NPM version](https://img.shields.io/npm/v/tspace-spear.svg)](https://www.npmjs.com)
4
4
  [![NPM downloads](https://img.shields.io/npm/dm/tspace-spear.svg)](https://www.npmjs.com)
5
5
 
6
- tspace-spear is a lightweight API framework for Node.js that is fast and highly focused on providing the best developer experience.
7
- It utilizes the native HTTP server.
6
+ tspace-spear is a lightweight and high-performance API framework for Node.js,
7
+ built on the native HTTP server with optional support for uWebSockets.js (C++) to achieve maximum speed and efficiency.
8
+
9
+ It is designed with a strong focus on delivering an excellent developer experience.
8
10
 
9
11
  ## Install
10
12
 
@@ -16,6 +18,7 @@ npm install tspace-spear --save
16
18
  ```
17
19
  ## Basic Usage
18
20
  - [Start Server](#start-server)
21
+ - [Adapter](#adapter)
19
22
  - [Cluster](#cluster)
20
23
  - [Global Prefix](#global-prefix)
21
24
  - [Logger](#logger)
@@ -31,7 +34,7 @@ npm install tspace-spear --save
31
34
  - [Controller](#controller)
32
35
  - [Router](#router)
33
36
  - [Swagger](#swagger)
34
- - [WebSocket](#web-socket)
37
+ - [WebSocket](#websocket)
35
38
  - [Example CRUD](#example-crud)
36
39
 
37
40
  ## Start Server
@@ -49,6 +52,35 @@ new Spear()
49
52
 
50
53
  ```
51
54
 
55
+ ## Adapter
56
+ tspace-spear supports multiple server adapters,
57
+ including the native Node.js HTTP server and uWebSockets.js for high performance.
58
+
59
+ ⚠️ Requirements for uWebSockets.js
60
+ Node.js 18 or higher is required
61
+ Installation is done via GitHub (no official npm release)
62
+
63
+ ```js
64
+ import { Spear } from "tspace-spear";
65
+ import uWS from "uWebSockets.js";
66
+
67
+ // Install via package.json
68
+ // "dependencies": {
69
+ // "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.45.0"
70
+ // }
71
+
72
+ new Spear({ adapter: uWS })
73
+ .get("/", () => "Hello world!")
74
+ .get("/json", () => {
75
+ return {
76
+ message: "Hello world!",
77
+ };
78
+ })
79
+ .listen(3000, () =>
80
+ console.log("uWS server is running at http://localhost:3000")
81
+ );
82
+ ```
83
+
52
84
  ## Cluster
53
85
  ```js
54
86
  import { Spear } from "tspace-spear";
@@ -619,7 +651,7 @@ class CatController {
619
651
  file : {
620
652
  type : 'array',
621
653
  items: {
622
- type:"file",
654
+ type :"string",
623
655
  format:"binary"
624
656
  }
625
657
  },
@@ -25,6 +25,7 @@ declare class Spear {
25
25
  private readonly _globalPrefix;
26
26
  private readonly _router;
27
27
  private readonly _parser;
28
+ private _adapter;
28
29
  private _cluster?;
29
30
  private _cors?;
30
31
  private _swagger;
@@ -37,7 +38,7 @@ declare class Spear {
37
38
  private _formatResponse;
38
39
  private _onListeners;
39
40
  private _fileUploadOptions;
40
- constructor({ controllers, middlewares, globalPrefix, logger, cluster }?: T.Application);
41
+ constructor({ controllers, middlewares, globalPrefix, logger, cluster, adapter }?: T.Application);
41
42
  /**
42
43
  * The get 'instance' method is used to get the instance of Spear.
43
44
  *
@@ -67,6 +68,14 @@ declare class Spear {
67
68
  * @returns {this}
68
69
  */
69
70
  use(middleware: (ctx: T.Context, next: T.NextFunction) => void): this;
71
+ /**
72
+ * The 'useAdater' method is used to switch between different server implementations,
73
+ * such as the native Node.js HTTP server or uWebSockets.js (uWS).
74
+ *
75
+ * @param {T.Adapter} adapter - The adapter instance (e.g., HTTP or uWS).
76
+ * @returns {this} Returns the current instance for chaining
77
+ */
78
+ useAdater(adapter: T.Adapter): this;
70
79
  /**
71
80
  * The 'useCluster' method is used cluster run the server
72
81
  *
@@ -274,7 +283,6 @@ declare class Spear {
274
283
  * @returns {this}
275
284
  */
276
285
  all(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
277
- private _clusterMode;
278
286
  private _import;
279
287
  private _registerControllers;
280
288
  private _registerMiddlewares;
@@ -282,7 +290,9 @@ declare class Spear {
282
290
  private _wrapHandlers;
283
291
  private _wrapResponse;
284
292
  private _nextFunction;
293
+ private _clusterMode;
285
294
  private _createServer;
295
+ private _uWSRequestResponse;
286
296
  private _normalizePath;
287
297
  private _swaggerHandler;
288
298
  }