@based/schema 5.1.0 → 5.1.2
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/README.md +1 -47
- package/dist/def/validation.js +56 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
## Display & format WIP
|
|
4
4
|
|
|
5
|
-
Using `display` will not validate or transform and will purely change how the value is shown in UI and API.
|
|
6
|
-
|
|
7
5
|
Use `format` to specify in which format the value has to represented and modified. This may impose some validation and will influence how the UI shows the value.
|
|
8
6
|
|
|
9
7
|
### For example
|
|
@@ -15,16 +13,13 @@ Use `format` to specify in which format the value has to represented and modifie
|
|
|
15
13
|
props: {
|
|
16
14
|
price: {
|
|
17
15
|
type: 'int32',
|
|
18
|
-
display: 'euro',
|
|
19
16
|
},
|
|
20
17
|
authorEmail: {
|
|
21
18
|
type: 'string',
|
|
22
19
|
format: 'email',
|
|
23
|
-
display: 'lowercase',
|
|
24
20
|
},
|
|
25
21
|
lastModified: {
|
|
26
22
|
type: 'timestamp',
|
|
27
|
-
display: 'date-time'
|
|
28
23
|
}
|
|
29
24
|
}
|
|
30
25
|
}
|
|
@@ -32,47 +27,6 @@ Use `format` to specify in which format the value has to represented and modifie
|
|
|
32
27
|
}
|
|
33
28
|
```
|
|
34
29
|
|
|
35
|
-
### Display options
|
|
36
|
-
|
|
37
|
-
#### Timestamp
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
'date',
|
|
41
|
-
'date-time',
|
|
42
|
-
'date-time-text',
|
|
43
|
-
'human',
|
|
44
|
-
'time',
|
|
45
|
-
'time-precise',
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
#### Number
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
'short',
|
|
52
|
-
'human',
|
|
53
|
-
'ratio',
|
|
54
|
-
'bytes',
|
|
55
|
-
'euro',
|
|
56
|
-
'dollar',
|
|
57
|
-
'pound',
|
|
58
|
-
|
|
59
|
-
'round-short',
|
|
60
|
-
'round-human',
|
|
61
|
-
'round-ratio',
|
|
62
|
-
'round-bytes',
|
|
63
|
-
'round-euro',
|
|
64
|
-
'round-dollar',
|
|
65
|
-
'round-pound',
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
#### String
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
'lowercase',
|
|
72
|
-
'uppercase',
|
|
73
|
-
'capitalize',
|
|
74
|
-
```
|
|
75
|
-
|
|
76
30
|
### Format options
|
|
77
31
|
|
|
78
32
|
#### String
|
|
@@ -135,7 +89,7 @@ Use `format` to specify in which format the value has to represented and modifie
|
|
|
135
89
|
'mimeType',
|
|
136
90
|
'latLong',
|
|
137
91
|
'slug',
|
|
138
|
-
'
|
|
92
|
+
'password',
|
|
139
93
|
'taxID',
|
|
140
94
|
'licensePlate',
|
|
141
95
|
'VAT',
|
package/dist/def/validation.js
CHANGED
|
@@ -381,13 +381,62 @@ const validateObj = (value, props, errors, path, required) => {
|
|
|
381
381
|
}
|
|
382
382
|
else if (val !== undefined) {
|
|
383
383
|
const test = getValidator(prop);
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
384
|
+
if ('items' in prop) {
|
|
385
|
+
if (typeof val !== 'object' || val === null) {
|
|
386
|
+
errors.push({
|
|
387
|
+
path: [...path, key],
|
|
388
|
+
value: val,
|
|
389
|
+
error: 'Invalid value',
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
let arr = val;
|
|
393
|
+
if (!Array.isArray(val)) {
|
|
394
|
+
arr = [];
|
|
395
|
+
for (const i in val) {
|
|
396
|
+
if (i === 'add') {
|
|
397
|
+
arr.push(...val.add);
|
|
398
|
+
}
|
|
399
|
+
else if (i === 'update') {
|
|
400
|
+
arr.push(...val.update);
|
|
401
|
+
}
|
|
402
|
+
else if (i === 'delete') {
|
|
403
|
+
arr.push(...val.delete);
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
arr = [];
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (!arr.length) {
|
|
411
|
+
errors.push({
|
|
412
|
+
path: [...path, key],
|
|
413
|
+
value: arr,
|
|
414
|
+
error: 'Invalid value',
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
for (const val of arr) {
|
|
419
|
+
const msg = typeof val === 'object' ? test(val?.id, prop) : test(val, prop);
|
|
420
|
+
if (msg !== true) {
|
|
421
|
+
errors.push({
|
|
422
|
+
path: [...path, key],
|
|
423
|
+
value: val,
|
|
424
|
+
error: typeof msg === 'string' ? msg : 'Invalid value',
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
const msg = getPropType(prop) === 'reference' && typeof val === 'object'
|
|
431
|
+
? test(val?.id, prop)
|
|
432
|
+
: test(val, prop);
|
|
433
|
+
if (msg !== true) {
|
|
434
|
+
errors.push({
|
|
435
|
+
path: [...path, key],
|
|
436
|
+
value: val,
|
|
437
|
+
error: typeof msg === 'string' ? msg : 'Invalid value',
|
|
438
|
+
});
|
|
439
|
+
}
|
|
391
440
|
}
|
|
392
441
|
}
|
|
393
442
|
}
|