@heliosjs/middlewares 1.0.2 → 1.3.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.
package/README.md CHANGED
@@ -45,8 +45,8 @@ import {
45
45
  Response,
46
46
  Status,
47
47
  ANY,
48
- Request,
49
- Response
48
+ IRequest,
49
+ IResponse
50
50
  } from 'quantum-flow/core';
51
51
  import {IsString} from 'class-validator'
52
52
  import { Catch, Cors, Sanitize, Use, SANITIZER } from 'quantum-flow/middlewares';
@@ -83,8 +83,8 @@ export class User {
83
83
  @Query() query: Record<string, string | string[]>,
84
84
  @Headers() headers: Record<string, string | string[]>,
85
85
  @Params(ParamDTO, 'param') params: string,
86
- @Req() req: Response,
87
- @Response() resp: Request,
86
+ @Request() req: IResponse,
87
+ @Response() resp: IRequest,
88
88
  @InjectWS() ws: IWebSocketService,
89
89
  ) {}
90
90
 
@@ -138,7 +138,7 @@ server.listen().catch(console.error);
138
138
  - Use `@Params` to access route parameters.
139
139
  - Use `@Files` to access files sent within multipart/form-data requests.
140
140
  Text sent as multipart/form-data is exposed with `@Body` decorators
141
- - Use `@Req` to access the original request object.
141
+ - Use `@Request` to access the original request object.
142
142
  - Use `@Response` to access the original object.
143
143
  - Use `@InjectWS` to access the websocket service.
144
144
  - Use `@InjectSSE` to access the server-side-event service.
@@ -150,7 +150,7 @@ Use `LambdaAdapter` to convert API Gateway events to requests and responses. Cre
150
150
  ```typescript
151
151
  Example Lambda handler creation
152
152
  import { LambdaAdapter, LambdaRequest, LambdaResponse } from 'quantum-flow/aws';
153
- import { Request, Query, Headers, Params, Response, Response, Request } from 'quantum-flow/core'
153
+ import { Request, Query, Headers, Params, Response, IResponse, IRequest } from 'quantum-flow/core'
154
154
 
155
155
  @Controller({ prefix: 'user' })
156
156
  class UserController {
@@ -158,16 +158,16 @@ class UserController {
158
158
  @Query() query: Record<string, string | string[]>,
159
159
  @Headers() headers: Record<string, string | string[]>,
160
160
  @Params(ParamDTO, 'param') params: string,
161
- @Req() req: Request,
162
- @Response() res: Response
161
+ @Request() req: IRequest,
162
+ @Response() res: IResponse
163
163
  ) { }
164
164
  }
165
165
  const lambdaAdapter = new LambdaAdapter(UserController);
166
166
  export const handler = lambdaAdapter.handler;
167
167
  ```
168
168
 
169
- You can access context and event throught @Req() decorator:
170
- @Req() request: LambdaRequest
169
+ You can access context and event throught @Request() decorator:
170
+ @Request() request: LambdaRequest
171
171
  request.context
172
172
  request.event
173
173
 
@@ -310,19 +310,19 @@ import { OnSSEConnection, OnSSEError, OnSSEClose } from 'quantum-flow/sse';
310
310
  @Controller('user')
