formflux 0.0.4 → 0.0.6

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
@@ -1,232 +1,206 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- 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"));
1
+ import ExtractFileContent from "./ExtractContent";
2
+ import writeFileContent from "./WriteFileContent";
3
+ import setContentToBody from "./SetBodyContentToReq";
4
+ import setFileNameToBody from "./setFileNameToBody";
5
+ import populateReqObj from "./setDatatoReqobj";
6
+ import EventHandlers from "./EventHandlers";
7
+ import FormfluxError from "./FormFluxError";
22
8
  class Formflux {
23
9
  static diskStorage(options) {
24
10
  return {
25
11
  any() {
26
- return function (req, res, next) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- 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));
90
- });
12
+ return async function (req, res, next) {
13
+ let obj = {
14
+ "originalReq": "",
15
+ "modifiedReq": Buffer.from(""),
16
+ "data": [],
17
+ "content": [],
18
+ "metaData": [],
19
+ "mimeType": [],
20
+ "fieldNameBody": [],
21
+ "fileName": [],
22
+ "modifiedFileName": [],
23
+ "contentBody": [],
24
+ "fieldNameFile": [],
25
+ "filePath": [],
26
+ "filesize": [],
27
+ "streams": []
28
+ };
29
+ let buff = [];
30
+ let reqType = req.headers["content-type"];
31
+ if (reqType && !reqType.includes("multipart/form-data"))
32
+ throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
33
+ let boundary = req.headers["content-type"]?.split("boundary=")[1];
34
+ req.on("data", (chunk) => {
35
+ buff.push(chunk);
36
+ });
37
+ req.on("end", () => {
38
+ try {
39
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
40
+ obj.data = obj.modifiedReq.toString("binary")?.split(`--${boundary}`); // separating the boundary
41
+ obj.data.pop();
42
+ obj.data.shift();
43
+ //*****Defaults*****
44
+ //To*********extract content
45
+ new ExtractFileContent(obj, options, null, null).extraction();
46
+ //To*********SetFileDataToReqObj
47
+ new populateReqObj(obj).populate();
48
+ let writeBool = false;
49
+ let parseBool = false;
50
+ let checkCompletion = (writeComplete, parsecomplete) => {
51
+ if (writeComplete && parsecomplete)
52
+ next();
53
+ };
54
+ EventHandlers.on("parseEnd", (message) => {
55
+ parseBool = true;
56
+ checkCompletion(writeBool, parseBool);
57
+ });
58
+ EventHandlers.on("writeEnd", (message) => {
59
+ writeBool = true;
60
+ checkCompletion(writeBool, parseBool);
61
+ });
62
+ new writeFileContent(req, obj, options, "any", "disk").writeContent();
63
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
64
+ new setFileNameToBody(obj).setFileNames(req);
65
+ new setContentToBody(obj).setBody(req);
66
+ }
67
+ catch (err) {
68
+ next(err);
69
+ }
70
+ });
71
+ req.on("error", () => {
72
+ next(new FormfluxError("Error in recieving request", 500));
91
73
  });
92
74
  };
93
75
  },
94
76
  fields(optionFields) {
95
- return function (req, res, next) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- 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));
160
- });
77
+ return async function (req, res, next) {
78
+ let obj = {
79
+ "originalReq": "",
80
+ "modifiedReq": Buffer.from(""),
81
+ "data": [],
82
+ "content": [],
83
+ "metaData": [],
84
+ "mimeType": [],
85
+ "fieldNameBody": [],
86
+ "fileName": [],
87
+ "modifiedFileName": [],
88
+ "contentBody": [],
89
+ "fieldNameFile": [],
90
+ "filePath": [],
91
+ "filesize": [],
92
+ "streams": []
93
+ };
94
+ let buff = [];
95
+ let reqType = req.headers["content-type"];
96
+ if (reqType && !reqType.includes("multipart/form-data"))
97
+ throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
98
+ let boundary = req.headers["content-type"]?.split("boundary=")[1];
99
+ req.on("data", (chunk) => {
100
+ buff.push(chunk);
101
+ });
102
+ req.on("end", () => {
103
+ try {
104
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
105
+ obj.data = obj.modifiedReq.toString("binary")?.split(`--${boundary}`); // separating the boundary
106
+ obj.data.pop();
107
+ obj.data.shift();
108
+ //*****Defaults*****
109
+ //To*********extract content
110
+ new ExtractFileContent(obj, options, optionFields, null).extraction();
111
+ //To*********SetFileDataToReqObj
112
+ new populateReqObj(obj).populate();
113
+ let writeBool = false;
114
+ let parseBool = false;
115
+ let checkCompletion = (writeComplete, parsecomplete) => {
116
+ if (writeComplete && parsecomplete)
117
+ next();
118
+ };
119
+ EventHandlers.on("parseEnd", (message) => {
120
+ parseBool = true;
121
+ checkCompletion(writeBool, parseBool);
122
+ });
123
+ EventHandlers.on("writeEnd", (message) => {
124
+ writeBool = true;
125
+ checkCompletion(writeBool, parseBool);
126
+ });
127
+ new writeFileContent(req, obj, options, "fields", "disk").writeContent();
128
+ // new setFileContentToReq(obj).setFileNames(req);
129
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
130
+ new setFileNameToBody(obj).setFileNames(req);
131
+ new setContentToBody(obj).setBody(req);
132
+ }
133
+ catch (err) {
134
+ next(err);
135
+ }
136
+ });
137
+ req.on("error", () => {
138
+ next(new FormfluxError("Error in recieving request", 500));
161
139
  });
162
140
  };
