@heliosjs/http 1.0.1
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 +540 -0
- package/dist/Application.d.ts +32 -0
- package/dist/Application.js +269 -0
- package/dist/Application.js.map +1 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.js +34 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators.d.ts +43 -0
- package/dist/decorators.js +81 -0
- package/dist/decorators.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/socket/decorators.d.ts +77 -0
- package/dist/socket/decorators.js +112 -0
- package/dist/socket/decorators.js.map +1 -0
- package/dist/socket/index.d.ts +1 -0
- package/dist/socket/index.js +18 -0
- package/dist/socket/index.js.map +1 -0
- package/dist/sse/decorators.d.ts +52 -0
- package/dist/sse/decorators.js +76 -0
- package/dist/sse/decorators.js.map +1 -0
- package/dist/sse/index.d.ts +1 -0
- package/dist/sse/index.js +18 -0
- package/dist/sse/index.js.map +1 -0
- package/dist/types/core/common.d.ts +44 -0
- package/dist/types/core/common.js +15 -0
- package/dist/types/core/common.js.map +1 -0
- package/dist/types/core/controller.d.ts +78 -0
- package/dist/types/core/controller.js +3 -0
- package/dist/types/core/controller.js.map +1 -0
- package/dist/types/core/cors.d.ts +10 -0
- package/dist/types/core/cors.js +3 -0
- package/dist/types/core/cors.js.map +1 -0
- package/dist/types/core/error.d.ts +72 -0
- package/dist/types/core/error.js +19 -0
- package/dist/types/core/error.js.map +1 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/index.js +26 -0
- package/dist/types/core/index.js.map +1 -0
- package/dist/types/core/multipart.d.ts +8 -0
- package/dist/types/core/multipart.js +3 -0
- package/dist/types/core/multipart.js.map +1 -0
- package/dist/types/core/request.d.ts +65 -0
- package/dist/types/core/request.js +3 -0
- package/dist/types/core/request.js.map +1 -0
- package/dist/types/core/response.d.ts +49 -0
- package/dist/types/core/response.js +3 -0
- package/dist/types/core/response.js.map +1 -0
- package/dist/types/core/sanitize.d.ts +8 -0
- package/dist/types/core/sanitize.js +3 -0
- package/dist/types/core/sanitize.js.map +1 -0
- package/dist/types/core/sse.d.ts +37 -0
- package/dist/types/core/sse.js +3 -0
- package/dist/types/core/sse.js.map +1 -0
- package/dist/types/http/http.d.ts +111 -0
- package/dist/types/http/http.js +3 -0
- package/dist/types/http/http.js.map +1 -0
- package/dist/types/http/index.d.ts +3 -0
- package/dist/types/http/index.js +20 -0
- package/dist/types/http/index.js.map +1 -0
- package/dist/types/http/plugin.d.ts +18 -0
- package/dist/types/http/plugin.js +3 -0
- package/dist/types/http/plugin.js.map +1 -0
- package/dist/types/http/static.d.ts +24 -0
- package/dist/types/http/static.js +3 -0
- package/dist/types/http/static.js.map +1 -0
- package/dist/types/ws/index.d.ts +50 -0
- package/dist/types/ws/index.js +3 -0
- package/dist/types/ws/index.js.map +1 -0
- package/dist/utils/core/controller.d.ts +25 -0
- package/dist/utils/core/controller.js +219 -0
- package/dist/utils/core/controller.js.map +1 -0
- package/dist/utils/core/cors.d.ts +8 -0
- package/dist/utils/core/cors.js +128 -0
- package/dist/utils/core/cors.js.map +1 -0
- package/dist/utils/core/endpoint.d.ts +3 -0
- package/dist/utils/core/endpoint.js +28 -0
- package/dist/utils/core/endpoint.js.map +1 -0
- package/dist/utils/core/error/apperror.d.ts +31 -0
- package/dist/utils/core/error/apperror.js +131 -0
- package/dist/utils/core/error/apperror.js.map +1 -0
- package/dist/utils/core/error/authorizations.d.ts +7 -0
- package/dist/utils/core/error/authorizations.js +17 -0
- package/dist/utils/core/error/authorizations.js.map +1 -0
- package/dist/utils/core/error/base.d.ts +20 -0
- package/dist/utils/core/error/base.js +52 -0
- package/dist/utils/core/error/base.js.map +1 -0
- package/dist/utils/core/error/dependencyFailed.d.ts +7 -0
- package/dist/utils/core/error/dependencyFailed.js +17 -0
- package/dist/utils/core/error/dependencyFailed.js.map +1 -0
- package/dist/utils/core/error/duplicateEntry.d.ts +7 -0
- package/dist/utils/core/error/duplicateEntry.js +17 -0
- package/dist/utils/core/error/duplicateEntry.js.map +1 -0
- package/dist/utils/core/error/forbidden.d.ts +7 -0
- package/dist/utils/core/error/forbidden.js +17 -0
- package/dist/utils/core/error/forbidden.js.map +1 -0
- package/dist/utils/core/error/helpers.d.ts +8 -0
- package/dist/utils/core/error/helpers.js +144 -0
- package/dist/utils/core/error/helpers.js.map +1 -0
- package/dist/utils/core/error/index.d.ts +12 -0
- package/dist/utils/core/error/index.js +29 -0
- package/dist/utils/core/error/index.js.map +1 -0
- package/dist/utils/core/error/invalidState.d.ts +7 -0
- package/dist/utils/core/error/invalidState.js +17 -0
- package/dist/utils/core/error/invalidState.js.map +1 -0
- package/dist/utils/core/error/notfound.d.ts +7 -0
- package/dist/utils/core/error/notfound.js +18 -0
- package/dist/utils/core/error/notfound.js.map +1 -0
- package/dist/utils/core/error/rateLimit.d.ts +7 -0
- package/dist/utils/core/error/rateLimit.js +17 -0
- package/dist/utils/core/error/rateLimit.js.map +1 -0
- package/dist/utils/core/error/serviceUnavailable.d.ts +7 -0
- package/dist/utils/core/error/serviceUnavailable.js +17 -0
- package/dist/utils/core/error/serviceUnavailable.js.map +1 -0
- package/dist/utils/core/error/validation.d.ts +10 -0
- package/dist/utils/core/error/validation.js +20 -0
- package/dist/utils/core/error/validation.js.map +1 -0
- package/dist/utils/core/headers.d.ts +2 -0
- package/dist/utils/core/headers.js +10 -0
- package/dist/utils/core/headers.js.map +1 -0
- package/dist/utils/core/helper.d.ts +6 -0
- package/dist/utils/core/helper.js +66 -0
- package/dist/utils/core/helper.js.map +1 -0
- package/dist/utils/core/index.d.ts +10 -0
- package/dist/utils/core/index.js +27 -0
- package/dist/utils/core/index.js.map +1 -0
- package/dist/utils/core/multipart.d.ts +9 -0
- package/dist/utils/core/multipart.js +207 -0
- package/dist/utils/core/multipart.js.map +1 -0
- package/dist/utils/core/request.d.ts +100 -0
- package/dist/utils/core/request.js +218 -0
- package/dist/utils/core/request.js.map +1 -0
- package/dist/utils/core/response.d.ts +48 -0
- package/dist/utils/core/response.js +269 -0
- package/dist/utils/core/response.js.map +1 -0
- package/dist/utils/core/routeWalker.d.ts +2 -0
- package/dist/utils/core/routeWalker.js +115 -0
- package/dist/utils/core/routeWalker.js.map +1 -0
- package/dist/utils/core/sanitize.d.ts +30 -0
- package/dist/utils/core/sanitize.js +134 -0
- package/dist/utils/core/sanitize.js.map +1 -0
- package/dist/utils/http/index.d.ts +5 -0
- package/dist/utils/http/index.js +22 -0
- package/dist/utils/http/index.js.map +1 -0
- package/dist/utils/http/plugin.d.ts +9 -0
- package/dist/utils/http/plugin.js +43 -0
- package/dist/utils/http/plugin.js.map +1 -0
- package/dist/utils/http/request.factory.d.ts +8 -0
- package/dist/utils/http/request.factory.js +55 -0
- package/dist/utils/http/request.factory.js.map +1 -0
- package/dist/utils/http/response.factory.d.ts +9 -0
- package/dist/utils/http/response.factory.js +14 -0
- package/dist/utils/http/response.factory.js.map +1 -0
- package/dist/utils/http/server.d.ts +18 -0
- package/dist/utils/http/server.js +58 -0
- package/dist/utils/http/server.js.map +1 -0
- package/dist/utils/http/static.d.ts +3 -0
- package/dist/utils/http/static.js +151 -0
- package/dist/utils/http/static.js.map +1 -0
- package/dist/utils/shared/index.d.ts +2 -0
- package/dist/utils/shared/index.js +19 -0
- package/dist/utils/shared/index.js.map +1 -0
- package/dist/utils/shared/parsers.d.ts +11 -0
- package/dist/utils/shared/parsers.js +133 -0
- package/dist/utils/shared/parsers.js.map +1 -0
- package/dist/utils/shared/validate.d.ts +1 -0
- package/dist/utils/shared/validate.js +41 -0
- package/dist/utils/shared/validate.js.map +1 -0
- package/dist/utils/socket/index.d.ts +3 -0
- package/dist/utils/socket/index.js +20 -0
- package/dist/utils/socket/index.js.map +1 -0
- package/dist/utils/socket/server.d.ts +33 -0
- package/dist/utils/socket/server.js +218 -0
- package/dist/utils/socket/server.js.map +1 -0
- package/dist/utils/socket/service.d.ts +20 -0
- package/dist/utils/socket/service.js +42 -0
- package/dist/utils/socket/service.js.map +1 -0
- package/dist/utils/socket/socket.d.ts +16 -0
- package/dist/utils/socket/socket.js +33 -0
- package/dist/utils/socket/socket.js.map +1 -0
- package/dist/utils/sse/index.d.ts +2 -0
- package/dist/utils/sse/index.js +19 -0
- package/dist/utils/sse/index.js.map +1 -0
- package/dist/utils/sse/server.d.ts +14 -0
- package/dist/utils/sse/server.js +85 -0
- package/dist/utils/sse/server.js.map +1 -0
- package/dist/utils/sse/service.d.ts +17 -0
- package/dist/utils/sse/service.js +40 -0
- package/dist/utils/sse/service.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { IncomingHttpHeaders } from 'http';
|
|
2
|
+
export type RequestSource = 'http' | 'lambda' | 'unknown';
|
|
3
|
+
export type EventType = 'apigateway' | 'apigatewayv2' | 'alb' | 'cloudfront' | 's3' | 'sns' | 'sqs' | 'dynamodb' | 'unknown';
|
|
4
|
+
export interface RequestOptions {
|
|
5
|
+
method: string;
|
|
6
|
+
requestUrl: URL;
|
|
7
|
+
url: string;
|
|
8
|
+
path: string;
|
|
9
|
+
headers: Record<string, string | string[]>;
|
|
10
|
+
query: Record<string, string | string[]>;
|
|
11
|
+
body: any;
|
|
12
|
+
params: Record<string, string>;
|
|
13
|
+
cookies: Record<string, string>;
|
|
14
|
+
sourceIp?: string;
|
|
15
|
+
userAgent?: string;
|
|
16
|
+
requestId: string;
|
|
17
|
+
stage?: string;
|
|
18
|
+
timestamp: Date;
|
|
19
|
+
raw?: any;
|
|
20
|
+
context?: any;
|
|
21
|
+
rawBody?: any;
|
|
22
|
+
event?: unknown;
|
|
23
|
+
isBase64Encoded?: boolean;
|
|
24
|
+
source: RequestSource;
|
|
25
|
+
}
|
|
26
|
+
export interface IRequest {
|
|
27
|
+
method: string;
|
|
28
|
+
path: string;
|
|
29
|
+
url: string;
|
|
30
|
+
requestUrl: URL;
|
|
31
|
+
headers: Record<string, string | string[]>;
|
|
32
|
+
query: Record<string, string | string[]>;
|
|
33
|
+
body: any;
|
|
34
|
+
params: Record<string, string>;
|
|
35
|
+
cookies: Record<string, string>;
|
|
36
|
+
sourceIp: string;
|
|
37
|
+
userAgent: string;
|
|
38
|
+
requestId: string;
|
|
39
|
+
stage: string;
|
|
40
|
+
timestamp: Date;
|
|
41
|
+
source: RequestSource;
|
|
42
|
+
raw: any;
|
|
43
|
+
context: any;
|
|
44
|
+
rawBody: any;
|
|
45
|
+
isBase64Encoded: any;
|
|
46
|
+
startTime: number;
|
|
47
|
+
getHeader(name: string): string | string[] | undefined;
|
|
48
|
+
getCookie(name: string): string | undefined;
|
|
49
|
+
getQuery(name: string): string | string[] | undefined;
|
|
50
|
+
getParam(name: string): string | undefined;
|
|
51
|
+
isHttp(): boolean;
|
|
52
|
+
isLambda(): boolean;
|
|
53
|
+
getLambdaEvent(): unknown;
|
|
54
|
+
getLambdaContext(): unknown;
|
|
55
|
+
getHttpRequest(): IncomingHttpHeaders | undefined;
|
|
56
|
+
setState(key: string, value: any): void;
|
|
57
|
+
getState<T = any>(key: string): T | undefined;
|
|
58
|
+
getAllState(): Map<string, any>;
|
|
59
|
+
isSecure(): boolean;
|
|
60
|
+
getClientIp(): string;
|
|
61
|
+
getHost(): string;
|
|
62
|
+
getFullUrl(): string;
|
|
63
|
+
clone(overrides?: Partial<RequestOptions>): IRequest;
|
|
64
|
+
toJSON(): Record<string, any>;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/types/core/request.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type ResponseSource = 'http' | 'lambda' | 'unknown';
|
|
2
|
+
export interface CookieOptions {
|
|
3
|
+
maxAge?: number;
|
|
4
|
+
expires?: Date;
|
|
5
|
+
path?: string;
|
|
6
|
+
domain?: string;
|
|
7
|
+
secure?: boolean;
|
|
8
|
+
httpOnly?: boolean;
|
|
9
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
10
|
+
priority?: 'low' | 'medium' | 'high';
|
|
11
|
+
partitioned?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ResponseOptions {
|
|
14
|
+
statusCode?: number;
|
|
15
|
+
headers?: Record<string, string | string[]>;
|
|
16
|
+
body?: any;
|
|
17
|
+
cookies?: string[];
|
|
18
|
+
isBase64Encoded?: boolean;
|
|
19
|
+
encoding?: BufferEncoding;
|
|
20
|
+
}
|
|
21
|
+
export interface IResponse {
|
|
22
|
+
headers: Record<string, string | string[]>;
|
|
23
|
+
data: any;
|
|
24
|
+
cookies: string[];
|
|
25
|
+
isBase64Encoded: boolean;
|
|
26
|
+
source: ResponseSource;
|
|
27
|
+
raw: any;
|
|
28
|
+
headersSent: boolean;
|
|
29
|
+
ok: boolean;
|
|
30
|
+
meta: {
|
|
31
|
+
requestUrl: URL;
|
|
32
|
+
method: string;
|
|
33
|
+
};
|
|
34
|
+
status: number;
|
|
35
|
+
getStatus(): number;
|
|
36
|
+
setHeader(name: string, value: string | string[]): this;
|
|
37
|
+
getHeader(name: string): string | string[] | undefined;
|
|
38
|
+
hasHeader(name: string): boolean;
|
|
39
|
+
removeHeader(name: string): this;
|
|
40
|
+
setHeaders(headers: Record<string, string | string[]>): this;
|
|
41
|
+
setCookie(name: string, value: string, options?: CookieOptions): this;
|
|
42
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
43
|
+
getCookies(): string[];
|
|
44
|
+
redirect(url: string, statusCode?: number): this;
|
|
45
|
+
end(data: unknown): this;
|
|
46
|
+
error(data: unknown): this;
|
|
47
|
+
reset(): this;
|
|
48
|
+
toJSON(): Record<string, any>;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/types/core/response.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../../../src/types/core/sanitize.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ServerResponse } from 'http';
|
|
2
|
+
export interface SSEClient {
|
|
3
|
+
id: string;
|
|
4
|
+
response: ServerResponse;
|
|
5
|
+
topics: Set<string>;
|
|
6
|
+
data: Record<string, any>;
|
|
7
|
+
connectedAt: Date;
|
|
8
|
+
}
|
|
9
|
+
export interface SSEMessage {
|
|
10
|
+
event?: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
retry?: number;
|
|
13
|
+
data: any;
|
|
14
|
+
}
|
|
15
|
+
export interface SSEEvent {
|
|
16
|
+
type: 'connection' | 'close';
|
|
17
|
+
client: SSEClient;
|
|
18
|
+
data?: any;
|
|
19
|
+
}
|
|
20
|
+
export interface ISSEServer {
|
|
21
|
+
createConnection(res: ServerResponse): SSEClient;
|
|
22
|
+
sendToClient(clientId: string, message: SSEMessage): boolean;
|
|
23
|
+
broadcast(message: SSEMessage, excludeClientId?: string): void;
|
|
24
|
+
getStats(): {
|
|
25
|
+
clients: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface ISSEService {
|
|
29
|
+
initialize(sse: ISSEServer): void;
|
|
30
|
+
sendToClient(clientId: string, message: SSEMessage): boolean;
|
|
31
|
+
broadcast(message: SSEMessage, excludeClientId?: string): void;
|
|
32
|
+
getStats(): {
|
|
33
|
+
clients: number;
|
|
34
|
+
};
|
|
35
|
+
isAvailable(): boolean;
|
|
36
|
+
createConnection(res: ServerResponse): SSEClient;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/types/core/sse.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { PubSub } from 'type-graphql';
|
|
2
|
+
import { InterceptorCB, MiddlewareCB } from '../core/common';
|
|
3
|
+
import { ControllerClass, ControllerType } from '../core/controller';
|
|
4
|
+
import { CORSConfig } from '../core/cors';
|
|
5
|
+
import { AppError } from '../core/error';
|
|
6
|
+
import { IRequest } from '../core/request';
|
|
7
|
+
import { IResponse } from '../core/response';
|
|
8
|
+
import { SanitizerConfig } from '../core/sanitize';
|
|
9
|
+
import { Plugin } from './plugin';
|
|
10
|
+
import { StaticConfig } from './static';
|
|
11
|
+
export interface ServerConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Port number the server listens on
|
|
14
|
+
* @type {number}
|
|
15
|
+
*/
|
|
16
|
+
port?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Hostname or IP address
|
|
19
|
+
* @type {string}
|
|
20
|
+
*/
|
|
21
|
+
host?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Array of middleware callback functions
|
|
24
|
+
* @type {MiddlewareCB[]}
|
|
25
|
+
*/
|
|
26
|
+
middlewares?: MiddlewareCB[];
|
|
27
|
+
/**
|
|
28
|
+
* Interceptor callback function
|
|
29
|
+
* @type {InterceptorCB}
|
|
30
|
+
*/
|
|
31
|
+
interceptor?: InterceptorCB;
|
|
32
|
+
/**
|
|
33
|
+
* Error handling callback
|
|
34
|
+
* @type {ErrorCB}
|
|
35
|
+
*/
|
|
36
|
+
errorHandler?: (error: AppError, req: IRequest, response: IResponse) => any;
|
|
37
|
+
/**
|
|
38
|
+
* Array of controller types
|
|
39
|
+
* @type {ControllerType[]}
|
|
40
|
+
*/
|
|
41
|
+
controllers?: ControllerType[];
|
|
42
|
+
/**
|
|
43
|
+
* CORS configuration object
|
|
44
|
+
* @type {CORSConfig}
|
|
45
|
+
*/
|
|
46
|
+
cors?: CORSConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Array of sanitizer configurations
|
|
49
|
+
* @type {SanitizerConfig[]}
|
|
50
|
+
*/
|
|
51
|
+
sanitizers?: SanitizerConfig[];
|
|
52
|
+
/**
|
|
53
|
+
* Array of static file serving configurations
|
|
54
|
+
* @type {StaticConfig[]}
|
|
55
|
+
*/
|
|
56
|
+
statics?: StaticConfig[];
|
|
57
|
+
/**
|
|
58
|
+
* WebSocket enablement and lazy loading
|
|
59
|
+
* @type {{ path: string; lazy?: boolean }}
|
|
60
|
+
*/
|
|
61
|
+
websocket?: {
|
|
62
|
+
path: string;
|
|
63
|
+
lazy?: boolean;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Server-Sent Events enablement
|
|
67
|
+
* @type {{ enabled: boolean }}
|
|
68
|
+
*/
|
|
69
|
+
sse?: {
|
|
70
|
+
enabled: boolean;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* GraphQL configuration including playground, pubSub, and resolvers
|
|
74
|
+
* @type {{ playground?: boolean; pubSub?: PubSub; resolvers?: Function[] }}
|
|
75
|
+
*/
|
|
76
|
+
graphql?: {
|
|
77
|
+
path: string;
|
|
78
|
+
playground?: boolean;
|
|
79
|
+
pubSub?: PubSub;
|
|
80
|
+
resolvers?: Function[];
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
import { Server } from 'http';
|
|
84
|
+
export interface IHttpServer {
|
|
85
|
+
readonly app: Server;
|
|
86
|
+
plugins: Plugin[];
|
|
87
|
+
controllers: ControllerClass[];
|
|
88
|
+
/**
|
|
89
|
+
* Starts HTTP server
|
|
90
|
+
* @param port - port
|
|
91
|
+
* @param host - host
|
|
92
|
+
* @returns Promise with HTTP server instance
|
|
93
|
+
* @throws Error
|
|
94
|
+
*/
|
|
95
|
+
listen(port?: number, host?: string): Promise<Server>;
|
|
96
|
+
/**
|
|
97
|
+
* Stops server
|
|
98
|
+
* @returns Promise
|
|
99
|
+
* @throws Error
|
|
100
|
+
*/
|
|
101
|
+
close(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Get server status
|
|
104
|
+
* @returns object with server config
|
|
105
|
+
*/
|
|
106
|
+
status(): {
|
|
107
|
+
running: boolean;
|
|
108
|
+
config: ServerConfig;
|
|
109
|
+
};
|
|
110
|
+
usePlugin(plugin: Plugin): IHttpServer;
|
|
111
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/types/http/http.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./http"), exports);
|
|
18
|
+
__exportStar(require("./plugin"), exports);
|
|
19
|
+
__exportStar(require("./static"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,2CAAyB;AACzB,2CAAyB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IncomingMessage, Server } from 'http';
|
|
2
|
+
import { IRequest, IResponse, MiddlewareCB } from '../core';
|
|
3
|
+
import { IHttpServer } from './http';
|
|
4
|
+
export interface HttpPluginHooks {
|
|
5
|
+
beforeRequest?: (req: IncomingMessage) => void | Promise<void>;
|
|
6
|
+
beforeRoute?: (req: IRequest, response: IResponse) => void | Promise<void>;
|
|
7
|
+
afterResponse?: (req: IRequest, res: IResponse) => void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface Plugin {
|
|
10
|
+
name: string;
|
|
11
|
+
onInit?(server: IHttpServer): void | Promise<void>;
|
|
12
|
+
onStart?(server: Server): void | Promise<void>;
|
|
13
|
+
onStop?(server: Server): void | Promise<void>;
|
|
14
|
+
middleware?: MiddlewareCB;
|
|
15
|
+
hooks?: HttpPluginHooks;
|
|
16
|
+
}
|
|
17
|
+
export type PluginHookKeys = keyof HttpPluginHooks;
|
|
18
|
+
export type PluginKeys = keyof Omit<Plugin, 'name' | 'hooks'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/types/http/plugin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { ServerResponse } from 'http';
|
|
3
|
+
export interface StaticOptions {
|
|
4
|
+
index?: string | boolean;
|
|
5
|
+
extensions?: string[];
|
|
6
|
+
maxAge?: number;
|
|
7
|
+
immutable?: boolean;
|
|
8
|
+
dotfiles?: 'allow' | 'deny' | 'ignore';
|
|
9
|
+
fallthrough?: boolean;
|
|
10
|
+
setHeaders?: (res: ServerResponse, path: string, stat: fs.Stats) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface StaticConfig {
|
|
13
|
+
path: string;
|
|
14
|
+
options?: StaticOptions;
|
|
15
|
+
}
|
|
16
|
+
export interface StaticOptions {
|
|
17
|
+
index?: string | boolean;
|
|
18
|
+
extensions?: string[];
|
|
19
|
+
maxAge?: number;
|
|
20
|
+
immutable?: boolean;
|
|
21
|
+
dotfiles?: 'allow' | 'deny' | 'ignore';
|
|
22
|
+
fallthrough?: boolean;
|
|
23
|
+
setHeaders?: (res: ServerResponse, path: string, stat: fs.Stats) => void;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.js","sourceRoot":"","sources":["../../../src/types/http/static.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
export type WebSocketHandlerType = 'connection' | 'message' | 'close' | 'error';
|
|
3
|
+
export interface WebSocketEvent {
|
|
4
|
+
type: WebSocketHandlerType;
|
|
5
|
+
client: WebSocketClient;
|
|
6
|
+
message?: WebSocketMessage;
|
|
7
|
+
data?: any;
|
|
8
|
+
}
|
|
9
|
+
export interface WebSocketClient {
|
|
10
|
+
id: string;
|
|
11
|
+
socket: WebSocket;
|
|
12
|
+
topics: Set<string>;
|
|
13
|
+
data: Record<string, any>;
|
|
14
|
+
connectedAt: Date;
|
|
15
|
+
}
|
|
16
|
+
export interface WebSocketMessage {
|
|
17
|
+
type: string;
|
|
18
|
+
topic?: string;
|
|
19
|
+
data: any;
|
|
20
|
+
clientId?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WebSocketStats {
|
|
23
|
+
clients: number;
|
|
24
|
+
topics: Array<{
|
|
25
|
+
topic: string;
|
|
26
|
+
subscribers: number;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
export interface IWebSocketService {
|
|
30
|
+
sendToClient(clientId: string, message: any): boolean;
|
|
31
|
+
publishToTopic(topic: string, data: any, exclude?: string[]): void;
|
|
32
|
+
broadcast(message: any, excludeClientId?: string): void;
|
|
33
|
+
getStats(): {
|
|
34
|
+
clients: number;
|
|
35
|
+
topics: Array<{
|
|
36
|
+
topic: string;
|
|
37
|
+
subscribers: number;
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
isAvailable(): boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface IWebSocketServer {
|
|
43
|
+
sendToClient(clientId: string, message: any): boolean;
|
|
44
|
+
publishToTopic(topic: string, data: any, exclude: string[]): void;
|
|
45
|
+
broadcast(message: any, excludeClientId?: string): void;
|
|
46
|
+
getStats(): WebSocketStats;
|
|
47
|
+
subscribeToTopic(client: WebSocketClient, topic: string): void;
|
|
48
|
+
unsubscribeFromTopic(client: WebSocketClient, topic: string): void;
|
|
49
|
+
registerControllers(controllers: any[]): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/ws/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { ControllerInstance, ControllerMethods, CORSConfig, InterceptorCB, IRequest, IResponse, MiddlewareCB, SanitizerConfig } from '../../types/core';
|
|
3
|
+
export declare const executeControllerMethod: (controller: ControllerInstance, propertyName: string, request: IRequest, response: IResponse) => Promise<any>;
|
|
4
|
+
export declare const getControllerMethods: (controller: ControllerInstance) => ControllerMethods;
|
|
5
|
+
export declare const getAllMethods: (obj: any) => string[];
|
|
6
|
+
export declare const findRouteInController: (instance: any, path: string, route: string, method: string) => {
|
|
7
|
+
name: string;
|
|
8
|
+
pathParams: Record<string, string>;
|
|
9
|
+
priority: number;
|
|
10
|
+
middlewares: MiddlewareCB[];
|
|
11
|
+
cors?: CORSConfig;
|
|
12
|
+
sanitizers: SanitizerConfig[];
|
|
13
|
+
};
|
|
14
|
+
export declare const NextFunction: (error: any) => void;
|
|
15
|
+
export declare const getResponse: (data: {
|
|
16
|
+
controllerInstance: ControllerInstance;
|
|
17
|
+
name: string;
|
|
18
|
+
interceptors: InterceptorCB[];
|
|
19
|
+
request: IRequest;
|
|
20
|
+
response: IResponse;
|
|
21
|
+
}) => Promise<any>;
|
|
22
|
+
export declare const applyMiddlewaresVsSanitizers: (request: IRequest, response: IResponse, functions: {
|
|
23
|
+
sanitizers: SanitizerConfig[][];
|
|
24
|
+
middlewares: MiddlewareCB[][];
|
|
25
|
+
}) => Promise<void>;
|