tspace-spear 1.2.3 → 1.2.5
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 +268 -19
- package/dist/lib/core/const/index.d.ts +153 -0
- package/dist/lib/core/const/index.js +105 -0
- package/dist/lib/core/const/index.js.map +1 -0
- package/dist/lib/core/decorators/context.d.ts +16 -9
- package/dist/lib/core/decorators/context.js +85 -59
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/headers.d.ts +2 -2
- package/dist/lib/core/decorators/headers.js +1 -1
- package/dist/lib/core/decorators/headers.js.map +1 -1
- package/dist/lib/core/decorators/methods.d.ts +7 -7
- package/dist/lib/core/decorators/methods.js.map +1 -1
- package/dist/lib/core/decorators/middleware.d.ts +3 -3
- package/dist/lib/core/decorators/middleware.js +2 -2
- package/dist/lib/core/decorators/middleware.js.map +1 -1
- package/dist/lib/core/decorators/statusCode.d.ts +1 -1
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/decorators/swagger.d.ts +1 -1
- package/dist/lib/core/decorators/swagger.js.map +1 -1
- package/dist/lib/core/server/fast-router.d.ts +133 -0
- package/dist/lib/core/server/fast-router.js +277 -0
- package/dist/lib/core/server/fast-router.js.map +1 -0
- package/dist/lib/core/server/index.d.ts +34 -37
- package/dist/lib/core/server/index.js +192 -501
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/net/index.d.ts +20 -0
- package/dist/lib/core/server/net/index.js +393 -0
- package/dist/lib/core/server/net/index.js.map +1 -0
- package/dist/lib/core/server/parser-factory.d.ts +10 -11
- package/dist/lib/core/server/parser-factory.js +259 -437
- package/dist/lib/core/server/parser-factory.js.map +1 -1
- package/dist/lib/core/server/response.d.ts +6 -0
- package/dist/lib/core/server/response.js +168 -0
- package/dist/lib/core/server/response.js.map +1 -0
- package/dist/lib/core/server/router.d.ts +2 -12
- package/dist/lib/core/server/router.js +2 -13
- package/dist/lib/core/server/router.js.map +1 -1
- package/dist/lib/core/server/uWS/index.d.ts +30 -0
- package/dist/lib/core/server/uWS/index.js +357 -0
- package/dist/lib/core/server/uWS/index.js.map +1 -0
- package/dist/lib/core/types/index.d.ts +144 -43
- package/dist/lib/core/utils/index.d.ts +12 -0
- package/dist/lib/core/utils/index.js +137 -0
- package/dist/lib/core/utils/index.js.map +1 -0
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +3 -2
- package/dist/lib/index.js.map +1 -1
- package/package.json +19 -14
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FastRouter = void 0;
|
|
4
|
+
const METHODS = [
|
|
5
|
+
"GET", "POST", "PUT", "PATCH",
|
|
6
|
+
"DELETE", "OPTIONS", "HEAD"
|
|
7
|
+
];
|
|
8
|
+
class FastRouter {
|
|
9
|
+
trees = Object.create(null);
|
|
10
|
+
_routes = [];
|
|
11
|
+
constructor() {
|
|
12
|
+
for (const m of METHODS) {
|
|
13
|
+
this.trees[m] = this._createNode();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get all registered routes in the router.
|
|
18
|
+
*
|
|
19
|
+
* Returns the internal route registry used for debugging,
|
|
20
|
+
* inspection, or serialization of the router tree.
|
|
21
|
+
*
|
|
22
|
+
* @returns Internal routes structure
|
|
23
|
+
*/
|
|
24
|
+
get routes() {
|
|
25
|
+
return this._routes;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Register a GET route.
|
|
29
|
+
*
|
|
30
|
+
* Handles HTTP GET requests for the specified path.
|
|
31
|
+
*
|
|
32
|
+
* @param path Route path (e.g. "/users/:id")
|
|
33
|
+
* @param handler Function executed when route matches
|
|
34
|
+
* @returns Router instance for chaining
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* router.get("/users", (req, res) => {});
|
|
38
|
+
*/
|
|
39
|
+
get(path, handler) {
|
|
40
|
+
this._add("GET", path, handler);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Register a POST route.
|
|
45
|
+
*
|
|
46
|
+
* Used for creating resources or submitting data.
|
|
47
|
+
*
|
|
48
|
+
* @param path Route path
|
|
49
|
+
* @param handler Route handler function
|
|
50
|
+
* @returns Router instance for chaining
|
|
51
|
+
*/
|
|
52
|
+
post(path, handler) {
|
|
53
|
+
this._add("POST", path, handler);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Register a PUT route.
|
|
58
|
+
*
|
|
59
|
+
* Typically used for full resource replacement.
|
|
60
|
+
*
|
|
61
|
+
* @param path Route path
|
|
62
|
+
* @param handler Route handler function
|
|
63
|
+
* @returns Router instance for chaining
|
|
64
|
+
*/
|
|
65
|
+
put(path, handler) {
|
|
66
|
+
this._add("PUT", path, handler);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Register a PATCH route.
|
|
71
|
+
*
|
|
72
|
+
* Used for partial updates to a resource.
|
|
73
|
+
*
|
|
74
|
+
* @param path Route path
|
|
75
|
+
* @param handler Route handler function
|
|
76
|
+
* @returns Router instance for chaining
|
|
77
|
+
*/
|
|
78
|
+
patch(path, handler) {
|
|
79
|
+
this._add("PATCH", path, handler);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Register a DELETE route.
|
|
84
|
+
*
|
|
85
|
+
* Used for removing a resource.
|
|
86
|
+
*
|
|
87
|
+
* @param path Route path
|
|
88
|
+
* @param handler Route handler function
|
|
89
|
+
* @returns Router instance for chaining
|
|
90
|
+
*/
|
|
91
|
+
delete(path, handler) {
|
|
92
|
+
this._add("DELETE", path, handler);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Register an OPTIONS route.
|
|
97
|
+
*
|
|
98
|
+
* Used for CORS preflight requests or capability discovery.
|
|
99
|
+
*
|
|
100
|
+
* @param path Route path
|
|
101
|
+
* @param handler Route handler function
|
|
102
|
+
* @returns Router instance for chaining
|
|
103
|
+
*/
|
|
104
|
+
options(path, handler) {
|
|
105
|
+
this._add("OPTIONS", path, handler);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Register a HEAD route.
|
|
110
|
+
*
|
|
111
|
+
* Same as GET but returns headers only (no body).
|
|
112
|
+
*
|
|
113
|
+
* @param path Route path
|
|
114
|
+
* @param handler Route handler function
|
|
115
|
+
* @returns Router instance for chaining
|
|
116
|
+
*/
|
|
117
|
+
head(path, handler) {
|
|
118
|
+
this._add("HEAD", path, handler);
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Register a route for all HTTP methods.
|
|
123
|
+
*
|
|
124
|
+
* This registers the same handler for every supported HTTP method.
|
|
125
|
+
* Useful for middleware-like or catch-all behavior.
|
|
126
|
+
*
|
|
127
|
+
* @param path Route path
|
|
128
|
+
* @param handler Route handler function
|
|
129
|
+
* @returns Router instance for chaining
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* router.all("/health", (req, res) => res.send("OK"));
|
|
133
|
+
*/
|
|
134
|
+
all(path, handler) {
|
|
135
|
+
for (const method of METHODS) {
|
|
136
|
+
this._add(method, path, handler);
|
|
137
|
+
}
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Lookup a route handler based on the incoming request.
|
|
142
|
+
*
|
|
143
|
+
* This method is responsible for resolving the correct route
|
|
144
|
+
* from the registered router tree and executing the matched handler.
|
|
145
|
+
*
|
|
146
|
+
* It supports parameterized routes, static routes, and (optionally)
|
|
147
|
+
* wildcard matching depending on router implementation.
|
|
148
|
+
*
|
|
149
|
+
* @param req Incoming HTTP request object
|
|
150
|
+
* @param res Server response object used to send output
|
|
151
|
+
*
|
|
152
|
+
* @returns void
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* router.lookup(req, res);
|
|
156
|
+
*
|
|
157
|
+
* @internal
|
|
158
|
+
* This is typically called by the HTTP server layer and should not
|
|
159
|
+
* be invoked directly in most application code.
|
|
160
|
+
*/
|
|
161
|
+
lookup(req, res) {
|
|
162
|
+
const method = req.method;
|
|
163
|
+
let node = this.trees[method];
|
|
164
|
+
if (!node) {
|
|
165
|
+
res.statusCode = 405;
|
|
166
|
+
console.log({ method });
|
|
167
|
+
return res.end("Method Not Allowed");
|
|
168
|
+
}
|
|
169
|
+
let url = req.url || "/";
|
|
170
|
+
let q = url.indexOf("?");
|
|
171
|
+
if (q !== -1)
|
|
172
|
+
url = url.slice(0, q);
|
|
173
|
+
const params = Object.create(null);
|
|
174
|
+
const rootWildcard = node.wildcard;
|
|
175
|
+
let start = 1;
|
|
176
|
+
for (let i = 1; i <= url.length; i++) {
|
|
177
|
+
if (url[i] === "/" || i === url.length) {
|
|
178
|
+
const part = url.slice(start, i);
|
|
179
|
+
if (!part) {
|
|
180
|
+
start = i + 1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
let next = node.static[part];
|
|
184
|
+
if (next) {
|
|
185
|
+
node = next;
|
|
186
|
+
start = i + 1;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (node.param) {
|
|
190
|
+
params[node.param.paramName] = part;
|
|
191
|
+
node = node.param;
|
|
192
|
+
start = i + 1;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (node.wildcard) {
|
|
196
|
+
params["*"] = url.slice(start);
|
|
197
|
+
node = node.wildcard;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
if (rootWildcard?.handler) {
|
|
201
|
+
return rootWildcard.handler(req, res, params);
|
|
202
|
+
}
|
|
203
|
+
res.statusCode = 404;
|
|
204
|
+
res.end("Not Found");
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (!node.handler) {
|
|
209
|
+
if (rootWildcard?.handler) {
|
|
210
|
+
return rootWildcard.handler(req, res, params);
|
|
211
|
+
}
|
|
212
|
+
res.statusCode = 404;
|
|
213
|
+
return res.end("Not Found");
|
|
214
|
+
}
|
|
215
|
+
return node.handler(req, res, params);
|
|
216
|
+
}
|
|
217
|
+
_createNode() {
|
|
218
|
+
return { static: Object.create(null) };
|
|
219
|
+
}
|
|
220
|
+
_add(method, path, handler) {
|
|
221
|
+
let node = this.trees[method];
|
|
222
|
+
let start = 1;
|
|
223
|
+
for (let i = 1; i <= path.length; i++) {
|
|
224
|
+
if (path[i] === "/" || i === path.length) {
|
|
225
|
+
const part = path.slice(start, i);
|
|
226
|
+
if (!part) {
|
|
227
|
+
start = i + 1;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (part[0] === ":") {
|
|
231
|
+
if (!node.param) {
|
|
232
|
+
node.param = this._createNode();
|
|
233
|
+
node.param.paramName = part.slice(1);
|
|
234
|
+
}
|
|
235
|
+
node = node.param;
|
|
236
|
+
}
|
|
237
|
+
else if (part === "*") {
|
|
238
|
+
if (!node.wildcard) {
|
|
239
|
+
node.wildcard = this._createNode();
|
|
240
|
+
}
|
|
241
|
+
node = node.wildcard;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
if (!node.static[part]) {
|
|
246
|
+
node.static[part] = this._createNode();
|
|
247
|
+
}
|
|
248
|
+
node = node.static[part];
|
|
249
|
+
}
|
|
250
|
+
start = i + 1;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
node.handler = handler;
|
|
254
|
+
this._routes.push({
|
|
255
|
+
path,
|
|
256
|
+
method,
|
|
257
|
+
params: this._extractParams(path)
|
|
258
|
+
});
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
_extractParams(path) {
|
|
262
|
+
const params = [];
|
|
263
|
+
let start = 1;
|
|
264
|
+
for (let i = 1; i <= path.length; i++) {
|
|
265
|
+
if (path[i] === "/" || i === path.length) {
|
|
266
|
+
const part = path.slice(start, i);
|
|
267
|
+
if (part && part[0] === ":") {
|
|
268
|
+
params.push(part.slice(1));
|
|
269
|
+
}
|
|
270
|
+
start = i + 1;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return params;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.FastRouter = FastRouter;
|
|
277
|
+
//# sourceMappingURL=fast-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fast-router.js","sourceRoot":"","sources":["../../../../src/lib/core/server/fast-router.ts"],"names":[],"mappings":";;;AAiBA,MAAM,OAAO,GAAG;IACd,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;IAC7B,QAAQ,EAAE,SAAS,EAAE,MAAM;CACnB,CAAA;AAGV,MAAa,UAAU;IACb,KAAK,GAAyB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,GAAc,EAAE,CAAA;IAE/B;QACE,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACrC,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;OAWG;IACI,GAAG,CAAC,IAAY,EAAE,OAAgB;QACvC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACI,IAAI,CAAC,IAAY,EAAE,OAAgB;QACxC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACI,GAA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CAAC,CAAC;YAChB,CAAC;QACH,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,IAAI;YACJ,MAAM;YACN,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;SAClC,CAAC,CAAC;QAEH,OAAO;IACT,CAAC;IAEO,cAAc,CAAC,IAAY;QACjC,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBAElC,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,CAAC;gBAED,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAjUD,gCAiUC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server } from 'http';
|
|
2
|
-
import findMyWayRouter, { type Instance } from 'find-my-way';
|
|
3
2
|
import WebSocket from 'ws';
|
|
3
|
+
import { FastRouter } from './fast-router';
|
|
4
4
|
import { Router } from './router';
|
|
5
5
|
import type { T } from '../types';
|
|
6
6
|
/**
|
|
@@ -22,17 +22,15 @@ import type { T } from '../types';
|
|
|
22
22
|
declare class Spear {
|
|
23
23
|
private readonly _controllers?;
|
|
24
24
|
private readonly _middlewares?;
|
|
25
|
-
private readonly _globalPrefix;
|
|
26
25
|
private readonly _router;
|
|
27
26
|
private readonly _parser;
|
|
27
|
+
private _globalPrefix;
|
|
28
28
|
private _adapter;
|
|
29
29
|
private _cluster?;
|
|
30
30
|
private _cors?;
|
|
31
31
|
private _swagger;
|
|
32
32
|
private _swaggerSpecs;
|
|
33
|
-
private
|
|
34
|
-
private _ws?;
|
|
35
|
-
private _wsOptions?;
|
|
33
|
+
private _ws;
|
|
36
34
|
private _errorHandler;
|
|
37
35
|
private _globalMiddlewares;
|
|
38
36
|
private _formatResponse;
|
|
@@ -48,9 +46,9 @@ declare class Spear {
|
|
|
48
46
|
/**
|
|
49
47
|
* The get 'routers' method is used get the all routers.
|
|
50
48
|
*
|
|
51
|
-
* @returns {
|
|
49
|
+
* @returns {FastRouter}
|
|
52
50
|
*/
|
|
53
|
-
get routers():
|
|
51
|
+
get routers(): FastRouter;
|
|
54
52
|
/**
|
|
55
53
|
* The 'ws' method is used to creates the WebSocket server.
|
|
56
54
|
*
|
|
@@ -67,15 +65,25 @@ declare class Spear {
|
|
|
67
65
|
* @property {Function} next - go to next function
|
|
68
66
|
* @returns {this}
|
|
69
67
|
*/
|
|
70
|
-
use(middleware:
|
|
68
|
+
use(middleware: T.ContextHandler): this;
|
|
69
|
+
/**
|
|
70
|
+
* The 'useGlobalPrefix' method is used to sets a global prefix for all routes in the router.
|
|
71
|
+
*
|
|
72
|
+
* If `globalPrefix` is `null` or `undefined`, it will default to an empty string,
|
|
73
|
+
* meaning no prefix will be applied.
|
|
74
|
+
*
|
|
75
|
+
* @param {string | null} globalPrefix - The base path prefix to apply to all routes.
|
|
76
|
+
* @returns {this} Returns the current instance for method chaining.
|
|
77
|
+
*/
|
|
78
|
+
useGlobalPrefix(globalPrefix: string | null): this;
|
|
71
79
|
/**
|
|
72
80
|
* The 'useAdater' method is used to switch between different server implementations,
|
|
73
81
|
* such as the native Node.js HTTP server or uWebSockets.js (uWS).
|
|
74
82
|
*
|
|
75
|
-
* @param {T.
|
|
83
|
+
* @param {T.AdapterServer} adapter - The adapter instance (e.g., HTTP or uWS).
|
|
76
84
|
* @returns {this} Returns the current instance for chaining
|
|
77
85
|
*/
|
|
78
|
-
useAdater(adapter: T.
|
|
86
|
+
useAdater(adapter: T.AdapterServer): this;
|
|
79
87
|
/**
|
|
80
88
|
* The 'useCluster' method is used cluster run the server
|
|
81
89
|
*
|
|
@@ -108,11 +116,11 @@ declare class Spear {
|
|
|
108
116
|
* The 'useFileUpload' method is a middleware used to handler file uploads. It adds a file upload of incoming HTTP requests.
|
|
109
117
|
*
|
|
110
118
|
* @param {?Object}
|
|
111
|
-
* @property {?number} limits
|
|
119
|
+
* @property {?number} limits // bytes. default Infinity
|
|
112
120
|
* @property {?string} tempFileDir
|
|
113
121
|
* @property {?Object} removeTempFile
|
|
114
122
|
* @property {boolean} removeTempFile.remove
|
|
115
|
-
* @property {number}
|
|
123
|
+
* @property {number} removeTempFile.ms
|
|
116
124
|
* @returns
|
|
117
125
|
*/
|
|
118
126
|
useFileUpload({ limit, tempFileDir, removeTempFile }?: {
|
|
@@ -176,7 +184,7 @@ declare class Spear {
|
|
|
176
184
|
* @param {function} format
|
|
177
185
|
* @returns
|
|
178
186
|
*/
|
|
179
|
-
response(format: (r: unknown, statusCode: number) => any): this;
|
|
187
|
+
response(format: (r: unknown, statusCode: number) => Record<string, any> | string): this;
|
|
180
188
|
/**
|
|
181
189
|
* The 'catch' method is middleware that is specifically designed to handle errors.
|
|
182
190
|
*
|
|
@@ -185,14 +193,14 @@ declare class Spear {
|
|
|
185
193
|
* @param {function} error
|
|
186
194
|
* @returns
|
|
187
195
|
*/
|
|
188
|
-
catch(error: (err: any, ctx: T.Context) =>
|
|
196
|
+
catch(error: (err: any, ctx: T.Context) => T.Response): this;
|
|
189
197
|
/**
|
|
190
198
|
* The 'notfound' method is middleware that is specifically designed to handle errors notfound that occur during the processing of requests
|
|
191
199
|
*
|
|
192
200
|
* @param {function} fn
|
|
193
201
|
* @returns
|
|
194
202
|
*/
|
|
195
|
-
notfound(fn: (ctx: T.Context) =>
|
|
203
|
+
notfound(fn: (ctx: T.Context) => T.Response): this;
|
|
196
204
|
/**
|
|
197
205
|
* The 'get' method is used to add the request handler to the router for the 'GET' method.
|
|
198
206
|
*
|
|
@@ -202,7 +210,7 @@ declare class Spear {
|
|
|
202
210
|
* @property {Function} next - go to next function
|
|
203
211
|
* @returns {this}
|
|
204
212
|
*/
|
|
205
|
-
get(path: string, ...handlers:
|
|
213
|
+
get(path: string, ...handlers: T.ContextHandler[]): this;
|
|
206
214
|
/**
|
|
207
215
|
* The 'post' method is used to add the request handler to the router for the 'POST' method.
|
|
208
216
|
*
|
|
@@ -212,7 +220,7 @@ declare class Spear {
|
|
|
212
220
|
* @property {Function} next - go to next function
|
|
213
221
|
* @returns {this}
|
|
214
222
|
*/
|
|
215
|
-
post(path: string, ...handlers:
|
|
223
|
+
post(path: string, ...handlers: T.ContextHandler[]): this;
|
|
216
224
|
/**
|
|
217
225
|
* The 'put' method is used to add the request handler to the router for the 'PUT' method.
|
|
218
226
|
*
|
|
@@ -222,7 +230,7 @@ declare class Spear {
|
|
|
222
230
|
* @property {Function} next - go to next function
|
|
223
231
|
* @returns {this}
|
|
224
232
|
*/
|
|
225
|
-
put(path: string, ...handlers:
|
|
233
|
+
put(path: string, ...handlers: T.ContextHandler[]): this;
|
|
226
234
|
/**
|
|
227
235
|
* The 'patch' method is used to add the request handler to the router for the 'PATCH' method.
|
|
228
236
|
*
|
|
@@ -232,7 +240,7 @@ declare class Spear {
|
|
|
232
240
|
* @property {Function} next - go to next function
|
|
233
241
|
* @returns {this}
|
|
234
242
|
*/
|
|
235
|
-
patch(path: string, ...handlers:
|
|
243
|
+
patch(path: string, ...handlers: T.ContextHandler[]): this;
|
|
236
244
|
/**
|
|
237
245
|
* The 'delete' method is used to add the request handler to the router for the 'DELETE' method.
|
|
238
246
|
*
|
|
@@ -242,7 +250,7 @@ declare class Spear {
|
|
|
242
250
|
* @property {Function} next - go to next function
|
|
243
251
|
* @returns {this}
|
|
244
252
|
*/
|
|
245
|
-
delete(path: string, ...handlers:
|
|
253
|
+
delete(path: string, ...handlers: T.ContextHandler[]): this;
|
|
246
254
|
/**
|
|
247
255
|
* The 'head' method is used to add the request handler to the router for 'HEAD' methods.
|
|
248
256
|
*
|
|
@@ -252,7 +260,7 @@ declare class Spear {
|
|
|
252
260
|
* @property {function} next - go to next function
|
|
253
261
|
* @returns {this}
|
|
254
262
|
*/
|
|
255
|
-
head(path: string, ...handlers:
|
|
263
|
+
head(path: string, ...handlers: T.ContextHandler[]): this;
|
|
256
264
|
/**
|
|
257
265
|
* The 'head' method is used to add the request handler to the router for 'HEAD' methods.
|
|
258
266
|
*
|
|
@@ -262,9 +270,9 @@ declare class Spear {
|
|
|
262
270
|
* @property {function} next - go to next function
|
|
263
271
|
* @returns {this}
|
|
264
272
|
*/
|
|
265
|
-
options(path: string, ...handlers:
|
|
273
|
+
options(path: string, ...handlers: T.ContextHandler[]): this;
|
|
266
274
|
/**
|
|
267
|
-
* The '
|
|
275
|
+
* The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
|
|
268
276
|
*
|
|
269
277
|
* @param {string} path
|
|
270
278
|
* @callback {...Function[]} handlers of the middlewares
|
|
@@ -272,27 +280,16 @@ declare class Spear {
|
|
|
272
280
|
* @property {function} next - go to next function
|
|
273
281
|
* @returns {this}
|
|
274
282
|
*/
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
|
|
278
|
-
*
|
|
279
|
-
* @param {string} path
|
|
280
|
-
* @callback {...Function[]} handlers of the middlewares
|
|
281
|
-
* @property {object} ctx - context { req , res , query , params , cookies , files , body}
|
|
282
|
-
* @property {function} next - go to next function
|
|
283
|
-
* @returns {this}
|
|
284
|
-
*/
|
|
285
|
-
all(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
283
|
+
all(path: string, ...handlers: T.ContextHandler[]): this;
|
|
286
284
|
private _import;
|
|
287
285
|
private _registerControllers;
|
|
288
286
|
private _registerMiddlewares;
|
|
289
|
-
private _customizeResponse;
|
|
290
287
|
private _wrapHandlers;
|
|
291
288
|
private _wrapResponse;
|
|
292
|
-
private
|
|
289
|
+
private _nextError;
|
|
293
290
|
private _clusterMode;
|
|
294
291
|
private _createServer;
|
|
295
|
-
private
|
|
292
|
+
private _createContext;
|
|
296
293
|
private _normalizePath;
|
|
297
294
|
private _swaggerHandler;
|
|
298
295
|
}
|