163
141
  },
164
142
  single(field) {
165
- return function (req, res, next) {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- 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));
229
- });
143
+ return async function (req, res, next) {
144
+ let obj = {
145
+ "originalReq": "",
146
+ "modifiedReq": Buffer.from(""),
147
+ "data": [],
148
+ "content": [],
149
+ "metaData": [],
150
+ "mimeType": [],
151
+ "fieldNameBody": [],
152
+ "fileName": [],
153
+ "modifiedFileName": [],
154
+ "contentBody": [],
155
+ "fieldNameFile": [],
156
+ "filePath": [],
157
+ "filesize": [],
158
+ "streams": []
159
+ };
160
+ let buff = [];
161
+ let reqType = req.headers["content-type"];
162
+ if (reqType && !reqType.includes("multipart/form-data"))
163
+ throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
164
+ let boundary = req.headers["content-type"]?.split("boundary=")[1];
165
+ req.on("data", (chunk) => {
166
+ buff.push(chunk);
167
+ });
168
+ req.on("end", () => {
169
+ try {
170
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
171
+ obj.data = obj.modifiedReq.toString("binary")?.split(`--${boundary}`); // separating the boundary
172
+ obj.data.pop();
173
+ obj.data.shift();
174
+ //*****Defaults*****
175
+ //To*********extract content
176
+ new ExtractFileContent(obj, options, null, field).extraction();
177
+ //To*********SetFileDataToReqObj
178
+ new populateReqObj(obj).populate();
179
+ let writeBool = false;
180
+ let parseBool = false;
181
+ let checkCompletion = (writeComplete, parsecomplete) => {
182
+ if (writeComplete && parsecomplete)
183
+ next();
184
+ };
185
+ EventHandlers.on("parseEnd", (message) => {
186
+ parseBool = true;
187
+ checkCompletion(writeBool, parseBool);
188
+ });
189
+ EventHandlers.on("writeEnd", (message) => {
190
+ writeBool = true;
191
+ checkCompletion(writeBool, parseBool);
192
+ });
193
+ new writeFileContent(req, obj, options, "single", "disk").writeContent();
194
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
195
+ new setFileNameToBody(obj).setFileNames(req);
196
+ new setContentToBody(obj).setBody(req);
197
+ }
198
+ catch (err) {
199
+ next(err);
200
+ }
201
+ });
202
+ req.on("error", () => {
203
+ next(new FormfluxError("Error in recieving request", 500));
230
204
  });
231
205
  };
232
206
  },
