@azteam/express 1.2.114 → 1.2.115
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/package.json +1 -1
- package/src/index.js +1 -0
- package/src/validate.js +132 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/validate.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/* schema */
|
|
2
|
+
|
|
3
|
+
export const schemaID = (optional = false) => ({
|
|
4
|
+
type: 'string',
|
|
5
|
+
length: 24,
|
|
6
|
+
pattern: /^[A-Fa-f0-9]{24}$/,
|
|
7
|
+
optional,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const schemaEmail = (optional = false) => ({
|
|
11
|
+
type: 'email',
|
|
12
|
+
optional,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const schemaUrl = (optional = false) => ({
|
|
16
|
+
type: 'url',
|
|
17
|
+
optional,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const schemaBoolean = (optional = false) => ({
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
convert: true,
|
|
23
|
+
optional,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const schemaDate = (optional = false) => ({
|
|
27
|
+
type: 'number',
|
|
28
|
+
convert: true,
|
|
29
|
+
integer: true,
|
|
30
|
+
optional,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const schemaNumber = (optional = false) => ({
|
|
34
|
+
type: 'number',
|
|
35
|
+
convert: true,
|
|
36
|
+
optional,
|
|
37
|
+
});
|
|
38
|
+
export const schemaInteger = (min = 0, max = 999999999, optional = false) => ({
|
|
39
|
+
type: 'number',
|
|
40
|
+
integer: true,
|
|
41
|
+
convert: true,
|
|
42
|
+
min,
|
|
43
|
+
max,
|
|
44
|
+
optional,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const schemaString = (min = 1, max = 255, optional = false) => ({
|
|
48
|
+
type: 'string',
|
|
49
|
+
min,
|
|
50
|
+
max,
|
|
51
|
+
optional,
|
|
52
|
+
});
|
|
53
|
+
export const schemaPassword = (optional = false) => ({
|
|
54
|
+
type: 'string',
|
|
55
|
+
min: 6,
|
|
56
|
+
max: 32,
|
|
57
|
+
optional,
|
|
58
|
+
});
|
|
59
|
+
export const schemaOTP = (optional = false) => ({
|
|
60
|
+
type: 'string',
|
|
61
|
+
length: 6,
|
|
62
|
+
pattern: /\d+/,
|
|
63
|
+
optional,
|
|
64
|
+
});
|
|
65
|
+
export const schemaImage = (optional = false) => ({
|
|
66
|
+
type: 'string',
|
|
67
|
+
max: 255,
|
|
68
|
+
optional,
|
|
69
|
+
});
|
|
70
|
+
export const schemaVideo = (optional = false) => ({
|
|
71
|
+
type: 'string',
|
|
72
|
+
max: 255,
|
|
73
|
+
optional,
|
|
74
|
+
});
|
|
75
|
+
export const schemaPhoneNumber = (optional = false) => ({
|
|
76
|
+
type: 'string',
|
|
77
|
+
length: 10,
|
|
78
|
+
pattern: /^((09|03|07|08|05)+([0-9]{8})\b)$/,
|
|
79
|
+
optional,
|
|
80
|
+
});
|
|
81
|
+
export const schemaSlug = (optional = false) => ({
|
|
82
|
+
type: 'string',
|
|
83
|
+
pattern: /[A-Za-z0-9_-]+/,
|
|
84
|
+
max: 300,
|
|
85
|
+
optional,
|
|
86
|
+
});
|
|
87
|
+
export const schemaVersion = (optional = false) => ({
|
|
88
|
+
type: 'string',
|
|
89
|
+
pattern: /^(\d+)\.(\d+)\.(\d+)$/,
|
|
90
|
+
max: 300,
|
|
91
|
+
optional,
|
|
92
|
+
});
|
|
93
|
+
export const schemaJSON = (optional = false) => ({
|
|
94
|
+
type: 'json',
|
|
95
|
+
optional,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const schemaGallery = (optional = false) => ({
|
|
99
|
+
type: 'array',
|
|
100
|
+
items: schemaImage(),
|
|
101
|
+
optional,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const schemaObject = (props = {}, optional = false) => ({
|
|
105
|
+
type: 'object',
|
|
106
|
+
strict: 'remove',
|
|
107
|
+
props,
|
|
108
|
+
optional,
|
|
109
|
+
});
|
|
110
|
+
/* rules */
|
|
111
|
+
|
|
112
|
+
export const rulesID = {
|
|
113
|
+
id: schemaID(),
|
|
114
|
+
};
|
|
115
|
+
export const rulesSlug = {
|
|
116
|
+
slug: schemaSlug(),
|
|
117
|
+
};
|
|
118
|
+
export const rulesPlatformType = {
|
|
119
|
+
type: {
|
|
120
|
+
type: 'enum',
|
|
121
|
+
values: ['web', 'app'],
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
export const rulesMetadata = {
|
|
125
|
+
metadata_disable: schemaBoolean(true),
|
|
126
|
+
metadata_title: schemaString(0, 255, true),
|
|
127
|
+
metadata_title_og: schemaString(0, 255, true),
|
|
128
|
+
metadata_description: schemaString(0, 255, true),
|
|
129
|
+
metadata_description_og: schemaString(0, 255, true),
|
|
130
|
+
metadata_keywords: schemaString(0, 255, true),
|
|
131
|
+
metadata_image_url: schemaImage(true),
|
|
132
|
+
};
|