vscroll 1.6.3 → 1.7.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.
Files changed (315) hide show
  1. package/dist/bundles/vscroll.esm5.js +5704 -5705
  2. package/dist/bundles/vscroll.esm5.js.map +1 -1
  3. package/dist/bundles/vscroll.esm5.min.js +2 -2
  4. package/dist/bundles/vscroll.esm5.min.js.map +1 -1
  5. package/dist/bundles/vscroll.esm6.js +5193 -5194
  6. package/dist/bundles/vscroll.esm6.js.map +1 -1
  7. package/dist/bundles/vscroll.esm6.min.js +2 -2
  8. package/dist/bundles/vscroll.esm6.min.js.map +1 -1
  9. package/dist/bundles/vscroll.umd.js +5712 -5714
  10. package/dist/bundles/vscroll.umd.js.map +1 -1
  11. package/dist/bundles/vscroll.umd.min.js +2 -2
  12. package/dist/bundles/vscroll.umd.min.js.map +1 -1
  13. package/dist/esm2015/classes/adapter/context.js +43 -43
  14. package/dist/esm2015/classes/adapter/context.js.map +1 -1
  15. package/dist/esm2015/classes/adapter/props.js +300 -300
  16. package/dist/esm2015/classes/adapter/wanted.js +28 -28
  17. package/dist/esm2015/classes/adapter/wanted.js.map +1 -1
  18. package/dist/esm2015/classes/adapter.js +487 -487
  19. package/dist/esm2015/classes/adapter.js.map +1 -1
  20. package/dist/esm2015/classes/buffer/cache.js +246 -246
  21. package/dist/esm2015/classes/buffer/cache.js.map +1 -1
  22. package/dist/esm2015/classes/buffer/checkCall.js +48 -48
  23. package/dist/esm2015/classes/buffer/checkCall.js.map +1 -1
  24. package/dist/esm2015/classes/buffer/defaultSize.js +127 -127
  25. package/dist/esm2015/classes/buffer/defaultSize.js.map +1 -1
  26. package/dist/esm2015/classes/buffer.js +342 -342
  27. package/dist/esm2015/classes/buffer.js.map +1 -1
  28. package/dist/esm2015/classes/datasource.js +23 -24
  29. package/dist/esm2015/classes/datasource.js.map +1 -1
  30. package/dist/esm2015/classes/domRoutines.js +160 -160
  31. package/dist/esm2015/classes/domRoutines.js.map +1 -1
  32. package/dist/esm2015/classes/item.js +61 -61
  33. package/dist/esm2015/classes/item.js.map +1 -1
  34. package/dist/esm2015/classes/logger.js +186 -186
  35. package/dist/esm2015/classes/logger.js.map +1 -1
  36. package/dist/esm2015/classes/paddings.js +72 -72
  37. package/dist/esm2015/classes/paddings.js.map +1 -1
  38. package/dist/esm2015/classes/reactive.js +54 -54
  39. package/dist/esm2015/classes/reactive.js.map +1 -1
  40. package/dist/esm2015/classes/settings.js +39 -39
  41. package/dist/esm2015/classes/settings.js.map +1 -1
  42. package/dist/esm2015/classes/state/clip.js +16 -16
  43. package/dist/esm2015/classes/state/clip.js.map +1 -1
  44. package/dist/esm2015/classes/state/cycle.js +60 -60
  45. package/dist/esm2015/classes/state/cycle.js.map +1 -1
  46. package/dist/esm2015/classes/state/fetch.js +122 -122
  47. package/dist/esm2015/classes/state/fetch.js.map +1 -1
  48. package/dist/esm2015/classes/state/render.js +14 -14
  49. package/dist/esm2015/classes/state/scroll.js +30 -30
  50. package/dist/esm2015/classes/state/scroll.js.map +1 -1
  51. package/dist/esm2015/classes/state.js +62 -62
  52. package/dist/esm2015/classes/state.js.map +1 -1
  53. package/dist/esm2015/classes/viewport.js +72 -72
  54. package/dist/esm2015/classes/viewport.js.map +1 -1
  55. package/dist/esm2015/index.js +9 -9
  56. package/dist/esm2015/inputs/adapter.js +242 -242
  57. package/dist/esm2015/inputs/common.js +11 -11
  58. package/dist/esm2015/inputs/datasource.js +20 -20
  59. package/dist/esm2015/inputs/index.js +7 -7
  60. package/dist/esm2015/inputs/settings.js +146 -146
  61. package/dist/esm2015/inputs/validation.js +371 -374
  62. package/dist/esm2015/inputs/validation.js.map +1 -1
  63. package/dist/esm2015/inputs/workflow.js +30 -30
  64. package/dist/esm2015/interfaces/adapter.js +1 -1
  65. package/dist/esm2015/interfaces/datasource.js +1 -1
  66. package/dist/esm2015/interfaces/index.js +1 -1
  67. package/dist/esm2015/interfaces/item.js +1 -1
  68. package/dist/esm2015/interfaces/process.js +1 -1
  69. package/dist/esm2015/interfaces/process.js.map +1 -1
  70. package/dist/esm2015/interfaces/routines.js +1 -1
  71. package/dist/esm2015/interfaces/settings.js +1 -1
  72. package/dist/esm2015/interfaces/state.js +1 -1
  73. package/dist/esm2015/interfaces/validation.js +1 -1
  74. package/dist/esm2015/interfaces/workflow.js +1 -1
  75. package/dist/esm2015/processes/adapter/append.js +36 -36
  76. package/dist/esm2015/processes/adapter/append.js.map +1 -1
  77. package/dist/esm2015/processes/adapter/check.js +32 -32
  78. package/dist/esm2015/processes/adapter/check.js.map +1 -1
  79. package/dist/esm2015/processes/adapter/clip.js +12 -12
  80. package/dist/esm2015/processes/adapter/fix.js +77 -77
  81. package/dist/esm2015/processes/adapter/fix.js.map +1 -1
  82. package/dist/esm2015/processes/adapter/insert.js +73 -73
  83. package/dist/esm2015/processes/adapter/insert.js.map +1 -1
  84. package/dist/esm2015/processes/adapter/pause.js +22 -22
  85. package/dist/esm2015/processes/adapter/pause.js.map +1 -1
  86. package/dist/esm2015/processes/adapter/reload.js +19 -19
  87. package/dist/esm2015/processes/adapter/reload.js.map +1 -1
  88. package/dist/esm2015/processes/adapter/remove.js +102 -102
  89. package/dist/esm2015/processes/adapter/remove.js.map +1 -1
  90. package/dist/esm2015/processes/adapter/replace.js +39 -39
  91. package/dist/esm2015/processes/adapter/replace.js.map +1 -1
  92. package/dist/esm2015/processes/adapter/reset.js +35 -35
  93. package/dist/esm2015/processes/adapter/reset.js.map +1 -1
  94. package/dist/esm2015/processes/adapter/update.js +43 -43
  95. package/dist/esm2015/processes/adapter/update.js.map +1 -1
  96. package/dist/esm2015/processes/adjust.js +141 -141
  97. package/dist/esm2015/processes/adjust.js.map +1 -1
  98. package/dist/esm2015/processes/clip.js +49 -49
  99. package/dist/esm2015/processes/clip.js.map +1 -1
  100. package/dist/esm2015/processes/end.js +52 -52
  101. package/dist/esm2015/processes/end.js.map +1 -1
  102. package/dist/esm2015/processes/fetch.js +91 -91
  103. package/dist/esm2015/processes/fetch.js.map +1 -1
  104. package/dist/esm2015/processes/index.js +24 -24
  105. package/dist/esm2015/processes/init.js +14 -14
  106. package/dist/esm2015/processes/misc/base.js +30 -30
  107. package/dist/esm2015/processes/misc/base.js.map +1 -1
  108. package/dist/esm2015/processes/misc/enums.js +36 -36
  109. package/dist/esm2015/processes/misc/index.js +2 -2
  110. package/dist/esm2015/processes/postFetch.js +65 -65
  111. package/dist/esm2015/processes/postFetch.js.map +1 -1
  112. package/dist/esm2015/processes/preClip.js +85 -85
  113. package/dist/esm2015/processes/preClip.js.map +1 -1
  114. package/dist/esm2015/processes/preFetch.js +240 -240
  115. package/dist/esm2015/processes/preFetch.js.map +1 -1
  116. package/dist/esm2015/processes/render.js +54 -54
  117. package/dist/esm2015/processes/render.js.map +1 -1
  118. package/dist/esm2015/processes/scroll.js +97 -97
  119. package/dist/esm2015/processes/scroll.js.map +1 -1
  120. package/dist/esm2015/processes/start.js +11 -11
  121. package/dist/esm2015/scroller.js +86 -86
  122. package/dist/esm2015/scroller.js.map +1 -1
  123. package/dist/esm2015/version.js +4 -4
  124. package/dist/esm2015/version.js.map +1 -1
  125. package/dist/esm2015/workflow-transducer.js +218 -218
  126. package/dist/esm2015/workflow-transducer.js.map +1 -1
  127. package/dist/esm2015/workflow.js +174 -174
  128. package/dist/esm2015/workflow.js.map +1 -1
  129. package/dist/esm5/classes/adapter/context.js +50 -50
  130. package/dist/esm5/classes/adapter/context.js.map +1 -1
  131. package/dist/esm5/classes/adapter/props.js +300 -300
  132. package/dist/esm5/classes/adapter/wanted.js +29 -29
  133. package/dist/esm5/classes/adapter/wanted.js.map +1 -1
  134. package/dist/esm5/classes/adapter.js +535 -535
  135. package/dist/esm5/classes/adapter.js.map +1 -1
  136. package/dist/esm5/classes/buffer/cache.js +260 -260
  137. package/dist/esm5/classes/buffer/cache.js.map +1 -1
  138. package/dist/esm5/classes/buffer/checkCall.js +56 -56
  139. package/dist/esm5/classes/buffer/checkCall.js.map +1 -1
  140. package/dist/esm5/classes/buffer/defaultSize.js +145 -145
  141. package/dist/esm5/classes/buffer/defaultSize.js.map +1 -1
  142. package/dist/esm5/classes/buffer.js +409 -409
  143. package/dist/esm5/classes/buffer.js.map +1 -1
  144. package/dist/esm5/classes/datasource.js +30 -31
  145. package/dist/esm5/classes/datasource.js.map +1 -1
  146. package/dist/esm5/classes/domRoutines.js +165 -165
  147. package/dist/esm5/classes/domRoutines.js.map +1 -1
  148. package/dist/esm5/classes/item.js +76 -76
  149. package/dist/esm5/classes/item.js.map +1 -1
  150. package/dist/esm5/classes/logger.js +210 -210
  151. package/dist/esm5/classes/logger.js.map +1 -1
  152. package/dist/esm5/classes/paddings.js +80 -80
  153. package/dist/esm5/classes/paddings.js.map +1 -1
  154. package/dist/esm5/classes/reactive.js +69 -69
  155. package/dist/esm5/classes/reactive.js.map +1 -1
  156. package/dist/esm5/classes/settings.js +47 -47
  157. package/dist/esm5/classes/settings.js.map +1 -1
  158. package/dist/esm5/classes/state/clip.js +22 -22
  159. package/dist/esm5/classes/state/clip.js.map +1 -1
  160. package/dist/esm5/classes/state/cycle.js +75 -75
  161. package/dist/esm5/classes/state/cycle.js.map +1 -1
  162. package/dist/esm5/classes/state/fetch.js +148 -148
  163. package/dist/esm5/classes/state/fetch.js.map +1 -1
  164. package/dist/esm5/classes/state/render.js +20 -20
  165. package/dist/esm5/classes/state/scroll.js +32 -32
  166. package/dist/esm5/classes/state/scroll.js.map +1 -1
  167. package/dist/esm5/classes/state.js +69 -69
  168. package/dist/esm5/classes/state.js.map +1 -1
  169. package/dist/esm5/classes/viewport.js +79 -79
  170. package/dist/esm5/classes/viewport.js.map +1 -1
  171. package/dist/esm5/index.js +9 -9
  172. package/dist/esm5/inputs/adapter.js +243 -243
  173. package/dist/esm5/inputs/common.js +11 -11
  174. package/dist/esm5/inputs/datasource.js +21 -21
  175. package/dist/esm5/inputs/index.js +7 -7
  176. package/dist/esm5/inputs/settings.js +147 -147
  177. package/dist/esm5/inputs/validation.js +393 -396
  178. package/dist/esm5/inputs/validation.js.map +1 -1
  179. package/dist/esm5/inputs/workflow.js +31 -31
  180. package/dist/esm5/interfaces/adapter.js +1 -1
  181. package/dist/esm5/interfaces/datasource.js +1 -1
  182. package/dist/esm5/interfaces/index.js +1 -1
  183. package/dist/esm5/interfaces/item.js +1 -1
  184. package/dist/esm5/interfaces/process.js +1 -1
  185. package/dist/esm5/interfaces/process.js.map +1 -1
  186. package/dist/esm5/interfaces/routines.js +1 -1
  187. package/dist/esm5/interfaces/settings.js +1 -1
  188. package/dist/esm5/interfaces/state.js +1 -1
  189. package/dist/esm5/interfaces/validation.js +1 -1
  190. package/dist/esm5/interfaces/workflow.js +1 -1
  191. package/dist/esm5/processes/adapter/append.js +44 -44
  192. package/dist/esm5/processes/adapter/append.js.map +1 -1
  193. package/dist/esm5/processes/adapter/check.js +39 -39
  194. package/dist/esm5/processes/adapter/check.js.map +1 -1
  195. package/dist/esm5/processes/adapter/clip.js +19 -19
  196. package/dist/esm5/processes/adapter/fix.js +89 -89
  197. package/dist/esm5/processes/adapter/fix.js.map +1 -1
  198. package/dist/esm5/processes/adapter/insert.js +81 -81
  199. package/dist/esm5/processes/adapter/insert.js.map +1 -1
  200. package/dist/esm5/processes/adapter/pause.js +29 -29
  201. package/dist/esm5/processes/adapter/pause.js.map +1 -1
  202. package/dist/esm5/processes/adapter/reload.js +26 -26
  203. package/dist/esm5/processes/adapter/reload.js.map +1 -1
  204. package/dist/esm5/processes/adapter/remove.js +115 -115
  205. package/dist/esm5/processes/adapter/remove.js.map +1 -1
  206. package/dist/esm5/processes/adapter/replace.js +47 -47
  207. package/dist/esm5/processes/adapter/replace.js.map +1 -1
  208. package/dist/esm5/processes/adapter/reset.js +42 -42
  209. package/dist/esm5/processes/adapter/reset.js.map +1 -1
  210. package/dist/esm5/processes/adapter/update.js +59 -59
  211. package/dist/esm5/processes/adapter/update.js.map +1 -1
  212. package/dist/esm5/processes/adjust.js +152 -152
  213. package/dist/esm5/processes/adjust.js.map +1 -1
  214. package/dist/esm5/processes/clip.js +60 -60
  215. package/dist/esm5/processes/clip.js.map +1 -1
  216. package/dist/esm5/processes/end.js +63 -63
  217. package/dist/esm5/processes/end.js.map +1 -1
  218. package/dist/esm5/processes/fetch.js +102 -102
  219. package/dist/esm5/processes/fetch.js.map +1 -1
  220. package/dist/esm5/processes/index.js +24 -24
  221. package/dist/esm5/processes/init.js +21 -21
  222. package/dist/esm5/processes/misc/base.js +44 -44
  223. package/dist/esm5/processes/misc/base.js.map +1 -1
  224. package/dist/esm5/processes/misc/enums.js +36 -36
  225. package/dist/esm5/processes/misc/index.js +2 -2
  226. package/dist/esm5/processes/postFetch.js +74 -74
  227. package/dist/esm5/processes/postFetch.js.map +1 -1
  228. package/dist/esm5/processes/preClip.js +94 -94
  229. package/dist/esm5/processes/preClip.js.map +1 -1
  230. package/dist/esm5/processes/preFetch.js +247 -247
  231. package/dist/esm5/processes/preFetch.js.map +1 -1
  232. package/dist/esm5/processes/render.js +63 -63
  233. package/dist/esm5/processes/render.js.map +1 -1
  234. package/dist/esm5/processes/scroll.js +107 -107
  235. package/dist/esm5/processes/scroll.js.map +1 -1
  236. package/dist/esm5/processes/start.js +18 -18
  237. package/dist/esm5/scroller.js +100 -100
  238. package/dist/esm5/scroller.js.map +1 -1
  239. package/dist/esm5/version.js +4 -4
  240. package/dist/esm5/version.js.map +1 -1
  241. package/dist/esm5/workflow-transducer.js +220 -220
  242. package/dist/esm5/workflow-transducer.js.map +1 -1
  243. package/dist/esm5/workflow.js +198 -198
  244. package/dist/esm5/workflow.js.map +1 -1
  245. package/dist/typings/classes/adapter/context.d.ts +4 -4
  246. package/dist/typings/classes/adapter/props.d.ts +52 -52
  247. package/dist/typings/classes/adapter/wanted.d.ts +14 -14
  248. package/dist/typings/classes/adapter.d.ts +79 -79
  249. package/dist/typings/classes/buffer/cache.d.ts +95 -95
  250. package/dist/typings/classes/buffer/checkCall.d.ts +12 -12
  251. package/dist/typings/classes/buffer/defaultSize.d.ts +32 -32
  252. package/dist/typings/classes/buffer.d.ts +64 -64
  253. package/dist/typings/classes/datasource.d.ts +11 -11
  254. package/dist/typings/classes/domRoutines.d.ts +36 -36
  255. package/dist/typings/classes/item.d.ts +28 -28
  256. package/dist/typings/classes/logger.d.ts +28 -28
  257. package/dist/typings/classes/paddings.d.ts +22 -22
  258. package/dist/typings/classes/reactive.d.ts +21 -21
  259. package/dist/typings/classes/settings.d.ts +119 -119
  260. package/dist/typings/classes/state/clip.d.ts +9 -9
  261. package/dist/typings/classes/state/cycle.d.ts +29 -29
  262. package/dist/typings/classes/state/fetch.d.ts +62 -62
  263. package/dist/typings/classes/state/render.d.ts +9 -9
  264. package/dist/typings/classes/state/scroll.d.ts +16 -16
  265. package/dist/typings/classes/state.d.ts +29 -29
  266. package/dist/typings/classes/viewport.d.ts +32 -32
  267. package/dist/typings/index.d.ts +10 -10
  268. package/dist/typings/inputs/adapter.d.ts +5 -5
  269. package/dist/typings/inputs/common.d.ts +9 -9
  270. package/dist/typings/inputs/datasource.d.ts +7 -7
  271. package/dist/typings/inputs/index.d.ts +7 -7
  272. package/dist/typings/inputs/settings.d.ts +41 -41
  273. package/dist/typings/inputs/validation.d.ts +82 -83
  274. package/dist/typings/inputs/workflow.d.ts +9 -9
  275. package/dist/typings/interfaces/adapter.d.ts +164 -164
  276. package/dist/typings/interfaces/datasource.d.ts +28 -28
  277. package/dist/typings/interfaces/index.d.ts +10 -10
  278. package/dist/typings/interfaces/item.d.ts +8 -8
  279. package/dist/typings/interfaces/process.d.ts +35 -35
  280. package/dist/typings/interfaces/routines.d.ts +166 -166
  281. package/dist/typings/interfaces/settings.d.ts +31 -31
  282. package/dist/typings/interfaces/state.d.ts +24 -24
  283. package/dist/typings/interfaces/validation.d.ts +33 -33
  284. package/dist/typings/interfaces/workflow.d.ts +53 -53
  285. package/dist/typings/processes/adapter/append.d.ts +14 -14
  286. package/dist/typings/processes/adapter/check.d.ts +6 -6
  287. package/dist/typings/processes/adapter/clip.d.ts +7 -7
  288. package/dist/typings/processes/adapter/fix.d.ts +13 -13
  289. package/dist/typings/processes/adapter/insert.d.ts +11 -11
  290. package/dist/typings/processes/adapter/pause.d.ts +8 -8
  291. package/dist/typings/processes/adapter/reload.d.ts +6 -6
  292. package/dist/typings/processes/adapter/remove.d.ts +11 -11
  293. package/dist/typings/processes/adapter/replace.d.ts +8 -8
  294. package/dist/typings/processes/adapter/reset.d.ts +7 -7
  295. package/dist/typings/processes/adapter/update.d.ts +8 -8
  296. package/dist/typings/processes/adjust.d.ts +10 -10
  297. package/dist/typings/processes/clip.d.ts +7 -7
  298. package/dist/typings/processes/end.d.ts +10 -10
  299. package/dist/typings/processes/fetch.d.ts +18 -18
  300. package/dist/typings/processes/index.d.ts +24 -24
  301. package/dist/typings/processes/init.d.ts +7 -7
  302. package/dist/typings/processes/misc/base.d.ts +4 -4
  303. package/dist/typings/processes/misc/enums.d.ts +33 -33
  304. package/dist/typings/processes/misc/index.d.ts +2 -2
  305. package/dist/typings/processes/postFetch.d.ts +8 -8
  306. package/dist/typings/processes/preClip.d.ts +12 -12
  307. package/dist/typings/processes/preFetch.d.ts +17 -17
  308. package/dist/typings/processes/render.d.ts +9 -9
  309. package/dist/typings/processes/scroll.d.ts +13 -13
  310. package/dist/typings/processes/start.d.ts +6 -6
  311. package/dist/typings/scroller.d.ts +26 -26
  312. package/dist/typings/version.d.ts +5 -5
  313. package/dist/typings/workflow-transducer.d.ts +2 -2
  314. package/dist/typings/workflow.d.ts +29 -29
  315. package/package.json +19 -18
