@spinajs/http 2.0.38 → 2.0.45
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/lib/controllers.d.ts +5 -5
- package/lib/controllers.js +15 -8
- package/lib/controllers.js.map +1 -1
- package/lib/decorators.d.ts +2 -2
- package/lib/decorators.js.map +1 -1
- package/lib/interfaces.d.ts +41 -8
- package/lib/interfaces.js +10 -4
- package/lib/interfaces.js.map +1 -1
- package/lib/response-methods/badRequest.d.ts +1 -1
- package/lib/response-methods/badRequest.js +1 -1
- package/lib/response-methods/badRequest.js.map +1 -1
- package/lib/response-methods/conflict.d.ts +1 -1
- package/lib/response-methods/conflict.js +1 -1
- package/lib/response-methods/conflict.js.map +1 -1
- package/lib/response-methods/cookieResponse.d.ts +1 -2
- package/lib/response-methods/cookieResponse.js +1 -1
- package/lib/response-methods/cookieResponse.js.map +1 -1
- package/lib/response-methods/created.d.ts +1 -1
- package/lib/response-methods/created.js +1 -1
- package/lib/response-methods/created.js.map +1 -1
- package/lib/response-methods/file.d.ts +12 -8
- package/lib/response-methods/file.js +85 -35
- package/lib/response-methods/file.js.map +1 -1
- package/lib/response-methods/forbidden.d.ts +1 -1
- package/lib/response-methods/forbidden.js +1 -1
- package/lib/response-methods/forbidden.js.map +1 -1
- package/lib/response-methods/noContent.d.ts +1 -1
- package/lib/response-methods/noContent.js +1 -1
- package/lib/response-methods/noContent.js.map +1 -1
- package/lib/response-methods/notAllowed.d.ts +1 -1
- package/lib/response-methods/notAllowed.js +1 -1
- package/lib/response-methods/notAllowed.js.map +1 -1
- package/lib/response-methods/notFound.d.ts +1 -1
- package/lib/response-methods/notFound.js +1 -1
- package/lib/response-methods/notFound.js.map +1 -1
- package/lib/response-methods/ok.d.ts +1 -1
- package/lib/response-methods/ok.js +1 -1
- package/lib/response-methods/ok.js.map +1 -1
- package/lib/response-methods/pug.d.ts +1 -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 +1 -1
- package/lib/response-methods/redirect.js +2 -2
- package/lib/response-methods/redirect.js.map +1 -1
- package/lib/response-methods/serverError.d.ts +1 -1
- package/lib/response-methods/serverError.js +1 -1
- package/lib/response-methods/serverError.js.map +1 -1
- package/lib/response-methods/unauthorized.d.ts +1 -1
- package/lib/response-methods/unauthorized.js +1 -1
- package/lib/response-methods/unauthorized.js.map +1 -1
- package/lib/responses.d.ts +0 -6
- package/lib/responses.js +1 -7
- package/lib/responses.js.map +1 -1
- package/lib/route-args/FromDi.d.ts +3 -3
- package/lib/route-args/FromDi.js +2 -2
- package/lib/route-args/FromDi.js.map +1 -1
- package/lib/route-args/FromForm.d.ts +8 -1
- package/lib/route-args/FromForm.js +54 -58
- package/lib/route-args/FromForm.js.map +1 -1
- package/lib/server.d.ts +3 -3
- package/lib/server.js +2 -2
- package/lib/server.js.map +1 -1
- package/package.json +15 -14
|
@@ -22,67 +22,117 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.JsonFileResponse = exports.FileResponse = void 0;
|
|
26
|
+
exports.JsonFileResponse = exports.FileResponse = exports.ZipResponse = void 0;
|
|
27
|
+
const di_1 = require("@spinajs/di");
|
|
30
28
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
31
|
-
const fs = __importStar(require("fs"));
|
|
32
29
|
const _ = __importStar(require("lodash"));
|
|
33
30
|
const mime_1 = require("mime");
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
class FileResponse extends responses_1.Response {
|
|
31
|
+
const interfaces_1 = require("./../interfaces");
|
|
32
|
+
class ZipResponse extends interfaces_1.Response {
|
|
37
33
|
/**
|
|
38
|
-
* Sends
|
|
34
|
+
* Sends zipped to client at given path & filename. If file exists
|
|
39
35
|
* it will send file with 200 OK, if not exists 404 NOT FOUND
|
|
40
|
-
* @param path - server full path to file
|
|
41
|
-
* @param filename - real filename send to client
|
|
42
|
-
* @param mimeType - optional mimetype. If not set, server will try to guess.
|
|
43
36
|
*/
|
|
44
|
-
constructor(
|
|
37
|
+
constructor(Options) {
|
|
38
|
+
var _a;
|
|
45
39
|
super(null);
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
this.Options = Options;
|
|
41
|
+
this.Options.mimeType = (_a = Options.mimeType) !== null && _a !== void 0 ? _a : (0, mime_1.getType)(Options.filename);
|
|
42
|
+
}
|
|
43
|
+
async execute(_req, res) {
|
|
44
|
+
const provider = await di_1.DI.resolve('__file_provider__', [this.Options.provider]);
|
|
45
|
+
const exists = await provider.exists(this.Options.path);
|
|
46
|
+
if (!exists) {
|
|
47
|
+
throw new exceptions_1.ResourceNotFound(`File ${this.Options.path} not exists`);
|
|
51
48
|
}
|
|
49
|
+
const file = (await provider.zip(this.Options.path)).asFilePath();
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
res.download(file, this.Options.filename, (err) => {
|
|
52
|
+
provider
|
|
53
|
+
.unlink(this.Options.path, true)
|
|
54
|
+
.then(() => {
|
|
55
|
+
return provider.unlink(file);
|
|
56
|
+
})
|
|
57
|
+
.then(() => {
|
|
58
|
+
if (!_.isNil(err)) {
|
|
59
|
+
reject(err);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
resolve();
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.catch((err) => {
|
|
66
|
+
reject(err);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ZipResponse = ZipResponse;
|
|
73
|
+
class FileResponse extends interfaces_1.Response {
|
|
74
|
+
/**
|
|
75
|
+
* Sends file to client at given path & filename. If file exists
|
|
76
|
+
* it will send file with 200 OK, if not exists 404 NOT FOUND
|
|
77
|
+
*/
|
|
78
|
+
constructor(Options) {
|
|
79
|
+
var _a;
|
|
80
|
+
super(null);
|
|
81
|
+
this.Options = Options;
|
|
82
|
+
this.Options.mimeType = (_a = Options.mimeType) !== null && _a !== void 0 ? _a : (0, mime_1.getType)(Options.filename);
|
|
52
83
|
}
|
|
53
84
|
async execute(_req, res) {
|
|
85
|
+
const provider = await di_1.DI.resolve('__file_provider__', [this.Options.provider]);
|
|
86
|
+
const exists = await provider.exists(this.Options.path);
|
|
87
|
+
if (!exists) {
|
|
88
|
+
throw new exceptions_1.ResourceNotFound(`File ${this.Options.path} not exists`);
|
|
89
|
+
}
|
|
90
|
+
const file = await provider.download(this.Options.path);
|
|
54
91
|
return new Promise((resolve, reject) => {
|
|
55
|
-
res.download(
|
|
56
|
-
|
|
92
|
+
res.download(file, this.Options.filename, (err) => {
|
|
93
|
+
provider
|
|
94
|
+
.unlink(this.Options.path, true)
|
|
95
|
+
.then(() => {
|
|
96
|
+
if (!_.isNil(err)) {
|
|
97
|
+
reject(err);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
resolve();
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
.catch((err) => {
|
|
57
104
|
reject(err);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
resolve();
|
|
61
|
-
}
|
|
105
|
+
});
|
|
62
106
|
});
|
|
63
107
|
});
|
|
64
108
|
}
|
|
65
109
|
}
|
|
66
110
|
exports.FileResponse = FileResponse;
|
|
67
|
-
class JsonFileResponse extends
|
|
111
|
+
class JsonFileResponse extends interfaces_1.Response {
|
|
68
112
|
constructor(data, filename) {
|
|
69
113
|
super(null);
|
|
70
114
|
this.data = data;
|
|
71
115
|
this.filename = filename;
|
|
72
116
|
}
|
|
73
117
|
async execute(_req, res) {
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
118
|
+
const provider = await di_1.DI.resolve('__file_provider__', ['fs-temp']);
|
|
119
|
+
const tmpPath = provider.tmppath();
|
|
120
|
+
provider.write(tmpPath, JSON.stringify(this.data));
|
|
77
121
|
return new Promise((resolve, reject) => {
|
|
78
|
-
res.download(
|
|
79
|
-
|
|
122
|
+
res.download(tmpPath, this.filename, (err) => {
|
|
123
|
+
provider
|
|
124
|
+
.unlink(tmpPath)
|
|
125
|
+
.then(() => {
|
|
126
|
+
if (err) {
|
|
127
|
+
reject(err);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
resolve();
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
.catch((err) => {
|
|
80
134
|
reject(err);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
resolve();
|
|
84
|
-
}
|
|
85
|
-
fs.unlink(tempPath, null);
|
|
135
|
+
});
|
|
86
136
|
});
|
|
87
137
|
});
|
|
88
138
|
}
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAiC;AACjC,oDAAuD;AAEvD,0CAA4B;AAC5B,+BAA+B;AAC/B,gDAAiE;AAGjE,MAAa,WAAY,SAAQ,qBAAQ;IACvC;;;OAGG;IACH,YAAsB,OAA6B;;QACjD,KAAK,CAAC,IAAI,CAAC,CAAC;QADQ,YAAO,GAAP,OAAO,CAAsB;QAGjD,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,IAAA,cAAO,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAC/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/forbidden.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"forbidden.js","sourceRoot":"","sources":["../../src/response-methods/forbidden.ts"],"names":[],"mappings":";;;AACA,8CAA2D;AAC3D,4CAA4C;AAE5C;;;;GAIG;AAEH,MAAa,SAAU,SAAQ,qBAAQ;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noContent.js","sourceRoot":"","sources":["../../src/response-methods/noContent.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"noContent.js","sourceRoot":"","sources":["../../src/response-methods/noContent.ts"],"names":[],"mappings":";;;AACA,8CAA2D;AAC3D,4CAA4C;AAE5C;;;;GAIG;AACH,MAAa,SAAU,SAAQ,qBAAQ;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"}
|
|
@@ -8,7 +8,7 @@ const responses_1 = require("../responses");
|
|
|
8
8
|
* Returns HTTP 403 FORBIDDEN ERROR
|
|
9
9
|
* @param err - error to send
|
|
10
10
|
*/
|
|
11
|
-
class NotAllowed extends
|
|
11
|
+
class NotAllowed extends interfaces_1.Response {
|
|
12
12
|
constructor(data) {
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notAllowed.js","sourceRoot":"","sources":["../../src/response-methods/notAllowed.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"notAllowed.js","sourceRoot":"","sources":["../../src/response-methods/notAllowed.ts"],"names":[],"mappings":";;;AACA,8CAA2D;AAC3D,4CAA4C;AAE5C;;;;GAIG;AAEH,MAAa,UAAW,SAAQ,qBAAQ;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,uBAAuB,CAAC,CAAC;IACtG,CAAC;CACF;AARD,gCAQC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notFound.js","sourceRoot":"","sources":["../../src/response-methods/notFound.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"notFound.js","sourceRoot":"","sources":["../../src/response-methods/notFound.ts"],"names":[],"mappings":";;;AACA,8CAA2D;AAC3D,4CAA4C;AAE5C;;;;GAIG;AACH,MAAa,QAAS,SAAQ,qBAAQ;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ok.js","sourceRoot":"","sources":["../../src/response-methods/ok.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"ok.js","sourceRoot":"","sources":["../../src/response-methods/ok.ts"],"names":[],"mappings":";;;AACA,8CAA2D;AAC3D,4CAA4C;AAE5C;;;;GAIG;AACH,MAAa,EAAG,SAAQ,qBAAQ;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"}
|
|
@@ -6,7 +6,7 @@ const responses_1 = require("../responses");
|
|
|
6
6
|
/**
|
|
7
7
|
* HTML resposne with HTML from pug file
|
|
8
8
|
*/
|
|
9
|
-
class TemplateResponse extends
|
|
9
|
+
class TemplateResponse extends interfaces_1.Response {
|
|
10
10
|
constructor(file, model, status) {
|
|
11
11
|
super(model);
|
|
12
12
|
this.status = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pug.js","sourceRoot":"","sources":["../../src/response-methods/pug.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"pug.js","sourceRoot":"","sources":["../../src/response-methods/pug.ts"],"names":[],"mappings":";;;AACA,8CAA2D;AAC3D,4CAA4C;AAE5C;;GAEG;AACH,MAAa,gBAAiB,SAAQ,qBAAQ;IAI5C,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,wBAAY,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;IAC3G,CAAC;CACF;AAdD,4CAcC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Redirect = void 0;
|
|
4
|
-
const
|
|
4
|
+
const interfaces_1 = require("../interfaces");
|
|
5
5
|
/**
|
|
6
6
|
* Redirects to another route ( simple alias for request.redirect for api consistency)
|
|
7
7
|
*
|
|
8
8
|
* @param url - url path to another location
|
|
9
9
|
*/
|
|
10
|
-
class Redirect extends
|
|
10
|
+
class Redirect extends interfaces_1.Response {
|
|
11
11
|
constructor(url) {
|
|
12
12
|
super(null);
|
|
13
13
|
this.url = url;
|
|
@@ -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,8CAAyC;AAEzC;;;;GAIG;AACH,MAAa,QAAS,SAAQ,qBAAQ;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"}
|
|
@@ -8,7 +8,7 @@ const responses_1 = require("../responses");
|
|
|
8
8
|
* Returns HTTP 500 INTERNAL SERVER ERROR
|
|
9
9
|
* @param err - error to send
|
|
10
10
|
*/
|
|
11
|
-
class ServerError extends
|
|
11
|
+
class ServerError extends interfaces_1.Response {
|
|
12
12
|
constructor(data) {
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverError.js","sourceRoot":"","sources":["../../src/response-methods/serverError.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"serverError.js","sourceRoot":"","sources":["../../src/response-methods/serverError.ts"],"names":[],"mappings":";;;AACA,8CAA2D;AAC3D,4CAA4C;AAE5C;;;;GAIG;AAEH,MAAa,WAAY,SAAQ,qBAAQ;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"}
|
|
@@ -8,7 +8,7 @@ const responses_1 = require("../responses");
|
|
|
8
8
|
* Returns HTTP 401 UNAHTORIZED response with json content
|
|
9
9
|
* @param data - data to send
|
|
10
10
|
*/
|
|
11
|
-
class Unauthorized extends
|
|
11
|
+
class Unauthorized extends interfaces_1.Response {
|
|
12
12
|
constructor(data) {
|
|
13
13
|
super(data);
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unauthorized.js","sourceRoot":"","sources":["../../src/response-methods/unauthorized.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"unauthorized.js","sourceRoot":"","sources":["../../src/response-methods/unauthorized.ts"],"names":[],"mappings":";;;AACA,8CAA2D;AAC3D,4CAA4C;AAE5C;;;;GAIG;AAEH,MAAa,YAAa,SAAQ,qBAAQ;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
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import { HTTP_STATUS_CODE } from './interfaces';
|
|
3
|
-
export declare type ResponseFunction = (req: express.Request, res: express.Response) => void;
|
|
4
|
-
export declare abstract class Response {
|
|
5
|
-
protected responseData: any;
|
|
6
|
-
constructor(responseData: any);
|
|
7
|
-
abstract execute(req: express.Request, res: express.Response, next?: express.NextFunction): Promise<ResponseFunction | void>;
|
|
8
|
-
}
|
|
9
3
|
/**
|
|
10
4
|
* Sends data & sets proper header as json
|
|
11
5
|
*
|
package/lib/responses.js
CHANGED
|
@@ -23,19 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.httpResponse = exports.htmlResponse = exports.textResponse = exports.jsonResponse =
|
|
26
|
+
exports.httpResponse = exports.htmlResponse = exports.textResponse = exports.jsonResponse = void 0;
|
|
27
27
|
const interfaces_1 = require("./interfaces");
|
|
28
28
|
const configuration_1 = require("@spinajs/configuration");
|
|
29
29
|
const di_1 = require("@spinajs/di");
|
|
30
30
|
const log_1 = require("@spinajs/log");
|
|
31
31
|
const randomstring = __importStar(require("randomstring"));
|
|
32
32
|
const templates_1 = require("@spinajs/templates");
|
|
33
|
-
class Response {
|
|
34
|
-
constructor(responseData) {
|
|
35
|
-
this.responseData = responseData;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.Response = Response;
|
|
39
33
|
/**
|
|
40
34
|
* Sends data & sets proper header as json
|
|
41
35
|
*
|
package/lib/responses.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../src/responses.ts"],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SACxD;aAAM,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,GAAG,8BAAiB,CAAC,IAAI,CAAC,KAAK,8BAAiB,CAAC,IAAI,EAAE;YACvG,IAAI,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE;gBACnC,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;gBACzF,IAAI,WAAW,EAAE;oBACf,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;iBACjE;qBAAM;oBACL,YAAY,CACV;wBACE,KAAK,EAAE;4BACL,OAAO,EAAE,8GAA8G;4BACvH,IAAI,EAAE,GAAG;yBACV;qBACF,EACD,6BAAgB,CAAC,WAAW,CAC7B,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;iBACb;aACF;iBAAM;gBACL,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;aACrC;SACF;aAAM;YACL,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SACrC;IACH,CAAC,CAAC;AACJ,CAAC;AA9BD,oCA8BC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IRouteArgs } from './RouteArgs';
|
|
2
2
|
import { IRouteParameter, ParameterType, IRouteCall, Request } from '../interfaces';
|
|
3
|
-
import {
|
|
4
|
-
export declare class FromDi extends
|
|
3
|
+
import { AsyncService, IContainer } from '@spinajs/di';
|
|
4
|
+
export declare class FromDi extends AsyncService implements IRouteArgs {
|
|
5
5
|
protected Container: IContainer;
|
|
6
6
|
constructor(c: IContainer);
|
|
7
|
-
|
|
7
|
+
resolve(): Promise<void>;
|
|
8
8
|
get SupportedType(): ParameterType;
|
|
9
9
|
extract(callData: IRouteCall, param: IRouteParameter, _req: Request): Promise<{
|
|
10
10
|
CallData: IRouteCall;
|
package/lib/route-args/FromDi.js
CHANGED
|
@@ -12,12 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.FromDi = void 0;
|
|
13
13
|
const interfaces_1 = require("../interfaces");
|
|
14
14
|
const di_1 = require("@spinajs/di");
|
|
15
|
-
let FromDi = class FromDi extends di_1.
|
|
15
|
+
let FromDi = class FromDi extends di_1.AsyncService {
|
|
16
16
|
constructor(c) {
|
|
17
17
|
super();
|
|
18
18
|
this.Container = c;
|
|
19
19
|
}
|
|
20
|
-
async
|
|
20
|
+
async resolve() { }
|
|
21
21
|
get SupportedType() {
|
|
22
22
|
return interfaces_1.ParameterType.FromDi;
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FromDi.js","sourceRoot":"","sources":["../../src/route-args/FromDi.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8CAAoF;AACpF,
|
|
1
|
+
{"version":3,"file":"FromDi.js","sourceRoot":"","sources":["../../src/route-args/FromDi.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8CAAoF;AACpF,oCAAsF;AAItF,IAAa,MAAM,GAAnB,MAAa,MAAO,SAAQ,iBAAY;IAGtC,YAAY,CAAa;QACvB,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,OAAO,KAAmB,CAAC;IAEjC,IAAW,aAAa;QACtB,OAAO,0BAAa,CAAC,MAAM,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,QAAoB,EAAE,KAAsB,EAAE,IAAa;QAC9E,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC3C,CAAC;CACF,CAAA;AAnBY,MAAM;IAFlB,IAAA,eAAU,GAAE;IACZ,IAAA,WAAM,EAAC,cAAS,CAAC;;GACL,MAAM,CAmBlB;AAnBY,wBAAM"}
|
|
@@ -3,6 +3,7 @@ import { IRouteParameter, ParameterType, IRouteCall, Request } from '../interfac
|
|
|
3
3
|
import * as express from 'express';
|
|
4
4
|
import { Fields, Files } from 'formidable';
|
|
5
5
|
import { Configuration } from '@spinajs/configuration';
|
|
6
|
+
import { fs } from '@spinajs/fs';
|
|
6
7
|
interface FormData {
|
|
7
8
|
Fields: Fields;
|
|
8
9
|
Files: Files;
|
|
@@ -10,7 +11,12 @@ interface FormData {
|
|
|
10
11
|
export declare type FormOptionsCallback = (conf: Configuration) => Promise<FormOptions>;
|
|
11
12
|
export interface FormOptions {
|
|
12
13
|
encoding?: string;
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Wchitch service is handling incoming file storage
|
|
16
|
+
* fs file provider, defaults to default provider set in configuration
|
|
17
|
+
* can be local, remote, aws s3, ftp, etc
|
|
18
|
+
*/
|
|
19
|
+
fileProvider?: string;
|
|
14
20
|
keepExtensions?: boolean;
|
|
15
21
|
maxFileSize?: number;
|
|
16
22
|
maxFieldsSize?: number;
|
|
@@ -21,6 +27,7 @@ export interface FormOptions {
|
|
|
21
27
|
}
|
|
22
28
|
export declare abstract class FromFormBase extends RouteArgs {
|
|
23
29
|
Data: FormData;
|
|
30
|
+
protected FileService: fs;
|
|
24
31
|
protected parseForm(callData: IRouteCall, param: IRouteParameter, req: Request): Promise<void>;
|
|
25
32
|
protected parse(req: express.Request, options: FormOptions): Promise<void>;
|
|
26
33
|
private _parse;
|