@@ -235,275 +209,259 @@ class Formflux {
235
209
  static memoryStorage(options) {
236
210
  return {
237
211
  any() {
238
- return function (req, res, next) {
239
- return __awaiter(this, void 0, void 0, function* () {
240
- 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));
302
- });
212
+ return async function (req, res, next) {
213
+ let obj = {
214
+ "originalReq": "",
215
+ "modifiedReq": Buffer.from(""),
216
+ "data": [],
217
+ "content": [],
218
+ "metaData": [],
219
+ "mimeType": [],
220
+ "fieldNameBody": [],
221
+ "fileName": [],
222
+ "modifiedFileName": [],
223
+ "contentBody": [],
224
+ "fieldNameFile": [],
225
+ "filePath": [],
226
+ "filesize": [],
227
+ "streams": []
228
+ };
229
+ let buff = [];
230
+ let reqType = req.headers["content-type"];
231
+ if (reqType && !reqType.includes("multipart/form-data"))
232
+ throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
233
+ let boundary = req.headers["content-type"]?.split("boundary=")[1];
234
+ req.on("data", (chunk) => {
235
+ buff.push(chunk);
236
+ });
237
+ req.on("end", () => {
238
+ try {
239
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
240
+ obj.data = obj.modifiedReq.toString("binary")?.split(`--${boundary}`); // separating the boundary
241
+ obj.data.pop();
242
+ obj.data.shift();
243
+ //*****Defaults*****
244
+ //To*********extract content
245
+ new ExtractFileContent(obj, options, null, null).extraction();
246
+ //To*********SetFileDataToReqObj
247
+ new populateReqObj(obj).populate();
248
+ let writeBool = false;
249
+ let parseBool = false;
250
+ let checkCompletion = (writeComplete, parsecomplete) => {
251
+ if (writeComplete && parsecomplete)
252
+ next();
253
+ };
254
+ EventHandlers.on("parseEnd", (message) => {
255
+ parseBool = true;
256
+ checkCompletion(writeBool, parseBool);
257
+ });
258
+ EventHandlers.on("writeEnd", (message) => {
259
+ writeBool = true;
260
+ checkCompletion(writeBool, parseBool);
261
+ });
262
+ new writeFileContent(req, obj, options, "any", "memory").writeContent();
263
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
264
+ new setFileNameToBody(obj).setFileNames(req);
265
+ new setContentToBody(obj).setBody(req);
266
+ }
267
+ catch (err) {
268
+ next(err);
269
+ }
270
+ });
271
+ req.on("error", () => {
272
+ next(new FormfluxError("Error in recieving request", 500));
303
273
  });
304
274
  };
305
275
  },
306
276
  fields(optionFields) {
307
- return function (req, res, next) {
308
- return __awaiter(this, void 0, void 0, function* () {
309
- 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));
371
- });
277
+ return async function (req, res, next) {
278
+ let obj = {
279
+ "originalReq": "",
280
+ "modifiedReq": Buffer.from(""),
281
+ "data": [],
282
+ "content": [],
283
+ "metaData": [],
284
+ "mimeType": [],
285
+ "fieldNameBody": [],
286
+ "fileName": [],
287
+ "modifiedFileName": [],
288
+ "contentBody": [],
289
+ "fieldNameFile": [],
290
+ "filePath": [],
291
+ "filesize": [],
292
+ "streams": []
293
+ };
294
+ let buff = [];
295
+ let reqType = req.headers["content-type"];
296
+ if (reqType && !reqType.includes("multipart/form-data"))
297
+ throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
298
+ let boundary = req.headers["content-type"]?.split("boundary=")[1];
299
+ req.on("data", (chunk) => {
300
+ buff.push(chunk);
301
+ });
302
+ req.on("end", () => {
303
+ try {
304
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
305
+ obj.data = obj.modifiedReq.toString("binary")?.split(`--${boundary}`); // separating the boundary
306
+ obj.data.pop();
307
+ obj.data.shift();
308
+ //*****Defaults*****
309
+ //To*********extract content
310
+ new ExtractFileContent(obj, options, optionFields, null).extraction();
311
+ //To*********SetFileDataToReqObj
312
+ new populateReqObj(obj).populate();
313
+ let writeBool = false;
314
+ let parseBool = false;
315
+ let checkCompletion = (writeComplete, parsecomplete) => {
316
+ if (writeComplete && parsecomplete)
317
+ next();
318
+ };
319
+ EventHandlers.on("parseEnd", (message) => {
320
+ parseBool = true;
321
+ checkCompletion(writeBool, parseBool);
322
+ });
323
+ EventHandlers.on("writeEnd", (message) => {
324
+ writeBool = true;
325
+ checkCompletion(writeBool, parseBool);
326
+ });
327
+ new writeFileContent(req, obj, options, "fields", "memory").writeContent();
328
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
329
+ new setFileNameToBody(obj).setFileNames(req);
330
+ new setContentToBody(obj).setBody(req);
331
+ }
332
+ catch (err) {
333
+ next(err);
334
+ }
335
+ });
336
+ req.on("error", () => {
337
+ next(new FormfluxError("Error in recieving request", 500));
372
338
  });
373
339
  };
374
340
  },
375
341
  single(field) {
376
- return function (req, res, next) {
377
- return __awaiter(this, void 0, void 0, function* () {
378
- 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));
440
- });
342
+ return async function (req, res, next) {
343
+ let obj = {
344
+ "originalReq": "",
345
+ "modifiedReq": Buffer.from(""),
346
+ "data": [],
347
+ "content": [],
348
+ "metaData": [],
349
+ "mimeType": [],
350
+ "fieldNameBody": [],
351
+ "fileName": [],
352
+ "modifiedFileName": [],
353
+ "contentBody": [],
354
+ "fieldNameFile": [],
355
+ "filePath": [],
356
+ "filesize": [],
357
+ "streams": []
358
+ };
359
+ let buff = [];
360
+ let reqType = req.headers["content-type"];
361
+ if (reqType && !reqType.includes("multipart/form-data"))
362
+ throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
363
+ let boundary = req.headers["content-type"]?.split("boundary=")[1];
364
+ req.on("data", (chunk) => {
365
+ buff.push(chunk);
366
+ });
367
+ req.on("end", () => {
368
+ try {
369
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
370
+ obj.data = obj.modifiedReq.toString("binary")?.split(`--${boundary}`); // separating the boundary
371
+ obj.data.pop();
372
+ obj.data.shift();
373
+ //*****Defaults*****
374
+ //To*********extract content
375
+ new ExtractFileContent(obj, options, null, field).extraction();
376
+ //To*********SetFileDataToReqObj
377
+ new populateReqObj(obj).populate();
378
+ let writeBool = false;
379
+ let parseBool = false;
380
+ let checkCompletion = (writeComplete, parsecomplete) => {
381
+ if (writeComplete && parsecomplete)
382
+ next();
383
+ };
384
+ EventHandlers.on("parseEnd", (message) => {
385
+ parseBool = true;
386
+ checkCompletion(writeBool, parseBool);
387
+ });
388
+ EventHandlers.on("writeEnd", (message) => {
389
+ writeBool = true;
390
+ checkCompletion(writeBool, parseBool);
391
+ });
392
+ new writeFileContent(req, obj, options, "single", "memory").writeContent();
393
+ if (options.attachFileToReqBody && options.attachFileToReqBody == true)
394
+ new setFileNameToBody(obj).setFileNames(req);
395
+ new setContentToBody(obj).setBody(req);
396
+ }
397
+ catch (err) {
398
+ next(err);
399
+ }
400
+ });
401
+ req.on("error", () => {
402
+ next(new FormfluxError("Error in recieving request", 500));
441
403
  });
442
404
  };
443
405
  },
