structured-fw 1.0.1 → 1.0.3
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.
|
@@ -2,6 +2,7 @@ import { FormValidationEntry, PostedDataDecoded, ValidationResult, ValidationRul
|
|
|
2
2
|
export declare class FormValidation {
|
|
3
3
|
fieldRules: Array<FormValidationEntry>;
|
|
4
4
|
singleError: boolean;
|
|
5
|
+
customValidators: Array<string>;
|
|
5
6
|
validators: {
|
|
6
7
|
[name: string]: ValidatorFunction;
|
|
7
8
|
};
|
|
@@ -2,6 +2,7 @@ export class FormValidation {
|
|
|
2
2
|
constructor() {
|
|
3
3
|
this.fieldRules = [];
|
|
4
4
|
this.singleError = false;
|
|
5
|
+
this.customValidators = [];
|
|
5
6
|
this.validators = {
|
|
6
7
|
'required': async (data, field) => {
|
|
7
8
|
if (!(field in data)) {
|
|
@@ -124,6 +125,7 @@ export class FormValidation {
|
|
|
124
125
|
if (typeof decorator === 'function') {
|
|
125
126
|
this.decorators[name] = decorator;
|
|
126
127
|
}
|
|
128
|
+
this.customValidators.push(name);
|
|
127
129
|
}
|
|
128
130
|
registerDecorator(name, decorator) {
|
|
129
131
|
this.decorators[name] = decorator;
|
|
@@ -138,7 +140,10 @@ export class FormValidation {
|
|
|
138
140
|
const isRequired = entry.rules.includes('required');
|
|
139
141
|
const value = data[entry.field[0]];
|
|
140
142
|
const possiblyValidDataExists = typeof value === 'string';
|
|
141
|
-
const
|
|
143
|
+
const usesCustomValidators = this.fieldRules[i].rules.some((rule) => {
|
|
144
|
+
return this.customValidators.includes(rule);
|
|
145
|
+
});
|
|
146
|
+
const isContent = !usesCustomValidators && !isRequired && (!possiblyValidDataExists || value.trim().length === 0);
|
|
142
147
|
if (!isContent) {
|
|
143
148
|
for (let j = 0; j < entry.rules.length; j++) {
|
|
144
149
|
const rule = entry.rules[j];
|
|
@@ -351,12 +351,17 @@ export class Request {
|
|
|
351
351
|
static parseBodyMultipart(bodyRaw, boundary) {
|
|
352
352
|
const pairsRaw = bodyRaw.split(boundary);
|
|
353
353
|
const pairs = pairsRaw.map((pair) => {
|
|
354
|
-
const parts =
|
|
355
|
-
if (parts) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
354
|
+
const parts = pair.split(/\r?\n\r?\n/, 2).filter((part) => { return part.length > 0; });
|
|
355
|
+
if (parts.length > 0) {
|
|
356
|
+
const header = parts[0];
|
|
357
|
+
const data = typeof parts[1] === 'string' ? parts[1].trim() : '';
|
|
358
|
+
const headerParts = /Content-Disposition: form-data; name="([^\r\n"]+)"/m.exec(header);
|
|
359
|
+
if (headerParts) {
|
|
360
|
+
return {
|
|
361
|
+
key: headerParts[1],
|
|
362
|
+
value: data
|
|
363
|
+
};
|
|
364
|
+
}
|
|
360
365
|
}
|
|
361
366
|
return null;
|
|
362
367
|
});
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"type": "module",
|
|
21
21
|
"main": "build/index",
|
|
22
|
-
"version": "1.0.
|
|
22
|
+
"version": "1.0.3",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"develop": "tsc --watch",
|
|
25
25
|
"startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,css index.js",
|