@palmares/schemas 0.1.25 → 0.2.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/CHANGELOG.md +26 -0
- package/dist/src/adapter/fields/array.cjs +96 -0
- package/dist/src/adapter/fields/array.d.ts.map +1 -0
- package/dist/src/adapter/fields/array.js +70 -0
- package/dist/src/adapter/fields/boolean.cjs +102 -0
- package/dist/src/adapter/fields/boolean.d.ts.map +1 -0
- package/dist/src/adapter/fields/boolean.js +76 -0
- package/dist/src/adapter/fields/datetime.cjs +102 -0
- package/dist/src/adapter/fields/datetime.d.ts.map +1 -0
- package/dist/src/adapter/fields/datetime.js +76 -0
- package/dist/src/adapter/fields/index.cjs +87 -0
- package/dist/src/adapter/fields/index.d.ts.map +1 -0
- package/dist/src/adapter/fields/index.js +61 -0
- package/dist/src/adapter/fields/number.cjs +102 -0
- package/dist/src/adapter/fields/number.d.ts.map +1 -0
- package/dist/src/adapter/fields/number.js +76 -0
- package/dist/src/adapter/fields/object.cjs +108 -0
- package/dist/src/adapter/fields/object.d.ts.map +1 -0
- package/dist/src/adapter/fields/object.js +82 -0
- package/dist/src/adapter/fields/string.cjs +102 -0
- package/dist/src/adapter/fields/string.d.ts.map +1 -0
- package/dist/src/adapter/fields/string.js +76 -0
- package/dist/src/adapter/fields/union.cjs +102 -0
- package/dist/src/adapter/fields/union.d.ts.map +1 -0
- package/dist/src/adapter/fields/union.js +76 -0
- package/dist/src/adapter/index.cjs +65 -0
- package/dist/src/adapter/index.d.ts.map +1 -0
- package/dist/src/adapter/index.js +40 -0
- package/dist/src/adapter/types.cjs +18 -0
- package/dist/src/adapter/types.d.ts.map +1 -0
- package/dist/src/adapter/types.js +0 -0
- package/dist/src/compile.cjs +59 -0
- package/dist/src/compile.d.ts.map +1 -0
- package/dist/src/compile.js +36 -0
- package/dist/src/conf.cjs +53 -0
- package/dist/src/conf.d.ts.map +1 -0
- package/dist/src/conf.js +27 -0
- package/dist/src/constants.cjs +40 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +14 -0
- package/dist/src/domain.cjs +63 -0
- package/dist/src/domain.d.ts.map +1 -0
- package/dist/src/domain.js +40 -0
- package/dist/src/exceptions.cjs +48 -0
- package/dist/{cjs/types → src}/exceptions.d.ts +0 -3
- package/dist/src/exceptions.d.ts.map +1 -0
- package/dist/src/exceptions.js +24 -0
- package/dist/src/index.cjs +6509 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6445 -0
- package/dist/src/middleware.cjs +58 -0
- package/dist/src/middleware.d.ts.map +1 -0
- package/dist/src/middleware.js +35 -0
- package/dist/src/model.cjs +5992 -0
- package/dist/src/model.d.ts.map +1 -0
- package/dist/src/model.js +5967 -0
- package/dist/src/parsers/convert-from-number.cjs +34 -0
- package/dist/src/parsers/convert-from-number.d.ts.map +1 -0
- package/dist/src/parsers/convert-from-number.js +11 -0
- package/dist/src/parsers/convert-from-string.cjs +40 -0
- package/dist/src/parsers/convert-from-string.d.ts.map +1 -0
- package/dist/src/parsers/convert-from-string.js +17 -0
- package/dist/src/parsers/index.cjs +50 -0
- package/dist/src/parsers/index.d.ts.map +1 -0
- package/dist/src/parsers/index.js +24 -0
- package/dist/src/schema/array.cjs +1863 -0
- package/dist/src/schema/array.d.ts.map +1 -0
- package/dist/src/schema/array.js +1837 -0
- package/dist/src/schema/boolean.cjs +1800 -0
- package/dist/src/schema/boolean.d.ts.map +1 -0
- package/dist/src/schema/boolean.js +1774 -0
- package/dist/src/schema/datetime.cjs +1789 -0
- package/dist/src/schema/datetime.d.ts.map +1 -0
- package/dist/src/schema/datetime.js +1763 -0
- package/dist/src/schema/index.cjs +2026 -0
- package/dist/src/schema/index.d.ts.map +1 -0
- package/dist/src/schema/index.js +2001 -0
- package/dist/src/schema/number.cjs +2026 -0
- package/dist/src/schema/number.d.ts.map +1 -0
- package/dist/src/schema/number.js +2000 -0
- package/dist/src/schema/object.cjs +1795 -0
- package/dist/src/schema/object.d.ts.map +1 -0
- package/dist/src/schema/object.js +1769 -0
- package/dist/src/schema/schema.cjs +844 -0
- package/dist/src/schema/schema.d.ts.map +1 -0
- package/dist/src/schema/schema.js +818 -0
- package/dist/src/schema/string.cjs +2126 -0
- package/dist/src/schema/string.d.ts.map +1 -0
- package/dist/src/schema/string.js +2100 -0
- package/dist/src/schema/types.cjs +18 -0
- package/dist/src/schema/types.d.ts.map +1 -0
- package/dist/src/schema/types.js +0 -0
- package/dist/src/schema/union.cjs +1737 -0
- package/dist/src/schema/union.d.ts.map +1 -0
- package/dist/src/schema/union.js +1711 -0
- package/dist/src/types.cjs +18 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +0 -0
- package/dist/src/utils.cjs +477 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +445 -0
- package/dist/src/validators/array.cjs +176 -0
- package/dist/src/validators/array.d.ts.map +1 -0
- package/dist/src/validators/array.js +150 -0
- package/dist/src/validators/boolean.cjs +71 -0
- package/dist/src/validators/boolean.d.ts.map +1 -0
- package/dist/src/validators/boolean.js +47 -0
- package/dist/src/validators/datetime.cjs +129 -0
- package/dist/src/validators/datetime.d.ts.map +1 -0
- package/dist/src/validators/datetime.js +103 -0
- package/dist/src/validators/number.cjs +194 -0
- package/dist/src/validators/number.d.ts.map +1 -0
- package/dist/src/validators/number.js +166 -0
- package/dist/src/validators/object.cjs +69 -0
- package/dist/src/validators/object.d.ts.map +1 -0
- package/dist/src/validators/object.js +46 -0
- package/dist/src/validators/schema.cjs +158 -0
- package/dist/src/validators/schema.d.ts.map +1 -0
- package/dist/src/validators/schema.js +132 -0
- package/dist/src/validators/string.cjs +255 -0
- package/dist/src/validators/string.d.ts.map +1 -0
- package/dist/src/validators/string.js +224 -0
- package/dist/src/validators/types.cjs +18 -0
- package/dist/src/validators/types.d.ts.map +1 -0
- package/dist/src/validators/types.js +0 -0
- package/dist/src/validators/union.cjs +69 -0
- package/dist/src/validators/union.d.ts.map +1 -0
- package/dist/src/validators/union.js +46 -0
- package/dist/src/validators/utils.cjs +165 -0
- package/dist/src/validators/utils.d.ts.map +1 -0
- package/dist/src/validators/utils.js +142 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/package.json +15 -23
- package/dist/cjs/src/adapter/fields/array.js +0 -152
- package/dist/cjs/src/adapter/fields/boolean.js +0 -162
- package/dist/cjs/src/adapter/fields/datetime.js +0 -162
- package/dist/cjs/src/adapter/fields/index.js +0 -311
- package/dist/cjs/src/adapter/fields/number.js +0 -162
- package/dist/cjs/src/adapter/fields/object.js +0 -171
- package/dist/cjs/src/adapter/fields/string.js +0 -162
- package/dist/cjs/src/adapter/fields/union.js +0 -162
- package/dist/cjs/src/adapter/index.js +0 -201
- package/dist/cjs/src/adapter/types.js +0 -4
- package/dist/cjs/src/compile.js +0 -262
- package/dist/cjs/src/conf.js +0 -26
- package/dist/cjs/src/constants.js +0 -36
- package/dist/cjs/src/domain.js +0 -156
- package/dist/cjs/src/exceptions.js +0 -168
- package/dist/cjs/src/index.js +0 -317
- package/dist/cjs/src/middleware.js +0 -213
- package/dist/cjs/src/model.js +0 -628
- package/dist/cjs/src/parsers/convert-from-number.js +0 -15
- package/dist/cjs/src/parsers/convert-from-string.js +0 -19
- package/dist/cjs/src/parsers/index.js +0 -20
- package/dist/cjs/src/schema/array.js +0 -1014
- package/dist/cjs/src/schema/boolean.js +0 -883
- package/dist/cjs/src/schema/datetime.js +0 -840
- package/dist/cjs/src/schema/index.js +0 -12
- package/dist/cjs/src/schema/number.js +0 -976
- package/dist/cjs/src/schema/object.js +0 -1052
- package/dist/cjs/src/schema/schema.js +0 -1840
- package/dist/cjs/src/schema/string.js +0 -1038
- package/dist/cjs/src/schema/types.js +0 -4
- package/dist/cjs/src/schema/union.js +0 -1070
- package/dist/cjs/src/types.js +0 -4
- package/dist/cjs/src/utils.js +0 -647
- package/dist/cjs/src/validators/array.js +0 -462
- package/dist/cjs/src/validators/boolean.js +0 -201
- package/dist/cjs/src/validators/datetime.js +0 -291
- package/dist/cjs/src/validators/number.js +0 -375
- package/dist/cjs/src/validators/object.js +0 -291
- package/dist/cjs/src/validators/schema.js +0 -322
- package/dist/cjs/src/validators/string.js +0 -467
- package/dist/cjs/src/validators/types.js +0 -4
- package/dist/cjs/src/validators/union.js +0 -233
- package/dist/cjs/src/validators/utils.js +0 -499
- package/dist/cjs/tsconfig.types.tsbuildinfo +0 -1
- package/dist/cjs/types/adapter/fields/array.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/boolean.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/datetime.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/index.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/number.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/object.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/string.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/union.d.ts.map +0 -1
- package/dist/cjs/types/adapter/index.d.ts.map +0 -1
- package/dist/cjs/types/adapter/types.d.ts.map +0 -1
- package/dist/cjs/types/compile.d.ts.map +0 -1
- package/dist/cjs/types/conf.d.ts.map +0 -1
- package/dist/cjs/types/constants.d.ts.map +0 -1
- package/dist/cjs/types/domain.d.ts.map +0 -1
- package/dist/cjs/types/exceptions.d.ts.map +0 -1
- package/dist/cjs/types/index.d.ts.map +0 -1
- package/dist/cjs/types/middleware.d.ts.map +0 -1
- package/dist/cjs/types/model.d.ts.map +0 -1
- package/dist/cjs/types/parsers/convert-from-number.d.ts.map +0 -1
- package/dist/cjs/types/parsers/convert-from-string.d.ts.map +0 -1
- package/dist/cjs/types/parsers/index.d.ts.map +0 -1
- package/dist/cjs/types/schema/array.d.ts.map +0 -1
- package/dist/cjs/types/schema/boolean.d.ts.map +0 -1
- package/dist/cjs/types/schema/datetime.d.ts.map +0 -1
- package/dist/cjs/types/schema/index.d.ts.map +0 -1
- package/dist/cjs/types/schema/number.d.ts.map +0 -1
- package/dist/cjs/types/schema/object.d.ts.map +0 -1
- package/dist/cjs/types/schema/schema.d.ts.map +0 -1
- package/dist/cjs/types/schema/string.d.ts.map +0 -1
- package/dist/cjs/types/schema/types.d.ts.map +0 -1
- package/dist/cjs/types/schema/union.d.ts.map +0 -1
- package/dist/cjs/types/types.d.ts.map +0 -1
- package/dist/cjs/types/utils.d.ts.map +0 -1
- package/dist/cjs/types/validators/array.d.ts.map +0 -1
- package/dist/cjs/types/validators/boolean.d.ts.map +0 -1
- package/dist/cjs/types/validators/datetime.d.ts.map +0 -1
- package/dist/cjs/types/validators/number.d.ts.map +0 -1
- package/dist/cjs/types/validators/object.d.ts.map +0 -1
- package/dist/cjs/types/validators/schema.d.ts.map +0 -1
- package/dist/cjs/types/validators/string.d.ts.map +0 -1
- package/dist/cjs/types/validators/types.d.ts.map +0 -1
- package/dist/cjs/types/validators/union.d.ts.map +0 -1
- package/dist/cjs/types/validators/utils.d.ts.map +0 -1
- package/dist/esm/src/adapter/fields/array.js +0 -13
- package/dist/esm/src/adapter/fields/boolean.js +0 -20
- package/dist/esm/src/adapter/fields/datetime.js +0 -20
- package/dist/esm/src/adapter/fields/index.js +0 -37
- package/dist/esm/src/adapter/fields/number.js +0 -20
- package/dist/esm/src/adapter/fields/object.js +0 -26
- package/dist/esm/src/adapter/fields/string.js +0 -20
- package/dist/esm/src/adapter/fields/union.js +0 -20
- package/dist/esm/src/adapter/index.js +0 -21
- package/dist/esm/src/adapter/types.js +0 -1
- package/dist/esm/src/compile.js +0 -10
- package/dist/esm/src/conf.js +0 -18
- package/dist/esm/src/constants.js +0 -4
- package/dist/esm/src/domain.js +0 -11
- package/dist/esm/src/exceptions.js +0 -15
- package/dist/esm/src/index.js +0 -126
- package/dist/esm/src/middleware.js +0 -29
- package/dist/esm/src/model.js +0 -264
- package/dist/esm/src/parsers/convert-from-number.js +0 -8
- package/dist/esm/src/parsers/convert-from-string.js +0 -14
- package/dist/esm/src/parsers/index.js +0 -2
- package/dist/esm/src/schema/array.js +0 -487
- package/dist/esm/src/schema/boolean.js +0 -520
- package/dist/esm/src/schema/datetime.js +0 -477
- package/dist/esm/src/schema/index.js +0 -3
- package/dist/esm/src/schema/number.js +0 -610
- package/dist/esm/src/schema/object.js +0 -521
- package/dist/esm/src/schema/schema.js +0 -767
- package/dist/esm/src/schema/string.js +0 -668
- package/dist/esm/src/schema/types.js +0 -1
- package/dist/esm/src/schema/union.js +0 -468
- package/dist/esm/src/types.js +0 -14
- package/dist/esm/src/utils.js +0 -207
- package/dist/esm/src/validators/array.js +0 -140
- package/dist/esm/src/validators/boolean.js +0 -37
- package/dist/esm/src/validators/datetime.js +0 -89
- package/dist/esm/src/validators/number.js +0 -148
- package/dist/esm/src/validators/object.js +0 -39
- package/dist/esm/src/validators/schema.js +0 -118
- package/dist/esm/src/validators/string.js +0 -202
- package/dist/esm/src/validators/types.js +0 -1
- package/dist/esm/src/validators/union.js +0 -39
- package/dist/esm/src/validators/utils.js +0 -147
- /package/dist/{cjs/types → src}/adapter/fields/array.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/boolean.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/datetime.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/number.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/object.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/string.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/union.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/types.d.ts +0 -0
- /package/dist/{cjs/types → src}/compile.d.ts +0 -0
- /package/dist/{cjs/types → src}/conf.d.ts +0 -0
- /package/dist/{cjs/types → src}/constants.d.ts +0 -0
- /package/dist/{cjs/types → src}/domain.d.ts +0 -0
- /package/dist/{cjs/types → src}/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/middleware.d.ts +0 -0
- /package/dist/{cjs/types → src}/model.d.ts +0 -0
- /package/dist/{cjs/types → src}/parsers/convert-from-number.d.ts +0 -0
- /package/dist/{cjs/types → src}/parsers/convert-from-string.d.ts +0 -0
- /package/dist/{cjs/types → src}/parsers/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/array.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/boolean.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/datetime.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/number.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/object.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/schema.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/string.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/types.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/union.d.ts +0 -0
- /package/dist/{cjs/types → src}/types.d.ts +0 -0
- /package/dist/{cjs/types → src}/utils.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/array.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/boolean.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/datetime.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/number.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/object.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/schema.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/string.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/types.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/union.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/utils.d.ts +0 -0
@@ -1,202 +0,0 @@
|
|
1
|
-
export function stringValidation() {
|
2
|
-
return {
|
3
|
-
name: 'string',
|
4
|
-
type: 'medium',
|
5
|
-
// eslint-disable-next-line ts/require-await
|
6
|
-
callback: async (value, path, _options)=>{
|
7
|
-
return {
|
8
|
-
parsed: value,
|
9
|
-
errors: typeof value === 'string' ? [] : [
|
10
|
-
{
|
11
|
-
isValid: typeof value === 'string',
|
12
|
-
code: 'string',
|
13
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
14
|
-
path: path || [],
|
15
|
-
message: 'The value must be a string. Received: ' + typeof value
|
16
|
-
}
|
17
|
-
]
|
18
|
-
};
|
19
|
-
}
|
20
|
-
};
|
21
|
-
}
|
22
|
-
export function maxLength(args) {
|
23
|
-
return {
|
24
|
-
name: 'maxLength',
|
25
|
-
type: 'low',
|
26
|
-
// eslint-disable-next-line ts/require-await
|
27
|
-
callback: async (value, path, _options)=>{
|
28
|
-
const isValid = value.length <= args.value;
|
29
|
-
return {
|
30
|
-
parsed: value,
|
31
|
-
errors: isValid ? [] : [
|
32
|
-
{
|
33
|
-
isValid: false,
|
34
|
-
code: 'maxLength',
|
35
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
36
|
-
path: path || [],
|
37
|
-
message: args.message
|
38
|
-
}
|
39
|
-
]
|
40
|
-
};
|
41
|
-
}
|
42
|
-
};
|
43
|
-
}
|
44
|
-
export function minLength(args) {
|
45
|
-
return {
|
46
|
-
name: 'minLength',
|
47
|
-
type: 'low',
|
48
|
-
// eslint-disable-next-line ts/require-await
|
49
|
-
callback: async (value, path, _options)=>{
|
50
|
-
const isValid = value.length >= args.value;
|
51
|
-
return {
|
52
|
-
parsed: value,
|
53
|
-
errors: isValid ? [] : [
|
54
|
-
{
|
55
|
-
isValid: false,
|
56
|
-
code: 'minLength',
|
57
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
58
|
-
path: path || [],
|
59
|
-
message: args.message
|
60
|
-
}
|
61
|
-
]
|
62
|
-
};
|
63
|
-
}
|
64
|
-
};
|
65
|
-
}
|
66
|
-
export function endsWith(args) {
|
67
|
-
return {
|
68
|
-
name: 'endsWith',
|
69
|
-
type: 'low',
|
70
|
-
// eslint-disable-next-line ts/require-await
|
71
|
-
callback: async (value, path, _options)=>{
|
72
|
-
const isValid = value.endsWith(args.value);
|
73
|
-
return {
|
74
|
-
parsed: value,
|
75
|
-
errors: isValid ? [] : [
|
76
|
-
{
|
77
|
-
isValid: false,
|
78
|
-
code: 'endsWith',
|
79
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
80
|
-
path: path || [],
|
81
|
-
message: args.message
|
82
|
-
}
|
83
|
-
]
|
84
|
-
};
|
85
|
-
}
|
86
|
-
};
|
87
|
-
}
|
88
|
-
export function startsWith(args) {
|
89
|
-
return {
|
90
|
-
name: 'startsWith',
|
91
|
-
type: 'low',
|
92
|
-
// eslint-disable-next-line ts/require-await
|
93
|
-
callback: async (value, path, _options)=>{
|
94
|
-
const isValid = value.startsWith(args.value);
|
95
|
-
return {
|
96
|
-
parsed: value,
|
97
|
-
errors: isValid ? [] : [
|
98
|
-
{
|
99
|
-
isValid: false,
|
100
|
-
code: 'startsWith',
|
101
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
102
|
-
path: path || [],
|
103
|
-
message: args.message
|
104
|
-
}
|
105
|
-
]
|
106
|
-
};
|
107
|
-
}
|
108
|
-
};
|
109
|
-
}
|
110
|
-
export function includes(args) {
|
111
|
-
return {
|
112
|
-
name: 'includes',
|
113
|
-
type: 'low',
|
114
|
-
// eslint-disable-next-line ts/require-await
|
115
|
-
callback: async (value, path, _options)=>{
|
116
|
-
const isValid = value.includes(args.value);
|
117
|
-
return {
|
118
|
-
parsed: value,
|
119
|
-
errors: isValid ? [] : [
|
120
|
-
{
|
121
|
-
isValid: false,
|
122
|
-
code: 'includes',
|
123
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
124
|
-
path: path || [],
|
125
|
-
message: args.message
|
126
|
-
}
|
127
|
-
]
|
128
|
-
};
|
129
|
-
}
|
130
|
-
};
|
131
|
-
}
|
132
|
-
export function regex(args) {
|
133
|
-
return {
|
134
|
-
name: 'regex',
|
135
|
-
type: 'low',
|
136
|
-
// eslint-disable-next-line ts/require-await
|
137
|
-
callback: async (value, path, _options)=>{
|
138
|
-
const isValid = args.value.test(value);
|
139
|
-
return {
|
140
|
-
parsed: value,
|
141
|
-
errors: isValid ? [] : [
|
142
|
-
{
|
143
|
-
isValid: false,
|
144
|
-
code: 'regex',
|
145
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
146
|
-
path: path || [],
|
147
|
-
message: args.message
|
148
|
-
}
|
149
|
-
]
|
150
|
-
};
|
151
|
-
}
|
152
|
-
};
|
153
|
-
}
|
154
|
-
export function uuid(args) {
|
155
|
-
// const uuidRegex =
|
156
|
-
// /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
157
|
-
const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
158
|
-
return {
|
159
|
-
name: 'uuid',
|
160
|
-
type: 'low',
|
161
|
-
// eslint-disable-next-line ts/require-await
|
162
|
-
callback: async (value, path, _options)=>{
|
163
|
-
const isValid = uuidRegex.test(value);
|
164
|
-
return {
|
165
|
-
parsed: value,
|
166
|
-
errors: isValid ? [] : [
|
167
|
-
{
|
168
|
-
isValid: false,
|
169
|
-
code: 'uuid',
|
170
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
171
|
-
path: path || [],
|
172
|
-
message: args.message
|
173
|
-
}
|
174
|
-
]
|
175
|
-
};
|
176
|
-
}
|
177
|
-
};
|
178
|
-
}
|
179
|
-
export function email(args) {
|
180
|
-
const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
181
|
-
console.log('aquiiiiii');
|
182
|
-
return {
|
183
|
-
name: 'email',
|
184
|
-
type: 'low',
|
185
|
-
// eslint-disable-next-line ts/require-await
|
186
|
-
callback: async (value, path, _options)=>{
|
187
|
-
const isValid = emailRegex.test(value);
|
188
|
-
return {
|
189
|
-
parsed: value,
|
190
|
-
errors: isValid ? [] : [
|
191
|
-
{
|
192
|
-
isValid: false,
|
193
|
-
code: 'email',
|
194
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
195
|
-
path: path || [],
|
196
|
-
message: args.message
|
197
|
-
}
|
198
|
-
]
|
199
|
-
};
|
200
|
-
}
|
201
|
-
};
|
202
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export { };
|
@@ -1,39 +0,0 @@
|
|
1
|
-
export function unionValidation(schemas) {
|
2
|
-
return {
|
3
|
-
name: 'union',
|
4
|
-
type: 'medium',
|
5
|
-
callback: async (value, path, options)=>{
|
6
|
-
const parsedValues = {
|
7
|
-
parsed: value,
|
8
|
-
errors: []
|
9
|
-
};
|
10
|
-
const startingToInternalBubbleUpLength = options.toInternalToBubbleUp?.length || 0;
|
11
|
-
// eslint-disable-next-line ts/prefer-for-of
|
12
|
-
for(let i = 0; i < schemas.length; i++){
|
13
|
-
const schemaWithProtected = schemas[i];
|
14
|
-
const parsedData = await schemaWithProtected.__parse(value, path, options);
|
15
|
-
parsedValues.parsed = parsedData.parsed;
|
16
|
-
if (Array.isArray(parsedData.errors)) if (Array.isArray(parsedValues.errors)) parsedValues.errors.push(...parsedData.errors);
|
17
|
-
else parsedValues.errors = parsedData.errors;
|
18
|
-
const hasNoErrorsSoItsAValidSchemaAndShouldResetOldErrors = // eslint-disable-next-line ts/no-unnecessary-condition
|
19
|
-
parsedData.errors === undefined || (parsedData.errors || []).length === 0;
|
20
|
-
if (hasNoErrorsSoItsAValidSchemaAndShouldResetOldErrors) {
|
21
|
-
return {
|
22
|
-
parsed: parsedValues.parsed,
|
23
|
-
errors: []
|
24
|
-
};
|
25
|
-
} else if (startingToInternalBubbleUpLength < (options.toInternalToBubbleUp?.length || 0)) {
|
26
|
-
// If there is a new toInternalToBubbleUp we should remove the ones that we added since this is not a
|
27
|
-
// valid schema, we shouldn't be calling the `toInternal` on that schemas.
|
28
|
-
const numberOfElementsToRemove = (options.toInternalToBubbleUp?.length || 0) - startingToInternalBubbleUpLength;
|
29
|
-
options.toInternalToBubbleUp?.splice(startingToInternalBubbleUpLength, numberOfElementsToRemove);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return {
|
33
|
-
parsed: parsedValues.parsed,
|
34
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
35
|
-
errors: Array.isArray(parsedValues.errors) ? parsedValues.errors : []
|
36
|
-
};
|
37
|
-
}
|
38
|
-
};
|
39
|
-
}
|
@@ -1,147 +0,0 @@
|
|
1
|
-
const priorityByType = {
|
2
|
-
low: 0,
|
3
|
-
medium: 1,
|
4
|
-
high: 2
|
5
|
-
};
|
6
|
-
const typeByPriority = Object.entries(priorityByType).reduce((acc, [key, value])=>{
|
7
|
-
acc[value] = key;
|
8
|
-
return acc;
|
9
|
-
}, {});
|
10
|
-
/**
|
11
|
-
* Okay, so what is this? This is a validator class, it represents a Node on a linked list. The linked list
|
12
|
-
* has lower priority validators on the end of the list and higher priority validators on the start of the
|
13
|
-
* list. Maybe in the future we can change that to a binary tree, but for now this is enough.
|
14
|
-
*
|
15
|
-
* Why did we choose this approach? Because what i was doing was that i saw myself repeating the same code 3
|
16
|
-
* times on the schema in order to make the validation work. Each validator had a different return type, i
|
17
|
-
* didn't like that. I wanted to add more power and control on the validator, not on the schema. So i created
|
18
|
-
* this class. So pretty much, over here and on each validator we can define the type it is. It can actually
|
19
|
-
* be three: `low`, `medium` and `high`. The `low` validators are the ones that are going to be executed last,
|
20
|
-
* The `high` validators are the ones that are going to be executed first. High validators validate if the value
|
21
|
-
* is null or undefined, if it allows that. It can stop the execution of the other validators if it wants to.
|
22
|
-
*
|
23
|
-
* Example: Let's say that the value is null, if the value is null, is there a reason to check if it's a number?
|
24
|
-
* No, right? So the high validator can stop the execution of the other validators.
|
25
|
-
* Same as before, if the value is not a number, is there a reason to check if it's value is greater than the
|
26
|
-
* `max` allowed 10? No, right? So the medium validator can stop the execution of the other validators.
|
27
|
-
*
|
28
|
-
* That's what this solve, it's a better approach than repeating the same code 3 times on the schema. It's also
|
29
|
-
* more powerful, because if we need to add any extra priorities we can do that easily without changing the schema.
|
30
|
-
*/ export class Validator {
|
31
|
-
$$type = '$PValidator';
|
32
|
-
child;
|
33
|
-
parent;
|
34
|
-
fallbackNamesAdded = new Set();
|
35
|
-
priority;
|
36
|
-
fallbacks = [];
|
37
|
-
constructor(type){
|
38
|
-
this.fallbackNamesAdded = new Set();
|
39
|
-
this.fallbacks = [];
|
40
|
-
this.priority = priorityByType[type];
|
41
|
-
}
|
42
|
-
/**
|
43
|
-
* We create all of the validators on the schema in order, i actually didn't want to go on that route but i
|
44
|
-
* found it easier to do so.
|
45
|
-
*
|
46
|
-
* The logic here is simple, if it's not the same priority we will walk on the linked list until we find
|
47
|
-
* a validator that matches the priority we are expecting. If we can't walk anymore, we create the next
|
48
|
-
* priority validator and append it to the linked list. Be aware that it's a double linked list, so we
|
49
|
-
* can walk both ways, from the end to the start and from the start to the end.
|
50
|
-
* So you don't really need to start from the root, the linked list can start from anywhere and it will
|
51
|
-
* find it's way through.
|
52
|
-
*
|
53
|
-
* I know there are better ways to do this instead of walking through the linked list, but like i explained
|
54
|
-
* before, this is enough for now.
|
55
|
-
*
|
56
|
-
* If the priority is higher than the current priority saved on the schema, we should substitute the
|
57
|
-
* rootValidator on the schema with the new one.
|
58
|
-
*
|
59
|
-
* @param schema - The schema that we are working on right now, all fallbacks are tied to that specific schema.
|
60
|
-
* @param type - The type of the fallback that we are adding.
|
61
|
-
* @param fallback - The fallback function that we are adding.
|
62
|
-
* @param childOrParent - If we are adding a fallback to the child or to the parent.
|
63
|
-
* @param options - The options that we are passing to the fallback.
|
64
|
-
*/ checkAppendOrCreate(schema, type, fallbackName, fallback, childOrParent, options) {
|
65
|
-
const schemaWithProtected = schema;
|
66
|
-
if (this[childOrParent]) this[childOrParent].addFallback(schemaWithProtected, type, fallbackName, fallback, options);
|
67
|
-
else {
|
68
|
-
const nextPriority = childOrParent === 'child' ? this.priority - 1 : this.priority + 1;
|
69
|
-
if (Object.keys(typeByPriority).includes(String(nextPriority))) {
|
70
|
-
const nextType = typeByPriority[nextPriority];
|
71
|
-
const validatorInstance = new Validator(nextType);
|
72
|
-
this[childOrParent] = validatorInstance;
|
73
|
-
this[childOrParent][childOrParent === 'parent' ? 'child' : 'parent'] = this;
|
74
|
-
this[childOrParent].addFallback(schemaWithProtected, type, fallbackName, fallback, options);
|
75
|
-
if (nextPriority > schemaWithProtected.__rootFallbacksValidator.priority) schemaWithProtected.__rootFallbacksValidator = validatorInstance;
|
76
|
-
}
|
77
|
-
}
|
78
|
-
}
|
79
|
-
addFallback(schema, type, fallbackName, fallback, options) {
|
80
|
-
if (this.fallbackNamesAdded.has(fallbackName) && options?.removeCurrent !== true) return;
|
81
|
-
this.fallbackNamesAdded.add(fallbackName);
|
82
|
-
const priority = priorityByType[type];
|
83
|
-
if (this.priority === priority) {
|
84
|
-
if (typeof options?.at === 'number') this.fallbacks.splice(options.at, options.removeCurrent === true ? 1 : 0, fallback);
|
85
|
-
else this.fallbacks.push(fallback);
|
86
|
-
} else if (priority > this.priority) this.checkAppendOrCreate(schema, type, fallbackName, fallback, 'parent', options);
|
87
|
-
else if (priority < this.priority) this.checkAppendOrCreate(schema, type, fallbackName, fallback, 'child', options);
|
88
|
-
}
|
89
|
-
/**
|
90
|
-
* Validates the value against all of the fallbacks, the fallbacks are executed in order, from the highest
|
91
|
-
* priority to the lowest priority. A validator can stop the execution of the other validators if it feels
|
92
|
-
* like so. Like on the example of a value being null or undefined.
|
93
|
-
*
|
94
|
-
* @param errorsAsHashedSet - This is a set that contains all of the errors that we already found, this is
|
95
|
-
* used to avoid duplicated errors.
|
96
|
-
* @param path - The path that we are validating right now.
|
97
|
-
* @param parseResult - The result of the parsing, it contains the parsed value and the errors that we found.
|
98
|
-
* @param options - The options that we are passing to the fallback.
|
99
|
-
*/ async validate(errorsAsHashedSet, path, parseResult, options) {
|
100
|
-
let doesItShouldPreventChildValidation = false;
|
101
|
-
for (const fallback of this.fallbacks){
|
102
|
-
const { parsed, errors, preventChildValidation } = await fallback(parseResult.parsed, path, options);
|
103
|
-
parseResult.parsed = parsed;
|
104
|
-
for (const error of errors){
|
105
|
-
if (error.isValid === false) {
|
106
|
-
const sortedError = Object.fromEntries(Object.entries(error).sort(([a], [b])=>a.localeCompare(b)));
|
107
|
-
const hashedError = JSON.stringify(sortedError);
|
108
|
-
if (errorsAsHashedSet.has(hashedError)) continue;
|
109
|
-
errorsAsHashedSet.add(hashedError);
|
110
|
-
if (!Array.isArray(parseResult.errors)) parseResult.errors = [];
|
111
|
-
parseResult.errors.push({
|
112
|
-
...error,
|
113
|
-
received: parseResult.parsed
|
114
|
-
});
|
115
|
-
}
|
116
|
-
}
|
117
|
-
doesItShouldPreventChildValidation = doesItShouldPreventChildValidation || preventChildValidation || false;
|
118
|
-
}
|
119
|
-
if (this.child && doesItShouldPreventChildValidation === false) return await this.child.validate(errorsAsHashedSet, path, parseResult, options);
|
120
|
-
return parseResult;
|
121
|
-
}
|
122
|
-
/**
|
123
|
-
* This static method takes care of everything for you. This means that you should only call this method
|
124
|
-
* for appending new fallbacks, it takes care of creating the root validator and making sure that the
|
125
|
-
* rootValidator on the schema is the highest priority one.
|
126
|
-
*
|
127
|
-
* @param schema - The schema that we are working on right now, all fallbacks are tied to that specific
|
128
|
-
* schema. We automatically define the rootValidator on the schema so you don't need to worry about that.
|
129
|
-
* @param fallback - The fallback that we are adding. This is an object that contains the type of the
|
130
|
-
* fallback and the callback that we are adding.
|
131
|
-
* @param options - The options that we are passing to the fallback. Options like `at` and `removeCurrent`
|
132
|
-
* are passed to the `addFallback` method.
|
133
|
-
*/ static createAndAppendFallback(schema, fallback, options) {
|
134
|
-
const schemaWithProtected = schema;
|
135
|
-
let validatorInstance = schemaWithProtected.__rootFallbacksValidator;
|
136
|
-
// eslint-disable-next-line ts/no-unnecessary-condition
|
137
|
-
if (schemaWithProtected.__rootFallbacksValidator === undefined) {
|
138
|
-
validatorInstance = new Validator(fallback.type);
|
139
|
-
schemaWithProtected.__rootFallbacksValidator = validatorInstance;
|
140
|
-
}
|
141
|
-
validatorInstance.addFallback(schema, fallback.type, fallback.name, fallback.callback, options);
|
142
|
-
return validatorInstance;
|
143
|
-
}
|
144
|
-
toString(ident = 0) {
|
145
|
-
return `Priority: ${this.priority}\nFallbacks: ${this.fallbacks.length}\n${this.child ? `Children:\n${this.child.toString(ident + 2)}` : ''}`;
|
146
|
-
}
|
147
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|