@jwn-js/common 2.0.20 → 2.0.21
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/ApiError.d.ts +47 -47
- package/Jwt.d.ts +36 -36
- package/LICENSE +21 -21
- package/Memcached.d.ts +64 -64
- package/README.md +20 -20
- package/Server.d.ts +139 -139
- package/cookieParse.d.ts +4 -4
- package/cookieString.d.ts +9 -9
- package/docs/assets/highlight.css +1 -1
- package/docs/assets/main.js +2 -2
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +28 -2
- package/docs/classes/ApiError.html +8 -9
- package/docs/classes/AsyncJwt.html +4 -4
- package/docs/classes/Controller.html +7 -7
- package/docs/classes/Jwt.html +4 -4
- package/docs/classes/Memcached.html +8 -8
- package/docs/classes/Model.html +3 -3
- package/docs/classes/Server.html +9 -9
- package/docs/classes/Ssr.html +2 -2
- package/docs/classes/Web.html +3 -3
- package/docs/index.html +1 -1
- package/docs/interfaces/ApiErrorMessage.html +1 -1
- package/docs/interfaces/ContextSsr.html +9 -9
- package/docs/interfaces/ContextWeb.html +1 -1
- package/docs/interfaces/OptionsSsr.html +1 -1
- package/docs/interfaces/OptionsWeb.html +1 -1
- package/docs/interfaces/Route.html +1 -1
- package/docs/interfaces/Schema.html +1 -1
- package/docs/interfaces/ServerHandler.html +1 -1
- package/docs/interfaces/ServerOptions.html +1 -1
- package/docs/interfaces/ServerWebsocket.html +1 -1
- package/docs/modules.html +27 -27
- package/index.d.ts +904 -905
- package/jsonBody.d.ts +5 -5
- package/multipartBody.d.ts +27 -27
- package/package.json +3 -3
- package/readConfig.d.ts +4 -4
- package/readConfigSync.d.ts +4 -4
- package/staticBody.d.ts +17 -17
- package/urlencodedBody.d.ts +5 -5
package/ApiError.d.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Input params of error
|
|
3
|
-
*/
|
|
4
|
-
interface ApiErrorMessage {
|
|
5
|
-
message?: string;
|
|
6
|
-
code?: number;
|
|
7
|
-
statusCode?: number;
|
|
8
|
-
data?: Record<string, unknown>;
|
|
9
|
-
headers?: Record<string, string>;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* @class Api Error
|
|
13
|
-
* @description Base error class for @jwn-js
|
|
14
|
-
*/
|
|
15
|
-
declare class ApiError extends Error {
|
|
16
|
-
statusCode: number;
|
|
17
|
-
code: number;
|
|
18
|
-
data: Record<string, unknown>;
|
|
19
|
-
headers: Record<string, string>;
|
|
20
|
-
/**
|
|
21
|
-
* @constructor
|
|
22
|
-
* @param message
|
|
23
|
-
* @param code
|
|
24
|
-
* @param statusCode
|
|
25
|
-
*/
|
|
26
|
-
constructor(message?: string, code?: number, statusCode?: number);
|
|
27
|
-
constructor(params: ApiErrorMessage | string, code?: number, statusCode?: number);
|
|
28
|
-
/**
|
|
29
|
-
* Get error message
|
|
30
|
-
*/
|
|
31
|
-
getMessage(): string;
|
|
32
|
-
/**
|
|
33
|
-
* Get internal status code
|
|
34
|
-
*/
|
|
35
|
-
getStatusCode(): number;
|
|
36
|
-
/**
|
|
37
|
-
* Get internal error code
|
|
38
|
-
*/
|
|
39
|
-
getCode(): number;
|
|
40
|
-
/**
|
|
41
|
-
* Get error data
|
|
42
|
-
*/
|
|
43
|
-
getData(): Record<string, unknown>;
|
|
44
|
-
/**
|
|
45
|
-
* Get error headers
|
|
46
|
-
*/
|
|
47
|
-
getHeaders(): Record<string, string>;
|
|
1
|
+
/**
|
|
2
|
+
* Input params of error
|
|
3
|
+
*/
|
|
4
|
+
interface ApiErrorMessage {
|
|
5
|
+
message?: string;
|
|
6
|
+
code?: number;
|
|
7
|
+
statusCode?: number;
|
|
8
|
+
data?: Record<string, unknown>;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @class Api Error
|
|
13
|
+
* @description Base error class for @jwn-js
|
|
14
|
+
*/
|
|
15
|
+
declare class ApiError extends Error {
|
|
16
|
+
statusCode: number;
|
|
17
|
+
code: number;
|
|
18
|
+
data: Record<string, unknown>;
|
|
19
|
+
headers: Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* @constructor
|
|
22
|
+
* @param message
|
|
23
|
+
* @param code
|
|
24
|
+
* @param statusCode
|
|
25
|
+
*/
|
|
26
|
+
constructor(message?: string, code?: number, statusCode?: number);
|
|
27
|
+
constructor(params: ApiErrorMessage | string, code?: number, statusCode?: number);
|
|
28
|
+
/**
|
|
29
|
+
* Get error message
|
|
30
|
+
*/
|
|
31
|
+
getMessage(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Get internal status code
|
|
34
|
+
*/
|
|
35
|
+
getStatusCode(): number;
|
|
36
|
+
/**
|
|
37
|
+
* Get internal error code
|
|
38
|
+
*/
|
|
39
|
+
getCode(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Get error data
|
|
42
|
+
*/
|
|
43
|
+
getData(): Record<string, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Get error headers
|
|
46
|
+
*/
|
|
47
|
+
getHeaders(): Record<string, string>;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export { ApiError, ApiErrorMessage };
|
package/Jwt.d.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @class Jwt
|
|
3
|
-
* @description working with jwt tokens
|
|
4
|
-
*/
|
|
5
|
-
declare class Jwt {
|
|
6
|
-
private readonly secret;
|
|
7
|
-
private readonly algorithm;
|
|
8
|
-
/**
|
|
9
|
-
* @constructor
|
|
10
|
-
* @param secret
|
|
11
|
-
* @param opt addition options
|
|
12
|
-
*/
|
|
13
|
-
constructor(secret: string, opt?: {
|
|
14
|
-
algorithm: string;
|
|
15
|
-
});
|
|
16
|
-
/**
|
|
17
|
-
* Verify jwt token
|
|
18
|
-
* @param jwt token
|
|
19
|
-
* @returns is token valid
|
|
20
|
-
*/
|
|
21
|
-
verify(jwt: string): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Get token
|
|
24
|
-
* @param data - user data
|
|
25
|
-
* @returns jwt
|
|
26
|
-
*/
|
|
27
|
-
sign(data: any): string;
|
|
28
|
-
/**
|
|
29
|
-
* Decode token
|
|
30
|
-
* @param jwt - jwt token
|
|
31
|
-
* @returns {head, body}
|
|
32
|
-
*/
|
|
33
|
-
decode(jwt: string): {
|
|
34
|
-
head: any;
|
|
35
|
-
body: any;
|
|
36
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @class Jwt
|
|
3
|
+
* @description working with jwt tokens
|
|
4
|
+
*/
|
|
5
|
+
declare class Jwt {
|
|
6
|
+
private readonly secret;
|
|
7
|
+
private readonly algorithm;
|
|
8
|
+
/**
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param secret
|
|
11
|
+
* @param opt addition options
|
|
12
|
+
*/
|
|
13
|
+
constructor(secret: string, opt?: {
|
|
14
|
+
algorithm: string;
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Verify jwt token
|
|
18
|
+
* @param jwt token
|
|
19
|
+
* @returns is token valid
|
|
20
|
+
*/
|
|
21
|
+
verify(jwt: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get token
|
|
24
|
+
* @param data - user data
|
|
25
|
+
* @returns jwt
|
|
26
|
+
*/
|
|
27
|
+
sign(data: any): string;
|
|
28
|
+
/**
|
|
29
|
+
* Decode token
|
|
30
|
+
* @param jwt - jwt token
|
|
31
|
+
* @returns {head, body}
|
|
32
|
+
*/
|
|
33
|
+
decode(jwt: string): {
|
|
34
|
+
head: any;
|
|
35
|
+
body: any;
|
|
36
|
+
};
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export { Jwt };
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Igor
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Igor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Memcached.d.ts
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
import { Client } from 'memjs';
|
|
2
2
|
|
|
3
|
-
declare class Memcached {
|
|
4
|
-
memjs: Client | null;
|
|
5
|
-
specialHeaders: Record<string, any>;
|
|
6
|
-
maxKeyLength: number;
|
|
7
|
-
debug: number;
|
|
8
|
-
prefix: string;
|
|
9
|
-
/**
|
|
10
|
-
* @constructor
|
|
11
|
-
* @param memjs - memjs Client instance
|
|
12
|
-
* @param specialHeaders - special headers
|
|
13
|
-
* @param maxKeyLength - max key length
|
|
14
|
-
* @param debug
|
|
15
|
-
*/
|
|
16
|
-
constructor(memjs: Client | null, specialHeaders?: {
|
|
17
|
-
'x-cache': string;
|
|
18
|
-
}, maxKeyLength?: number, debug?: number);
|
|
19
|
-
/**
|
|
20
|
-
* Is Client exists
|
|
21
|
-
*/
|
|
22
|
-
isClient(): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Is in client is one or more conected servers
|
|
25
|
-
*/
|
|
26
|
-
isConnectedServers(): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Set value to memcache
|
|
29
|
-
* @param key string key
|
|
30
|
-
* @param value value
|
|
31
|
-
* @param expires expiers in second
|
|
32
|
-
*/
|
|
33
|
-
setValue(key: string, value: string | Buffer, expires: number | undefined | null): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Get value from memory
|
|
36
|
-
* @param key string key
|
|
37
|
-
*/
|
|
38
|
-
getValue(key: string): Promise<null | Buffer>;
|
|
39
|
-
/**
|
|
40
|
-
* Delete value
|
|
41
|
-
* @param key
|
|
42
|
-
*/
|
|
43
|
-
deleteValue(key: string): Promise<boolean>;
|
|
44
|
-
/**
|
|
45
|
-
* Set page to cache
|
|
46
|
-
* @param url https://yur.site.net
|
|
47
|
-
* @param headers
|
|
48
|
-
* @param data eny data string or Buffer
|
|
49
|
-
* @param expires
|
|
50
|
-
*/
|
|
51
|
-
setPage(url: string, headers: Record<string, any>, data: string | Buffer, expires: number | undefined | null): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Get Page and headers
|
|
54
|
-
* @param url https://your.site.net
|
|
55
|
-
* @returns {data, headers}
|
|
56
|
-
*/
|
|
57
|
-
getPage(url: string): Promise<null | {
|
|
58
|
-
data: Buffer;
|
|
59
|
-
headers: Record<string, any>;
|
|
60
|
-
}>;
|
|
61
|
-
/**
|
|
62
|
-
* Keys to lower case in Object
|
|
63
|
-
* @param o
|
|
64
|
-
* @private
|
|
65
|
-
*/
|
|
66
|
-
private objectKeysToLower;
|
|
3
|
+
declare class Memcached {
|
|
4
|
+
memjs: Client | null;
|
|
5
|
+
specialHeaders: Record<string, any>;
|
|
6
|
+
maxKeyLength: number;
|
|
7
|
+
debug: number;
|
|
8
|
+
prefix: string;
|
|
9
|
+
/**
|
|
10
|
+
* @constructor
|
|
11
|
+
* @param memjs - memjs Client instance
|
|
12
|
+
* @param specialHeaders - special headers
|
|
13
|
+
* @param maxKeyLength - max key length
|
|
14
|
+
* @param debug
|
|
15
|
+
*/
|
|
16
|
+
constructor(memjs: Client | null, specialHeaders?: {
|
|
17
|
+
'x-cache': string;
|
|
18
|
+
}, maxKeyLength?: number, debug?: number);
|
|
19
|
+
/**
|
|
20
|
+
* Is Client exists
|
|
21
|
+
*/
|
|
22
|
+
isClient(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Is in client is one or more conected servers
|
|
25
|
+
*/
|
|
26
|
+
isConnectedServers(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Set value to memcache
|
|
29
|
+
* @param key string key
|
|
30
|
+
* @param value value
|
|
31
|
+
* @param expires expiers in second
|
|
32
|
+
*/
|
|
33
|
+
setValue(key: string, value: string | Buffer, expires: number | undefined | null): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Get value from memory
|
|
36
|
+
* @param key string key
|
|
37
|
+
*/
|
|
38
|
+
getValue(key: string): Promise<null | Buffer>;
|
|
39
|
+
/**
|
|
40
|
+
* Delete value
|
|
41
|
+
* @param key
|
|
42
|
+
*/
|
|
43
|
+
deleteValue(key: string): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Set page to cache
|
|
46
|
+
* @param url https://yur.site.net
|
|
47
|
+
* @param headers
|
|
48
|
+
* @param data eny data string or Buffer
|
|
49
|
+
* @param expires
|
|
50
|
+
*/
|
|
51
|
+
setPage(url: string, headers: Record<string, any>, data: string | Buffer, expires: number | undefined | null): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get Page and headers
|
|
54
|
+
* @param url https://your.site.net
|
|
55
|
+
* @returns {data, headers}
|
|
56
|
+
*/
|
|
57
|
+
getPage(url: string): Promise<null | {
|
|
58
|
+
data: Buffer;
|
|
59
|
+
headers: Record<string, any>;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Keys to lower case in Object
|
|
63
|
+
* @param o
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
private objectKeysToLower;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export { Memcached };
|
package/README.md
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
<h1 align="center"> @jwn-js/common </h1>
|
|
2
|
-
<p align="center">
|
|
3
|
-
<b>@jwn-js/common utils for build server on node js</b>
|
|
4
|
-
</p>
|
|
5
|
-
|
|
6
|
-
## Installation
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
yarn add @jwn-js/common
|
|
10
|
-
```
|
|
11
|
-
or
|
|
12
|
-
```bash
|
|
13
|
-
npm i @jwn-js/common
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### Docs
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
./docs
|
|
20
|
-
```
|
|
1
|
+
<h1 align="center"> @jwn-js/common </h1>
|
|
2
|
+
<p align="center">
|
|
3
|
+
<b>@jwn-js/common utils for build server on node js</b>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
yarn add @jwn-js/common
|
|
10
|
+
```
|
|
11
|
+
or
|
|
12
|
+
```bash
|
|
13
|
+
npm i @jwn-js/common
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Docs
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
./docs
|
|
20
|
+
```
|
package/Server.d.ts
CHANGED
|
@@ -1,144 +1,144 @@
|
|
|
1
1
|
import { RecognizedString, HttpResponse, HttpRequest, WebSocketBehavior, AppOptions, TemplatedApp } from 'uWebSockets.js';
|
|
2
2
|
|
|
3
|
-
declare module 'uWebSockets.js' {
|
|
4
|
-
interface HttpRequest {
|
|
5
|
-
cookies: Record<string, any>;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
interface Handler {
|
|
9
|
-
method?: 'any' | 'connect' | 'del' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
10
|
-
pattern?: RecognizedString;
|
|
11
|
-
handler: (res: HttpResponse, req: HttpRequest, next: CallableFunction) => void | Promise<void | boolean | Error | string>;
|
|
12
|
-
}
|
|
13
|
-
interface WebSocket {
|
|
14
|
-
method: 'ws';
|
|
15
|
-
pattern?: RecognizedString;
|
|
16
|
-
behavior: WebSocketBehavior;
|
|
17
|
-
}
|
|
18
|
-
declare type Routes = Array<Handler | WebSocket | CallableFunction>;
|
|
19
|
-
interface Options {
|
|
20
|
-
routes: Routes;
|
|
21
|
-
host?: string;
|
|
22
|
-
port?: number;
|
|
23
|
-
timeout?: number;
|
|
24
|
-
mode?: "development" | "production";
|
|
25
|
-
appOptions?: AppOptions;
|
|
26
|
-
logLevel?: "info" | "warn" | "error" | "silent";
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Status code to string
|
|
30
|
-
*/
|
|
31
|
-
declare const codeToStatus: (code: number) => any;
|
|
32
|
-
/**
|
|
33
|
-
* Create server
|
|
34
|
-
*/
|
|
35
|
-
declare class Server {
|
|
36
|
-
private _logLevel;
|
|
37
|
-
/**
|
|
38
|
-
* Listen socket
|
|
39
|
-
* @private
|
|
40
|
-
*/
|
|
41
|
-
private _socket;
|
|
42
|
-
/**
|
|
43
|
-
* Request timeout
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
private readonly _timeout;
|
|
47
|
-
private readonly _routes;
|
|
48
|
-
private _host;
|
|
49
|
-
private _port;
|
|
50
|
-
private readonly _mode;
|
|
51
|
-
private readonly _appOptions;
|
|
52
|
-
private _app;
|
|
53
|
-
private _protocol;
|
|
54
|
-
/**
|
|
55
|
-
*Timeout identification
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
private _timeoutId;
|
|
59
|
-
/**
|
|
60
|
-
* Default route options
|
|
61
|
-
* @private
|
|
62
|
-
*/
|
|
63
|
-
private _defaultRoute;
|
|
64
|
-
/**
|
|
65
|
-
* @constructor
|
|
66
|
-
* @param options
|
|
67
|
-
*/
|
|
68
|
-
constructor(options: Options);
|
|
69
|
-
/**
|
|
70
|
-
* Get TemplatedApp instance
|
|
71
|
-
*/
|
|
72
|
-
getApp(): TemplatedApp;
|
|
73
|
-
/**
|
|
74
|
-
* Create app (server http)
|
|
75
|
-
* @returns this
|
|
76
|
-
*/
|
|
77
|
-
app(): this;
|
|
78
|
-
/**
|
|
79
|
-
* Create sslApp
|
|
80
|
-
* @returns this
|
|
81
|
-
*/
|
|
82
|
-
sslApp(): this;
|
|
83
|
-
/**
|
|
84
|
-
* Push route
|
|
85
|
-
* @param route
|
|
86
|
-
* @returns this
|
|
87
|
-
*/
|
|
88
|
-
push(route: Handler | WebSocket | CallableFunction): this;
|
|
89
|
-
/**
|
|
90
|
-
* unshift route
|
|
91
|
-
* @param route
|
|
92
|
-
* @returns this
|
|
93
|
-
*/
|
|
94
|
-
unshift(route: Handler | WebSocket | CallableFunction): this;
|
|
95
|
-
/**
|
|
96
|
-
* Create server listener
|
|
97
|
-
* @param host - host or port
|
|
98
|
-
* @param port
|
|
99
|
-
* @param fn
|
|
100
|
-
* @returns this
|
|
101
|
-
*/
|
|
102
|
-
listen(host: string, port: number, fn?: CallableFunction): this;
|
|
103
|
-
listen(port: number, fn?: CallableFunction): this;
|
|
104
|
-
listen(fn?: CallableFunction): this;
|
|
105
|
-
/**
|
|
106
|
-
* Closes a uSockets listen socket.
|
|
107
|
-
*/
|
|
108
|
-
close(): Promise<this>;
|
|
109
|
-
/**
|
|
110
|
-
* Return socket port
|
|
111
|
-
*/
|
|
112
|
-
socketPort(): Promise<number>;
|
|
113
|
-
/**
|
|
114
|
-
* Create decoration of handler
|
|
115
|
-
* @param res http response
|
|
116
|
-
* @param req http request
|
|
117
|
-
* @param fn handler
|
|
118
|
-
* @private
|
|
119
|
-
*/
|
|
120
|
-
private _createHandler;
|
|
121
|
-
/**
|
|
122
|
-
* Redirect request
|
|
123
|
-
* @param res
|
|
124
|
-
* @param req
|
|
125
|
-
* @param url string of url
|
|
126
|
-
* @param code redirect status code
|
|
127
|
-
* @private
|
|
128
|
-
*/
|
|
129
|
-
private static _redirect;
|
|
130
|
-
/**
|
|
131
|
-
* Abort request by timeout
|
|
132
|
-
* @private
|
|
133
|
-
*/
|
|
134
|
-
private _abortTimeout;
|
|
135
|
-
/**
|
|
136
|
-
* lookup for host
|
|
137
|
-
* @param host
|
|
138
|
-
* @param resolve
|
|
139
|
-
* @private
|
|
140
|
-
*/
|
|
141
|
-
private _lookup;
|
|
3
|
+
declare module 'uWebSockets.js' {
|
|
4
|
+
interface HttpRequest {
|
|
5
|
+
cookies: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface Handler {
|
|
9
|
+
method?: 'any' | 'connect' | 'del' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
10
|
+
pattern?: RecognizedString;
|
|
11
|
+
handler: (res: HttpResponse, req: HttpRequest, next: CallableFunction) => void | Promise<void | boolean | Error | string>;
|
|
12
|
+
}
|
|
13
|
+
interface WebSocket {
|
|
14
|
+
method: 'ws';
|
|
15
|
+
pattern?: RecognizedString;
|
|
16
|
+
behavior: WebSocketBehavior;
|
|
17
|
+
}
|
|
18
|
+
declare type Routes = Array<Handler | WebSocket | CallableFunction>;
|
|
19
|
+
interface Options {
|
|
20
|
+
routes: Routes;
|
|
21
|
+
host?: string;
|
|
22
|
+
port?: number;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
mode?: "development" | "production";
|
|
25
|
+
appOptions?: AppOptions;
|
|
26
|
+
logLevel?: "info" | "warn" | "error" | "silent";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Status code to string
|
|
30
|
+
*/
|
|
31
|
+
declare const codeToStatus: (code: number) => any;
|
|
32
|
+
/**
|
|
33
|
+
* Create server
|
|
34
|
+
*/
|
|
35
|
+
declare class Server {
|
|
36
|
+
private _logLevel;
|
|
37
|
+
/**
|
|
38
|
+
* Listen socket
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
private _socket;
|
|
42
|
+
/**
|
|
43
|
+
* Request timeout
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
private readonly _timeout;
|
|
47
|
+
private readonly _routes;
|
|
48
|
+
private _host;
|
|
49
|
+
private _port;
|
|
50
|
+
private readonly _mode;
|
|
51
|
+
private readonly _appOptions;
|
|
52
|
+
private _app;
|
|
53
|
+
private _protocol;
|
|
54
|
+
/**
|
|
55
|
+
*Timeout identification
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
private _timeoutId;
|
|
59
|
+
/**
|
|
60
|
+
* Default route options
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
private _defaultRoute;
|
|
64
|
+
/**
|
|
65
|
+
* @constructor
|
|
66
|
+
* @param options
|
|
67
|
+
*/
|
|
68
|
+
constructor(options: Options);
|
|
69
|
+
/**
|
|
70
|
+
* Get TemplatedApp instance
|
|
71
|
+
*/
|
|
72
|
+
getApp(): TemplatedApp;
|
|
73
|
+
/**
|
|
74
|
+
* Create app (server http)
|
|
75
|
+
* @returns this
|
|
76
|
+
*/
|
|
77
|
+
app(): this;
|
|
78
|
+
/**
|
|
79
|
+
* Create sslApp
|
|
80
|
+
* @returns this
|
|
81
|
+
*/
|
|
82
|
+
sslApp(): this;
|
|
83
|
+
/**
|
|
84
|
+
* Push route
|
|
85
|
+
* @param route
|
|
86
|
+
* @returns this
|
|
87
|
+
*/
|
|
88
|
+
push(route: Handler | WebSocket | CallableFunction): this;
|
|
89
|
+
/**
|
|
90
|
+
* unshift route
|
|
91
|
+
* @param route
|
|
92
|
+
* @returns this
|
|
93
|
+
*/
|
|
94
|
+
unshift(route: Handler | WebSocket | CallableFunction): this;
|
|
95
|
+
/**
|
|
96
|
+
* Create server listener
|
|
97
|
+
* @param host - host or port
|
|
98
|
+
* @param port
|
|
99
|
+
* @param fn
|
|
100
|
+
* @returns this
|
|
101
|
+
*/
|
|
102
|
+
listen(host: string, port: number, fn?: CallableFunction): this;
|
|
103
|
+
listen(port: number, fn?: CallableFunction): this;
|
|
104
|
+
listen(fn?: CallableFunction): this;
|
|
105
|
+
/**
|
|
106
|
+
* Closes a uSockets listen socket.
|
|
107
|
+
*/
|
|
108
|
+
close(): Promise<this>;
|
|
109
|
+
/**
|
|
110
|
+
* Return socket port
|
|
111
|
+
*/
|
|
112
|
+
socketPort(): Promise<number>;
|
|
113
|
+
/**
|
|
114
|
+
* Create decoration of handler
|
|
115
|
+
* @param res http response
|
|
116
|
+
* @param req http request
|
|
117
|
+
* @param fn handler
|
|
118
|
+
* @private
|
|
119
|
+
*/
|
|
120
|
+
private _createHandler;
|
|
121
|
+
/**
|
|
122
|
+
* Redirect request
|
|
123
|
+
* @param res
|
|
124
|
+
* @param req
|
|
125
|
+
* @param url string of url
|
|
126
|
+
* @param code redirect status code
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
private static _redirect;
|
|
130
|
+
/**
|
|
131
|
+
* Abort request by timeout
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
private _abortTimeout;
|
|
135
|
+
/**
|
|
136
|
+
* lookup for host
|
|
137
|
+
* @param host
|
|
138
|
+
* @param resolve
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
141
|
+
private _lookup;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
export { Handler, Options, Routes, Server, WebSocket, codeToStatus };
|