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