tspace-spear 1.2.1-beta.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/README.md +41 -11
- package/dist/lib/core/decorators/context.d.ts +91 -0
- package/dist/lib/core/decorators/context.js +86 -0
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/controller.d.ts +34 -0
- package/dist/lib/core/decorators/controller.js +33 -0
- package/dist/lib/core/decorators/controller.js.map +1 -1
- package/dist/lib/core/decorators/headers.d.ts +31 -0
- package/dist/lib/core/decorators/headers.js +29 -0
- package/dist/lib/core/decorators/headers.js.map +1 -1
- 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/methods.js +78 -1
- package/dist/lib/core/decorators/methods.js.map +1 -1
- package/dist/lib/core/decorators/middleware.d.ts +39 -0
- package/dist/lib/core/decorators/middleware.js +37 -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/statusCode.js +24 -0
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/decorators/swagger.d.ts +36 -0
- package/dist/lib/core/decorators/swagger.js +35 -1
- package/dist/lib/core/decorators/swagger.js.map +1 -1
- package/dist/lib/core/server/index.d.ts +292 -0
- package/dist/lib/core/server/index.js +363 -359
- 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 +34 -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 +2 -11
- package/dist/tests/benchmark.test.js.map +1 -1
- package/package.json +12 -10
- package/dist/lib/core/server/radix-router.js +0 -65
- package/dist/lib/core/server/radix-router.js.map +0 -1
|
@@ -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,6 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Middleware = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Attaches a middleware function to a controller method.
|
|
6
|
+
*
|
|
7
|
+
* The middleware will be executed **before the route handler**.
|
|
8
|
+
* If the middleware calls `next(err)`, the error will be forwarded
|
|
9
|
+
* to the framework's error handler. Otherwise, the original
|
|
10
|
+
* controller method will be executed.
|
|
11
|
+
*
|
|
12
|
+
* This decorator also stores middleware metadata using `Reflect.defineMetadata`
|
|
13
|
+
* so the framework can discover and execute it during the request lifecycle.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* class UserController {
|
|
18
|
+
*
|
|
19
|
+
* \@Middleware(authMiddleware)
|
|
20
|
+
* async profile(ctx: T.Context) {
|
|
21
|
+
* return { user: ctx.user };
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Example middleware:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const authMiddleware: T.RequestFunction = (ctx, next) => {
|
|
31
|
+
* if (!ctx.user) {
|
|
32
|
+
* return next(new Error("Unauthorized"));
|
|
33
|
+
* }
|
|
34
|
+
* next();
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param {T.RequestFunction} middleware - Middleware function to execute before the route handler.
|
|
39
|
+
* @returns {MethodDecorator}
|
|
40
|
+
*/
|
|
4
41
|
const Middleware = (middleware) => {
|
|
5
42
|
return (target, key, descriptor) => {
|
|
6
43
|
const originalMethod = descriptor.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;
|
|
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;
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StatusCode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Sets the HTTP response status code before executing the controller method.
|
|
6
|
+
*
|
|
7
|
+
* The provided status code will be automatically clamped between **100** and **599**
|
|
8
|
+
* to ensure a valid HTTP status range. It also sets the default
|
|
9
|
+
* `Content-Type` header to `application/json`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* class UserController {
|
|
14
|
+
* \@StatusCode(201)
|
|
15
|
+
* async create(ctx: T.Context) {
|
|
16
|
+
* return { success: true };
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* In this example the response will be sent with:
|
|
22
|
+
* - Status: **201 Created**
|
|
23
|
+
* - Header: `Content-Type: application/json`
|
|
24
|
+
*
|
|
25
|
+
* @param {T.StatusCode} statusCode - HTTP status code to send with the response.
|
|
26
|
+
* @returns {MethodDecorator}
|
|
27
|
+
*/
|
|
4
28
|
const StatusCode = (statusCode) => {
|
|
5
29
|
return (target, key, descriptor) => {
|
|
6
30
|
const originalMethod = descriptor.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statusCode.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/statusCode.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"statusCode.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/statusCode.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,UAAU,GAAG,CAAC,UAAwB,EAAY,EAAE;IAC7D,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAChE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,MAAM,IAAI,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC;QAE1E,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAc,EAAE,IAAoB;YACnE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;YAChE,OAAO,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC,CAAC;AAbW,QAAA,UAAU,cAarB"}
|
|
@@ -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;
|
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Swagger = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Attaches Swagger/OpenAPI specification metadata to a controller method.
|
|
6
|
+
*
|
|
7
|
+
* This decorator stores route documentation using `Reflect.defineMetadata`
|
|
8
|
+
* so the framework can later collect it and generate **Swagger / OpenAPI**
|
|
9
|
+
* documentation automatically.
|
|
10
|
+
*
|
|
11
|
+
* The metadata is stored on the controller constructor under the key `"swaggers"`.
|
|
12
|
+
* Each decorated method contributes a Swagger specification object.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* class UserController {
|
|
17
|
+
*
|
|
18
|
+
* \@Swagger({
|
|
19
|
+
* summary: "Get user profile",
|
|
20
|
+
* description: "Returns the authenticated user's profile",
|
|
21
|
+
* tags: ["Users"],
|
|
22
|
+
* responses: {
|
|
23
|
+
* 200: {
|
|
24
|
+
* description: "Successful response"
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* })
|
|
28
|
+
* async profile(ctx: T.Context) {
|
|
29
|
+
* return { id: 1, name: "John" };
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param {T.Swagger.Spec} data - Swagger/OpenAPI specification for the route.
|
|
36
|
+
* @returns {MethodDecorator}
|
|
37
|
+
*/
|
|
4
38
|
const Swagger = (data) => {
|
|
5
39
|
return (target, propertyKey) => {
|
|
6
40
|
const controller = target.constructor;
|
|
@@ -9,7 +43,7 @@ const Swagger = (data) => {
|
|
|
9
43
|
: [];
|
|
10
44
|
swaggers.push({
|
|
11
45
|
handler: propertyKey,
|
|
12
|
-
...data
|
|
46
|
+
...data,
|
|
13
47
|
});
|
|
14
48
|
Reflect.defineMetadata("swaggers", swaggers, controller);
|
|
15
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/swagger.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/swagger.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,MAAM,OAAO,GAAG,CAAC,IAAoB,EAAE,EAAE;IAC9C,OAAO,CAAC,MAAW,EAAE,WAAgB,EAAE,EAAE;QACvC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;QAEtC,MAAM,QAAQ,GAAU,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC;YACjE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC;YAC7C,CAAC,CAAC,EAAE,CAAC;QAEP,QAAQ,CAAC,IAAI,CAAC;YACZ,OAAO,EAAE,WAAW;YACpB,GAAG,IAAI;SACR,CAAC,CAAC;QAEH,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,OAAO,WAelB"}
|
|
@@ -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;
|