444
406
  };
445
407
  }
446
408
  bodyParser() {
447
- return function (req, res, next) {
448
- return __awaiter(this, void 0, void 0, function* () {
449
- 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)
489
- next();
490
- };
491
- EventHandlers_1.default.on("parseEnd", (message) => {
492
- parseBool = true;
409
+ return async function (req, res, next) {
410
+ let obj = {
411
+ "originalReq": "",
412
+ "modifiedReq": Buffer.from(""),
413
+ "data": [],
414
+ "content": [],
415
+ "metaData": [],
416
+ "mimeType": [],
417
+ "fieldNameBody": [],
418
+ "fileName": [],
419
+ "modifiedFileName": [],
420
+ "contentBody": [],
421
+ "fieldNameFile": [],
422
+ "filePath": [],
423
+ "filesize": [],
424
+ "streams": []
425
+ };
426
+ let buff = [];
427
+ let reqType = req.headers["content-type"];
428
+ if (reqType && !reqType.includes("multipart/form-data"))
429
+ throw new FormfluxError("Invalid Request Type.Expected multipart/form-data", 400);
430
+ let boundary = req.headers["content-type"]?.split("boundary=")[1];
431
+ req.on("data", (chunk) => {
432
+ buff.push(chunk);
433
+ });
434
+ req.on("end", () => {
435
+ try {
436
+ obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
437
+ obj.data = obj.modifiedReq.toString("binary")?.split(`--${boundary}`); // separating the boundary
438
+ obj.data.pop();
439
+ obj.data.shift();
440
+ //*****Defaults*****
441
+ //To*********extract content
442
+ new ExtractFileContent(obj, null, null, null).extraction();
443
+ //To*********SetFileDataToReqObj
444
+ let writeBool = false;
445
+ let parseBool = false;
446
+ let checkCompletion = (writeComplete, parsecomplete) => {
447
+ if (writeComplete && parsecomplete)
493
448
  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));
503
- });
449
+ };
450
+ EventHandlers.on("parseEnd", (message) => {
451
+ parseBool = true;
452
+ next();
453
+ });
454
+ new setContentToBody(obj).setBody(req);
455
+ }
456
+ catch (err) {
457
+ next(err);
458
+ }
459
+ });
460
+ req.on("error", () => {
461
+ next(new FormfluxError("Error in recieving request", 500));
504
462
  });
505
463
  };
506
464
  }
507
465
  }
508
- exports.default = Formflux;
466
+ export default Formflux;
509
467
  //# sourceMappingURL=FormFlux.js.map