311
311
  export class User {
312
312
  @OnSSEConnection()
313
- async onsseconnection(@Req() req, @Response() res) {
313
+ async onsseconnection(@Request() req, @Response() res) {
314
314
  console.log('SSE connection established');
315
315
  return req.body;
316
316
  }
317
317
 
318
318
  @OnSSEError()
319
- async onsseerror(@Req() req, @Response() res) {
319
+ async onsseerror(@Request() req, @Response() res) {
320
320
  console.log('SSE error occurred');
321
321
  return req.body;
322
322
  }
323
323
 
324
324
  @OnSSEClose()
325
- async onsseclose(@Req() req, @Response() res) {
325
+ async onsseclose(@Request() req, @Response() res) {
326
326
  console.log('SSE connection closed');
327
327
  return req.body;
328
328
  }
@@ -1,8 +1,8 @@
1
1
  import { ServerResponse } from 'http';
2
2
  import { AppError } from './error';
3
- import { Request } from './request';
4
- import { Response } from './response';
5
- export type Router = (req: Request, res?: ServerResponse) => Promise<{
3
+ import { IRequest } from './request';
4
+ import { IResponse } from './response';
5
+ export type Router = (req: IRequest, res?: ServerResponse) => Promise<{
6
6
  status: number;
7
7
  data: any;
8
8
  message?: string;
@@ -10,9 +10,9 @@ export type Router = (req: Request, res?: ServerResponse) => Promise<{
10
10
  export interface IController {
11
11
  handleRequest: Router;
12
12
  }
13
- export type MiddlewareCB = (request: Request, response: Response, next: (args?: any) => any) => void | Promise<Request> | Request | Promise<void> | void;
14
- export type InterceptorCB = (data: any, req?: Request, res?: Response) => Promise<unknown> | unknown;
15
- export type ErrorCB = (error: AppError, req?: Request, res?: Response) => any;
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
16
  export type ParamDecoratorType = 'body' | 'params' | 'query' | 'request' | 'headers' | 'cookies' | 'response' | 'multipart' | 'event' | 'context' | 'sse' | 'ws';
17
17
  export interface ParamMetadata {
18
18
  index: number;
@@ -1,7 +1,7 @@
1
1
  import { ServerResponse } from 'http';
2
2
  import { ErrorCB, HTTP_METHODS, InterceptorCB, MiddlewareCB } from './common';
3
3
  import { CORSConfig } from './cors';
4
- import { Request } from './request';
4
+ import { IRequest } from './request';
5
5
  import { SanitizerConfig } from './sanitize';
6
6
  export type ControllerClass = {
7
7
  new (...args: any[]): any;
@@ -13,7 +13,7 @@ export type ControllerMethods = Array<{
13
13
  middlewares?: MiddlewareCB[];
14
14
  }>;
15
15
  export type ControllerType = {
16
- handleRequest?(request: Request, response: ServerResponse): Promise<any>;
16
+ handleRequest?(request: IRequest, response: ServerResponse): Promise<any>;
17
17
  ws?: WsControllerHandlers;
18
18
  sse?: SeeControllerHandlers;
19
19
  new (...args: any[]): any;
@@ -1,5 +1,5 @@
1
- import { Request } from './request';
2
- import { Response } from './response';
1
+ import { IRequest } from './request';
2
+ import { IResponse } from './response';
3
3
  export declare enum ErrorCode {
4
4
  BAD_REQUEST = "BAD_REQUEST",
5
5
  UNAUTHORIZED = "UNAUTHORIZED",
@@ -69,4 +69,4 @@ export interface ErrorHandlerConfig {
69
69
  logStack?: boolean;
70
70
  customHandlers?: Record<ErrorCode, (error: AppError) => any>;
71
71
  }
72
- export type ErorrHandler = (error: Error, req: Request, response: Response) => any;
72
+ export type ErorrHandler = (error: Error, req: IRequest, response: IResponse) => any;
@@ -23,7 +23,7 @@ export interface RequestOptions {
23
23
  isBase64Encoded?: boolean;
24
24
  source: RequestSource;
25
25
  }
26
- export interface Request {
26
+ export interface IRequest {
27
27
  method: string;
28
28
  path: string;
29
29
  url: string;
@@ -60,6 +60,6 @@ export interface Request {
60
60
  getClientIp(): string;
61
61
  getHost(): string;
62
62
  getFullUrl(): string;
63
- clone(overrides?: Partial<RequestOptions>): Request;
63
+ clone(overrides?: Partial<RequestOptions>): IRequest;
64
64
  toJSON(): Record<string, any>;
65
65
  }
@@ -18,7 +18,7 @@ export interface ResponseOptions {
18
18
  isBase64Encoded?: boolean;
19
19
  encoding?: BufferEncoding;
20
20
  }
21
- export interface Response {
21
+ export interface IResponse {
22
22
  headers: Record<string, string | string[]>;
23
23
  data: any;
24
24
  cookies: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliosjs/middlewares",
3
- "version": "1.0.2",
3
+ "version": "1.3.0",
4
4
  "description": "Core functionality for Quantum Flow",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,13 +13,13 @@
13
13
  "README.md"
14
14
  ],
15
15
  "scripts": {
16
- "build": "yarn clean && tsc -p tsconfig.build.json",
16
+ "build": "yarn clean && tsc -p tsconfig.build.json && resolve-tspaths",
17
17
  "clean": "rm -rf dist",
18
18
  "prepublishOnly": "yarn build",
19
- "publish:public": "yarn publish --access public --no-git-tag-version",
20
- "publish:patch": "yarn version --patch --no-git-tag-version && yarn publish --access public",
21
- "publish:minor": "yarn version --minor --no-git-tag-version && yarn publish --access public",
22
- "publish:major": "yarn version --major --no-git-tag-version && yarn publish --access public"
19
+ "publish:public": "yarn publish --access public",
20
+ "publish:patch": "yarn version --patch && yarn build && npm pack && npm publish *.tgz --access public && rm *.tgz",
21
+ "publish:minor": "yarn version --minor && yarn publish --access public",
22
+ "publish:major": "yarn version --major && yarn publish --access public"
23
23
  },
24
24
  "dependencies": {
25
25
  "reflect-metadata": "^0.2.2"