tspace-spear 1.2.1 → 1.2.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.
- package/dist/lib/core/decorators/context.d.ts +91 -0
- package/dist/lib/core/decorators/controller.d.ts +34 -0
- package/dist/lib/core/decorators/headers.d.ts +31 -0
- package/dist/lib/core/decorators/index.d.ts +9 -0
- package/dist/lib/core/decorators/methods.d.ts +82 -0
- package/dist/lib/core/decorators/middleware.d.ts +39 -0
- package/dist/lib/core/decorators/middleware.js.map +1 -1
- package/dist/lib/core/decorators/statusCode.d.ts +26 -0
- package/dist/lib/core/decorators/swagger.d.ts +36 -0
- package/dist/lib/core/server/index.d.ts +292 -0
- package/dist/lib/core/server/index.js +33 -13
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/parser-factory.d.ts +23 -0
- package/dist/lib/core/server/parser-factory.js.map +1 -1
- package/dist/lib/core/server/router.d.ts +99 -0
- package/dist/lib/core/server/router.js.map +1 -1
- package/dist/lib/core/types/index.d.ts +228 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/tests/benchmark.test.d.ts +1 -0
- package/dist/tests/benchmark.test.js.map +1 -1
- package/package.json +7 -4
- package/dist/lib/core/server/radix-router.js +0 -65
- package/dist/lib/core/server/radix-router.js.map +0 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract specific fields from `ctx.body`.
|
|
3
|
+
*
|
|
4
|
+
* This decorator filters the request body and keeps only the
|
|
5
|
+
* specified keys. The filtered result replaces `ctx.body`
|
|
6
|
+
* before the controller method is executed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* @Body('email', 'password')
|
|
11
|
+
* async login(ctx: T.Context) {
|
|
12
|
+
* // ctx.body = { email: "...", password: "..." }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param {...string} bodyParms - Body field names to extract.
|
|
17
|
+
* @returns {MethodDecorator}
|
|
18
|
+
*/
|
|
19
|
+
export declare const Body: (...bodyParms: string[]) => Function;
|
|
20
|
+
/**
|
|
21
|
+
* Extract specific uploaded files from `ctx.files`.
|
|
22
|
+
*
|
|
23
|
+
* Filters uploaded files and keeps only the specified
|
|
24
|
+
* file field names before executing the controller method.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* \@Files('avatar', 'resume')
|
|
29
|
+
* async upload(ctx: T.Context) {
|
|
30
|
+
* // ctx.files = { avatar: File, resume: File }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param {...string} filesParms - File field names to extract.
|
|
35
|
+
* @returns {MethodDecorator}
|
|
36
|
+
*/
|
|
37
|
+
export declare const Files: (...filesParms: string[]) => Function;
|
|
38
|
+
/**
|
|
39
|
+
* Extract specific route parameters from `ctx.params`.
|
|
40
|
+
*
|
|
41
|
+
* Filters route parameters and keeps only the specified
|
|
42
|
+
* parameter names.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* \@Params('id')
|
|
47
|
+
* async getUser(ctx: T.Context) {
|
|
48
|
+
* // ctx.params = { id: "123" }
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param {...string} paramsData - Route parameter names to extract.
|
|
53
|
+
* @returns {MethodDecorator}
|
|
54
|
+
*/
|
|
55
|
+
export declare const Params: (...paramsData: string[]) => Function;
|
|
56
|
+
/**
|
|
57
|
+
* Extract specific query parameters from `ctx.query`.
|
|
58
|
+
*
|
|
59
|
+
* Filters query parameters and keeps only the specified
|
|
60
|
+
* query keys.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* \@Query('page', 'limit')
|
|
65
|
+
* async listUsers(ctx: T.Context) {
|
|
66
|
+
* // ctx.query = { page: "1", limit: "10" }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param {...string} queryParms - Query parameter names to extract.
|
|
71
|
+
* @returns {MethodDecorator}
|
|
72
|
+
*/
|
|
73
|
+
export declare const Query: (...queryParms: string[]) => Function;
|
|
74
|
+
/**
|
|
75
|
+
* Extract specific cookies from `ctx.cookies`.
|
|
76
|
+
*
|
|
77
|
+
* Filters cookies and keeps only the specified cookie keys
|
|
78
|
+
* before executing the controller method.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* \@Cookies('token')
|
|
83
|
+
* async profile(ctx: T.Context) {
|
|
84
|
+
* // ctx.cookies = { token: "..." }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @param {...string} cookiesParms - Cookie names to extract.
|
|
89
|
+
* @returns {MethodDecorator}
|
|
90
|
+
*/
|
|
91
|
+
export declare const Cookies: (...cookiesParms: string[]) => Function;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declares a class as a controller and assigns a base route path.
|
|
3
|
+
*
|
|
4
|
+
* The provided path will be used as the **base URL prefix**
|
|
5
|
+
* for all routes defined inside the controller. The path must
|
|
6
|
+
* start with `/`.
|
|
7
|
+
*
|
|
8
|
+
* This decorator stores the controller path using
|
|
9
|
+
* `Reflect.defineMetadata` under the key `"controllers"`.
|
|
10
|
+
* The framework can later read this metadata to register
|
|
11
|
+
* routes automatically.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* \@Controller('/users')
|
|
16
|
+
* class UserController {
|
|
17
|
+
*
|
|
18
|
+
* async list(ctx: T.Context) {
|
|
19
|
+
* return [{ id: 1, name: "John" }];
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* If a route handler defines `/profile`, the final route becomes:
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* /users/profile
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param {`/${string}`} path - Base route path for the controller.
|
|
32
|
+
* @returns {ClassDecorator}
|
|
33
|
+
*/
|
|
34
|
+
export declare const Controller: (path: `/${string}`) => ClassDecorator;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OutgoingHttpHeaders } from 'http';
|
|
2
|
+
/**
|
|
3
|
+
* Sets the HTTP response headers and status code before the controller method executes.
|
|
4
|
+
*
|
|
5
|
+
* This decorator calls `res.writeHead()` on the underlying Node.js response object,
|
|
6
|
+
* allowing you to define the response **status code** and **headers** in advance.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* class UserController {
|
|
11
|
+
*
|
|
12
|
+
* \@WriteHeader(200, { "Content-Type": "application/json" })
|
|
13
|
+
* async profile(ctx: T.Context) {
|
|
14
|
+
* return { id: 1, name: "John" };
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Example response:
|
|
21
|
+
*
|
|
22
|
+
* ```
|
|
23
|
+
* HTTP/1.1 200 OK
|
|
24
|
+
* Content-Type: application/json
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param {number} statusCode - HTTP status code to send with the response.
|
|
28
|
+
* @param {OutgoingHttpHeaders} contentType - Response headers to set.
|
|
29
|
+
* @returns {Function}
|
|
30
|
+
*/
|
|
31
|
+
export declare const WriteHeader: (statusCode: number, contentType: OutgoingHttpHeaders) => Function;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export * from './methods';
|
|
3
|
+
export * from './headers';
|
|
4
|
+
export * from './middleware';
|
|
5
|
+
export * from './controller';
|
|
6
|
+
export * from './headers';
|
|
7
|
+
export * from './statusCode';
|
|
8
|
+
export * from './context';
|
|
9
|
+
export * from './swagger';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps a controller method to an HTTP GET route.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* \@Get('/users')
|
|
7
|
+
* async list(ctx: T.Context) {
|
|
8
|
+
* return [{ id: 1, name: "John" }];
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const Get: (path: `/${string}`) => (target: any, propertyKey: any) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Maps a controller method to an HTTP POST route.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* \@Post('/users')
|
|
19
|
+
* async create(ctx: T.Context) {
|
|
20
|
+
* return { success: true };
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const Post: (path: `/${string}`) => (target: any, propertyKey: any) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Maps a controller method to an HTTP PUT route.
|
|
27
|
+
*
|
|
28
|
+
* Used for replacing a resource.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* \@Put('/users/:id')
|
|
33
|
+
* async update(ctx: T.Context) {}
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const Put: (path: `/${string}`) => (target: any, propertyKey: any) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Maps a controller method to an HTTP PATCH route.
|
|
39
|
+
*
|
|
40
|
+
* Used for partially updating a resource.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* \@Patch('/users/:id')
|
|
45
|
+
* async patch(ctx: T.Context) {}
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const Patch: (path: `/${string}`) => (target: any, propertyKey: any) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Maps a controller method to an HTTP DELETE route.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* \@Delete('/users/:id')
|
|
55
|
+
* async remove(ctx: T.Context) {}
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const Delete: (path: `/${string}`) => (target: any, propertyKey: any) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Maps a controller method to an HTTP HEAD route.
|
|
61
|
+
*
|
|
62
|
+
* HEAD responses contain only headers and no response body.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* \@Head('/health')
|
|
67
|
+
* async health(ctx: T.Context) {}
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const Head: (path: `/${string}`) => (target: any, propertyKey: any) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Maps a controller method to an HTTP OPTIONS route.
|
|
73
|
+
*
|
|
74
|
+
* Typically used for CORS preflight requests.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* \@Options('/users')
|
|
79
|
+
* async options(ctx: T.Context) {}
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const Options: (path: `/${string}`) => (target: any, propertyKey: any) => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { T } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Attaches a middleware function to a controller method.
|
|
4
|
+
*
|
|
5
|
+
* The middleware will be executed **before the route handler**.
|
|
6
|
+
* If the middleware calls `next(err)`, the error will be forwarded
|
|
7
|
+
* to the framework's error handler. Otherwise, the original
|
|
8
|
+
* controller method will be executed.
|
|
9
|
+
*
|
|
10
|
+
* This decorator also stores middleware metadata using `Reflect.defineMetadata`
|
|
11
|
+
* so the framework can discover and execute it during the request lifecycle.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* class UserController {
|
|
16
|
+
*
|
|
17
|
+
* \@Middleware(authMiddleware)
|
|
18
|
+
* async profile(ctx: T.Context) {
|
|
19
|
+
* return { user: ctx.user };
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Example middleware:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const authMiddleware: T.RequestFunction = (ctx, next) => {
|
|
29
|
+
* if (!ctx.user) {
|
|
30
|
+
* return next(new Error("Unauthorized"));
|
|
31
|
+
* }
|
|
32
|
+
* next();
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param {T.RequestFunction} middleware - Middleware function to execute before the route handler.
|
|
37
|
+
* @returns {MethodDecorator}
|
|
38
|
+
*/
|
|
39
|
+
export declare const Middleware: (middleware: T.RequestFunction) => Function;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACI,MAAM,UAAU,GAAG,CAAC,UAA6B,EAAY,EAAE;IAEpE,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,UAAU,GAAc,EAAE,IAAoB;YAC/D,IAAI;
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACI,MAAM,UAAU,GAAG,CAAC,UAA6B,EAAY,EAAE;IAEpE,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,UAAU,GAAc,EAAE,IAAoB;YAC/D,IAAI,CAAC;gBAEH,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;gBAE1D,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,GAAS,EAAE,EAAE;oBACnC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;wBAChB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;oBACnB,CAAC;oBAED,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;gBAC9C,CAAC,CAAC,CAAC;YAEL,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,UAAU,cAuBrB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type T } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Sets the HTTP response status code before executing the controller method.
|
|
4
|
+
*
|
|
5
|
+
* The provided status code will be automatically clamped between **100** and **599**
|
|
6
|
+
* to ensure a valid HTTP status range. It also sets the default
|
|
7
|
+
* `Content-Type` header to `application/json`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* class UserController {
|
|
12
|
+
* \@StatusCode(201)
|
|
13
|
+
* async create(ctx: T.Context) {
|
|
14
|
+
* return { success: true };
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* In this example the response will be sent with:
|
|
20
|
+
* - Status: **201 Created**
|
|
21
|
+
* - Header: `Content-Type: application/json`
|
|
22
|
+
*
|
|
23
|
+
* @param {T.StatusCode} statusCode - HTTP status code to send with the response.
|
|
24
|
+
* @returns {MethodDecorator}
|
|
25
|
+
*/
|
|
26
|
+
export declare const StatusCode: (statusCode: T.StatusCode) => Function;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type T } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Attaches Swagger/OpenAPI specification metadata to a controller method.
|
|
4
|
+
*
|
|
5
|
+
* This decorator stores route documentation using `Reflect.defineMetadata`
|
|
6
|
+
* so the framework can later collect it and generate **Swagger / OpenAPI**
|
|
7
|
+
* documentation automatically.
|
|
8
|
+
*
|
|
9
|
+
* The metadata is stored on the controller constructor under the key `"swaggers"`.
|
|
10
|
+
* Each decorated method contributes a Swagger specification object.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* class UserController {
|
|
15
|
+
*
|
|
16
|
+
* \@Swagger({
|
|
17
|
+
* summary: "Get user profile",
|
|
18
|
+
* description: "Returns the authenticated user's profile",
|
|
19
|
+
* tags: ["Users"],
|
|
20
|
+
* responses: {
|
|
21
|
+
* 200: {
|
|
22
|
+
* description: "Successful response"
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* })
|
|
26
|
+
* async profile(ctx: T.Context) {
|
|
27
|
+
* return { id: 1, name: "John" };
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param {T.Swagger.Spec} data - Swagger/OpenAPI specification for the route.
|
|
34
|
+
* @returns {MethodDecorator}
|
|
35
|
+
*/
|
|
36
|
+
export declare const Swagger: (data: T.Swagger.Spec) => (target: any, propertyKey: any) => void;
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { Server } from 'http';
|
|
2
|
+
import findMyWayRouter, { type Instance } from 'find-my-way';
|
|
3
|
+
import WebSocket from 'ws';
|
|
4
|
+
import { Router } from './router';
|
|
5
|
+
import type { T } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* The 'Spear' class is used to create a server and handle HTTP requests.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Spear} application
|
|
11
|
+
* @example
|
|
12
|
+
* new Spear()
|
|
13
|
+
* .get('/' , () => 'Hello world!')
|
|
14
|
+
* .get('/json' , () => {
|
|
15
|
+
* return {
|
|
16
|
+
* message : 'Hello world!'
|
|
17
|
+
* }
|
|
18
|
+
* })
|
|
19
|
+
* .listen(3000 , () => console.log('server listening on port : 3000'))
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
declare class Spear {
|
|
23
|
+
private readonly _controllers?;
|
|
24
|
+
private readonly _middlewares?;
|
|
25
|
+
private readonly _globalPrefix;
|
|
26
|
+
private readonly _router;
|
|
27
|
+
private readonly _parser;
|
|
28
|
+
private _cluster?;
|
|
29
|
+
private _cors?;
|
|
30
|
+
private _swagger;
|
|
31
|
+
private _swaggerSpecs;
|
|
32
|
+
private _wss?;
|
|
33
|
+
private _ws?;
|
|
34
|
+
private _wsOptions?;
|
|
35
|
+
private _errorHandler;
|
|
36
|
+
private _globalMiddlewares;
|
|
37
|
+
private _formatResponse;
|
|
38
|
+
private _onListeners;
|
|
39
|
+
private _fileUploadOptions;
|
|
40
|
+
constructor({ controllers, middlewares, globalPrefix, logger, cluster }?: T.Application);
|
|
41
|
+
/**
|
|
42
|
+
* The get 'instance' method is used to get the instance of Spear.
|
|
43
|
+
*
|
|
44
|
+
* @returns {this}
|
|
45
|
+
*/
|
|
46
|
+
get instance(): this;
|
|
47
|
+
/**
|
|
48
|
+
* The get 'routers' method is used get the all routers.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Instance<findMyWayRouter.HTTPVersion.V1>}
|
|
51
|
+
*/
|
|
52
|
+
get routers(): Instance<findMyWayRouter.HTTPVersion.V1>;
|
|
53
|
+
/**
|
|
54
|
+
* The 'ws' method is used to creates the WebSocket server.
|
|
55
|
+
*
|
|
56
|
+
* @callback {Function} WebSocketServer
|
|
57
|
+
* @param {WebSocketServer} wss - WebSocketServer
|
|
58
|
+
* @returns {this}
|
|
59
|
+
*/
|
|
60
|
+
ws(handlers: () => T.WebSocketHandler, options?: WebSocket.ServerOptions): this;
|
|
61
|
+
/**
|
|
62
|
+
* The 'use' method is used to add the middleware into the request pipeline.
|
|
63
|
+
*
|
|
64
|
+
* @callback {Function} middleware
|
|
65
|
+
* @property {Object} ctx - context { req , res , query , params , cookies , files , body}
|
|
66
|
+
* @property {Function} next - go to next function
|
|
67
|
+
* @returns {this}
|
|
68
|
+
*/
|
|
69
|
+
use(middleware: (ctx: T.Context, next: T.NextFunction) => void): this;
|
|
70
|
+
/**
|
|
71
|
+
* The 'useCluster' method is used cluster run the server
|
|
72
|
+
*
|
|
73
|
+
* @param {boolean | number} cluster
|
|
74
|
+
* @returns {this}
|
|
75
|
+
*/
|
|
76
|
+
useCluster(cluster?: number | boolean): this;
|
|
77
|
+
/**
|
|
78
|
+
* The 'useLogger' method is used to add the middleware view logger response.
|
|
79
|
+
*
|
|
80
|
+
* @callback {Function} middleware
|
|
81
|
+
* @property {Object} ctx - context { req , res , query , params , cookies , files , body}
|
|
82
|
+
* @property {Function} next - go to next function
|
|
83
|
+
* @returns {this}
|
|
84
|
+
*/
|
|
85
|
+
useLogger({ methods, exceptPath }?: {
|
|
86
|
+
methods?: T.MethodInput[];
|
|
87
|
+
exceptPath?: string[] | RegExp;
|
|
88
|
+
}): this;
|
|
89
|
+
/**
|
|
90
|
+
* The 'useBodyParser' method is a middleware used to parse the request body of incoming HTTP requests.
|
|
91
|
+
* @param {object?}
|
|
92
|
+
* @property {array?} except the body parser with some methods
|
|
93
|
+
* @returns {this}
|
|
94
|
+
*/
|
|
95
|
+
useBodyParser({ except }?: {
|
|
96
|
+
except?: T.MethodInput[];
|
|
97
|
+
}): this;
|
|
98
|
+
/**
|
|
99
|
+
* The 'useFileUpload' method is a middleware used to handler file uploads. It adds a file upload of incoming HTTP requests.
|
|
100
|
+
*
|
|
101
|
+
* @param {?Object}
|
|
102
|
+
* @property {?number} limits
|
|
103
|
+
* @property {?string} tempFileDir
|
|
104
|
+
* @property {?Object} removeTempFile
|
|
105
|
+
* @property {boolean} removeTempFile.remove
|
|
106
|
+
* @property {number} removeTempFile.ms
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
useFileUpload({ limit, tempFileDir, removeTempFile }?: {
|
|
110
|
+
limit?: number;
|
|
111
|
+
tempFileDir?: string;
|
|
112
|
+
removeTempFile?: {
|
|
113
|
+
remove: boolean;
|
|
114
|
+
ms: number;
|
|
115
|
+
};
|
|
116
|
+
}): this;
|
|
117
|
+
/**
|
|
118
|
+
* The 'useCookiesParser' method is a middleware used to parses cookies attached to the client request object.
|
|
119
|
+
*
|
|
120
|
+
* @returns {this}
|
|
121
|
+
*/
|
|
122
|
+
useCookiesParser(): this;
|
|
123
|
+
/**
|
|
124
|
+
* The 'useRouter' method is used to add the router in the request context.
|
|
125
|
+
*
|
|
126
|
+
* @parms {Function} router
|
|
127
|
+
* @property {Function} router - get() , post() , put() , patch() , delete()
|
|
128
|
+
* @returns {this}
|
|
129
|
+
*/
|
|
130
|
+
useRouter(router: Router): this;
|
|
131
|
+
/**
|
|
132
|
+
* The 'useSwagger' method is a middleware used to create swagger api.
|
|
133
|
+
*
|
|
134
|
+
* @param {?Object} doc
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
useSwagger(doc?: T.Swagger.Doc): this;
|
|
138
|
+
/**
|
|
139
|
+
* The 'listen' method is used to bind and start a server to a particular port and optionally a hostname.
|
|
140
|
+
*
|
|
141
|
+
* @param {number} port
|
|
142
|
+
* @param {function} callback
|
|
143
|
+
* @returns
|
|
144
|
+
*/
|
|
145
|
+
listen(port: number, hostname?: string | ((callback: {
|
|
146
|
+
server: Server;
|
|
147
|
+
port: number;
|
|
148
|
+
}) => void), callback?: (callback: {
|
|
149
|
+
server: Server;
|
|
150
|
+
port: number;
|
|
151
|
+
}) => void): Promise<Server>;
|
|
152
|
+
/**
|
|
153
|
+
* The 'cors' is used to enable the cors origins on the server.
|
|
154
|
+
*
|
|
155
|
+
* @params {Object}
|
|
156
|
+
* @property {(string | RegExp)[]} origins
|
|
157
|
+
* @property {boolean} credentials
|
|
158
|
+
* @returns
|
|
159
|
+
*/
|
|
160
|
+
cors({ origins, credentials }?: {
|
|
161
|
+
origins?: (string | RegExp)[];
|
|
162
|
+
credentials?: boolean;
|
|
163
|
+
}): this;
|
|
164
|
+
/**
|
|
165
|
+
* The 'response' method is used to format the response
|
|
166
|
+
*
|
|
167
|
+
* @param {function} format
|
|
168
|
+
* @returns
|
|
169
|
+
*/
|
|
170
|
+
response(format: (r: unknown, statusCode: number) => any): this;
|
|
171
|
+
/**
|
|
172
|
+
* The 'catch' method is middleware that is specifically designed to handle errors.
|
|
173
|
+
*
|
|
174
|
+
* that occur during the processing of requests
|
|
175
|
+
*
|
|
176
|
+
* @param {function} error
|
|
177
|
+
* @returns
|
|
178
|
+
*/
|
|
179
|
+
catch(error: (err: any, ctx: T.Context) => any): this;
|
|
180
|
+
/**
|
|
181
|
+
* The 'notfound' method is middleware that is specifically designed to handle errors notfound that occur during the processing of requests
|
|
182
|
+
*
|
|
183
|
+
* @param {function} fn
|
|
184
|
+
* @returns
|
|
185
|
+
*/
|
|
186
|
+
notfound(fn: (ctx: T.Context) => any): this;
|
|
187
|
+
/**
|
|
188
|
+
* The 'get' method is used to add the request handler to the router for the 'GET' method.
|
|
189
|
+
*
|
|
190
|
+
* @param {string} path
|
|
191
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
192
|
+
* @property {Object} ctx - context { req , res , query , params , cookies , files , body}
|
|
193
|
+
* @property {Function} next - go to next function
|
|
194
|
+
* @returns {this}
|
|
195
|
+
*/
|
|
196
|
+
get(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
197
|
+
/**
|
|
198
|
+
* The 'post' method is used to add the request handler to the router for the 'POST' method.
|
|
199
|
+
*
|
|
200
|
+
* @param {string} path
|
|
201
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
202
|
+
* @property {Object} ctx - context { req , res , query , params , cookies , files , body}
|
|
203
|
+
* @property {Function} next - go to next function
|
|
204
|
+
* @returns {this}
|
|
205
|
+
*/
|
|
206
|
+
post(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
207
|
+
/**
|
|
208
|
+
* The 'put' method is used to add the request handler to the router for the 'PUT' method.
|
|
209
|
+
*
|
|
210
|
+
* @param {string} path
|
|
211
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
212
|
+
* @property {Object} ctx - context { req , res , query , params , cookies , files , body}
|
|
213
|
+
* @property {Function} next - go to next function
|
|
214
|
+
* @returns {this}
|
|
215
|
+
*/
|
|
216
|
+
put(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
217
|
+
/**
|
|
218
|
+
* The 'patch' method is used to add the request handler to the router for the 'PATCH' method.
|
|
219
|
+
*
|
|
220
|
+
* @param {string} path
|
|
221
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
222
|
+
* @property {Object} ctx - context { req , res , query , params , cookies , files , body}
|
|
223
|
+
* @property {Function} next - go to next function
|
|
224
|
+
* @returns {this}
|
|
225
|
+
*/
|
|
226
|
+
patch(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
227
|
+
/**
|
|
228
|
+
* The 'delete' method is used to add the request handler to the router for the 'DELETE' method.
|
|
229
|
+
*
|
|
230
|
+
* @param {string} path
|
|
231
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
232
|
+
* @property {Object} ctx - context { req , res , query , params , cookies , files , body}
|
|
233
|
+
* @property {Function} next - go to next function
|
|
234
|
+
* @returns {this}
|
|
235
|
+
*/
|
|
236
|
+
delete(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
237
|
+
/**
|
|
238
|
+
* The 'head' method is used to add the request handler to the router for 'HEAD' methods.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} path
|
|
241
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
242
|
+
* @property {object} ctx - context { req , res , query , params , cookies , files , body}
|
|
243
|
+
* @property {function} next - go to next function
|
|
244
|
+
* @returns {this}
|
|
245
|
+
*/
|
|
246
|
+
head(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
247
|
+
/**
|
|
248
|
+
* The 'head' method is used to add the request handler to the router for 'HEAD' methods.
|
|
249
|
+
*
|
|
250
|
+
* @param {string} path
|
|
251
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
252
|
+
* @property {object} ctx - context { req , res , query , params , cookies , files , body}
|
|
253
|
+
* @property {function} next - go to next function
|
|
254
|
+
* @returns {this}
|
|
255
|
+
*/
|
|
256
|
+
options(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
257
|
+
/**
|
|
258
|
+
* The 'any' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
|
|
259
|
+
*
|
|
260
|
+
* @param {string} path
|
|
261
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
262
|
+
* @property {object} ctx - context { req , res , query , params , cookies , files , body}
|
|
263
|
+
* @property {function} next - go to next function
|
|
264
|
+
* @returns {this}
|
|
265
|
+
*/
|
|
266
|
+
any(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
267
|
+
/**
|
|
268
|
+
* The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
|
|
269
|
+
*
|
|
270
|
+
* @param {string} path
|
|
271
|
+
* @callback {...Function[]} handlers of the middlewares
|
|
272
|
+
* @property {object} ctx - context { req , res , query , params , cookies , files , body}
|
|
273
|
+
* @property {function} next - go to next function
|
|
274
|
+
* @returns {this}
|
|
275
|
+
*/
|
|
276
|
+
all(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
277
|
+
private _clusterMode;
|
|
278
|
+
private _import;
|
|
279
|
+
private _registerControllers;
|
|
280
|
+
private _registerMiddlewares;
|
|
281
|
+
private _customizeResponse;
|
|
282
|
+
private _wrapHandlers;
|
|
283
|
+
private _wrapResponse;
|
|
284
|
+
private _nextFunction;
|
|
285
|
+
private _createServer;
|
|
286
|
+
private _normalizePath;
|
|
287
|
+
private _swaggerHandler;
|
|
288
|
+
}
|
|
289
|
+
export declare class Application extends Spear {
|
|
290
|
+
}
|
|
291
|
+
export { Spear };
|
|
292
|
+
export default Spear;
|