@heliosjs/middlewares 1.0.0

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.
Files changed (74) hide show
  1. package/README.md +540 -0
  2. package/dist/catch.d.ts +2 -0
  3. package/dist/catch.js +11 -0
  4. package/dist/catch.js.map +1 -0
  5. package/dist/constants.d.ts +25 -0
  6. package/dist/constants.js +34 -0
  7. package/dist/constants.js.map +1 -0
  8. package/dist/cors.d.ts +2 -0
  9. package/dist/cors.js +22 -0
  10. package/dist/cors.js.map +1 -0
  11. package/dist/index.d.ts +6 -0
  12. package/dist/index.js +23 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/sanitize.d.ts +2 -0
  15. package/dist/sanitize.js +16 -0
  16. package/dist/sanitize.js.map +1 -0
  17. package/dist/status.d.ts +17 -0
  18. package/dist/status.js +36 -0
  19. package/dist/status.js.map +1 -0
  20. package/dist/types/core/common.d.ts +44 -0
  21. package/dist/types/core/common.js +15 -0
  22. package/dist/types/core/common.js.map +1 -0
  23. package/dist/types/core/controller.d.ts +78 -0
  24. package/dist/types/core/controller.js +3 -0
  25. package/dist/types/core/controller.js.map +1 -0
  26. package/dist/types/core/cors.d.ts +10 -0
  27. package/dist/types/core/cors.js +3 -0
  28. package/dist/types/core/cors.js.map +1 -0
  29. package/dist/types/core/error.d.ts +72 -0
  30. package/dist/types/core/error.js +19 -0
  31. package/dist/types/core/error.js.map +1 -0
  32. package/dist/types/core/index.d.ts +9 -0
  33. package/dist/types/core/index.js +26 -0
  34. package/dist/types/core/index.js.map +1 -0
  35. package/dist/types/core/multipart.d.ts +8 -0
  36. package/dist/types/core/multipart.js +3 -0
  37. package/dist/types/core/multipart.js.map +1 -0
  38. package/dist/types/core/request.d.ts +65 -0
  39. package/dist/types/core/request.js +3 -0
  40. package/dist/types/core/request.js.map +1 -0
  41. package/dist/types/core/response.d.ts +49 -0
  42. package/dist/types/core/response.js +3 -0
  43. package/dist/types/core/response.js.map +1 -0
  44. package/dist/types/core/sanitize.d.ts +8 -0
  45. package/dist/types/core/sanitize.js +3 -0
  46. package/dist/types/core/sanitize.js.map +1 -0
  47. package/dist/types/core/sse.d.ts +37 -0
  48. package/dist/types/core/sse.js +3 -0
  49. package/dist/types/core/sse.js.map +1 -0
  50. package/dist/types/ws/index.d.ts +50 -0
  51. package/dist/types/ws/index.js +3 -0
  52. package/dist/types/ws/index.js.map +1 -0
  53. package/dist/use.d.ts +2 -0
  54. package/dist/use.js +12 -0
  55. package/dist/use.js.map +1 -0
  56. package/dist/utils/shared/index.d.ts +2 -0
  57. package/dist/utils/shared/index.js +19 -0
  58. package/dist/utils/shared/index.js.map +1 -0
  59. package/dist/utils/shared/parsers.d.ts +11 -0
  60. package/dist/utils/shared/parsers.js +133 -0
  61. package/dist/utils/shared/parsers.js.map +1 -0
  62. package/dist/utils/shared/validate.d.ts +1 -0
  63. package/dist/utils/shared/validate.js +41 -0
  64. package/dist/utils/shared/validate.js.map +1 -0
  65. package/dist/utils/sse/index.d.ts +2 -0
  66. package/dist/utils/sse/index.js +19 -0
  67. package/dist/utils/sse/index.js.map +1 -0
  68. package/dist/utils/sse/server.d.ts +14 -0
  69. package/dist/utils/sse/server.js +85 -0
  70. package/dist/utils/sse/server.js.map +1 -0
  71. package/dist/utils/sse/service.d.ts +17 -0
  72. package/dist/utils/sse/service.js +40 -0
  73. package/dist/utils/sse/service.js.map +1 -0
  74. package/package.json +30 -0
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sanitize = Sanitize;
4
+ const constants_1 = require("./constants");
5
+ function Sanitize(sanitizeConfig) {
6
+ return function (target, propertyKey, descriptor) {
7
+ const configs = Array.isArray(sanitizeConfig) ? sanitizeConfig : [sanitizeConfig];
8
+ if (propertyKey && descriptor) {
9
+ Reflect.defineMetadata(constants_1.SANITIZE, configs, target, propertyKey);
10
+ }
11
+ else {
12
+ Reflect.defineMetadata(constants_1.SANITIZE, configs, target.prototype || target);
13
+ }
14
+ };
15
+ }
16
+ //# sourceMappingURL=sanitize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":";;AAGA,4BAUC;AAbD,2CAAuC;AAGvC,SAAgB,QAAQ,CAAC,cAAmD;IAC1E,OAAO,UAAU,MAAW,EAAE,WAAoB,EAAE,UAA+B;QACjF,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;QAElF,IAAI,WAAW,IAAI,UAAU,EAAE,CAAC;YAC9B,OAAO,CAAC,cAAc,CAAC,oBAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,cAAc,CAAC,oBAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;QACxE,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Method or class decorator to set the HTTP status code for the response.
3
+ * @param status HTTP status code to set.
4
+ */
5
+ export declare function Status(status: number): (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
6
+ /**
7
+ * Shortcut decorator to set HTTP 200 OK status.
8
+ */
9
+ export declare const Ok200: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
10
+ /**
11
+ * Shortcut decorator to set HTTP 201 Created status.
12
+ */
13
+ export declare const Ok201: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
14
+ /**
15
+ * Shortcut decorator to set HTTP 204 No Content status.
16
+ */
17
+ export declare const Ok204: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
package/dist/status.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Ok204 = exports.Ok201 = exports.Ok200 = void 0;
4
+ exports.Status = Status;
5
+ const constants_1 = require("./constants");
6
+ /**
7
+ * Method or class decorator to set the HTTP status code for the response.
8
+ * @param status HTTP status code to set.
9
+ */
10
+ function Status(status) {
11
+ return function (target, propertyKey, descriptor) {
12
+ if (!propertyKey) {
13
+ Reflect.defineMetadata(constants_1.OK_METADATA_KEY, status, target.prototype || target);
14
+ return;
15
+ }
16
+ if (descriptor) {
17
+ Reflect.defineMetadata(constants_1.OK_METADATA_KEY, status, target, propertyKey);
18
+ }
19
+ };
20
+ }
21
+ /**
22
+ * Shortcut decorator to set HTTP 200 OK status.
23
+ */
24
+ const Ok200 = () => Status(200);
25
+ exports.Ok200 = Ok200;
26
+ /**
27
+ * Shortcut decorator to set HTTP 201 Created status.
28
+ */
29
+ const Ok201 = () => Status(201);
30
+ exports.Ok201 = Ok201;
31
+ /**
32
+ * Shortcut decorator to set HTTP 204 No Content status.
33
+ */
34
+ const Ok204 = () => Status(204);
35
+ exports.Ok204 = Ok204;
36
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":";;;AAMA,wBAeC;AArBD,2CAA8C;AAE9C;;;GAGG;AACH,SAAgB,MAAM,CAAC,MAAc;IACnC,OAAO,UACL,MAAW,EACX,WAA6B,EAC7B,UAAyC;QAEzC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,cAAc,CAAC,2BAAe,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;YAC5E,OAAO;QACT,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,cAAc,CAAC,2BAAe,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACvE,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACI,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAA1B,QAAA,KAAK,SAAqB;AAEvC;;GAEG;AACI,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAA1B,QAAA,KAAK,SAAqB;AAEvC;;GAEG;AACI,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAA1B,QAAA,KAAK,SAAqB"}
@@ -0,0 +1,44 @@
1
+ import { ServerResponse } from 'http';
2
+ import { AppError } from './error';
3
+ import { IRequest } from './request';
4
+ import { IResponse } from './response';
5
+ export type Router = (req: IRequest, res?: ServerResponse) => Promise<{
6
+ status: number;
7
+ data: any;
8
+ message?: string;
9
+ }>;
10
+ export interface IController {
11
+ handleRequest: Router;
12
+ }
13
+ export type MiddlewareCB = (request: IRequest, response: IResponse, next: (args?: any) => any) => void | Promise<IRequest> | IRequest | Promise<void> | void;
14
+ export type InterceptorCB = (data: any, req?: IRequest, res?: IResponse) => Promise<unknown> | unknown;
15
+ export type ErrorCB = (error: AppError, req?: IRequest, res?: IResponse) => any;
16
+ export type ParamDecoratorType = 'body' | 'params' | 'query' | 'request' | 'headers' | 'cookies' | 'response' | 'multipart' | 'event' | 'context' | 'sse' | 'ws';
17
+ export interface ParamMetadata {
18
+ index: number;
19
+ type: ParamDecoratorType;
20
+ dto?: any;
21
+ name?: string;
22
+ }
23
+ export type ResponseWithStatus = {
24
+ status: number;
25
+ [key: string]: any;
26
+ };
27
+ export declare enum HTTP_METHODS {
28
+ ANY = "ANY",
29
+ GET = "GET",
30
+ POST = "POST",
31
+ PATCH = "PATCH",
32
+ DELETE = "DELETE",
33
+ PUT = "PUT",
34
+ OPTIONS = "OPTIONS",
35
+ HEAD = "HEAD"
36
+ }
37
+ export type Meta = {
38
+ requestUrl: URL;
39
+ method: string;
40
+ requestId: string;
41
+ sourceIp: string;
42
+ userAgent: string;
43
+ startTime: number;
44
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HTTP_METHODS = void 0;
4
+ var HTTP_METHODS;
5
+ (function (HTTP_METHODS) {
6
+ HTTP_METHODS["ANY"] = "ANY";
7
+ HTTP_METHODS["GET"] = "GET";
8
+ HTTP_METHODS["POST"] = "POST";
9
+ HTTP_METHODS["PATCH"] = "PATCH";
10
+ HTTP_METHODS["DELETE"] = "DELETE";
11
+ HTTP_METHODS["PUT"] = "PUT";
12
+ HTTP_METHODS["OPTIONS"] = "OPTIONS";
13
+ HTTP_METHODS["HEAD"] = "HEAD";
14
+ })(HTTP_METHODS || (exports.HTTP_METHODS = HTTP_METHODS = {}));
15
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/types/core/common.ts"],"names":[],"mappings":";;;AAsDA,IAAY,YASX;AATD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,2BAAW,CAAA;IACX,6BAAa,CAAA;IACb,+BAAe,CAAA;IACf,iCAAiB,CAAA;IACjB,2BAAW,CAAA;IACX,mCAAmB,CAAA;IACnB,6BAAa,CAAA;AACf,CAAC,EATW,YAAY,4BAAZ,YAAY,QASvB"}
@@ -0,0 +1,78 @@
1
+ import { ServerResponse } from 'http';
2
+ import { ErrorCB, HTTP_METHODS, InterceptorCB, MiddlewareCB } from './common';
3
+ import { CORSConfig } from './cors';
4
+ import { IRequest } from './request';
5
+ import { SanitizerConfig } from './sanitize';
6
+ export type ControllerClass = {
7
+ new (...args: any[]): any;
8
+ };
9
+ export type ControllerMethods = Array<{
10
+ name: string;
11
+ httpMethod: HTTP_METHODS;
12
+ pattern: string;
13
+ middlewares?: MiddlewareCB[];
14
+ }>;
15
+ export type ControllerType = {
16
+ handleRequest?(request: IRequest, response: ServerResponse): Promise<any>;
17
+ ws?: WsControllerHandlers;
18
+ sse?: SeeControllerHandlers;
19
+ new (...args: any[]): any;
20
+ };
21
+ export type ControllerInstance = InstanceType<ControllerType>;
22
+ export type ControllerMetadata = {
23
+ routePrefix: string;
24
+ middlewares: MiddlewareCB[];
25
+ interceptor?: InterceptorCB;
26
+ subControllers: ControllerInstance[];
27
+ errorHandler?: ErrorCB;
28
+ cors?: CORSConfig;
29
+ sanitizers: SanitizerConfig[];
30
+ };
31
+ export interface ControllerConfig {
32
+ prefix: string;
33
+ middlewares?: Array<MiddlewareCB>;
34
+ controllers?: ControllerInstance[];
35
+ interceptor?: InterceptorCB;
36
+ }
37
+ export type RouteContext = {
38
+ controllerInstance: any;
39
+ controllerMeta: ControllerMetadata;
40
+ path: string;
41
+ method: string;
42
+ middlewareChain: MiddlewareCB[];
43
+ interceptorChain: InterceptorCB[];
44
+ corsChain: CORSConfig[];
45
+ errorHandlerChain: ErrorCB[];
46
+ subPath: string;
47
+ sanitizersChain: SanitizerConfig[];
48
+ };
49
+ export type SSE_HANDLER_META = {
50
+ type: string;
51
+ method: string;
52
+ };
53
+ export type HandlerMeta = {
54
+ type: 'connection';
55
+ topic: undefined;
56
+ method: 'onconnect';
57
+ fn: (...args: any[]) => any;
58
+ };
59
+ export type WsHandlerMeta = HandlerMeta & {
60
+ topic?: string;
61
+ };
62
+ export type WsControllerHandlers = {
63
+ handlers: {
64
+ connection: WsHandlerMeta[];
65
+ message: WsHandlerMeta[];
66
+ close: WsHandlerMeta[];
67
+ error: WsHandlerMeta[];
68
+ };
69
+ topics: HandlerMeta[];
70
+ };
71
+ export type SeeControllerHandlers = {
72
+ handlers: {
73
+ connection: HandlerMeta[];
74
+ close: HandlerMeta[];
75
+ error: HandlerMeta[];
76
+ };
77
+ };
78
+ export type NextFunction = (error?: unknown) => void;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/types/core/controller.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ export interface CORSConfig {
2
+ origin?: string | string[] | ((origin: string) => boolean);
3
+ methods?: string[];
4
+ allowedHeaders?: string[];
5
+ exposedHeaders?: string[];
6
+ credentials?: boolean;
7
+ maxAge?: number;
8
+ preflightContinue?: boolean;
9
+ optionsSuccessStatus?: number;
10
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=cors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../../src/types/core/cors.ts"],"names":[],"mappings":""}
@@ -0,0 +1,72 @@
1
+ import { IRequest } from './request';
2
+ import { IResponse } from './response';
3
+ export declare enum ErrorCode {
4
+ BAD_REQUEST = "BAD_REQUEST",
5
+ UNAUTHORIZED = "UNAUTHORIZED",
6
+ FORBIDDEN = "FORBIDDEN",
7
+ NOT_FOUND = "NOT_FOUND",
8
+ VALIDATION_FAILED = "VALIDATION_FAILED",
9
+ RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
10
+ INTERNAL_ERROR = "INTERNAL_ERROR",
11
+ SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
12
+ DATABASE_ERROR = "DATABASE_ERROR",
13
+ DUPLICATE_ENTRY = "DUPLICATE_ENTRY",
14
+ INVALID_STATE = "INVALID_STATE",
15
+ DEPENDENCY_FAILED = "DEPENDENCY_FAILED"
16
+ }
17
+ export interface ErrorDetails {
18
+ field?: string;
19
+ value?: any;
20
+ constraint?: string;
21
+ [key: string]: any;
22
+ }
23
+ export interface AppError extends Error {
24
+ code: ErrorCode;
25
+ status: number;
26
+ details?: ErrorDetails[];
27
+ timestamp: Date;
28
+ requestId?: string;
29
+ path?: string;
30
+ method?: string;
31
+ toResponse(): ErrorResponse;
32
+ }
33
+ export interface IValidationError extends AppError {
34
+ code: ErrorCode.VALIDATION_FAILED;
35
+ details?: ErrorDetails[];
36
+ }
37
+ export interface ErrorResponse {
38
+ success: false;
39
+ error: {
40
+ code: ErrorCode;
41
+ status: number;
42
+ message: string;
43
+ details?: ErrorDetails[];
44
+ timestamp: string;
45
+ requestId?: string;
46
+ path?: string;
47
+ };
48
+ }
49
+ export interface ErrorHandlerConfig {
50
+ includeStack?: boolean;
51
+ logErrors?: boolean;
52
+ logStack?: boolean;
53
+ customHandlers?: Record<ErrorCode, (error: AppError) => any>;
54
+ }
55
+ export interface SerializedError {
56
+ type: 'Error' | 'HttpError' | 'AxiosError' | 'Unknown' | 'ValidationError';
57
+ message: string;
58
+ status?: number;
59
+ code?: string;
60
+ stack?: string;
61
+ data?: any;
62
+ original?: any;
63
+ errors?: any[];
64
+ details?: ErrorDetails[];
65
+ }
66
+ export interface ErrorHandlerConfig {
67
+ includeStack?: boolean;
68
+ logErrors?: boolean;
69
+ logStack?: boolean;
70
+ customHandlers?: Record<ErrorCode, (error: AppError) => any>;
71
+ }
72
+ export type ErorrHandler = (error: Error, req: IRequest, response: IResponse) => any;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorCode = void 0;
4
+ var ErrorCode;
5
+ (function (ErrorCode) {
6
+ ErrorCode["BAD_REQUEST"] = "BAD_REQUEST";
7
+ ErrorCode["UNAUTHORIZED"] = "UNAUTHORIZED";
8
+ ErrorCode["FORBIDDEN"] = "FORBIDDEN";
9
+ ErrorCode["NOT_FOUND"] = "NOT_FOUND";
10
+ ErrorCode["VALIDATION_FAILED"] = "VALIDATION_FAILED";
11
+ ErrorCode["RATE_LIMIT_EXCEEDED"] = "RATE_LIMIT_EXCEEDED";
12
+ ErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
13
+ ErrorCode["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
14
+ ErrorCode["DATABASE_ERROR"] = "DATABASE_ERROR";
15
+ ErrorCode["DUPLICATE_ENTRY"] = "DUPLICATE_ENTRY";
16
+ ErrorCode["INVALID_STATE"] = "INVALID_STATE";
17
+ ErrorCode["DEPENDENCY_FAILED"] = "DEPENDENCY_FAILED";
18
+ })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
19
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/types/core/error.ts"],"names":[],"mappings":";;;AAGA,IAAY,SAaX;AAbD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,0CAA6B,CAAA;IAC7B,oCAAuB,CAAA;IACvB,oCAAuB,CAAA;IACvB,oDAAuC,CAAA;IACvC,wDAA2C,CAAA;IAC3C,8CAAiC,CAAA;IACjC,wDAA2C,CAAA;IAC3C,8CAAiC,CAAA;IACjC,gDAAmC,CAAA;IACnC,4CAA+B,CAAA;IAC/B,oDAAuC,CAAA;AACzC,CAAC,EAbW,SAAS,yBAAT,SAAS,QAapB"}
@@ -0,0 +1,9 @@
1
+ export * from './common';
2
+ export * from './controller';
3
+ export * from './cors';
4
+ export * from './error';
5
+ export * from './multipart';
6
+ export * from './request';
7
+ export * from './response';
8
+ export * from './sanitize';
9
+ export * from './sse';
@@ -0,0 +1,26 @@
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("./common"), exports);
18
+ __exportStar(require("./controller"), exports);
19
+ __exportStar(require("./cors"), exports);
20
+ __exportStar(require("./error"), exports);
21
+ __exportStar(require("./multipart"), exports);
22
+ __exportStar(require("./request"), exports);
23
+ __exportStar(require("./response"), exports);
24
+ __exportStar(require("./sanitize"), exports);
25
+ __exportStar(require("./sse"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,yCAAuB;AACvB,0CAAwB;AACxB,8CAA4B;AAC5B,4CAA0B;AAC1B,6CAA2B;AAC3B,6CAA2B;AAC3B,wCAAsB"}
@@ -0,0 +1,8 @@
1
+ export interface MultipartFile {
2
+ fieldname: string;
3
+ filename: string;
4
+ contentType: string;
5
+ data: Buffer;
6
+ size: number;
7
+ encoding?: string;
8
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=multipart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../../src/types/core/multipart.ts"],"names":[],"mappings":""}
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=request.js.map
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/types/core/response.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import * as Joi from 'joi';
2
+ export interface SanitizerConfig {
3
+ schema: Joi.Schema;
4
+ action?: 'validate' | 'sanitize' | 'both';
5
+ options?: Joi.ValidationOptions;
6
+ stripUnknown?: boolean;
7
+ type: 'headers' | 'body' | 'params' | 'query';
8
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=sanitize.js.map
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/types/core/sse.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
+ }