@spinajs/http
Advanced tools
Comparing version 2.0.14 to 2.0.19
import * as express from 'express'; | ||
import { Response } from '../responses'; | ||
import { Row, FormatterOptionsArgs } from '@fast-csv/format'; | ||
export declare class FileResponse extends Response { | ||
@@ -18,9 +17,2 @@ protected path: string; | ||
} | ||
export declare class CvsFileResponse<I extends Row, O extends Row> extends Response { | ||
protected data: any; | ||
protected filename: string; | ||
protected options?: FormatterOptionsArgs<I, O> | undefined; | ||
constructor(data: any, filename: string, options?: FormatterOptionsArgs<I, O> | undefined); | ||
execute(_req: express.Request, res: express.Response): Promise<void>; | ||
} | ||
export declare class JsonFileResponse extends Response { | ||
@@ -27,0 +19,0 @@ protected data: any; |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JsonFileResponse = exports.CvsFileResponse = exports.FileResponse = void 0; | ||
exports.JsonFileResponse = exports.FileResponse = void 0; | ||
const exceptions_1 = require("@spinajs/exceptions"); | ||
@@ -36,3 +36,2 @@ const fs = __importStar(require("fs")); | ||
const responses_1 = require("../responses"); | ||
const format_1 = require("@fast-csv/format"); | ||
const tempfile_1 = __importDefault(require("tempfile")); | ||
@@ -70,31 +69,2 @@ class FileResponse extends responses_1.Response { | ||
exports.FileResponse = FileResponse; | ||
class CvsFileResponse extends responses_1.Response { | ||
constructor(data, filename, options) { | ||
super(null); | ||
this.data = data; | ||
this.filename = filename; | ||
this.options = options; | ||
} | ||
async execute(_req, res) { | ||
const csvStream = (0, format_1.format)(this.options); | ||
const tempPath = (0, tempfile_1.default)('.cvs'); | ||
const file = await fs.promises.open(tempPath, 'w'); | ||
return new Promise((resolve, reject) => { | ||
csvStream.pipe(file.createWriteStream()).on('end', () => { | ||
file.close().then(() => { | ||
res.download(tempPath, this.filename, (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
fs.unlink(tempPath, null); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
exports.CvsFileResponse = CvsFileResponse; | ||
class JsonFileResponse extends responses_1.Response { | ||
@@ -101,0 +71,0 @@ constructor(data, filename) { |
@@ -56,3 +56,3 @@ import { RouteArgs } from './RouteArgs'; | ||
}>; | ||
protected parseCvs(path: string, options: any): Promise<unknown>; | ||
protected parseCvs(path: string): Promise<unknown>; | ||
} | ||
@@ -59,0 +59,0 @@ export declare class FromFormField extends FromFormBase { |
@@ -42,4 +42,4 @@ "use strict"; | ||
const di_1 = require("@spinajs/di"); | ||
const parse_1 = require("@fast-csv/parse"); | ||
const fs = __importStar(require("fs")); | ||
const csv_1 = require("csv"); | ||
class FromFormBase extends RouteArgs_1.RouteArgs { | ||
@@ -178,3 +178,3 @@ async parseForm(callData, param, req) { | ||
} | ||
const data = await this.parseCvs(sourceFile, param.Options); | ||
const data = await this.parseCvs(sourceFile); | ||
return { | ||
@@ -187,7 +187,7 @@ CallData: Object.assign(Object.assign({}, callData), { Payload: { | ||
} | ||
async parseCvs(path, options) { | ||
async parseCvs(path) { | ||
const data = []; | ||
return new Promise((res, rej) => { | ||
fs.createReadStream(path) | ||
.pipe((0, parse_1.parse)(options)) | ||
.pipe((0, csv_1.parse)()) | ||
.on('error', (err) => rej(err)) | ||
@@ -194,0 +194,0 @@ .on('data', (row) => data.push(row)) |
{ | ||
"name": "@spinajs/http", | ||
"version": "2.0.14", | ||
"version": "2.0.19", | ||
"description": "framework HTTP module base on express.js", | ||
@@ -53,9 +53,9 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@spinajs/configuration": "^2.0.12", | ||
"@spinajs/di": "^2.0.12", | ||
"@spinajs/configuration": "^2.0.19", | ||
"@spinajs/di": "^2.0.19", | ||
"@spinajs/exceptions": "^2.0.12", | ||
"@spinajs/internal-logger": "^2.0.12", | ||
"@spinajs/log": "^2.0.14", | ||
"@spinajs/reflection": "^2.0.14", | ||
"@spinajs/validation": "^2.0.14", | ||
"@spinajs/internal-logger": "^2.0.19", | ||
"@spinajs/log": "^2.0.19", | ||
"@spinajs/reflection": "^2.0.19", | ||
"@spinajs/validation": "^2.0.19", | ||
"compression": "^1.7.4", | ||
@@ -65,4 +65,4 @@ "cookie-parser": "^1.4.5", | ||
"cors": "^2.8.5", | ||
"csv": "^6.2.0", | ||
"express": "^4.17.1", | ||
"fast-csv": "4.3.2", | ||
"formidable": "^2.0.1", | ||
@@ -79,3 +79,3 @@ "glob": "^7.1.4", | ||
}, | ||
"gitHead": "81b84e0b70c385409a01e655412c48d021a96352" | ||
"gitHead": "51e801176ecec955cbf1eb2d91e9f4740cb2b471" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
228486
3884
+ Addedcsv@^6.2.0
+ Addedcsv@6.3.10(transitive)
+ Addedcsv-generate@4.4.1(transitive)
+ Addedcsv-parse@5.5.6(transitive)
+ Addedcsv-stringify@6.5.1(transitive)
+ Addedstream-transform@3.3.2(transitive)
- Removedfast-csv@4.3.2
- Removed@fast-csv/format@4.3.1(transitive)
- Removed@fast-csv/parse@4.3.2(transitive)
- Removed@types/node@14.18.63(transitive)
- Removedfast-csv@4.3.2(transitive)
- Removedlodash.escaperegexp@4.1.2(transitive)
- Removedlodash.groupby@4.6.0(transitive)
- Removedlodash.isboolean@3.0.3(transitive)
- Removedlodash.isequal@4.5.0(transitive)
- Removedlodash.isfunction@3.0.9(transitive)
- Removedlodash.isnil@4.0.0(transitive)
- Removedlodash.isundefined@3.0.1(transitive)
- Removedlodash.uniq@4.5.0(transitive)
Updated@spinajs/di@^2.0.19
Updated@spinajs/log@^2.0.19
Updated@spinajs/reflection@^2.0.19
Updated@spinajs/validation@^2.0.19