pols-validator 2.7.8 → 3.0.0
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/.vscode/settings.json +2 -1
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +48 -46
- package/dist/rulesEngine.d.ts +3 -1
- package/dist/rulesEngine.d.ts.map +1 -1
- package/dist/rulesEngine.js +11 -2
- package/package.json +1 -1
- package/tsconfig.json +0 -20
package/.vscode/settings.json
CHANGED
package/dist/rules.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAiB,MAAM,eAAe,CAAA;AAK3D,MAAM,MAAM,eAAe,GAAG;IAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB,CAAA;
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAiB,MAAM,eAAe,CAAA;AAK3D,MAAM,MAAM,eAAe,GAAG;IAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB,CAAA;AAED,qBAAa,MAAO,SAAQ,YAAY;IACvC,cAAc;IAWd,cAAc;IAed,UAAU;IAUV,MAAM;IAMN,MAAM;IA4BN,KAAK,CAAC,OAAO,EAAE,MAAM;IAQrB,QAAQ;IAUR,SAAS;IAQT,SAAS;IAIT,eAAe;IAIf,WAAW;IAQX,SAAS,CAAC,KAAK,EAAE,MAAM;IAYvB,SAAS,CAAC,KAAK,EAAE,MAAM;IAYvB,cAAc,CAAC,KAAK,EAAE,MAAM;IAY5B,IAAI,CAAC,KAAK,EAAE,MAAM;IAMlB,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM;IAmClD,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAY3B,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAM9B,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM;IAMtD,IAAI,CAAC,KAAK,EAAE,MAAM;IAMlB,KAAK,CAAC,KAAK,EAAE,MAAM;IAMnB,IAAI,CAAC,KAAK,EAAE,MAAM;IAMlB,KAAK,CAAC,KAAK,EAAE,MAAM;IAMnB,iBAAiB;IAOjB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IA4CxC,SAAS;IA+CT,KAAK;IAQL,KAAK;IAQL,SAAS;IAQT,KAAK,CAAC,QAAQ,EAAE,MAAM;IAStB,iBAAiB;IAQjB,QAAQ;IASR,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;IAMlG,UAAU;IAQV,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAMhC,IAAI,CAAC,SAAS,EAAE,MAAM;IAMtB,KAAK;IAML,IAAI;IAMJ,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe;CAajC"}
|
package/dist/rules.js
CHANGED
|
@@ -5,50 +5,6 @@ const rulesEngine_1 = require("./rulesEngine");
|
|
|
5
5
|
const pols_date_1 = require("pols-date");
|
|
6
6
|
const isomorphic_dompurify_1 = require("isomorphic-dompurify");
|
|
7
7
|
const pols_utils_1 = require("pols-utils");
|
|
8
|
-
const isObject = (context, wrapper, schema) => {
|
|
9
|
-
const message = `'${wrapper.label}' debe ser un objeto`;
|
|
10
|
-
if (typeof wrapper.value == 'string') {
|
|
11
|
-
try {
|
|
12
|
-
wrapper.value = JSON.parse(wrapper.value);
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return message;
|
|
16
|
-
}
|
|
17
|
-
if (wrapper.value == null || typeof wrapper.value != 'object')
|
|
18
|
-
return message;
|
|
19
|
-
}
|
|
20
|
-
else if (wrapper.value != null) {
|
|
21
|
-
if (typeof wrapper.value != 'object')
|
|
22
|
-
return message;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
return message;
|
|
26
|
-
}
|
|
27
|
-
/* Realiza la validación de cada propiedad */
|
|
28
|
-
if (schema) {
|
|
29
|
-
const newWrapperValue = {};
|
|
30
|
-
const errorMessages = [];
|
|
31
|
-
for (const key in schema) {
|
|
32
|
-
const rulesInside = schema[key];
|
|
33
|
-
const labelIndise = rulesInside.label ?? key;
|
|
34
|
-
rulesInside.label = `${context.label ? `${context.label}${context.separator}` : ''}${labelIndise}`;
|
|
35
|
-
const result2 = rulesInside.validate(wrapper.value[key], false);
|
|
36
|
-
if (result2.error == true) {
|
|
37
|
-
errorMessages.push(...result2.messages);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
if (result2.result !== undefined)
|
|
41
|
-
newWrapperValue[key] = result2.result;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (errorMessages.length) {
|
|
45
|
-
return errorMessages;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
wrapper.value = newWrapperValue;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
8
|
class PRules extends rulesEngine_1.PRulesEngine {
|
|
53
9
|
isAlphanumeric() {
|
|
54
10
|
this.add(this.isAlphanumeric.name, (wrapper) => {
|
|
@@ -232,12 +188,14 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
232
188
|
rules.label = `${this.label ? `${this.label}${rules.label ? this.separator : ''}` : ''}${rules.label ?? ''}`;
|
|
233
189
|
const result = rules.validate(element, false);
|
|
234
190
|
if (result.error == true) {
|
|
191
|
+
wrapper.value[i] = result.interim;
|
|
235
192
|
messages.push(...result.messages);
|
|
236
193
|
}
|
|
237
194
|
else {
|
|
238
|
-
wrapper.value[i] = result.
|
|
195
|
+
wrapper.value[i] = result.sanitized;
|
|
239
196
|
}
|
|
240
197
|
}
|
|
198
|
+
wrapper.interim = wrapper.value;
|
|
241
199
|
if (messages.length)
|
|
242
200
|
return messages;
|
|
243
201
|
});
|
|
@@ -301,7 +259,51 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
301
259
|
}
|
|
302
260
|
isObject(schema) {
|
|
303
261
|
return this.add(this.isObject.name, (wrapper) => {
|
|
304
|
-
|
|
262
|
+
const message = `'${wrapper.label}' debe ser un objeto`;
|
|
263
|
+
if (typeof wrapper.value == 'string') {
|
|
264
|
+
try {
|
|
265
|
+
wrapper.value = JSON.parse(wrapper.value);
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
return message;
|
|
269
|
+
}
|
|
270
|
+
if (wrapper.value == null || typeof wrapper.value != 'object')
|
|
271
|
+
return message;
|
|
272
|
+
}
|
|
273
|
+
else if (wrapper.value != null) {
|
|
274
|
+
if (typeof wrapper.value != 'object')
|
|
275
|
+
return message;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
return message;
|
|
279
|
+
}
|
|
280
|
+
/* Realiza la validación de cada propiedad */
|
|
281
|
+
if (schema) {
|
|
282
|
+
const interim = {};
|
|
283
|
+
const errorMessages = [];
|
|
284
|
+
for (const key in schema) {
|
|
285
|
+
const rulesInside = schema[key];
|
|
286
|
+
const labelIndise = rulesInside.label ?? key;
|
|
287
|
+
rulesInside.label = `${this.label ? `${this.label}${this.separator}` : ''}${labelIndise}`;
|
|
288
|
+
const propertyResult = rulesInside.validate(wrapper.value[key], false);
|
|
289
|
+
if (propertyResult.error == true) {
|
|
290
|
+
if (propertyResult.interim !== undefined)
|
|
291
|
+
interim[key] = propertyResult.interim;
|
|
292
|
+
errorMessages.push(...propertyResult.messages);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
if (propertyResult.sanitized !== undefined)
|
|
296
|
+
interim[key] = propertyResult.sanitized;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (errorMessages.length) {
|
|
300
|
+
wrapper.interim = interim;
|
|
301
|
+
return errorMessages;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
wrapper.value = interim;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
305
307
|
});
|
|
306
308
|
}
|
|
307
309
|
isBoolean() {
|
package/dist/rulesEngine.d.ts
CHANGED
|
@@ -10,15 +10,17 @@ export type PRulesFunction = (wrapper: PRulesWrapper, ...args: unknown[]) => str
|
|
|
10
10
|
export type PRulesWrapper<T = unknown> = {
|
|
11
11
|
value: T;
|
|
12
12
|
label: string;
|
|
13
|
+
interim?: T;
|
|
13
14
|
};
|
|
14
15
|
export type PRulesResponse<T> = {
|
|
15
16
|
error: false;
|
|
16
17
|
success: true;
|
|
17
|
-
|
|
18
|
+
sanitized: T;
|
|
18
19
|
} | {
|
|
19
20
|
error: true;
|
|
20
21
|
success: false;
|
|
21
22
|
messages: string[];
|
|
23
|
+
interim: T;
|
|
22
24
|
};
|
|
23
25
|
export declare class PRulesEngine {
|
|
24
26
|
prefix: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rulesEngine.d.ts","sourceRoot":"","sources":["../src/rulesEngine.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,CAAC;IACJ,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB,CAAC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,GAAG,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AAO,CAAO;IAEvB,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,eAAe,CAAe;gBAE1B,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO;gBACtD,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO;gBACtC,MAAM,CAAC,EAAE,YAAY;IAmBjC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc;IAQ9D,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,UAAO,GAAG,cAAc,CAAC,CAAC,CAAC;CAmE5D"}
|
package/dist/rulesEngine.js
CHANGED
|
@@ -46,6 +46,7 @@ class PRulesEngine {
|
|
|
46
46
|
return {
|
|
47
47
|
error: true,
|
|
48
48
|
success: false,
|
|
49
|
+
interim: undefined,
|
|
49
50
|
messages: [`'${label}' es requerido`]
|
|
50
51
|
};
|
|
51
52
|
}
|
|
@@ -54,10 +55,17 @@ class PRulesEngine {
|
|
|
54
55
|
target = this.default;
|
|
55
56
|
}
|
|
56
57
|
else {
|
|
58
|
+
let newValue;
|
|
59
|
+
if (target == null) {
|
|
60
|
+
newValue = target;
|
|
61
|
+
}
|
|
62
|
+
else if (typeof target == 'string') {
|
|
63
|
+
newValue = null;
|
|
64
|
+
}
|
|
57
65
|
return {
|
|
58
66
|
error: false,
|
|
59
67
|
success: true,
|
|
60
|
-
|
|
68
|
+
sanitized: newValue
|
|
61
69
|
};
|
|
62
70
|
}
|
|
63
71
|
}
|
|
@@ -81,6 +89,7 @@ class PRulesEngine {
|
|
|
81
89
|
return {
|
|
82
90
|
error: true,
|
|
83
91
|
success: false,
|
|
92
|
+
interim: wrapper.interim,
|
|
84
93
|
messages: errorMessages
|
|
85
94
|
};
|
|
86
95
|
}
|
|
@@ -88,7 +97,7 @@ class PRulesEngine {
|
|
|
88
97
|
return {
|
|
89
98
|
error: false,
|
|
90
99
|
success: true,
|
|
91
|
-
|
|
100
|
+
sanitized: wrapper.value
|
|
92
101
|
};
|
|
93
102
|
}
|
|
94
103
|
}
|
package/package.json
CHANGED
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"forceConsistentCasingInFileNames": true,
|
|
8
|
-
"strict": false,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"declarationMap": true,
|
|
12
|
-
"outDir": "./dist"
|
|
13
|
-
},
|
|
14
|
-
"include": [
|
|
15
|
-
"src/**/*.ts"
|
|
16
|
-
],
|
|
17
|
-
"exclude": [
|
|
18
|
-
"node_modules"
|
|
19
|
-
]
|
|
20
|
-
}
|