@spinajs/http 1.0.14 → 1.2.103
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 +11 -0
- package/lib/config/http.js +17 -17
- package/lib/config/http.js.map +1 -1
- package/lib/controllers.d.ts +6 -4
- package/lib/controllers.js +53 -184
- package/lib/controllers.js.map +1 -1
- package/lib/decorators.d.ts +49 -24
- package/lib/decorators.js +97 -40
- package/lib/decorators.js.map +1 -1
- package/lib/exceptions.d.ts +0 -0
- package/lib/exceptions.js +1 -0
- package/lib/exceptions.js.map +1 -0
- package/lib/http.d.ts +0 -0
- package/lib/http.js +1 -0
- package/lib/http.js.map +1 -0
- package/lib/hydrators/datetime.d.ts +8 -0
- package/lib/hydrators/datetime.js +63 -0
- package/lib/hydrators/datetime.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -3
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +44 -15
- package/lib/interfaces.js +31 -12
- package/lib/interfaces.js.map +1 -1
- package/lib/response-methods/badRequest.d.ts +3 -2
- package/lib/response-methods/badRequest.js +1 -1
- package/lib/response-methods/badRequest.js.map +1 -1
- package/lib/response-methods/conflict.d.ts +3 -2
- package/lib/response-methods/conflict.js +1 -1
- package/lib/response-methods/conflict.js.map +1 -1
- package/lib/response-methods/cookieResponse.d.ts +3 -2
- package/lib/response-methods/cookieResponse.js +9 -5
- package/lib/response-methods/cookieResponse.js.map +1 -1
- package/lib/response-methods/created.d.ts +3 -2
- package/lib/response-methods/created.js +1 -1
- package/lib/response-methods/created.js.map +1 -1
- package/lib/response-methods/file.d.ts +16 -2
- package/lib/response-methods/file.js +67 -5
- package/lib/response-methods/file.js.map +1 -1
- package/lib/response-methods/forbidden.d.ts +3 -2
- package/lib/response-methods/forbidden.js +1 -1
- package/lib/response-methods/forbidden.js.map +1 -1
- package/lib/response-methods/index.js +6 -2
- package/lib/response-methods/index.js.map +1 -1
- package/lib/response-methods/noContent.d.ts +3 -2
- package/lib/response-methods/noContent.js +1 -1
- package/lib/response-methods/noContent.js.map +1 -1
- package/lib/response-methods/notFound.d.ts +3 -2
- package/lib/response-methods/notFound.js +1 -1
- package/lib/response-methods/notFound.js.map +1 -1
- package/lib/response-methods/ok.d.ts +3 -2
- package/lib/response-methods/ok.js +1 -1
- package/lib/response-methods/ok.js.map +1 -1
- package/lib/response-methods/pug.d.ts +3 -2
- package/lib/response-methods/pug.js +1 -1
- package/lib/response-methods/pug.js.map +1 -1
- package/lib/response-methods/redirect.d.ts +2 -2
- package/lib/response-methods/redirect.js +2 -4
- package/lib/response-methods/redirect.js.map +1 -1
- package/lib/response-methods/serverError.d.ts +3 -2
- package/lib/response-methods/serverError.js +1 -1
- package/lib/response-methods/serverError.js.map +1 -1
- package/lib/response-methods/unauthorized.d.ts +3 -2
- package/lib/response-methods/unauthorized.js +1 -1
- package/lib/response-methods/unauthorized.js.map +1 -1
- package/lib/responses.d.ts +1 -1
- package/lib/responses.js +28 -11
- package/lib/responses.js.map +1 -1
- package/lib/route-args/ArgAsRequest.d.ts +11 -0
- package/lib/{transformers/PureFormatter.js → route-args/ArgAsRequest.js} +13 -12
- package/lib/route-args/ArgAsRequest.js.map +1 -0
- package/lib/route-args/ArgAsResponse.d.ts +10 -0
- package/lib/{dto/order-dto.js → route-args/ArgAsResponse.js} +16 -18
- package/lib/route-args/ArgAsResponse.js.map +1 -0
- package/lib/route-args/ArgHydrator.d.ts +3 -0
- package/lib/route-args/ArgHydrator.js +7 -0
- package/lib/route-args/ArgHydrator.js.map +1 -0
- package/lib/route-args/FromBody.d.ts +10 -0
- package/lib/route-args/FromBody.js +44 -0
- package/lib/route-args/FromBody.js.map +1 -0
- package/lib/route-args/FromCoockie.d.ts +13 -0
- package/lib/route-args/FromCoockie.js +71 -0
- package/lib/route-args/FromCoockie.js.map +1 -0
- package/lib/route-args/FromCookie.d.ts +13 -0
- package/lib/route-args/FromCookie.js +74 -0
- package/lib/route-args/FromCookie.js.map +1 -0
- package/lib/route-args/FromDi.d.ts +14 -0
- package/lib/route-args/FromDi.js +36 -0
- package/lib/route-args/FromDi.js.map +1 -0
- package/lib/route-args/FromForm.d.ts +82 -0
- package/lib/route-args/FromForm.js +259 -0
- package/lib/route-args/FromForm.js.map +1 -0
- package/lib/route-args/FromHeaderArg.d.ts +12 -0
- package/lib/route-args/FromHeaderArg.js +30 -0
- package/lib/route-args/FromHeaderArg.js.map +1 -0
- package/lib/route-args/FromParams.d.ts +10 -0
- package/lib/route-args/FromParams.js +25 -0
- package/lib/route-args/FromParams.js.map +1 -0
- package/lib/route-args/FromQuery.d.ts +10 -0
- package/lib/{dto/limit-dto.js → route-args/FromQuery.js} +16 -18
- package/lib/route-args/FromQuery.js.map +1 -0
- package/lib/route-args/RouteArgs.d.ts +19 -0
- package/lib/route-args/RouteArgs.js +64 -0
- package/lib/route-args/RouteArgs.js.map +1 -0
- package/lib/route-args/index.d.ts +11 -0
- package/lib/route-args/index.js +28 -0
- package/lib/route-args/index.js.map +1 -0
- package/lib/schemas/RouteArgsSchemas.d.ts +15 -0
- package/lib/schemas/RouteArgsSchemas.js +19 -0
- package/lib/schemas/RouteArgsSchemas.js.map +1 -0
- package/lib/server.d.ts +3 -2
- package/lib/server.js +30 -14
- package/lib/server.js.map +1 -1
- package/lib/transformers/PureTransformer.d.ts +1 -1
- package/lib/transformers/PureTransformer.js +2 -2
- package/lib/transformers/PureTransformer.js.map +1 -1
- package/package.json +27 -54
- package/lib/dto/index.d.ts +0 -2
- package/lib/dto/index.js +0 -15
- package/lib/dto/index.js.map +0 -1
- package/lib/dto/limit-dto.d.ts +0 -32
- package/lib/dto/limit-dto.js.map +0 -1
- package/lib/dto/order-dto.d.ts +0 -32
- package/lib/dto/order-dto.js.map +0 -1
- package/lib/schemas.d.ts +0 -24
- package/lib/schemas.js +0 -96
- package/lib/schemas.js.map +0 -1
- package/lib/static/favicon.ico +0 -0
- package/lib/static/style.css +0 -15
- package/lib/transformers/PureFormatter.d.ts +0 -7
- package/lib/transformers/PureFormatter.js.map +0 -1
- package/lib/views/responses/badRequest.pug +0 -13
- package/lib/views/responses/conflict.pug +0 -13
- package/lib/views/responses/forbidden.pug +0 -13
- package/lib/views/responses/noContent.pug +0 -13
- package/lib/views/responses/notFound.pug +0 -13
- package/lib/views/responses/ok.pug +0 -12
- package/lib/views/responses/serverError.pug +0 -13
- package/lib/views/responses/unauthorized.pug +0 -13
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 400 BAD REQUEST ERROR
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class BadRequest extends Response {
|
|
9
10
|
constructor(data: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class BadRequest extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.BAD_REQUEST, 'responses/badRequest');
|
|
16
|
+
return await (0, responses_1.httpResponse)(this.responseData, interfaces_1.HTTP_STATUS_CODE.BAD_REQUEST, 'responses/badRequest');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.BadRequest = BadRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badRequest.js","sourceRoot":"","sources":["../../src/response-methods/badRequest.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"badRequest.js","sourceRoot":"","sources":["../../src/response-methods/badRequest.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AAEH,MAAa,UAAW,SAAQ,oBAAQ;IACtC,YAAY,IAAS;QACnB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;IACrG,CAAC;CACF;AARD,gCAQC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 409 Conflict
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class Conflict extends Response {
|
|
9
10
|
constructor(data: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class Conflict extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.CONFLICT, 'responses/conflict');
|
|
16
|
+
return await (0, responses_1.httpResponse)(this.responseData, interfaces_1.HTTP_STATUS_CODE.CONFLICT, 'responses/conflict');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.Conflict = Conflict;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict.js","sourceRoot":"","sources":["../../src/response-methods/conflict.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"conflict.js","sourceRoot":"","sources":["../../src/response-methods/conflict.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AAEH,MAAa,QAAS,SAAQ,oBAAQ;IACpC,YAAY,IAAS;QACnB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAChG,CAAC;CACF;AARD,4BAQC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Simpel wrapper for coockie response for api consistency.
|
|
5
6
|
* It also signs cookie with coockie-secure
|
|
@@ -10,5 +11,5 @@ export declare class CookieResponse extends Response {
|
|
|
10
11
|
protected cookieLifetime: number;
|
|
11
12
|
protected data?: any;
|
|
12
13
|
constructor(name: string, value: string, cookieLifetime: number, data?: any);
|
|
13
|
-
execute(_req: express.Request, res: express.Response): Promise<
|
|
14
|
+
execute(_req: express.Request, res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
14
15
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,7 +18,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
14
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
19
|
if (mod && mod.__esModule) return mod;
|
|
16
20
|
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
22
|
__setModuleDefault(result, mod);
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
@@ -38,8 +42,8 @@ class CookieResponse extends responses_1.Response {
|
|
|
38
42
|
this.data = data;
|
|
39
43
|
}
|
|
40
44
|
async execute(_req, res) {
|
|
41
|
-
const cfg = di_1.DI.
|
|
42
|
-
const cookieOpt = this.cookieLifetime ? this.cookieLifetime
|
|
45
|
+
const cfg = di_1.DI.get(configuration_1.Configuration);
|
|
46
|
+
const cookieOpt = this.cookieLifetime ? { maxAge: this.cookieLifetime } : cfg.get('http.cookie.options');
|
|
43
47
|
if (!this.responseData) {
|
|
44
48
|
res.clearCookie(this.name, cookieOpt);
|
|
45
49
|
}
|
|
@@ -48,7 +52,7 @@ class CookieResponse extends responses_1.Response {
|
|
|
48
52
|
const signed = cs.sign(this.responseData, secureKey);
|
|
49
53
|
res.cookie(this.name, signed, cookieOpt);
|
|
50
54
|
}
|
|
51
|
-
return responses_1.httpResponse(this.data, interfaces_1.HTTP_STATUS_CODE.OK, 'responses/ok');
|
|
55
|
+
return await (0, responses_1.httpResponse)(this.data, interfaces_1.HTTP_STATUS_CODE.OK, 'responses/ok');
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
exports.CookieResponse = CookieResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookieResponse.js","sourceRoot":"","sources":["../../src/response-methods/cookieResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cookieResponse.js","sourceRoot":"","sources":["../../src/response-methods/cookieResponse.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAAsD;AACtD,0DAAuD;AACvD,oCAAiC;AACjC,qDAAuC;AACvC,8CAAiD;AAGjD;;;GAGG;AACH,MAAa,cAAe,SAAQ,oBAAQ;IAC1C,YAAsB,IAAY,EAAY,KAAa,EAAY,cAAsB,EAAY,IAAU;QACjH,KAAK,CAAC,KAAK,CAAC,CAAC;QADO,SAAI,GAAJ,IAAI,CAAQ;QAAY,UAAK,GAAL,KAAK,CAAQ;QAAY,mBAAc,GAAd,cAAc,CAAQ;QAAY,SAAI,GAAJ,IAAI,CAAM;IAEnH,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAC/D,MAAM,GAAG,GAAkB,OAAE,CAAC,GAAG,CAAC,6BAAa,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAgB,qBAAqB,CAAC,CAAC;QAExH,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,SAA0B,CAAC,CAAC;SACxD;aAAM;YACL,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAS,oBAAoB,CAAC,CAAC;YACxD,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;YAErD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,SAAgB,CAAC,CAAC;SACjD;QAED,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,IAAI,EAAE,6BAAgB,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;IAC5E,CAAC;CACF;AApBD,wCAoBC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 201 CREATED
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class Created extends Response {
|
|
9
10
|
constructor(data: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class Created extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.CREATED, 'responses/created');
|
|
16
|
+
return await (0, responses_1.httpResponse)(this.responseData, interfaces_1.HTTP_STATUS_CODE.CREATED, 'responses/created');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.Created = Created;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"created.js","sourceRoot":"","sources":["../../src/response-methods/created.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"created.js","sourceRoot":"","sources":["../../src/response-methods/created.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AACH,MAAa,OAAQ,SAAQ,oBAAQ;IACnC,YAAY,IAAS;QACnB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IAC9F,CAAC;CACF;AARD,0BAQC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
2
|
+
import { Response } from '../responses';
|
|
3
|
+
import { Row, FormatterOptionsArgs } from '@fast-csv/format';
|
|
3
4
|
export declare class FileResponse extends Response {
|
|
4
5
|
protected path: string;
|
|
5
6
|
protected filename: string;
|
|
@@ -12,5 +13,18 @@ export declare class FileResponse extends Response {
|
|
|
12
13
|
* @param mimeType - optional mimetype. If not set, server will try to guess.
|
|
13
14
|
*/
|
|
14
15
|
constructor(path: string, filename: string, mimeType?: string);
|
|
15
|
-
execute(_req: express.Request, res: express.Response): Promise<
|
|
16
|
+
execute(_req: express.Request, res: express.Response): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare class CvsFileResponse<I extends Row, O extends Row> extends Response {
|
|
19
|
+
protected data: any;
|
|
20
|
+
protected filename: string;
|
|
21
|
+
protected options?: FormatterOptionsArgs<I, O> | undefined;
|
|
22
|
+
constructor(data: any, filename: string, options?: FormatterOptionsArgs<I, O> | undefined);
|
|
23
|
+
execute(_req: express.Request, res: express.Response): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare class JsonFileResponse extends Response {
|
|
26
|
+
protected data: any;
|
|
27
|
+
protected filename: string;
|
|
28
|
+
constructor(data: any, filename: string);
|
|
29
|
+
execute(_req: express.Request, res: express.Response): Promise<void>;
|
|
16
30
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,17 +18,22 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
14
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
19
|
if (mod && mod.__esModule) return mod;
|
|
16
20
|
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
22
|
__setModuleDefault(result, mod);
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
21
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.FileResponse = void 0;
|
|
29
|
+
exports.JsonFileResponse = exports.CvsFileResponse = exports.FileResponse = void 0;
|
|
23
30
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
24
31
|
const fs = __importStar(require("fs"));
|
|
25
32
|
const _ = __importStar(require("lodash"));
|
|
26
33
|
const mime_1 = require("mime");
|
|
27
34
|
const responses_1 = require("../responses");
|
|
35
|
+
const format_1 = require("@fast-csv/format");
|
|
36
|
+
const tempfile_1 = __importDefault(require("tempfile"));
|
|
28
37
|
class FileResponse extends responses_1.Response {
|
|
29
38
|
/**
|
|
30
39
|
* Sends file to client at given path & filename. If file exists
|
|
@@ -35,7 +44,7 @@ class FileResponse extends responses_1.Response {
|
|
|
35
44
|
*/
|
|
36
45
|
constructor(path, filename, mimeType) {
|
|
37
46
|
super(null);
|
|
38
|
-
this.mimeType = mimeType ? mimeType : mime_1.getType(filename);
|
|
47
|
+
this.mimeType = mimeType ? mimeType : (0, mime_1.getType)(filename);
|
|
39
48
|
this.filename = filename;
|
|
40
49
|
this.path = path;
|
|
41
50
|
if (!fs.existsSync(path)) {
|
|
@@ -44,7 +53,7 @@ class FileResponse extends responses_1.Response {
|
|
|
44
53
|
}
|
|
45
54
|
async execute(_req, res) {
|
|
46
55
|
return new Promise((resolve, reject) => {
|
|
47
|
-
res.download(this.path, (err) => {
|
|
56
|
+
res.download(this.path, this.filename, (err) => {
|
|
48
57
|
if (!_.isNil(err)) {
|
|
49
58
|
reject(err);
|
|
50
59
|
}
|
|
@@ -56,4 +65,57 @@ class FileResponse extends responses_1.Response {
|
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
exports.FileResponse = FileResponse;
|
|
68
|
+
class CvsFileResponse extends responses_1.Response {
|
|
69
|
+
constructor(data, filename, options) {
|
|
70
|
+
super(null);
|
|
71
|
+
this.data = data;
|
|
72
|
+
this.filename = filename;
|
|
73
|
+
this.options = options;
|
|
74
|
+
}
|
|
75
|
+
async execute(_req, res) {
|
|
76
|
+
const csvStream = (0, format_1.format)(this.options);
|
|
77
|
+
const tempPath = (0, tempfile_1.default)('.cvs');
|
|
78
|
+
const file = await fs.promises.open(tempPath, 'w');
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
csvStream.pipe(file.createWriteStream()).on('end', () => {
|
|
81
|
+
file.close().then(() => {
|
|
82
|
+
res.download(tempPath, this.filename, (err) => {
|
|
83
|
+
if (err) {
|
|
84
|
+
reject(err);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
resolve();
|
|
88
|
+
}
|
|
89
|
+
fs.unlink(tempPath, null);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.CvsFileResponse = CvsFileResponse;
|
|
97
|
+
class JsonFileResponse extends responses_1.Response {
|
|
98
|
+
constructor(data, filename) {
|
|
99
|
+
super(null);
|
|
100
|
+
this.data = data;
|
|
101
|
+
this.filename = filename;
|
|
102
|
+
}
|
|
103
|
+
async execute(_req, res) {
|
|
104
|
+
const tempPath = (0, tempfile_1.default)('.json');
|
|
105
|
+
const file = await fs.promises.open(tempPath, 'w');
|
|
106
|
+
await file.writeFile(JSON.stringify(this.data));
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
res.download(tempPath, this.filename, (err) => {
|
|
109
|
+
if (err) {
|
|
110
|
+
reject(err);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
resolve();
|
|
114
|
+
}
|
|
115
|
+
fs.unlink(tempPath, null);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.JsonFileResponse = JsonFileResponse;
|
|
59
121
|
//# sourceMappingURL=file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/response-methods/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/response-methods/file.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 403 FORBIDDEN ERROR
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class Forbidden extends Response {
|
|
9
10
|
constructor(data: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class Forbidden extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.FORBIDDEN, 'responses/forbidden');
|
|
16
|
+
return await (0, responses_1.httpResponse)(this.responseData, interfaces_1.HTTP_STATUS_CODE.FORBIDDEN, 'responses/forbidden');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.Forbidden = Forbidden;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forbidden.js","sourceRoot":"","sources":["../../src/response-methods/forbidden.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"forbidden.js","sourceRoot":"","sources":["../../src/response-methods/forbidden.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AAEH,MAAa,SAAU,SAAQ,oBAAQ;IACrC,YAAY,IAAS;QACnB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;IAClG,CAAC;CACF;AARD,8BAQC"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./badRequest"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/response-methods/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/response-methods/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,yCAAuB;AACvB,8CAA4B;AAC5B,8CAA4B;AAC5B,6CAA2B;AAC3B,uCAAqB;AACrB,wCAAsB;AACtB,gDAA8B;AAC9B,iDAA+B;AAC/B,mDAAiC;AACjC,6CAA2B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 204 NO CONTENT
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class NoContent extends Response {
|
|
9
10
|
constructor(data: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class NoContent extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.NO_CONTENT, 'responses/noContent');
|
|
16
|
+
return await (0, responses_1.httpResponse)(this.responseData, interfaces_1.HTTP_STATUS_CODE.NO_CONTENT, 'responses/noContent');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.NoContent = NoContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noContent.js","sourceRoot":"","sources":["../../src/response-methods/noContent.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"noContent.js","sourceRoot":"","sources":["../../src/response-methods/noContent.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AACH,MAAa,SAAU,SAAQ,oBAAQ;IACrC,YAAY,IAAS;QACnB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;IACnG,CAAC;CACF;AARD,8BAQC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 404 NOT FOUND ERROR
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class NotFound extends Response {
|
|
9
10
|
constructor(data?: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class NotFound extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.NOT_FOUND, 'responses/notFound');
|
|
16
|
+
return await (0, responses_1.httpResponse)(this.responseData, interfaces_1.HTTP_STATUS_CODE.NOT_FOUND, 'responses/notFound');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.NotFound = NotFound;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notFound.js","sourceRoot":"","sources":["../../src/response-methods/notFound.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"notFound.js","sourceRoot":"","sources":["../../src/response-methods/notFound.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AACH,MAAa,QAAS,SAAQ,oBAAQ;IACpC,YAAY,IAAU;QACpB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;IACjG,CAAC;CACF;AARD,4BAQC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 200 OK response with json content
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class Ok extends Response {
|
|
9
10
|
constructor(data?: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class Ok extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.OK, 'responses/ok');
|
|
16
|
+
return await (0, responses_1.httpResponse)(this.responseData, interfaces_1.HTTP_STATUS_CODE.OK, 'responses/ok');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.Ok = Ok;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ok.js","sourceRoot":"","sources":["../../src/response-methods/ok.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"ok.js","sourceRoot":"","sources":["../../src/response-methods/ok.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AACH,MAAa,EAAG,SAAQ,oBAAQ;IAC9B,YAAY,IAAU;QACpB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;IACpF,CAAC;CACF;AARD,gBAQC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
3
|
import { HTTP_STATUS_CODE } from '../interfaces';
|
|
3
|
-
import { Response
|
|
4
|
+
import { Response } from '../responses';
|
|
4
5
|
/**
|
|
5
6
|
* HTML resposne with HTML from pug file
|
|
6
7
|
*/
|
|
@@ -8,5 +9,5 @@ export declare class PugResponse extends Response {
|
|
|
8
9
|
protected file: string;
|
|
9
10
|
protected status: HTTP_STATUS_CODE;
|
|
10
11
|
constructor(file: string, model: any, status?: HTTP_STATUS_CODE);
|
|
11
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
12
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
12
13
|
}
|
|
@@ -14,7 +14,7 @@ class PugResponse extends responses_1.Response {
|
|
|
14
14
|
this.status = status;
|
|
15
15
|
}
|
|
16
16
|
async execute(_req, _res) {
|
|
17
|
-
return responses_1.pugResponse(this.file, this.responseData, this.status ? this.status : interfaces_1.HTTP_STATUS_CODE.OK);
|
|
17
|
+
return await (0, responses_1.pugResponse)(this.file, this.responseData, this.status ? this.status : interfaces_1.HTTP_STATUS_CODE.OK);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.PugResponse = PugResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pug.js","sourceRoot":"","sources":["../../src/response-methods/pug.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"pug.js","sourceRoot":"","sources":["../../src/response-methods/pug.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAqD;AAErD;;GAEG;AACH,MAAa,WAAY,SAAQ,oBAAQ;IAIvC,YAAY,IAAY,EAAE,KAAU,EAAE,MAAyB;QAC7D,KAAK,CAAC,KAAK,CAAC,CAAC;QAHL,WAAM,GAAqB,IAAI,CAAC;QAKxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,uBAAW,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,6BAAgB,CAAC,EAAE,CAAC,CAAC;IAC1G,CAAC;CACF;AAdD,kCAcC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
2
|
+
import { Response } from '../responses';
|
|
3
3
|
/**
|
|
4
4
|
* Redirects to another route ( simple alias for request.redirect for api consistency)
|
|
5
5
|
*
|
|
@@ -8,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
8
8
|
export declare class Redirect extends Response {
|
|
9
9
|
protected url: string;
|
|
10
10
|
constructor(url: any);
|
|
11
|
-
execute(_req: express.Request,
|
|
11
|
+
execute(_req: express.Request, res: express.Response): Promise<void>;
|
|
12
12
|
}
|
|
@@ -12,10 +12,8 @@ class Redirect extends responses_1.Response {
|
|
|
12
12
|
super(null);
|
|
13
13
|
this.url = url;
|
|
14
14
|
}
|
|
15
|
-
async execute(_req,
|
|
16
|
-
|
|
17
|
-
res.redirect(this.url);
|
|
18
|
-
};
|
|
15
|
+
async execute(_req, res) {
|
|
16
|
+
res.redirect(this.url);
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
19
|
exports.Redirect = Redirect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../src/response-methods/redirect.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../src/response-methods/redirect.ts"],"names":[],"mappings":";;;AACA,4CAAwC;AAExC;;;;GAIG;AACH,MAAa,QAAS,SAAQ,oBAAQ;IAGpC,YAAY,GAAQ;QAClB,KAAK,CAAC,IAAI,CAAC,CAAC;QAEZ,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAC/D,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;CACF;AAZD,4BAYC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 500 INTERNAL SERVER ERROR
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class ServerError extends Response {
|
|
9
10
|
constructor(data: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class ServerError extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.INTERNAL_ERROR, 'responses/serverError');
|
|
16
|
+
return await (0, responses_1.httpResponse)({ error: this.responseData }, interfaces_1.HTTP_STATUS_CODE.INTERNAL_ERROR, 'responses/serverError');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.ServerError = ServerError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverError.js","sourceRoot":"","sources":["../../src/response-methods/serverError.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"serverError.js","sourceRoot":"","sources":["../../src/response-methods/serverError.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AAEH,MAAa,WAAY,SAAQ,oBAAQ;IACvC,YAAY,IAAS;QACnB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,EAAE,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,EAAE,6BAAgB,CAAC,cAAc,EAAE,uBAAuB,CAAC,CAAC;IACpH,CAAC;CACF;AARD,kCAQC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
1
2
|
import * as express from 'express';
|
|
2
|
-
import { Response
|
|
3
|
+
import { Response } from '../responses';
|
|
3
4
|
/**
|
|
4
5
|
* Internall response function.
|
|
5
6
|
* Returns HTTP 401 UNAHTORIZED response with json content
|
|
@@ -7,5 +8,5 @@ import { Response, ResponseFunction } from '../responses';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class Unauthorized extends Response {
|
|
9
10
|
constructor(data: any);
|
|
10
|
-
execute(_req: express.Request, _res: express.Response): Promise<
|
|
11
|
+
execute(_req: express.Request, _res: express.Response): Promise<(req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>) => void>;
|
|
11
12
|
}
|
|
@@ -13,7 +13,7 @@ class Unauthorized extends responses_1.Response {
|
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
15
15
|
async execute(_req, _res) {
|
|
16
|
-
return responses_1.httpResponse(this.responseData, interfaces_1.HTTP_STATUS_CODE.UNAUTHORIZED, 'responses/unauthorized');
|
|
16
|
+
return await (0, responses_1.httpResponse)(this.responseData, interfaces_1.HTTP_STATUS_CODE.UNAUTHORIZED, 'responses/unauthorized');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.Unauthorized = Unauthorized;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unauthorized.js","sourceRoot":"","sources":["../../src/response-methods/unauthorized.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"unauthorized.js","sourceRoot":"","sources":["../../src/response-methods/unauthorized.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAAsD;AAEtD;;;;GAIG;AAEH,MAAa,YAAa,SAAQ,oBAAQ;IACxC,YAAY,IAAS;QACnB,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,OAAO,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,YAAY,EAAE,wBAAwB,CAAC,CAAC;IACxG,CAAC;CACF;AARD,oCAQC"}
|
package/lib/responses.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare type ResponseFunction = (req: express.Request, res: express.Respo
|
|
|
4
4
|
export declare abstract class Response {
|
|
5
5
|
protected responseData: any;
|
|
6
6
|
constructor(responseData: any);
|
|
7
|
-
abstract execute(req: express.Request, res: express.Response, next?: express.NextFunction): Promise<ResponseFunction>;
|
|
7
|
+
abstract execute(req: express.Request, res: express.Response, next?: express.NextFunction): Promise<ResponseFunction | void>;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Sends data & sets proper header as json
|