formflux 0.0.7 → 0.0.9

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/dist/FormFlux.js CHANGED
@@ -8,502 +8,560 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
11
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
40
  };
14
41
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const ExtractContent_1 = __importDefault(require("./ExtractContent"));
16
- const WriteFileContent_1 = __importDefault(require("./WriteFileContent"));
17
- const SetBodyContentToReq_1 = __importDefault(require("./SetBodyContentToReq"));
18
- const setFileNameToBody_1 = __importDefault(require("./setFileNameToBody"));
19
- const setDatatoReqobj_1 = __importDefault(require("./setDatatoReqobj"));
20
- const EventHandlers_1 = __importDefault(require("./EventHandlers"));
21
- const FormFluxError_1 = __importDefault(require("./FormFluxError"));
22
- class Formflux {
23
- static diskStorage(options) {
42
+ var ExtractContent_1 = __importDefault(require("./ExtractContent"));
43
+ var WriteFileContent_1 = __importDefault(require("./WriteFileContent"));
44
+ var SetBodyContentToReq_1 = __importDefault(require("./SetBodyContentToReq"));
45
+ var setFileNameToBody_1 = __importDefault(require("./setFileNameToBody"));
46
+ var setDatatoReqobj_1 = __importDefault(require("./setDatatoReqobj"));
47
+ var EventHandlers_1 = __importDefault(require("./EventHandlers"));
48
+ var FormFluxError_1 = __importDefault(require("./FormFluxError"));
49
+ var Formflux = /** @class */ (function () {
50
+ function Formflux() {
51
+ }
52
+ Formflux.diskStorage = function (options) {
24
53
  return {
25
- any() {
54
+ any: function () {
26
55
  return function (req, res, next) {
27
- return __awaiter(this, void 0, void 0, function* () {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var obj, buff, reqType, boundary;
28
58
  var _a;
29
- let obj = {
30
- "originalReq": "",
31
- "modifiedReq": Buffer.from(""),
32
- "data": [],
33
- "content": [],
34
- "metaData": [],
35
- "mimeType": [],
36
- "fieldNameBody": [],
37
- "fileName": [],
38
- "modifiedFileName": [],
39
- "contentBody": [],
40
- "fieldNameFile": [],
41
- "filePath": [],
42
- "filesize": [],
43
- "streams": []
44
- };
45
- let buff = [];
46
- let reqType = req.headers["content-type"];
47
- if (reqType && !reqType.includes("multipart/form-data"))
48
- throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
49
- let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
50
- req.on("data", (chunk) => {
51
- buff.push(chunk);
52
- });
53
- req.on("end", () => {
54
- var _a;
55
- try {
56
- obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
57
- obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
58
- obj.data.pop();
59
- obj.data.shift();
60
- //*****Defaults*****
61
- //To*********extract content
62
- new ExtractContent_1.default(obj, options, null, null).extraction();
63
- //To*********SetFileDataToReqObj
64
- new setDatatoReqobj_1.default(obj).populate();
65
- let writeBool = false;
66
- let parseBool = false;
67
- let checkCompletion = (writeComplete, parsecomplete) => {
68
- if (writeComplete && parsecomplete)
69
- next();
70
- };
71
- EventHandlers_1.default.on("parseEnd", (message) => {
72
- parseBool = true;
73
- checkCompletion(writeBool, parseBool);
74
- });
75
- EventHandlers_1.default.on("writeEnd", (message) => {
76
- writeBool = true;
77
- checkCompletion(writeBool, parseBool);
78
- });
79
- new WriteFileContent_1.default(req, obj, options, "any", "disk").writeContent();
80
- if (options.attachFileToReqBody && options.attachFileToReqBody == true)
81
- new setFileNameToBody_1.default(obj).setFileNames(req);
82
- new SetBodyContentToReq_1.default(obj).setBody(req);
83
- }
84
- catch (err) {
85
- next(err);
86
- }
87
- });
88
- req.on("error", () => {
89
- next(new FormFluxError_1.default("Error in recieving request", 500));
59
+ return __generator(this, function (_b) {
60
+ obj = {
61
+ "originalReq": "",
62
+ "modifiedReq": Buffer.from(""),
63
+ "data": [],
64
+ "content": [],
65
+ "metaData": [],
66
+ "mimeType": [],
67
+ "fieldNameBody": [],
68
+ "fileName": [],
69
+ "modifiedFileName": [],
70
+ "contentBody": [],
71
+ "fieldNameFile": [],
72
+ "filePath": [],
73
+ "filesize": [],
74
+ "streams": []
75
+ };
76
+ buff = [];
77
+ reqType = req.headers["content-type"];
78
+ if (reqType && !reqType.includes("multipart/form-data"))
79
+ throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
80
+ boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
81
+ req.on("data", function (chunk) {
82
+ buff.push(chunk);
83
+ });
84
+ req.on("end", function () {
85
+ var _a;
86
+ try {
87
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
88
+ obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split("--".concat(boundary)); // separating the boundary
89
+ obj.data.pop();
90
+ obj.data.shift();
91
+ //*****Defaults*****
92
+ //To*********extract content
93
+ new ExtractContent_1.default(obj, options, null, null).extraction();
94
+ //To*********SetFileDataToReqObj
95
+ new setDatatoReqobj_1.default(obj).populate();
96
+ var writeBool_1 = false;
97
+ var parseBool_1 = false;
98
+ var checkCompletion_1 = function (writeComplete, parsecomplete) {
99
+ if (writeComplete && parsecomplete)
100
+ next();
101
+ };
102
+ EventHandlers_1.default.on("parseEnd", function (message) {
103
+ parseBool_1 = true;
104
+ checkCompletion_1(writeBool_1, parseBool_1);
105
+ });
106
+ EventHandlers_1.default.on("writeEnd", function (message) {
107
+ writeBool_1 = true;
108
+ checkCompletion_1(writeBool_1, parseBool_1);
109
+ });
110
+ new WriteFileContent_1.default(req, obj, options, "any", "disk").writeContent();
111
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
112
+ new setFileNameToBody_1.default(obj).setFileNames(req);
113
+ new SetBodyContentToReq_1.default(obj).setBody(req);
114
+ }
115
+ catch (err) {
116
+ next(err);
117
+ }
118
+ });
119
+ req.on("error", function () {
120
+ next(new FormFluxError_1.default("Error in recieving request", 500));
121
+ });
122
+ return [2 /*return*/];
90
123
  });
91
124
  });
92
125
  };
93
126
  },
94
- fields(optionFields) {
127
+ fields: function (optionFields) {
95
128
  return function (req, res, next) {
96
- return __awaiter(this, void 0, void 0, function* () {
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ var obj, buff, reqType, boundary;
97
131
  var _a;
98
- let obj = {
99
- "originalReq": "",
100
- "modifiedReq": Buffer.from(""),
101
- "data": [],
102
- "content": [],
103
- "metaData": [],
104
- "mimeType": [],
105
- "fieldNameBody": [],
106
- "fileName": [],
107
- "modifiedFileName": [],
108
- "contentBody": [],
109
- "fieldNameFile": [],
110
- "filePath": [],
111
- "filesize": [],
112
- "streams": []
113
- };
114
- let buff = [];
115
- let reqType = req.headers["content-type"];
116
- if (reqType && !reqType.includes("multipart/form-data"))
117
- throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
118
- let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
119
- req.on("data", (chunk) => {
120
- buff.push(chunk);
121
- });
122
- req.on("end", () => {
123
- var _a;
124
- try {
125
- obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
126
- obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
127
- obj.data.pop();
128
- obj.data.shift();
129
- //*****Defaults*****
130
- //To*********extract content
131
- new ExtractContent_1.default(obj, options, optionFields, null).extraction();
132
- //To*********SetFileDataToReqObj
133
- new setDatatoReqobj_1.default(obj).populate();
134
- let writeBool = false;
135
- let parseBool = false;
136
- let checkCompletion = (writeComplete, parsecomplete) => {
137
- if (writeComplete && parsecomplete)
138
- next();
139
- };
140
- EventHandlers_1.default.on("parseEnd", (message) => {
141
- parseBool = true;
142
- checkCompletion(writeBool, parseBool);
143
- });
144
- EventHandlers_1.default.on("writeEnd", (message) => {
145
- writeBool = true;
146
- checkCompletion(writeBool, parseBool);
147
- });
148
- new WriteFileContent_1.default(req, obj, options, "fields", "disk").writeContent();
149
- // new setFileContentToReq(obj).setFileNames(req);
150
- if (options.attachFileToReqBody && options.attachFileToReqBody == true)
151
- new setFileNameToBody_1.default(obj).setFileNames(req);
152
- new SetBodyContentToReq_1.default(obj).setBody(req);
153
- }
154
- catch (err) {
155
- next(err);
156
- }
157
- });
158
- req.on("error", () => {
159
- next(new FormFluxError_1.default("Error in recieving request", 500));
132
+ return __generator(this, function (_b) {
133
+ obj = {
134
+ "originalReq": "",
135
+ "modifiedReq": Buffer.from(""),
136
+ "data": [],
137
+ "content": [],
138
+ "metaData": [],
139
+ "mimeType": [],
140
+ "fieldNameBody": [],
141
+ "fileName": [],
142
+ "modifiedFileName": [],
143
+ "contentBody": [],
144
+ "fieldNameFile": [],
145
+ "filePath": [],
146
+ "filesize": [],
147
+ "streams": []
148
+ };
149
+ buff = [];
150
+ reqType = req.headers["content-type"];
151
+ if (reqType && !reqType.includes("multipart/form-data"))
152
+ throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
153
+ boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
154
+ req.on("data", function (chunk) {
155
+ buff.push(chunk);
156
+ });
157
+ req.on("end", function () {
158
+ var _a;
159
+ try {
160
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
161
+ obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split("--".concat(boundary)); // separating the boundary
162
+ obj.data.pop();
163
+ obj.data.shift();
164
+ //*****Defaults*****
165
+ //To*********extract content
166
+ new ExtractContent_1.default(obj, options, optionFields, null).extraction();
167
+ //To*********SetFileDataToReqObj
168
+ new setDatatoReqobj_1.default(obj).populate();
169
+ var writeBool_2 = false;
170
+ var parseBool_2 = false;
171
+ var checkCompletion_2 = function (writeComplete, parsecomplete) {
172
+ if (writeComplete && parsecomplete)
173
+ next();
174
+ };
175
+ EventHandlers_1.default.on("parseEnd", function (message) {
176
+ parseBool_2 = true;
177
+ checkCompletion_2(writeBool_2, parseBool_2);
178
+ });
179
+ EventHandlers_1.default.on("writeEnd", function (message) {
180
+ writeBool_2 = true;
181
+ checkCompletion_2(writeBool_2, parseBool_2);
182
+ });
183
+ new WriteFileContent_1.default(req, obj, options, "fields", "disk").writeContent();
184
+ // new setFileContentToReq(obj).setFileNames(req);
185
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
186
+ new setFileNameToBody_1.default(obj).setFileNames(req);
187
+ new SetBodyContentToReq_1.default(obj).setBody(req);
188
+ }
189
+ catch (err) {
190
+ next(err);
191
+ }
192
+ });
193
+ req.on("error", function () {
194
+ next(new FormFluxError_1.default("Error in recieving request", 500));
195
+ });
196
+ return [2 /*return*/];
160
197
  });
161
198
  });
162
199
  };
163
200
  },
164
- single(field) {
201
+ single: function (field) {
165
202
  return function (req, res, next) {
166
- return __awaiter(this, void 0, void 0, function* () {
203
+ return __awaiter(this, void 0, void 0, function () {
204
+ var obj, buff, reqType, boundary;
167
205
  var _a;
168
- let obj = {
169
- "originalReq": "",
170
- "modifiedReq": Buffer.from(""),
171
- "data": [],
172
- "content": [],
173
- "metaData": [],
174
- "mimeType": [],
175
- "fieldNameBody": [],
176
- "fileName": [],
177
- "modifiedFileName": [],
178
- "contentBody": [],
179
- "fieldNameFile": [],
180
- "filePath": [],
181
- "filesize": [],
182
- "streams": []
183
- };
184
- let buff = [];
185
- let reqType = req.headers["content-type"];
186
- if (reqType && !reqType.includes("multipart/form-data"))
187
- throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
188
- let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
189
- req.on("data", (chunk) => {
190
- buff.push(chunk);
191
- });
192
- req.on("end", () => {
193
- var _a;
194
- try {
195
- obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
196
- obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
197
- obj.data.pop();
198
- obj.data.shift();
199
- //*****Defaults*****
200
- //To*********extract content
201
- new ExtractContent_1.default(obj, options, null, field).extraction();
202
- //To*********SetFileDataToReqObj
203
- new setDatatoReqobj_1.default(obj).populate();
204
- let writeBool = false;
205
- let parseBool = false;
206
- let checkCompletion = (writeComplete, parsecomplete) => {
207
- if (writeComplete && parsecomplete)
208
- next();
209
- };
210
- EventHandlers_1.default.on("parseEnd", (message) => {
211
- parseBool = true;
212
- checkCompletion(writeBool, parseBool);
213
- });
214
- EventHandlers_1.default.on("writeEnd", (message) => {
215
- writeBool = true;
216
- checkCompletion(writeBool, parseBool);
217
- });
218
- new WriteFileContent_1.default(req, obj, options, "single", "disk").writeContent();
219
- if (options.attachFileToReqBody && options.attachFileToReqBody == true)
220
- new setFileNameToBody_1.default(obj).setFileNames(req);
221
- new SetBodyContentToReq_1.default(obj).setBody(req);
222
- }
223
- catch (err) {
224
- next(err);
225
- }
226
- });
227
- req.on("error", () => {
228
- next(new FormFluxError_1.default("Error in recieving request", 500));
206
+ return __generator(this, function (_b) {
207
+ obj = {
208
+ "originalReq": "",
209
+ "modifiedReq": Buffer.from(""),
210
+ "data": [],
211
+ "content": [],
212
+ "metaData": [],
213
+ "mimeType": [],
214
+ "fieldNameBody": [],
215
+ "fileName": [],
216
+ "modifiedFileName": [],
217
+ "contentBody": [],
218
+ "fieldNameFile": [],
219
+ "filePath": [],
220
+ "filesize": [],
221
+ "streams": []
222
+ };
223
+ buff = [];
224
+ reqType = req.headers["content-type"];
225
+ if (reqType && !reqType.includes("multipart/form-data"))
226
+ throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
227
+ boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
228
+ req.on("data", function (chunk) {
229
+ buff.push(chunk);
230
+ });
231
+ req.on("end", function () {
232
+ var _a;
233
+ try {
234
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
235
+ obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split("--".concat(boundary)); // separating the boundary
236
+ obj.data.pop();
237
+ obj.data.shift();
238
+ //*****Defaults*****
239
+ //To*********extract content
240
+ new ExtractContent_1.default(obj, options, null, field).extraction();
241
+ //To*********SetFileDataToReqObj
242
+ new setDatatoReqobj_1.default(obj).populate();
243
+ var writeBool_3 = false;
244
+ var parseBool_3 = false;
245
+ var checkCompletion_3 = function (writeComplete, parsecomplete) {
246
+ if (writeComplete && parsecomplete)
247
+ next();
248
+ };
249
+ EventHandlers_1.default.on("parseEnd", function (message) {
250
+ parseBool_3 = true;
251
+ checkCompletion_3(writeBool_3, parseBool_3);
252
+ });
253
+ EventHandlers_1.default.on("writeEnd", function (message) {
254
+ writeBool_3 = true;
255
+ checkCompletion_3(writeBool_3, parseBool_3);
256
+ });
257
+ new WriteFileContent_1.default(req, obj, options, "single", "disk").writeContent();
258
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
259
+ new setFileNameToBody_1.default(obj).setFileNames(req);
260
+ new SetBodyContentToReq_1.default(obj).setBody(req);
261
+ }
262
+ catch (err) {
263
+ next(err);
264
+ }
265
+ });
266
+ req.on("error", function () {
267
+ next(new FormFluxError_1.default("Error in recieving request", 500));
268
+ });
269
+ return [2 /*return*/];
229
270
  });
230
271
  });
231
272
  };
232
273
  },
233
274
  };
234
- }
235
- static memoryStorage(options) {
275
+ };
276
+ Formflux.memoryStorage = function (options) {
236
277
  return {
237
- any() {
278
+ any: function () {
238
279
  return function (req, res, next) {
239
- return __awaiter(this, void 0, void 0, function* () {
280
+ return __awaiter(this, void 0, void 0, function () {
281
+ var obj, buff, reqType, boundary;
240
282
  var _a;
241
- let obj = {
242
- "originalReq": "",
243
- "modifiedReq": Buffer.from(""),
244
- "data": [],
245
- "content": [],
246
- "metaData": [],
247
- "mimeType": [],
248
- "fieldNameBody": [],
249
- "fileName": [],
250
- "modifiedFileName": [],
251
- "contentBody": [],
252
- "fieldNameFile": [],
253
- "filePath": [],
254
- "filesize": [],
255
- "streams": []
256
- };
257
- let buff = [];
258
- let reqType = req.headers["content-type"];
259
- if (reqType && !reqType.includes("multipart/form-data"))
260
- throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
261
- let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
262
- req.on("data", (chunk) => {
263
- buff.push(chunk);
264
- });
265
- req.on("end", () => {
266
- var _a;
267
- try {
268
- obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
269
- obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
270
- obj.data.pop();
271
- obj.data.shift();
272
- //*****Defaults*****
273
- //To*********extract content
274
- new ExtractContent_1.default(obj, options, null, null).extraction();
275
- //To*********SetFileDataToReqObj
276
- new setDatatoReqobj_1.default(obj).populate();
277
- let writeBool = false;
278
- let parseBool = false;
279
- let checkCompletion = (writeComplete, parsecomplete) => {
280
- if (writeComplete && parsecomplete)
281
- next();
282
- };
283
- EventHandlers_1.default.on("parseEnd", (message) => {
284
- parseBool = true;
285
- checkCompletion(writeBool, parseBool);
286
- });
287
- EventHandlers_1.default.on("writeEnd", (message) => {
288
- writeBool = true;
289
- checkCompletion(writeBool, parseBool);
290
- });
291
- new WriteFileContent_1.default(req, obj, options, "any", "memory").writeContent();
292
- if (options.attachFileToReqBody && options.attachFileToReqBody == true)
293
- new setFileNameToBody_1.default(obj).setFileNames(req);
294
- new SetBodyContentToReq_1.default(obj).setBody(req);
295
- }
296
- catch (err) {
297
- next(err);
298
- }
299
- });
300
- req.on("error", () => {
301
- next(new FormFluxError_1.default("Error in recieving request", 500));
283
+ return __generator(this, function (_b) {
284
+ obj = {
285
+ "originalReq": "",
286
+ "modifiedReq": Buffer.from(""),
287
+ "data": [],
288
+ "content": [],
289
+ "metaData": [],
290
+ "mimeType": [],
291
+ "fieldNameBody": [],
292
+ "fileName": [],
293
+ "modifiedFileName": [],
294
+ "contentBody": [],
295
+ "fieldNameFile": [],
296
+ "filePath": [],
297
+ "filesize": [],
298
+ "streams": []
299
+ };
300
+ buff = [];
301
+ reqType = req.headers["content-type"];
302
+ if (reqType && !reqType.includes("multipart/form-data"))
303
+ throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
304
+ boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
305
+ req.on("data", function (chunk) {
306
+ buff.push(chunk);
307
+ });
308
+ req.on("end", function () {
309
+ var _a;
310
+ try {
311
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
312
+ obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split("--".concat(boundary)); // separating the boundary
313
+ obj.data.pop();
314
+ obj.data.shift();
315
+ //*****Defaults*****
316
+ //To*********extract content
317
+ new ExtractContent_1.default(obj, options, null, null).extraction();
318
+ //To*********SetFileDataToReqObj
319
+ new setDatatoReqobj_1.default(obj).populate();
320
+ var writeBool_4 = false;
321
+ var parseBool_4 = false;
322
+ var checkCompletion_4 = function (writeComplete, parsecomplete) {
323
+ if (writeComplete && parsecomplete)
324
+ next();
325
+ };
326
+ EventHandlers_1.default.on("parseEnd", function (message) {
327
+ parseBool_4 = true;
328
+ checkCompletion_4(writeBool_4, parseBool_4);
329
+ });
330
+ EventHandlers_1.default.on("writeEnd", function (message) {
331
+ writeBool_4 = true;
332
+ checkCompletion_4(writeBool_4, parseBool_4);
333
+ });
334
+ new WriteFileContent_1.default(req, obj, options, "any", "memory").writeContent();
335
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
336
+ new setFileNameToBody_1.default(obj).setFileNames(req);
337
+ new SetBodyContentToReq_1.default(obj).setBody(req);
338
+ }
339
+ catch (err) {
340
+ next(err);
341
+ }
342
+ });
343
+ req.on("error", function () {
344
+ next(new FormFluxError_1.default("Error in recieving request", 500));
345
+ });
346
+ return [2 /*return*/];
302
347
  });
303
348
  });
304
349
  };
305
350
  },
306
- fields(optionFields) {
351
+ fields: function (optionFields) {
307
352
  return function (req, res, next) {
308
- return __awaiter(this, void 0, void 0, function* () {
353
+ return __awaiter(this, void 0, void 0, function () {
354
+ var obj, buff, reqType, boundary;
309
355
  var _a;
310
- let obj = {
311
- "originalReq": "",
312
- "modifiedReq": Buffer.from(""),
313
- "data": [],
314
- "content": [],
315
- "metaData": [],
316
- "mimeType": [],
317
- "fieldNameBody": [],
318
- "fileName": [],
319
- "modifiedFileName": [],
320
- "contentBody": [],
321
- "fieldNameFile": [],
322
- "filePath": [],
323
- "filesize": [],
324
- "streams": []
325
- };
326
- let buff = [];
327
- let reqType = req.headers["content-type"];
328
- if (reqType && !reqType.includes("multipart/form-data"))
329
- throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
330
- let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
331
- req.on("data", (chunk) => {
332
- buff.push(chunk);
333
- });
334
- req.on("end", () => {
335
- var _a;
336
- try {
337
- obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
338
- obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
339
- obj.data.pop();
340
- obj.data.shift();
341
- //*****Defaults*****
342
- //To*********extract content
343
- new ExtractContent_1.default(obj, options, optionFields, null).extraction();
344
- //To*********SetFileDataToReqObj
345
- new setDatatoReqobj_1.default(obj).populate();
346
- let writeBool = false;
347
- let parseBool = false;
348
- let checkCompletion = (writeComplete, parsecomplete) => {
349
- if (writeComplete && parsecomplete)
350
- next();
351
- };
352
- EventHandlers_1.default.on("parseEnd", (message) => {
353
- parseBool = true;
354
- checkCompletion(writeBool, parseBool);
355
- });
356
- EventHandlers_1.default.on("writeEnd", (message) => {
357
- writeBool = true;
358
- checkCompletion(writeBool, parseBool);
359
- });
360
- new WriteFileContent_1.default(req, obj, options, "fields", "memory").writeContent();
361
- if (options.attachFileToReqBody && options.attachFileToReqBody == true)
362
- new setFileNameToBody_1.default(obj).setFileNames(req);
363
- new SetBodyContentToReq_1.default(obj).setBody(req);
364
- }
365
- catch (err) {
366
- next(err);
367
- }
368
- });
369
- req.on("error", () => {
370
- next(new FormFluxError_1.default("Error in recieving request", 500));
356
+ return __generator(this, function (_b) {
357
+ obj = {
358
+ "originalReq": "",
359
+ "modifiedReq": Buffer.from(""),
360
+ "data": [],
361
+ "content": [],
362
+ "metaData": [],
363
+ "mimeType": [],
364
+ "fieldNameBody": [],
365
+ "fileName": [],
366
+ "modifiedFileName": [],
367
+ "contentBody": [],
368
+ "fieldNameFile": [],
369
+ "filePath": [],
370
+ "filesize": [],
371
+ "streams": []
372
+ };
373
+ buff = [];
374
+ reqType = req.headers["content-type"];
375
+ if (reqType && !reqType.includes("multipart/form-data"))
376
+ throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
377
+ boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
378
+ req.on("data", function (chunk) {
379
+ buff.push(chunk);
380
+ });
381
+ req.on("end", function () {
382
+ var _a;
383
+ try {
384
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
385
+ obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split("--".concat(boundary)); // separating the boundary
386
+ obj.data.pop();
387
+ obj.data.shift();
388
+ //*****Defaults*****
389
+ //To*********extract content
390
+ new ExtractContent_1.default(obj, options, optionFields, null).extraction();
391
+ //To*********SetFileDataToReqObj
392
+ new setDatatoReqobj_1.default(obj).populate();
393
+ var writeBool_5 = false;
394
+ var parseBool_5 = false;
395
+ var checkCompletion_5 = function (writeComplete, parsecomplete) {
396
+ if (writeComplete && parsecomplete)
397
+ next();
398
+ };
399
+ EventHandlers_1.default.on("parseEnd", function (message) {
400
+ parseBool_5 = true;
401
+ checkCompletion_5(writeBool_5, parseBool_5);
402
+ });
403
+ EventHandlers_1.default.on("writeEnd", function (message) {
404
+ writeBool_5 = true;
405
+ checkCompletion_5(writeBool_5, parseBool_5);
406
+ });
407
+ new WriteFileContent_1.default(req, obj, options, "fields", "memory").writeContent();
408
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
409
+ new setFileNameToBody_1.default(obj).setFileNames(req);
410
+ new SetBodyContentToReq_1.default(obj).setBody(req);
411
+ }
412
+ catch (err) {
413
+ next(err);
414
+ }
415
+ });
416
+ req.on("error", function () {
417
+ next(new FormFluxError_1.default("Error in recieving request", 500));
418
+ });
419
+ return [2 /*return*/];
371
420
  });
372
421
  });
373
422
  };
374
423
  },
375
- single(field) {
424
+ single: function (field) {
376
425
  return function (req, res, next) {
377
- return __awaiter(this, void 0, void 0, function* () {
426
+ return __awaiter(this, void 0, void 0, function () {
427
+ var obj, buff, reqType, boundary;
378
428
  var _a;
379
- let obj = {
380
- "originalReq": "",
381
- "modifiedReq": Buffer.from(""),
382
- "data": [],
383
- "content": [],
384
- "metaData": [],
385
- "mimeType": [],
386
- "fieldNameBody": [],
387
- "fileName": [],
388
- "modifiedFileName": [],
389
- "contentBody": [],
390
- "fieldNameFile": [],
391
- "filePath": [],
392
- "filesize": [],
393
- "streams": []
394
- };
395
- let buff = [];
396
- let reqType = req.headers["content-type"];
397
- if (reqType && !reqType.includes("multipart/form-data"))
398
- throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
399
- let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
400
- req.on("data", (chunk) => {
401
- buff.push(chunk);
402
- });
403
- req.on("end", () => {
404
- var _a;
405
- try {
406
- obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
407
- obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
408
- obj.data.pop();
409
- obj.data.shift();
410
- //*****Defaults*****
411
- //To*********extract content
412
- new ExtractContent_1.default(obj, options, null, field).extraction();
413
- //To*********SetFileDataToReqObj
414
- new setDatatoReqobj_1.default(obj).populate();
415
- let writeBool = false;
416
- let parseBool = false;
417
- let checkCompletion = (writeComplete, parsecomplete) => {
418
- if (writeComplete && parsecomplete)
419
- next();
420
- };
421
- EventHandlers_1.default.on("parseEnd", (message) => {
422
- parseBool = true;
423
- checkCompletion(writeBool, parseBool);
424
- });
425
- EventHandlers_1.default.on("writeEnd", (message) => {
426
- writeBool = true;
427
- checkCompletion(writeBool, parseBool);
428
- });
429
- new WriteFileContent_1.default(req, obj, options, "single", "memory").writeContent();
430
- if (options.attachFileToReqBody && options.attachFileToReqBody == true)
431
- new setFileNameToBody_1.default(obj).setFileNames(req);
432
- new SetBodyContentToReq_1.default(obj).setBody(req);
433
- }
434
- catch (err) {
435
- next(err);
436
- }
437
- });
438
- req.on("error", () => {
439
- next(new FormFluxError_1.default("Error in recieving request", 500));
429
+ return __generator(this, function (_b) {
430
+ obj = {
431
+ "originalReq": "",
432
+ "modifiedReq": Buffer.from(""),
433
+ "data": [],
434
+ "content": [],
435
+ "metaData": [],
436
+ "mimeType": [],
437
+ "fieldNameBody": [],
438
+ "fileName": [],
439
+ "modifiedFileName": [],
440
+ "contentBody": [],
441
+ "fieldNameFile": [],
442
+ "filePath": [],
443
+ "filesize": [],
444
+ "streams": []
445
+ };
446
+ buff = [];
447
+ reqType = req.headers["content-type"];
448
+ if (reqType && !reqType.includes("multipart/form-data"))
449
+ throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
450
+ boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
451
+ req.on("data", function (chunk) {
452
+ buff.push(chunk);
453
+ });
454
+ req.on("end", function () {
455
+ var _a;
456
+ try {
457
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
458
+ obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split("--".concat(boundary)); // separating the boundary
459
+ obj.data.pop();
460
+ obj.data.shift();
461
+ //*****Defaults*****
462
+ //To*********extract content
463
+ new ExtractContent_1.default(obj, options, null, field).extraction();
464
+ //To*********SetFileDataToReqObj
465
+ new setDatatoReqobj_1.default(obj).populate();
466
+ var writeBool_6 = false;
467
+ var parseBool_6 = false;
468
+ var checkCompletion_6 = function (writeComplete, parsecomplete) {
469
+ if (writeComplete && parsecomplete)
470
+ next();
471
+ };
472
+ EventHandlers_1.default.on("parseEnd", function (message) {
473
+ parseBool_6 = true;
474
+ checkCompletion_6(writeBool_6, parseBool_6);
475
+ });
476
+ EventHandlers_1.default.on("writeEnd", function (message) {
477
+ writeBool_6 = true;
478
+ checkCompletion_6(writeBool_6, parseBool_6);
479
+ });
480
+ new WriteFileContent_1.default(req, obj, options, "single", "memory").writeContent();
481
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
482
+ new setFileNameToBody_1.default(obj).setFileNames(req);
483
+ new SetBodyContentToReq_1.default(obj).setBody(req);
484
+ }
485
+ catch (err) {
486
+ next(err);
487
+ }
488
+ });
489
+ req.on("error", function () {
490
+ next(new FormFluxError_1.default("Error in recieving request", 500));
491
+ });
492
+ return [2 /*return*/];
440
493
  });
441
494
  });
442
495
  };
443
496
  },
444
497
  };
445
- }
446
- bodyParser() {
498
+ };
499
+ Formflux.prototype.bodyParser = function () {
447
500
  return function (req, res, next) {
448
- return __awaiter(this, void 0, void 0, function* () {
501
+ return __awaiter(this, void 0, void 0, function () {
502
+ var obj, buff, reqType, boundary;
449
503
  var _a;
450
- let obj = {
451
- "originalReq": "",
452
- "modifiedReq": Buffer.from(""),
453
- "data": [],
454
- "content": [],
455
- "metaData": [],
456
- "mimeType": [],
457
- "fieldNameBody": [],
458
- "fileName": [],
459
- "modifiedFileName": [],
460
- "contentBody": [],
461
- "fieldNameFile": [],
462
- "filePath": [],
463
- "filesize": [],
464
- "streams": []
465
- };
466
- let buff = [];
467
- let reqType = req.headers["content-type"];
468
- if (reqType && !reqType.includes("multipart/form-data"))
469
- throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
470
- let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
471
- req.on("data", (chunk) => {
472
- buff.push(chunk);
473
- });
474
- req.on("end", () => {
475
- var _a;
476
- try {
477
- obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
478
- obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
479
- obj.data.pop();
480
- obj.data.shift();
481
- //*****Defaults*****
482
- //To*********extract content
483
- new ExtractContent_1.default(obj, null, null, null).extraction();
484
- //To*********SetFileDataToReqObj
485
- let writeBool = false;
486
- let parseBool = false;
487
- let checkCompletion = (writeComplete, parsecomplete) => {
488
- if (writeComplete && parsecomplete)
504
+ return __generator(this, function (_b) {
505
+ obj = {
506
+ "originalReq": "",
507
+ "modifiedReq": Buffer.from(""),
508
+ "data": [],
509
+ "content": [],
510
+ "metaData": [],
511
+ "mimeType": [],
512
+ "fieldNameBody": [],
513
+ "fileName": [],
514
+ "modifiedFileName": [],
515
+ "contentBody": [],
516
+ "fieldNameFile": [],
517
+ "filePath": [],
518
+ "filesize": [],
519
+ "streams": []
520
+ };
521
+ buff = [];
522
+ reqType = req.headers["content-type"];
523
+ if (reqType && !reqType.includes("multipart/form-data"))
524
+ throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
525
+ boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
526
+ req.on("data", function (chunk) {
527
+ buff.push(chunk);
528
+ });
529
+ req.on("end", function () {
530
+ var _a;
531
+ try {
532
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
533
+ obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split("--".concat(boundary)); // separating the boundary
534
+ obj.data.pop();
535
+ obj.data.shift();
536
+ //*****Defaults*****
537
+ //To*********extract content
538
+ new ExtractContent_1.default(obj, null, null, null).extraction();
539
+ //To*********SetFileDataToReqObj
540
+ var writeBool = false;
541
+ var parseBool_7 = false;
542
+ var checkCompletion = function (writeComplete, parsecomplete) {
543
+ if (writeComplete && parsecomplete)
544
+ next();
545
+ };
546
+ EventHandlers_1.default.on("parseEnd", function (message) {
547
+ parseBool_7 = true;
489
548
  next();
490
- };
491
- EventHandlers_1.default.on("parseEnd", (message) => {
492
- parseBool = true;
493
- next();
494
- });
495
- new SetBodyContentToReq_1.default(obj).setBody(req);
496
- }
497
- catch (err) {
498
- next(err);
499
- }
500
- });
501
- req.on("error", () => {
502
- next(new FormFluxError_1.default("Error in recieving request", 500));
549
+ });
550
+ new SetBodyContentToReq_1.default(obj).setBody(req);
551
+ }
552
+ catch (err) {
553
+ next(err);
554
+ }
555
+ });
556
+ req.on("error", function () {
557
+ next(new FormFluxError_1.default("Error in recieving request", 500));
558
+ });
559
+ return [2 /*return*/];
503
560
  });
504
561
  });
505
562
  };
506
- }
507
- }
563
+ };
564
+ return Formflux;
565
+ }());
508
566
  exports.default = Formflux;
509
567
  //# sourceMappingURL=FormFlux.js.map