@@ -1,375 +1,372 @@
1
- export var ValidatorType;
2
- (function (ValidatorType) {
3
- ValidatorType["number"] = "must be a number";
4
- ValidatorType["integer"] = "must be an integer";
5
- ValidatorType["integerUnlimited"] = "must be an integer or infinity";
6
- ValidatorType["moreOrEqual"] = "must be a number greater than (or equal to) {arg1}";
7
- ValidatorType["itemList"] = "must be an array of items {arg1}";
8
- ValidatorType["boolean"] = "must be a boolean";
9
- ValidatorType["object"] = "must be an object";
10
- ValidatorType["element"] = "must be an html element";
11
- ValidatorType["function"] = "must be a function";
12
- ValidatorType["funcOfxArguments"] = "must have {arg1} argument(s)";
13
- ValidatorType["funcOfxAndMoreArguments"] = "must have at least {arg1} argument(s)";
14
- ValidatorType["funcOfXToYArguments"] = "must have {arg1} to {arg2} arguments";
15
- ValidatorType["oneOfCan"] = "can be present as only one item of {arg1} list";
16
- ValidatorType["oneOfMust"] = "must be present as only one item of {arg1} list";
17
- ValidatorType["or"] = "must satisfy at least 1 validator from {arg1} list";
18
- ValidatorType["enum"] = "must belong to {arg1} list";
19
- })(ValidatorType || (ValidatorType = {}));
20
- const getError = (msg, args) => (args || ['']).reduce((acc, arg, index) => acc.replace(`{arg${index + 1}}`, arg), msg);
21
- const getNumber = (value) => typeof value === 'number' || (typeof value === 'string' && value !== '')
22
- ? Number(value)
23
- : NaN;
24
- const onNumber = (value) => {
25
- const parsedValue = getNumber(value);
26
- const errors = [];
27
- if (Number.isNaN(parsedValue)) {
28
- errors.push(ValidatorType.number);
29
- }
30
- return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
31
- };
32
- const onInteger = (value) => {
33
- const errors = [];
34
- value = getNumber(value);
35
- const parsedValue = parseInt(String(value), 10);
36
- if (value !== parsedValue) {
37
- errors.push(ValidatorType.integer);
38
- }
39
- return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
40
- };
41
- const onIntegerUnlimited = (value) => {
42
- let parsedValue = value;
43
- const errors = [];
44
- value = getNumber(value);
45
- if (!Number.isFinite(value)) {
46
- parsedValue = value;
47
- }
48
- else {
49
- parsedValue = parseInt(String(value), 10);
50
- }
51
- if (value !== parsedValue) {
52
- errors.push(ValidatorType.integerUnlimited);
53
- }
54
- return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
55
- };
56
- const onMoreOrEqual = (limit, fallback) => (value) => {
57
- const result = onNumber(value);
58
- if (!result.isValid) {
59
- return result;
60
- }
61
- let parsedValue = result.value;
62
- const errors = [];
63
- if (parsedValue < limit) {
64
- if (!fallback) {
65
- errors.push(getError(ValidatorType.moreOrEqual, [String(limit)]));
66
- }
67
- else {
68
- parsedValue = limit;
69
- }
70
- }
71
- return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
72
- };
73
- const onBoolean = (value) => {
74
- const errors = [];
75
- let parsedValue = value;
76
- if (value === 'true') {
77
- parsedValue = true;
78
- }
79
- else if (value === 'false') {
80
- parsedValue = false;
81
- }
82
- if (typeof parsedValue !== 'boolean') {
83
- errors.push(ValidatorType.boolean);
84
- }
85
- return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
86
- };
87
- const onObject = (value) => {
88
- const errors = [];
89
- if (!value || Object.prototype.toString.call(value) !== '[object Object]') {
90
- errors.push(ValidatorType.object);
91
- }
92
- return { value, isSet: true, isValid: !errors.length, errors };
93
- };
94
- const onHtmlElement = (value) => {
95
- const errors = [];
96
- if (!(value instanceof Element) && !(value instanceof Document)) {
97
- errors.push(ValidatorType.element);
98
- }
99
- return { value, isSet: true, isValid: !errors.length, errors };
100
- };
101
- const onItemList = (value) => {
102
- let parsedValue = value;
103
- const errors = [];
104
- if (!Array.isArray(value)) {
105
- errors.push(ValidatorType.itemList);
106
- parsedValue = [];
107
- }
108
- else if (!value.length) {
109
- errors.push(getError(ValidatorType.itemList, ['with at least 1 item']));
110
- }
111
- else if (value.length > 1) {
112
- const type = typeof value[0];
113
- for (let i = value.length - 1; i >= 0; i--) {
114
- if (typeof value[i] !== type) {
115
- errors.push(getError(ValidatorType.itemList, ['of items of the same type']));
116
- break;
117
- }
118
- }
119
- }
120
- return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
121
- };
122
- const onFunction = (value) => {
123
- const errors = [];
124
- if (typeof value !== 'function') {
125
- errors.push(ValidatorType.function);
126
- }
127
- return { value: value, isSet: true, isValid: !errors.length, errors };
128
- };
129
- const onFunctionWithXArguments = (argsCount) => (value) => {
130
- const result = onFunction(value);
131
- if (!result.isValid) {
132
- return result;
133
- }
134
- value = result.value;
135
- const errors = [];
136
- if (value.length !== argsCount) {
137
- errors.push(getError(ValidatorType.funcOfxArguments, [String(argsCount)]));
138
- }
139
- return { value: value, isSet: true, isValid: !errors.length, errors };
140
- };
141
- const onFunctionWithXAndMoreArguments = (argsCount) => (value) => {
142
- const result = onFunction(value);
143
- if (!result.isValid) {
144
- return result;
145
- }
146
- value = result.value;
147
- const errors = [];
148
- if (value.length < argsCount) {
149
- errors.push(getError(ValidatorType.funcOfxArguments, [String(argsCount)]));
150
- }
151
- return { value: value, isSet: true, isValid: !errors.length, errors };
152
- };
153
- const onFunctionWithXToYArguments = (from, to) => (value) => {
154
- const result = onFunction(value);
155
- if (!result.isValid) {
156
- return result;
157
- }
158
- value = result.value;
159
- const errors = [];
160
- if (value.length < from || value.length > to) {
161
- errors.push(getError(ValidatorType.funcOfXToYArguments, [String(from), String(to)]));
162
- }
163
- return { value: value, isSet: true, isValid: !errors.length, errors };
164
- };
165
- const onOneOf = (tokens, must) => (value, context) => {
166
- const errors = [];
167
- const isSet = value !== void 0;
168
- let noOneIsPresent = !isSet;
169
- const err = must ? ValidatorType.oneOfMust : ValidatorType.oneOfCan;
170
- if (!Array.isArray(tokens) || !tokens.length) {
171
- errors.push(getError(err, ['undefined']));
172
- }
173
- else {
174
- for (let i = tokens.length - 1; i >= 0; i--) {
175
- const token = tokens[i];
176
- if (typeof token !== 'string') {
177
- errors.push(getError(err, [tokens.join('", "')]) + ' (non-string token)');
178
- break;
179
- }
180
- const isAnotherPresent = context && Object.prototype.hasOwnProperty.call(context, token);
181
- if (isSet && isAnotherPresent) {
182
- errors.push(getError(err, [tokens.join('", "')]) + ` (${token} is present)`);
183
- break;
184
- }
185
- if (noOneIsPresent && isAnotherPresent) {
186
- noOneIsPresent = false;
187
- }
188
- }
189
- if (must && noOneIsPresent) {
190
- errors.push(getError(err, [tokens.join('", "')]));
191
- }
192
- }
193
- return { value, isSet, isValid: !errors.length, errors };
194
- };
195
- const onOr = (validators) => (value) => {
196
- const errors = [];
197
- if (validators.every(validator => !validator.method(value).isValid)) {
198
- errors.push(validators.map(v => v.type).join(' OR '));
199
- }
200
- return { value, isSet: true, isValid: !errors.length, errors };
201
- };
202
- var AbstractEnum;
203
- (function (AbstractEnum) {
204
- })(AbstractEnum || (AbstractEnum = {}));
205
- const onEnum = (list) => (value) => {
206
- const errors = [];
207
- const values = Object.keys(list).filter(k => isNaN(Number(k))).map(k => list[k]);
208
- if (!values.some(item => item === value)) {
209
- errors.push(getError(ValidatorType.enum, ['[' + values.join(',') + ']']));
210
- }
211
- return { value, isSet: true, isValid: !errors.length, errors };
212
- };
213
- export const VALIDATORS = {
214
- NUMBER: {
215
- type: ValidatorType.number,
216
- method: onNumber
217
- },
218
- INTEGER: {
219
- type: ValidatorType.integer,
220
- method: onInteger
221
- },
222
- INTEGER_UNLIMITED: {
223
- type: ValidatorType.integerUnlimited,
224
- method: onIntegerUnlimited
225
- },
226
- MORE_OR_EQUAL: (limit, fallback) => ({
227
- type: ValidatorType.moreOrEqual,
228
- method: onMoreOrEqual(limit, fallback)
229
- }),
230
- BOOLEAN: {
231
- type: ValidatorType.boolean,
232
- method: onBoolean
233
- },
234
- OBJECT: {
235
- type: ValidatorType.object,
236
- method: onObject
237
- },
238
- ITEM_LIST: {
239
- type: ValidatorType.itemList,
240
- method: onItemList
241
- },
242
- ELEMENT: {
243
- type: ValidatorType.element,
244
- method: onHtmlElement
245
- },
246
- FUNC: {
247
- type: ValidatorType.function,
248
- method: onFunction
249
- },
250
- FUNC_WITH_X_ARGUMENTS: (count) => ({
251
- type: ValidatorType.funcOfxArguments,
252
- method: onFunctionWithXArguments(count)
253
- }),
254
- FUNC_WITH_X_AND_MORE_ARGUMENTS: (count) => ({
255
- type: ValidatorType.funcOfxAndMoreArguments,
256
- method: onFunctionWithXAndMoreArguments(count)
257
- }),
258
- FUNC_WITH_X_TO_Y_ARGUMENTS: (from, to) => ({
259
- type: ValidatorType.funcOfXToYArguments,
260
- method: onFunctionWithXToYArguments(from, to)
261
- }),
262
- ONE_OF_CAN: (list) => ({
263
- type: ValidatorType.oneOfCan,
264
- method: onOneOf(list, false)
265
- }),
266
- ONE_OF_MUST: (list) => ({
267
- type: ValidatorType.oneOfMust,
268
- method: onOneOf(list, true)
269
- }),
270
- OR: (list) => ({
271
- type: ValidatorType.or,
272
- method: onOr(list)
273
- }),
274
- ENUM: (list) => ({
275
- type: ValidatorType.enum,
276
- method: onEnum(list)
277
- })
278
- };
279
- export class ValidatedData {
280
- constructor(context) {
281
- this.params = {};
282
- this.contextErrors = [];
283
- this.errors = [];
284
- this.isValid = true;
285
- this.setContext(context);
286
- }
287
- setContext(context) {
288
- if (!context || Object.prototype.toString.call(context) !== '[object Object]') {
289
- this.setCommonError('context is not an object');
290
- this.isValidContext = false;
291
- }
292
- else {
293
- this.isValidContext = true;
294
- }
295
- this.context = context;
296
- }
297
- setValidity() {
298
- this.errors = Object.keys(this.params).reduce((acc, key) => [
299
- ...acc, ...this.params[key].errors
300
- ], []);
301
- this.isValid = !this.errors.length;
302
- }
303
- setCommonError(error) {
304
- this.contextErrors.push(error);
305
- this.errors.push(error);
306
- this.isValid = false;
307
- }
308
- setParam(token, value) {
309
- if (!value.isValid) {
310
- value.errors = !value.isSet
311
- ? [`"${token}" must be set`]
312
- : value.errors.map((err) => `"${token}" ${err}`);
313
- }
314
- this.params[token] = value;
315
- this.setValidity();
316
- }
317
- showErrors() {
318
- return this.errors.length
319
- ? 'validation failed: ' + this.errors.join(', ')
320
- : '';
321
- }
322
- }
323
- export const runValidator = (current, validator, context) => {
324
- const { value, errors } = current;
325
- const result = validator.method(value, context);
326
- const _errors = [...errors, ...result.errors];
327
- return {
328
- value: result.value,
329
- isSet: result.isSet,
330
- isValid: !_errors.length,
331
- errors: _errors
332
- };
333
- };
334
- const getDefault = (value, prop) => {
335
- const empty = value === void 0;
336
- const auto = !prop.mandatory && prop.defaultValue !== void 0;
337
- return {
338
- value: !empty ? value : (auto ? prop.defaultValue : void 0),
339
- isSet: !empty || auto,
340
- isValid: !empty || !prop.mandatory,
341
- errors: []
342
- };
343
- };
344
- export const validateOne = (context, name, prop) => {
345
- const result = getDefault(context[name], prop);
346
- if (!result.isSet) {
347
- const oneOfMust = prop.validators.find(v => v.type === ValidatorType.oneOfMust);
348
- if (oneOfMust) {
349
- return runValidator(result, oneOfMust, context);
350
- }
351
- }
352
- else {
353
- for (const validator of Object.values(prop.validators)) {
354
- const current = runValidator(result, validator, context);
355
- if (!current.isValid && prop.defaultValue !== void 0) {
356
- return {
357
- value: prop.defaultValue,
358
- isSet: true,
359
- isValid: true,
360
- errors: []
361
- };
362
- }
363
- Object.assign(result, current);
364
- }
365
- }
366
- return result;
367
- };
368
- export const validate = (context, params) => {
369
- const data = new ValidatedData(context);
370
- Object.entries(params).forEach(([key, prop]) => data.setParam(key, data.isValidContext
371
- ? validateOne(data.context, key, prop)
372
- : getDefault(void 0, prop)));
373
- return data;
374
- };
1
+ export var ValidatorType;
2
+ (function (ValidatorType) {
3
+ ValidatorType["number"] = "must be a number";
4
+ ValidatorType["integer"] = "must be an integer";
5
+ ValidatorType["integerUnlimited"] = "must be an integer or infinity";
6
+ ValidatorType["moreOrEqual"] = "must be a number greater than (or equal to) {arg1}";
7
+ ValidatorType["itemList"] = "must be an array of items {arg1}";
8
+ ValidatorType["boolean"] = "must be a boolean";
9
+ ValidatorType["object"] = "must be an object";
10
+ ValidatorType["element"] = "must be an html element";
11
+ ValidatorType["function"] = "must be a function";
12
+ ValidatorType["funcOfxArguments"] = "must have {arg1} argument(s)";
13
+ ValidatorType["funcOfxAndMoreArguments"] = "must have at least {arg1} argument(s)";
14
+ ValidatorType["funcOfXToYArguments"] = "must have {arg1} to {arg2} arguments";
15
+ ValidatorType["oneOfCan"] = "can be present as only one item of {arg1} list";
16
+ ValidatorType["oneOfMust"] = "must be present as only one item of {arg1} list";
17
+ ValidatorType["or"] = "must satisfy at least 1 validator from {arg1} list";
18
+ ValidatorType["enum"] = "must belong to {arg1} list";
19
+ })(ValidatorType || (ValidatorType = {}));
20
+ const getError = (msg, args) => (args || ['']).reduce((acc, arg, index) => acc.replace(`{arg${index + 1}}`, arg), msg);
21
+ const getNumber = (value) => typeof value === 'number' || (typeof value === 'string' && value !== '')
22
+ ? Number(value)
23
+ : NaN;
24
+ const onNumber = (value) => {
25
+ const parsedValue = getNumber(value);
26
+ const errors = [];
27
+ if (Number.isNaN(parsedValue)) {
28
+ errors.push(ValidatorType.number);
29
+ }
30
+ return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
31
+ };
32
+ const onInteger = (value) => {
33
+ const errors = [];
34
+ value = getNumber(value);
35
+ const parsedValue = parseInt(String(value), 10);
36
+ if (value !== parsedValue) {
37
+ errors.push(ValidatorType.integer);
38
+ }
39
+ return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
40
+ };
41
+ const onIntegerUnlimited = (value) => {
42
+ let parsedValue = value;
43
+ const errors = [];
44
+ value = getNumber(value);
45
+ if (!Number.isFinite(value)) {
46
+ parsedValue = value;
47
+ }
48
+ else {
49
+ parsedValue = parseInt(String(value), 10);
50
+ }
51
+ if (value !== parsedValue) {
52
+ errors.push(ValidatorType.integerUnlimited);
53
+ }
54
+ return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
55
+ };
56
+ const onMoreOrEqual = (limit, fallback) => (value) => {
57
+ const result = onNumber(value);
58
+ if (!result.isValid) {
59
+ return result;
60
+ }
61
+ let parsedValue = result.value;
62
+ const errors = [];
63
+ if (parsedValue < limit) {
64
+ if (!fallback) {
65
+ errors.push(getError(ValidatorType.moreOrEqual, [String(limit)]));
66
+ }
67
+ else {
68
+ parsedValue = limit;
69
+ }
70
+ }
71
+ return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
72
+ };
73
+ const onBoolean = (value) => {
74
+ const errors = [];
75
+ let parsedValue = value;
76
+ if (value === 'true') {
77
+ parsedValue = true;
78
+ }
79
+ else if (value === 'false') {
80
+ parsedValue = false;
81
+ }
82
+ if (typeof parsedValue !== 'boolean') {
83
+ errors.push(ValidatorType.boolean);
84
+ }
85
+ return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
86
+ };
87
+ const onObject = (value) => {
88
+ const errors = [];
89
+ if (!value || Object.prototype.toString.call(value) !== '[object Object]') {
90
+ errors.push(ValidatorType.object);
91
+ }
92
+ return { value, isSet: true, isValid: !errors.length, errors };
93
+ };
94
+ const onHtmlElement = (value) => {
95
+ const errors = [];
96
+ if (!(value instanceof Element) && !(value instanceof Document)) {
97
+ errors.push(ValidatorType.element);
98
+ }
99
+ return { value, isSet: true, isValid: !errors.length, errors };
100
+ };
101
+ const onItemList = (value) => {
102
+ let parsedValue = value;
103
+ const errors = [];
104
+ if (!Array.isArray(value)) {
105
+ errors.push(ValidatorType.itemList);
106
+ parsedValue = [];
107
+ }
108
+ else if (!value.length) {
109
+ errors.push(getError(ValidatorType.itemList, ['with at least 1 item']));
110
+ }
111
+ else if (value.length > 1) {
112
+ const type = typeof value[0];
113
+ for (let i = value.length - 1; i >= 0; i--) {
114
+ if (typeof value[i] !== type) {
115
+ errors.push(getError(ValidatorType.itemList, ['of items of the same type']));
116
+ break;
117
+ }
118
+ }
119
+ }
120
+ return { value: parsedValue, isSet: true, isValid: !errors.length, errors };
121
+ };
122
+ const onFunction = (value) => {
123
+ const errors = [];
124
+ if (typeof value !== 'function') {
125
+ errors.push(ValidatorType.function);
126
+ }
127
+ return { value: value, isSet: true, isValid: !errors.length, errors };
128
+ };
129
+ const onFunctionWithXArguments = (argsCount) => (value) => {
130
+ const result = onFunction(value);
131
+ if (!result.isValid) {
132
+ return result;
133
+ }
134
+ value = result.value;
135
+ const errors = [];
136
+ if (value.length !== argsCount) {
137
+ errors.push(getError(ValidatorType.funcOfxArguments, [String(argsCount)]));
138
+ }
139
+ return { value: value, isSet: true, isValid: !errors.length, errors };
140
+ };
141
+ const onFunctionWithXAndMoreArguments = (argsCount) => (value) => {
142
+ const result = onFunction(value);
143
+ if (!result.isValid) {
144
+ return result;
145
+ }
146
+ value = result.value;
147
+ const errors = [];
148
+ if (value.length < argsCount) {
149
+ errors.push(getError(ValidatorType.funcOfxArguments, [String(argsCount)]));
150
+ }
151
+ return { value: value, isSet: true, isValid: !errors.length, errors };
152
+ };
153
+ const onFunctionWithXToYArguments = (from, to) => (value) => {
154
+ const result = onFunction(value);
155
+ if (!result.isValid) {
156
+ return result;
157
+ }
158
+ value = result.value;
159
+ const errors = [];
160
+ if (value.length < from || value.length > to) {
161
+ errors.push(getError(ValidatorType.funcOfXToYArguments, [String(from), String(to)]));
162
+ }
163
+ return { value: value, isSet: true, isValid: !errors.length, errors };
164
+ };
165
+ const onOneOf = (tokens, must) => (value, context) => {
166
+ const errors = [];
167
+ const isSet = value !== void 0;
168
+ let noOneIsPresent = !isSet;
169
+ const err = must ? ValidatorType.oneOfMust : ValidatorType.oneOfCan;
170
+ if (!Array.isArray(tokens) || !tokens.length) {
171
+ errors.push(getError(err, ['undefined']));
172
+ }
173
+ else {
174
+ for (let i = tokens.length - 1; i >= 0; i--) {
175
+ const token = tokens[i];
176
+ if (typeof token !== 'string') {
177
+ errors.push(getError(err, [tokens.join('", "')]) + ' (non-string token)');
178
+ break;
179
+ }
180
+ const isAnotherPresent = context && Object.prototype.hasOwnProperty.call(context, token);
181
+ if (isSet && isAnotherPresent) {
182
+ errors.push(getError(err, [tokens.join('", "')]) + ` (${token} is present)`);
183
+ break;
184
+ }
185
+ if (noOneIsPresent && isAnotherPresent) {
186
+ noOneIsPresent = false;
187
+ }
188
+ }
189
+ if (must && noOneIsPresent) {
190
+ errors.push(getError(err, [tokens.join('", "')]));
191
+ }
192
+ }
193
+ return { value, isSet, isValid: !errors.length, errors };
194
+ };
195
+ const onOr = (validators) => (value) => {
196
+ const errors = [];
197
+ if (validators.every(validator => !validator.method(value).isValid)) {
198
+ errors.push(validators.map(v => v.type).join(' OR '));
199
+ }
200
+ return { value, isSet: true, isValid: !errors.length, errors };
201
+ };
202
+ const onEnum = (list) => (value) => {
203
+ const errors = [];
204
+ const values = Object.keys(list).filter(k => isNaN(Number(k))).map(k => list[k]);
205
+ if (!values.some(item => item === value)) {
206
+ errors.push(getError(ValidatorType.enum, ['[' + values.join(',') + ']']));
207
+ }
208
+ return { value, isSet: true, isValid: !errors.length, errors };
209
+ };
210
+ export const VALIDATORS = {
211
+ NUMBER: {
212
+ type: ValidatorType.number,
213
+ method: onNumber
214
+ },
215
+ INTEGER: {
216
+ type: ValidatorType.integer,
217
+ method: onInteger
218
+ },
219
+ INTEGER_UNLIMITED: {
220
+ type: ValidatorType.integerUnlimited,
221
+ method: onIntegerUnlimited
222
+ },
223
+ MORE_OR_EQUAL: (limit, fallback) => ({
224
+ type: ValidatorType.moreOrEqual,
225
+ method: onMoreOrEqual(limit, fallback)
226
+ }),
227
+ BOOLEAN: {
228
+ type: ValidatorType.boolean,
229
+ method: onBoolean
230
+ },
231
+ OBJECT: {
232
+ type: ValidatorType.object,
233
+ method: onObject
234
+ },
235
+ ITEM_LIST: {
236
+ type: ValidatorType.itemList,
237
+ method: onItemList
238
+ },
239
+ ELEMENT: {
240
+ type: ValidatorType.element,
241
+ method: onHtmlElement
242
+ },
243
+ FUNC: {
244
+ type: ValidatorType.function,
245
+ method: onFunction
246
+ },
247
+ FUNC_WITH_X_ARGUMENTS: (count) => ({
248
+ type: ValidatorType.funcOfxArguments,
249
+ method: onFunctionWithXArguments(count)
250
+ }),
251
+ FUNC_WITH_X_AND_MORE_ARGUMENTS: (count) => ({
252
+ type: ValidatorType.funcOfxAndMoreArguments,
253
+ method: onFunctionWithXAndMoreArguments(count)
254
+ }),
255
+ FUNC_WITH_X_TO_Y_ARGUMENTS: (from, to) => ({
256
+ type: ValidatorType.funcOfXToYArguments,
257
+ method: onFunctionWithXToYArguments(from, to)
258
+ }),
259
+ ONE_OF_CAN: (list) => ({
260
+ type: ValidatorType.oneOfCan,
261
+ method: onOneOf(list, false)
262
+ }),
263
+ ONE_OF_MUST: (list) => ({
264
+ type: ValidatorType.oneOfMust,
265
+ method: onOneOf(list, true)
266
+ }),
267
+ OR: (list) => ({
268
+ type: ValidatorType.or,
269
+ method: onOr(list)
270
+ }),
271
+ ENUM: (list) => ({
272
+ type: ValidatorType.enum,
273
+ method: onEnum(list)
274
+ })
275
+ };
276
+ export class ValidatedData {
277
+ constructor(context) {
278
+ this.params = {};
279
+ this.contextErrors = [];
280
+ this.errors = [];
281
+ this.isValid = true;
282
+ this.setContext(context);
283
+ }
284
+ setContext(context) {
285
+ if (!context || Object.prototype.toString.call(context) !== '[object Object]') {
286
+ this.setCommonError('context is not an object');
287
+ this.isValidContext = false;
288
+ }
289
+ else {
290
+ this.isValidContext = true;
291
+ }
292
+ this.context = context;
293
+ }
294
+ setValidity() {
295
+ this.errors = Object.keys(this.params).reduce((acc, key) => [
296
+ ...acc, ...this.params[key].errors
297
+ ], []);
298
+ this.isValid = !this.errors.length;
299
+ }
300
+ setCommonError(error) {
301
+ this.contextErrors.push(error);
302
+ this.errors.push(error);
303
+ this.isValid = false;
304
+ }
305
+ setParam(token, value) {
306
+ if (!value.isValid) {
307
+ value.errors = !value.isSet
308
+ ? [`"${token}" must be set`]
309
+ : value.errors.map((err) => `"${token}" ${err}`);
310
+ }
311
+ this.params[token] = value;
312
+ this.setValidity();
313
+ }
314
+ showErrors() {
315
+ return this.errors.length
316
+ ? 'validation failed: ' + this.errors.join(', ')
317
+ : '';
318
+ }
319
+ }
320
+ export const runValidator = (current, validator, context) => {
321
+ const { value, errors } = current;
322
+ const result = validator.method(value, context);
323
+ const _errors = [...errors, ...result.errors];
324
+ return {
325
+ value: result.value,
326
+ isSet: result.isSet,
327
+ isValid: !_errors.length,
328
+ errors: _errors
329
+ };
330
+ };
331
+ const getDefault = (value, prop) => {
332
+ const empty = value === void 0;
333
+ const auto = !prop.mandatory && prop.defaultValue !== void 0;
334
+ return {
335
+ value: !empty ? value : (auto ? prop.defaultValue : void 0),
336
+ isSet: !empty || auto,
337
+ isValid: !empty || !prop.mandatory,
338
+ errors: []
339
+ };
340
+ };
341
+ export const validateOne = (context, name, prop) => {
342
+ const result = getDefault(context[name], prop);
343
+ if (!result.isSet) {
344
+ const oneOfMust = prop.validators.find(v => v.type === ValidatorType.oneOfMust);
345
+ if (oneOfMust) {
346
+ return runValidator(result, oneOfMust, context);
347
+ }
348
+ }
349
+ else {
350
+ for (const validator of Object.values(prop.validators)) {
351
+ const current = runValidator(result, validator, context);
352
+ if (!current.isValid && prop.defaultValue !== void 0) {
353
+ return {
354
+ value: prop.defaultValue,
355
+ isSet: true,
356
+ isValid: true,
357
+ errors: []
358
+ };
359
+ }
360
+ Object.assign(result, current);
361
+ }
362
+ }
363
+ return result;
364
+ };
365
+ export const validate = (context, params) => {
366
+ const data = new ValidatedData(context);
367
+ Object.entries(params).forEach(([key, prop]) => data.setParam(key, data.isValidContext
368
+ ? validateOne(data.context, key, prop)
369
+ : getDefault(void 0, prop)));
370
+ return data;
371
+ };
375
372
  //# sourceMappingURL=validation.js.map