@live-change/framework 0.7.33 → 0.7.34
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/lib/utils/validators.js +99 -2
- package/package.json +8 -8
package/lib/utils/validators.js
CHANGED
|
@@ -74,9 +74,106 @@ let validators = {
|
|
|
74
74
|
return false
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
return
|
|
78
|
-
}
|
|
77
|
+
return validator
|
|
78
|
+
},
|
|
79
79
|
|
|
80
|
+
switchBy: ({ prop, cases }, { getValidator }) => {
|
|
81
|
+
let validators = {}
|
|
82
|
+
for(let [value, then] of Object.entries(cases)) {
|
|
83
|
+
validators[value] = then.map(getValidator)
|
|
84
|
+
}
|
|
85
|
+
const validator = (value, context) => {
|
|
86
|
+
let selectorValue = getField(context, prop)
|
|
87
|
+
for(let v of (validators[selectorValue] || [])) {
|
|
88
|
+
const err = v(value, context)
|
|
89
|
+
if(err) return err
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
validator.isRequired = (context) => {
|
|
93
|
+
let value = getField(context, prop)
|
|
94
|
+
for(let v of validators[value]) {
|
|
95
|
+
if(v.isRequired && v.isRequired(context)) return true
|
|
96
|
+
}
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
return validator
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
ifNotOneOf: ({ prop, what, then }, { getValidator }) => {
|
|
103
|
+
let validators = then.map(getValidator)
|
|
104
|
+
const validator = (value, context) => {
|
|
105
|
+
console.error("VIF NOT ONE OF", getField(context, prop), what, what.includes(getField(context, prop)))
|
|
106
|
+
if(!what.includes(getField(context, prop))) {
|
|
107
|
+
console.log("V", validators)
|
|
108
|
+
for(let v of validators) {
|
|
109
|
+
const err = v(value, context)
|
|
110
|
+
if(err) return err
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
validator.isRequired = (context) => {
|
|
115
|
+
if(!what.includes(getField(context, prop))) {
|
|
116
|
+
for(let v of validators) {
|
|
117
|
+
if(v.isRequired && v.isRequired(context)) return true
|
|
118
|
+
}
|
|
119
|
+
return false
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return validator
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
ifEmpty: ({ prop, then }, { getValidator }) => {
|
|
126
|
+
let validators = then.map(getValidator)
|
|
127
|
+
const validator = (value, context) => {
|
|
128
|
+
console.log("IFEMPTY CTX", context, "FIELD", prop, "VALUE", getField(context, prop))
|
|
129
|
+
if(!getField(context, prop)) {
|
|
130
|
+
console.log("V", validators)
|
|
131
|
+
for(let v of validators) {
|
|
132
|
+
const err = v(value, context)
|
|
133
|
+
if(err) return err
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
validator.isRequired = (context) => {
|
|
138
|
+
if(!getField(context, prop)) {
|
|
139
|
+
for(let v of validators) {
|
|
140
|
+
if(v.isRequired && v.isRequired(context)) return true
|
|
141
|
+
}
|
|
142
|
+
return false
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return validator
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
ifIncludes: ({ prop, that, then }, { getValidator }) => {
|
|
150
|
+
let validators = then.map(getValidator)
|
|
151
|
+
const validator = (value, context) => {
|
|
152
|
+
if(getField(context, prop).includes(that)) {
|
|
153
|
+
for(let v of validators) {
|
|
154
|
+
const err = v(value, context)
|
|
155
|
+
if(err) return err
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
validator.isRequired = (context) => {
|
|
160
|
+
if(getField(context, prop).includes(that)) {
|
|
161
|
+
for(let v of validators) {
|
|
162
|
+
if(v.isRequired && v.isRequired(context)) return true
|
|
163
|
+
}
|
|
164
|
+
return false
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return validator
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
httpUrl: (settings) => (value) => {
|
|
171
|
+
if(!value) return false // ignore empty
|
|
172
|
+
const match = value.match(
|
|
173
|
+
/^(?:http(s)?:\/\/)[\w.-]+(?:\.[\w\.-]+)+[\w\-\._%~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/
|
|
174
|
+
)
|
|
175
|
+
if(!match) return 'wrongUrl'
|
|
176
|
+
}
|
|
80
177
|
}
|
|
81
178
|
|
|
82
179
|
module.exports = validators
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.34",
|
|
4
4
|
"description": "Live Change Framework - ultimate solution for real time mobile/web apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/live-change/live-change-framework",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@live-change/dao": "0.5.
|
|
25
|
-
"@live-change/dao-websocket": "0.5.
|
|
26
|
-
"@live-change/db": "0.6.
|
|
27
|
-
"@live-change/db-store-level": "0.6.
|
|
28
|
-
"@live-change/db-store-lmdb": "0.6.
|
|
24
|
+
"@live-change/dao": "0.5.22",
|
|
25
|
+
"@live-change/dao-websocket": "0.5.22",
|
|
26
|
+
"@live-change/db": "0.6.23",
|
|
27
|
+
"@live-change/db-store-level": "0.6.23",
|
|
28
|
+
"@live-change/db-store-lmdb": "0.6.23",
|
|
29
29
|
"@live-change/sockjs": "0.4.1",
|
|
30
|
-
"@live-change/uid": "^0.7.
|
|
30
|
+
"@live-change/uid": "^0.7.34",
|
|
31
31
|
"cookie": "^0.4.1",
|
|
32
32
|
"express": "^4.18.2",
|
|
33
33
|
"os-service": "^2.2.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"tape": "^5.3.2",
|
|
36
36
|
"websocket": "^1.0.34"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "730c14caf86069665193ce157b2663358abef342"
|
|
39
39
|
}
|