@defra/forms-model 3.0.2

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 (336) hide show
  1. package/LICENCE +8 -0
  2. package/README.md +22 -0
  3. package/dist/browser/components/component-types.d.ts +3 -0
  4. package/dist/browser/components/component-types.d.ts.map +1 -0
  5. package/dist/browser/components/component-types.js +220 -0
  6. package/dist/browser/components/component-types.js.map +1 -0
  7. package/dist/browser/components/conditional-component-types.d.ts +3 -0
  8. package/dist/browser/components/conditional-component-types.d.ts.map +1 -0
  9. package/dist/browser/components/conditional-component-types.js +28 -0
  10. package/dist/browser/components/conditional-component-types.js.map +1 -0
  11. package/dist/browser/components/index.d.ts +4 -0
  12. package/dist/browser/components/index.d.ts.map +1 -0
  13. package/dist/browser/components/index.js +45 -0
  14. package/dist/browser/components/index.js.map +1 -0
  15. package/dist/browser/components/types.d.ts +244 -0
  16. package/dist/browser/components/types.d.ts.map +1 -0
  17. package/dist/browser/components/types.js +56 -0
  18. package/dist/browser/components/types.js.map +1 -0
  19. package/dist/browser/conditions/condition-abstract.d.ts +16 -0
  20. package/dist/browser/conditions/condition-abstract.d.ts.map +1 -0
  21. package/dist/browser/conditions/condition-abstract.js +62 -0
  22. package/dist/browser/conditions/condition-abstract.js.map +1 -0
  23. package/dist/browser/conditions/condition-field.d.ts +13 -0
  24. package/dist/browser/conditions/condition-field.d.ts.map +1 -0
  25. package/dist/browser/conditions/condition-field.js +45 -0
  26. package/dist/browser/conditions/condition-field.js.map +1 -0
  27. package/dist/browser/conditions/condition-group-def.d.ts +10 -0
  28. package/dist/browser/conditions/condition-group-def.d.ts.map +1 -0
  29. package/dist/browser/conditions/condition-group-def.js +45 -0
  30. package/dist/browser/conditions/condition-group-def.js.map +1 -0
  31. package/dist/browser/conditions/condition-group.d.ts +15 -0
  32. package/dist/browser/conditions/condition-group.d.ts.map +1 -0
  33. package/dist/browser/conditions/condition-group.js +64 -0
  34. package/dist/browser/conditions/condition-group.js.map +1 -0
  35. package/dist/browser/conditions/condition-model.d.ts +41 -0
  36. package/dist/browser/conditions/condition-model.d.ts.map +1 -0
  37. package/dist/browser/conditions/condition-model.js +214 -0
  38. package/dist/browser/conditions/condition-model.js.map +1 -0
  39. package/dist/browser/conditions/condition-operators.d.ts +248 -0
  40. package/dist/browser/conditions/condition-operators.d.ts.map +1 -0
  41. package/dist/browser/conditions/condition-operators.js +132 -0
  42. package/dist/browser/conditions/condition-operators.js.map +1 -0
  43. package/dist/browser/conditions/condition-ref.d.ts +12 -0
  44. package/dist/browser/conditions/condition-ref.d.ts.map +1 -0
  45. package/dist/browser/conditions/condition-ref.js +51 -0
  46. package/dist/browser/conditions/condition-ref.js.map +1 -0
  47. package/dist/browser/conditions/condition-value-abstract.d.ts +8 -0
  48. package/dist/browser/conditions/condition-value-abstract.d.ts.map +1 -0
  49. package/dist/browser/conditions/condition-value-abstract.js +41 -0
  50. package/dist/browser/conditions/condition-value-abstract.js.map +1 -0
  51. package/dist/browser/conditions/condition-value-registration.d.ts +10 -0
  52. package/dist/browser/conditions/condition-value-registration.d.ts.map +1 -0
  53. package/dist/browser/conditions/condition-value-registration.js +37 -0
  54. package/dist/browser/conditions/condition-value-registration.js.map +1 -0
  55. package/dist/browser/conditions/condition-values.d.ts +38 -0
  56. package/dist/browser/conditions/condition-values.d.ts.map +1 -0
  57. package/dist/browser/conditions/condition-values.js +127 -0
  58. package/dist/browser/conditions/condition-values.js.map +1 -0
  59. package/dist/browser/conditions/condition.d.ts +15 -0
  60. package/dist/browser/conditions/condition.d.ts.map +1 -0
  61. package/dist/browser/conditions/condition.js +56 -0
  62. package/dist/browser/conditions/condition.js.map +1 -0
  63. package/dist/browser/conditions/helpers.d.ts +3 -0
  64. package/dist/browser/conditions/helpers.d.ts.map +1 -0
  65. package/dist/browser/conditions/helpers.js +26 -0
  66. package/dist/browser/conditions/helpers.js.map +1 -0
  67. package/dist/browser/conditions/index.d.ts +11 -0
  68. package/dist/browser/conditions/index.d.ts.map +1 -0
  69. package/dist/browser/conditions/index.js +144 -0
  70. package/dist/browser/conditions/index.js.map +1 -0
  71. package/dist/browser/conditions/inline-condition-model.d.ts +86 -0
  72. package/dist/browser/conditions/inline-condition-model.d.ts.map +1 -0
  73. package/dist/browser/conditions/inline-condition-model.js +418 -0
  74. package/dist/browser/conditions/inline-condition-model.js.map +1 -0
  75. package/dist/browser/conditions/inline-condition-operators.d.ts +175 -0
  76. package/dist/browser/conditions/inline-condition-operators.d.ts.map +1 -0
  77. package/dist/browser/conditions/inline-condition-operators.js +132 -0
  78. package/dist/browser/conditions/inline-condition-operators.js.map +1 -0
  79. package/dist/browser/conditions/inline-condition-values.d.ts +93 -0
  80. package/dist/browser/conditions/inline-condition-values.d.ts.map +1 -0
  81. package/dist/browser/conditions/inline-condition-values.js +159 -0
  82. package/dist/browser/conditions/inline-condition-values.js.map +1 -0
  83. package/dist/browser/conditions/types.d.ts +38 -0
  84. package/dist/browser/conditions/types.d.ts.map +1 -0
  85. package/dist/browser/conditions/types.js +24 -0
  86. package/dist/browser/conditions/types.js.map +1 -0
  87. package/dist/browser/data-model/conditions-wrapper.d.ts +19 -0
  88. package/dist/browser/data-model/conditions-wrapper.d.ts.map +1 -0
  89. package/dist/browser/data-model/conditions-wrapper.js +49 -0
  90. package/dist/browser/data-model/conditions-wrapper.js.map +1 -0
  91. package/dist/browser/data-model/index.d.ts +4 -0
  92. package/dist/browser/data-model/index.d.ts.map +1 -0
  93. package/dist/browser/data-model/index.js +66 -0
  94. package/dist/browser/data-model/index.js.map +1 -0
  95. package/dist/browser/data-model/input-wrapper.d.ts +16 -0
  96. package/dist/browser/data-model/input-wrapper.d.ts.map +1 -0
  97. package/dist/browser/data-model/input-wrapper.js +49 -0
  98. package/dist/browser/data-model/input-wrapper.js.map +1 -0
  99. package/dist/browser/data-model/types.d.ts +153 -0
  100. package/dist/browser/data-model/types.d.ts.map +1 -0
  101. package/dist/browser/data-model/types.js +34 -0
  102. package/dist/browser/data-model/types.js.map +1 -0
  103. package/dist/browser/form/form-configuration.d.ts +8 -0
  104. package/dist/browser/form/form-configuration.d.ts.map +1 -0
  105. package/dist/browser/form/form-configuration.js +38 -0
  106. package/dist/browser/form/form-configuration.js.map +1 -0
  107. package/dist/browser/form/index.d.ts +2 -0
  108. package/dist/browser/form/index.d.ts.map +1 -0
  109. package/dist/browser/form/index.js +24 -0
  110. package/dist/browser/form/index.js.map +1 -0
  111. package/dist/browser/index.d.ts +12 -0
  112. package/dist/browser/index.d.ts.map +1 -0
  113. package/dist/browser/index.js +138 -0
  114. package/dist/browser/index.js.map +1 -0
  115. package/dist/browser/migration/index.d.ts +2 -0
  116. package/dist/browser/migration/index.d.ts.map +1 -0
  117. package/dist/browser/migration/index.js +24 -0
  118. package/dist/browser/migration/index.js.map +1 -0
  119. package/dist/browser/migration/migration.0-2.d.ts +3 -0
  120. package/dist/browser/migration/migration.0-2.d.ts.map +1 -0
  121. package/dist/browser/migration/migration.0-2.js +65 -0
  122. package/dist/browser/migration/migration.0-2.js.map +1 -0
  123. package/dist/browser/migration/migration.1-2.d.ts +3 -0
  124. package/dist/browser/migration/migration.1-2.d.ts.map +1 -0
  125. package/dist/browser/migration/migration.1-2.js +108 -0
  126. package/dist/browser/migration/migration.1-2.js.map +1 -0
  127. package/dist/browser/migration/types.d.ts +2 -0
  128. package/dist/browser/migration/types.d.ts.map +1 -0
  129. package/dist/browser/migration/types.js +16 -0
  130. package/dist/browser/migration/types.js.map +1 -0
  131. package/dist/browser/migration/whichMigrations.d.ts +7 -0
  132. package/dist/browser/migration/whichMigrations.d.ts.map +1 -0
  133. package/dist/browser/migration/whichMigrations.js +38 -0
  134. package/dist/browser/migration/whichMigrations.js.map +1 -0
  135. package/dist/browser/schema/index.d.ts +2 -0
  136. package/dist/browser/schema/index.d.ts.map +1 -0
  137. package/dist/browser/schema/index.js +30 -0
  138. package/dist/browser/schema/index.js.map +1 -0
  139. package/dist/browser/schema/schema.d.ts +20 -0
  140. package/dist/browser/schema/schema.d.ts.map +1 -0
  141. package/dist/browser/schema/schema.js +255 -0
  142. package/dist/browser/schema/schema.js.map +1 -0
  143. package/dist/browser/utils/helpers.d.ts +9 -0
  144. package/dist/browser/utils/helpers.d.ts.map +1 -0
  145. package/dist/browser/utils/helpers.js +48 -0
  146. package/dist/browser/utils/helpers.js.map +1 -0
  147. package/dist/browser/utils/logger.d.ts +11 -0
  148. package/dist/browser/utils/logger.d.ts.map +1 -0
  149. package/dist/browser/utils/logger.js +46 -0
  150. package/dist/browser/utils/logger.js.map +1 -0
  151. package/dist/module/components/component-types.d.ts +3 -0
  152. package/dist/module/components/component-types.d.ts.map +1 -0
  153. package/dist/module/components/component-types.js +206 -0
  154. package/dist/module/components/component-types.js.map +1 -0
  155. package/dist/module/components/conditional-component-types.d.ts +3 -0
  156. package/dist/module/components/conditional-component-types.d.ts.map +1 -0
  157. package/dist/module/components/conditional-component-types.js +14 -0
  158. package/dist/module/components/conditional-component-types.js.map +1 -0
  159. package/dist/module/components/index.d.ts +4 -0
  160. package/dist/module/components/index.d.ts.map +1 -0
  161. package/dist/module/components/index.js +34 -0
  162. package/dist/module/components/index.js.map +1 -0
  163. package/dist/module/components/types.d.ts +244 -0
  164. package/dist/module/components/types.d.ts.map +1 -0
  165. package/dist/module/components/types.js +42 -0
  166. package/dist/module/components/types.js.map +1 -0
  167. package/dist/module/conditions/condition-abstract.d.ts +16 -0
  168. package/dist/module/conditions/condition-abstract.d.ts.map +1 -0
  169. package/dist/module/conditions/condition-abstract.js +45 -0
  170. package/dist/module/conditions/condition-abstract.js.map +1 -0
  171. package/dist/module/conditions/condition-field.d.ts +13 -0
  172. package/dist/module/conditions/condition-field.d.ts.map +1 -0
  173. package/dist/module/conditions/condition-field.js +26 -0
  174. package/dist/module/conditions/condition-field.js.map +1 -0
  175. package/dist/module/conditions/condition-group-def.d.ts +10 -0
  176. package/dist/module/conditions/condition-group-def.d.ts.map +1 -0
  177. package/dist/module/conditions/condition-group-def.js +26 -0
  178. package/dist/module/conditions/condition-group-def.js.map +1 -0
  179. package/dist/module/conditions/condition-group.d.ts +15 -0
  180. package/dist/module/conditions/condition-group.d.ts.map +1 -0
  181. package/dist/module/conditions/condition-group.js +47 -0
  182. package/dist/module/conditions/condition-group.js.map +1 -0
  183. package/dist/module/conditions/condition-model.d.ts +41 -0
  184. package/dist/module/conditions/condition-model.d.ts.map +1 -0
  185. package/dist/module/conditions/condition-model.js +199 -0
  186. package/dist/module/conditions/condition-model.js.map +1 -0
  187. package/dist/module/conditions/condition-operators.d.ts +248 -0
  188. package/dist/module/conditions/condition-operators.d.ts.map +1 -0
  189. package/dist/module/conditions/condition-operators.js +119 -0
  190. package/dist/module/conditions/condition-operators.js.map +1 -0
  191. package/dist/module/conditions/condition-ref.d.ts +12 -0
  192. package/dist/module/conditions/condition-ref.d.ts.map +1 -0
  193. package/dist/module/conditions/condition-ref.js +33 -0
  194. package/dist/module/conditions/condition-ref.js.map +1 -0
  195. package/dist/module/conditions/condition-value-abstract.d.ts +8 -0
  196. package/dist/module/conditions/condition-value-abstract.d.ts.map +1 -0
  197. package/dist/module/conditions/condition-value-abstract.js +24 -0
  198. package/dist/module/conditions/condition-value-abstract.js.map +1 -0
  199. package/dist/module/conditions/condition-value-registration.d.ts +10 -0
  200. package/dist/module/conditions/condition-value-registration.d.ts.map +1 -0
  201. package/dist/module/conditions/condition-value-registration.js +19 -0
  202. package/dist/module/conditions/condition-value-registration.js.map +1 -0
  203. package/dist/module/conditions/condition-values.d.ts +38 -0
  204. package/dist/module/conditions/condition-values.d.ts.map +1 -0
  205. package/dist/module/conditions/condition-values.js +106 -0
  206. package/dist/module/conditions/condition-values.js.map +1 -0
  207. package/dist/module/conditions/condition.d.ts +15 -0
  208. package/dist/module/conditions/condition.d.ts.map +1 -0
  209. package/dist/module/conditions/condition.js +40 -0
  210. package/dist/module/conditions/condition.js.map +1 -0
  211. package/dist/module/conditions/helpers.d.ts +3 -0
  212. package/dist/module/conditions/helpers.d.ts.map +1 -0
  213. package/dist/module/conditions/helpers.js +12 -0
  214. package/dist/module/conditions/helpers.js.map +1 -0
  215. package/dist/module/conditions/index.d.ts +11 -0
  216. package/dist/module/conditions/index.d.ts.map +1 -0
  217. package/dist/module/conditions/index.js +140 -0
  218. package/dist/module/conditions/index.js.map +1 -0
  219. package/dist/module/conditions/inline-condition-model.d.ts +86 -0
  220. package/dist/module/conditions/inline-condition-model.d.ts.map +1 -0
  221. package/dist/module/conditions/inline-condition-model.js +384 -0
  222. package/dist/module/conditions/inline-condition-model.js.map +1 -0
  223. package/dist/module/conditions/inline-condition-operators.d.ts +175 -0
  224. package/dist/module/conditions/inline-condition-operators.d.ts.map +1 -0
  225. package/dist/module/conditions/inline-condition-operators.js +119 -0
  226. package/dist/module/conditions/inline-condition-operators.js.map +1 -0
  227. package/dist/module/conditions/inline-condition-values.d.ts +93 -0
  228. package/dist/module/conditions/inline-condition-values.d.ts.map +1 -0
  229. package/dist/module/conditions/inline-condition-values.js +134 -0
  230. package/dist/module/conditions/inline-condition-values.js.map +1 -0
  231. package/dist/module/conditions/types.d.ts +38 -0
  232. package/dist/module/conditions/types.d.ts.map +1 -0
  233. package/dist/module/conditions/types.js +10 -0
  234. package/dist/module/conditions/types.js.map +1 -0
  235. package/dist/module/data-model/conditions-wrapper.d.ts +19 -0
  236. package/dist/module/data-model/conditions-wrapper.d.ts.map +1 -0
  237. package/dist/module/data-model/conditions-wrapper.js +30 -0
  238. package/dist/module/data-model/conditions-wrapper.js.map +1 -0
  239. package/dist/module/data-model/index.d.ts +4 -0
  240. package/dist/module/data-model/index.d.ts.map +1 -0
  241. package/dist/module/data-model/index.js +55 -0
  242. package/dist/module/data-model/index.js.map +1 -0
  243. package/dist/module/data-model/input-wrapper.d.ts +16 -0
  244. package/dist/module/data-model/input-wrapper.d.ts.map +1 -0
  245. package/dist/module/data-model/input-wrapper.js +25 -0
  246. package/dist/module/data-model/input-wrapper.js.map +1 -0
  247. package/dist/module/data-model/types.d.ts +153 -0
  248. package/dist/module/data-model/types.d.ts.map +1 -0
  249. package/dist/module/data-model/types.js +20 -0
  250. package/dist/module/data-model/types.js.map +1 -0
  251. package/dist/module/form/form-configuration.d.ts +8 -0
  252. package/dist/module/form/form-configuration.d.ts.map +1 -0
  253. package/dist/module/form/form-configuration.js +17 -0
  254. package/dist/module/form/form-configuration.js.map +1 -0
  255. package/dist/module/form/index.d.ts +2 -0
  256. package/dist/module/form/index.d.ts.map +1 -0
  257. package/dist/module/form/index.js +11 -0
  258. package/dist/module/form/index.js.map +1 -0
  259. package/dist/module/index.d.ts +12 -0
  260. package/dist/module/index.d.ts.map +1 -0
  261. package/dist/module/index.js +135 -0
  262. package/dist/module/index.js.map +1 -0
  263. package/dist/module/migration/index.d.ts +2 -0
  264. package/dist/module/migration/index.d.ts.map +1 -0
  265. package/dist/module/migration/index.js +11 -0
  266. package/dist/module/migration/index.js.map +1 -0
  267. package/dist/module/migration/migration.0-2.d.ts +3 -0
  268. package/dist/module/migration/migration.0-2.d.ts.map +1 -0
  269. package/dist/module/migration/migration.0-2.js +42 -0
  270. package/dist/module/migration/migration.0-2.js.map +1 -0
  271. package/dist/module/migration/migration.1-2.d.ts +3 -0
  272. package/dist/module/migration/migration.1-2.d.ts.map +1 -0
  273. package/dist/module/migration/migration.1-2.js +90 -0
  274. package/dist/module/migration/migration.1-2.js.map +1 -0
  275. package/dist/module/migration/types.d.ts +2 -0
  276. package/dist/module/migration/types.d.ts.map +1 -0
  277. package/dist/module/migration/types.js +1 -0
  278. package/dist/module/migration/types.js.map +1 -0
  279. package/dist/module/migration/whichMigrations.d.ts +7 -0
  280. package/dist/module/migration/whichMigrations.d.ts.map +1 -0
  281. package/dist/module/migration/whichMigrations.js +26 -0
  282. package/dist/module/migration/whichMigrations.js.map +1 -0
  283. package/dist/module/schema/index.d.ts +2 -0
  284. package/dist/module/schema/index.d.ts.map +1 -0
  285. package/dist/module/schema/index.js +17 -0
  286. package/dist/module/schema/index.js.map +1 -0
  287. package/dist/module/schema/schema.d.ts +20 -0
  288. package/dist/module/schema/schema.d.ts.map +1 -0
  289. package/dist/module/schema/schema.js +239 -0
  290. package/dist/module/schema/schema.js.map +1 -0
  291. package/dist/module/utils/helpers.d.ts +9 -0
  292. package/dist/module/utils/helpers.d.ts.map +1 -0
  293. package/dist/module/utils/helpers.js +35 -0
  294. package/dist/module/utils/helpers.js.map +1 -0
  295. package/dist/module/utils/logger.d.ts +11 -0
  296. package/dist/module/utils/logger.d.ts.map +1 -0
  297. package/dist/module/utils/logger.js +27 -0
  298. package/dist/module/utils/logger.js.map +1 -0
  299. package/package.json +35 -0
  300. package/src/components/component-types.ts +229 -0
  301. package/src/components/conditional-component-types.ts +14 -0
  302. package/src/components/index.ts +3 -0
  303. package/src/components/types.ts +362 -0
  304. package/src/conditions/condition-abstract.ts +59 -0
  305. package/src/conditions/condition-field.ts +29 -0
  306. package/src/conditions/condition-group-def.ts +29 -0
  307. package/src/conditions/condition-group.ts +61 -0
  308. package/src/conditions/condition-model.ts +314 -0
  309. package/src/conditions/condition-operators.ts +176 -0
  310. package/src/conditions/condition-ref.ts +47 -0
  311. package/src/conditions/condition-value-abstract.ts +31 -0
  312. package/src/conditions/condition-value-registration.ts +18 -0
  313. package/src/conditions/condition-values.ts +146 -0
  314. package/src/conditions/condition.ts +64 -0
  315. package/src/conditions/helpers.ts +7 -0
  316. package/src/conditions/index.ts +27 -0
  317. package/src/conditions/inline-condition-model.ts +550 -0
  318. package/src/conditions/inline-condition-operators.ts +166 -0
  319. package/src/conditions/inline-condition-values.ts +153 -0
  320. package/src/conditions/types.ts +30 -0
  321. package/src/data-model/conditions-wrapper.ts +42 -0
  322. package/src/data-model/index.ts +3 -0
  323. package/src/data-model/input-wrapper.ts +40 -0
  324. package/src/data-model/types.ts +179 -0
  325. package/src/form/form-configuration.ts +21 -0
  326. package/src/form/index.ts +1 -0
  327. package/src/index.ts +11 -0
  328. package/src/migration/index.ts +1 -0
  329. package/src/migration/migration.0-2.ts +29 -0
  330. package/src/migration/migration.1-2.ts +105 -0
  331. package/src/migration/types.ts +1 -0
  332. package/src/migration/whichMigrations.ts +23 -0
  333. package/src/schema/index.ts +1 -0
  334. package/src/schema/schema.ts +300 -0
  335. package/src/utils/helpers.ts +37 -0
  336. package/src/utils/logger.ts +29 -0
@@ -0,0 +1,153 @@
1
+ const conditionValueFactories = {}
2
+
3
+ class Registration {
4
+ type
5
+
6
+ constructor(type, factory) {
7
+ conditionValueFactories[type] = factory
8
+ this.type = type
9
+ }
10
+ }
11
+
12
+ export class AbstractConditionValue {
13
+ type
14
+
15
+ constructor(registration) {
16
+ if (new.target === AbstractConditionValue) {
17
+ throw new TypeError('Cannot construct ConditionValue instances directly')
18
+ }
19
+ if (!(registration instanceof Registration)) {
20
+ throw new TypeError(
21
+ 'You must register your value type! Call registerValueType!'
22
+ )
23
+ }
24
+ this.type = registration.type
25
+ }
26
+
27
+ toPresentationString() {}
28
+ toExpression() {}
29
+ }
30
+
31
+ const valueType = registerValueType('Value', (obj) => ConditionValue.from(obj))
32
+ export class ConditionValue extends AbstractConditionValue {
33
+ value
34
+ display
35
+
36
+ constructor(value, display) {
37
+ super(valueType)
38
+ if (!value || typeof value !== 'string') {
39
+ throw Error(`value ${value} is not valid`)
40
+ }
41
+ if (display && typeof display !== 'string') {
42
+ throw Error(`display ${display} is not valid`)
43
+ }
44
+ this.value = value
45
+ this.display = display || value
46
+ }
47
+
48
+ toPresentationString() {
49
+ return this.display
50
+ }
51
+
52
+ toExpression() {
53
+ return this.value
54
+ }
55
+
56
+ static from(obj) {
57
+ return new ConditionValue(obj.value, obj.display)
58
+ }
59
+
60
+ clone() {
61
+ return ConditionValue.from(this)
62
+ }
63
+ }
64
+
65
+ export const dateDirections = {
66
+ FUTURE: 'in the future',
67
+ PAST: 'in the past'
68
+ }
69
+
70
+ export const dateUnits = {
71
+ YEARS: { display: 'year(s)', value: 'years' },
72
+ MONTHS: { display: 'month(s)', value: 'months' },
73
+ DAYS: { display: 'day(s)', value: 'days' }
74
+ }
75
+ export const timeUnits = {
76
+ HOURS: { display: 'hour(s)', value: 'hours' },
77
+ MINUTES: { display: 'minute(s)', value: 'minutes' },
78
+ SECONDS: { display: 'second(s)', value: 'seconds' }
79
+ }
80
+ export const dateTimeUnits = Object.assign({}, dateUnits, timeUnits)
81
+
82
+ export const relativeTimeValueType = registerValueType('RelativeTime', (obj) =>
83
+ RelativeTimeValue.from(obj)
84
+ )
85
+ export class RelativeTimeValue extends AbstractConditionValue {
86
+ timePeriod
87
+ timeUnit
88
+ direction
89
+ timeOnly
90
+
91
+ constructor(timePeriod, timeUnit, direction, timeOnly = false) {
92
+ super(relativeTimeValueType)
93
+ if (typeof timePeriod !== 'string') {
94
+ throw Error(`time period ${timePeriod} is not valid`)
95
+ }
96
+ if (
97
+ !Object.values(dateTimeUnits)
98
+ .map((it) => it.value)
99
+ .includes(timeUnit)
100
+ ) {
101
+ throw Error(`time unit ${timeUnit} is not valid`)
102
+ }
103
+ if (!Object.values(dateDirections).includes(direction)) {
104
+ throw Error(`direction ${direction} is not valid`)
105
+ }
106
+ this.timePeriod = timePeriod
107
+ this.timeUnit = timeUnit
108
+ this.direction = direction
109
+ this.timeOnly = timeOnly
110
+ }
111
+
112
+ toPresentationString() {
113
+ return `${this.timePeriod} ${this.timeUnit} ${this.direction}`
114
+ }
115
+
116
+ toExpression() {
117
+ const timePeriod =
118
+ this.direction === dateDirections.PAST
119
+ ? 0 - Number(this.timePeriod)
120
+ : this.timePeriod
121
+ return this.timeOnly
122
+ ? `timeForComparison(${timePeriod}, '${this.timeUnit}')`
123
+ : `dateForComparison(${timePeriod}, '${this.timeUnit}')`
124
+ }
125
+
126
+ static from(obj) {
127
+ return new RelativeTimeValue(
128
+ obj.timePeriod,
129
+ obj.timeUnit,
130
+ obj.direction,
131
+ obj.timeOnly
132
+ )
133
+ }
134
+
135
+ clone() {
136
+ return RelativeTimeValue.from(this)
137
+ }
138
+ }
139
+
140
+ /**
141
+ * All value types should call this, and should be located in this file.
142
+ * Furthermore the types should be registered without the classes needing to be instantiated.
143
+ *
144
+ * Otherwise we can't guarantee they've been registered for deserialization before
145
+ * valueFrom is called
146
+ */
147
+ function registerValueType(type, factory) {
148
+ return new Registration(type, factory)
149
+ }
150
+
151
+ export function valueFrom(obj) {
152
+ return conditionValueFactories[obj.type](obj)
153
+ }
@@ -0,0 +1,30 @@
1
+ import { Condition } from './condition'
2
+ import { ConditionRef } from './condition-ref'
3
+ import { ConditionGroup } from './condition-group'
4
+
5
+ export type ConditionsArray = (Condition | ConditionGroup | ConditionRef)[]
6
+
7
+ export enum Coordinator {
8
+ AND = 'and',
9
+ OR = 'or'
10
+ }
11
+
12
+ export type DateTimeUnitValues =
13
+ | 'years'
14
+ | 'months'
15
+ | 'days'
16
+ | 'hours'
17
+ | 'minutes'
18
+ | 'seconds'
19
+
20
+ export type DateUnits = {
21
+ YEARS: { display: 'year(s)'; value: 'years' }
22
+ MONTHS: { display: 'month(s)'; value: 'months' }
23
+ DAYS: { display: 'day(s)'; value: 'days' }
24
+ }
25
+
26
+ export type TimeUnits = {
27
+ HOURS: { display: 'hour(s)'; value: 'hours' }
28
+ MINUTES: { display: 'minute(s)'; value: 'minutes' }
29
+ SECONDS: { display: 'second(s)'; value: 'seconds' }
30
+ }
@@ -0,0 +1,42 @@
1
+ import { Condition } from '../conditions/condition'
2
+ import { ConditionsModel } from '../conditions/condition-model'
3
+
4
+ export type ConditionWrapperValue =
5
+ | string
6
+ | {
7
+ name: string
8
+ conditions: Condition[]
9
+ }
10
+
11
+ export type ConditionRawData = {
12
+ name: string
13
+ displayName: string
14
+ value: ConditionWrapperValue
15
+ }
16
+
17
+ export class ConditionsWrapper {
18
+ name: string
19
+ displayName: string
20
+ value: ConditionWrapperValue
21
+
22
+ constructor(rawData: ConditionRawData) {
23
+ const { name, displayName, value } = rawData
24
+ this.displayName = displayName || name
25
+ this.value = value
26
+ this.name = name
27
+ }
28
+
29
+ get expression() {
30
+ if (typeof this.value === 'string') {
31
+ // Previously conditions were defined as strings, e.g: "section.age < 18"
32
+ // keep this so application can support legacy forms exports.
33
+ return this.value
34
+ }
35
+
36
+ return ConditionsModel.from(this.value).toExpression()
37
+ }
38
+
39
+ clone(): ConditionsWrapper {
40
+ return new ConditionsWrapper(this)
41
+ }
42
+ }
@@ -0,0 +1,3 @@
1
+ export { InputWrapper } from './input-wrapper'
2
+ export { ConditionsWrapper, ConditionRawData } from './conditions-wrapper'
3
+ export { Page, Item, Section, List, ConfirmationPage } from './types'
@@ -0,0 +1,40 @@
1
+ import { clone } from '../utils/helpers'
2
+ import { ComponentDef } from '../components/types'
3
+ import { Page } from './types'
4
+
5
+ export class InputWrapper {
6
+ name: string | undefined = undefined
7
+ title: string | undefined = undefined
8
+ type: string | undefined = undefined
9
+ propertyPath: string | undefined
10
+ #parentItemName: string | undefined
11
+ page: Page
12
+
13
+ constructor(
14
+ rawData: ComponentDef,
15
+ page: Page,
16
+ options: { ignoreSection?: boolean; parentItemName?: string }
17
+ ) {
18
+ Object.assign(this, rawData)
19
+ const myPage = clone(page)
20
+
21
+ delete myPage.components
22
+
23
+ this.page = myPage
24
+ this.propertyPath =
25
+ !options.ignoreSection && page.section
26
+ ? `${page.section}.${this.name}`
27
+ : this.name
28
+ this.#parentItemName = options.parentItemName
29
+ }
30
+
31
+ get displayName(): string | undefined {
32
+ const titleWithContext = this.#parentItemName
33
+ ? `${this.title} under ${this.#parentItemName}`
34
+ : this.title
35
+
36
+ return this.page.section
37
+ ? `${titleWithContext} in ${this.page.section}`
38
+ : titleWithContext
39
+ }
40
+ }
@@ -0,0 +1,179 @@
1
+ import { ConditionRawData } from '.'
2
+ import { ComponentDef } from '../components/types'
3
+
4
+ type Toggleable<T> = boolean | T
5
+
6
+ export interface Next {
7
+ path: string
8
+ condition?: string
9
+ }
10
+ export type Link = Next
11
+
12
+ export interface Page {
13
+ title: string
14
+ path: string
15
+ controller: string
16
+ components?: ComponentDef[]
17
+ section: string // the section ID
18
+ next?: { path: string; condition?: string }[]
19
+ }
20
+
21
+ export interface RepeatingFieldPage extends Page {
22
+ controller: 'RepeatingFieldPageController'
23
+ options: {
24
+ summaryDisplayMode?: {
25
+ samePage?: boolean
26
+ separatePage?: boolean
27
+ hideRowTitles?: boolean
28
+ }
29
+ customText?: {
30
+ separatePageTitle?: string
31
+ }
32
+ }
33
+ }
34
+
35
+ export interface Section {
36
+ name: string
37
+ title: string
38
+ hideTitle: boolean
39
+ }
40
+
41
+ export interface Item {
42
+ text: string
43
+ value: string | number | boolean
44
+ description?: string
45
+ condition?: string
46
+ }
47
+
48
+ export interface List {
49
+ name: string
50
+ title: string
51
+ type: 'string' | 'number' | 'boolean'
52
+ items: Item[]
53
+ }
54
+
55
+ export interface Feedback {
56
+ feedbackForm?: boolean
57
+ url?: string
58
+ emailAddress?: string
59
+ }
60
+
61
+ export type PhaseBanner = {
62
+ phase?: 'alpha' | 'beta'
63
+ feedbackUrl?: string
64
+ }
65
+
66
+ export type MultipleApiKeys = {
67
+ test?: string
68
+ production?: string
69
+ }
70
+
71
+ export enum OutputType {
72
+ Email = 'email',
73
+ Notify = 'notify',
74
+ Webhook = 'webhook'
75
+ }
76
+
77
+ export type EmailOutputConfiguration = {
78
+ emailAddress: string
79
+ }
80
+
81
+ export type NotifyOutputConfiguration = {
82
+ apiKey: string
83
+ templateId: string
84
+ emailField: string
85
+ personalisation: string[]
86
+ personalisationFieldCustomisation?: {
87
+ [personalisationName: string]: string[]
88
+ }
89
+ addReferencesToPersonalisation?: boolean
90
+ emailReplyToIdConfiguration?: {
91
+ emailReplyToId: string
92
+ condition?: string | undefined
93
+ }[]
94
+ }
95
+
96
+ export type WebhookOutputConfiguration = {
97
+ url: string
98
+ }
99
+
100
+ export type OutputConfiguration =
101
+ | EmailOutputConfiguration
102
+ | NotifyOutputConfiguration
103
+ | WebhookOutputConfiguration
104
+
105
+ export type Output = {
106
+ name: string
107
+ title: string
108
+ type: OutputType
109
+ outputConfiguration: OutputConfiguration
110
+ }
111
+
112
+ export type ConfirmationPage = {
113
+ customText: {
114
+ title: string
115
+ paymentSkipped: Toggleable<string>
116
+ nextSteps: Toggleable<string>
117
+ }
118
+ components: ComponentDef[]
119
+ }
120
+
121
+ export type PaymentSkippedWarningPage = {
122
+ customText: {
123
+ title: string
124
+ caption: string
125
+ body: string
126
+ }
127
+ }
128
+
129
+ export type SpecialPages = {
130
+ confirmationPage?: ConfirmationPage
131
+ paymentSkippedWarningPage?: PaymentSkippedWarningPage
132
+ }
133
+
134
+ export function isMultipleApiKey(
135
+ payApiKey: string | MultipleApiKeys | undefined
136
+ ): payApiKey is MultipleApiKeys {
137
+ const obj = payApiKey as MultipleApiKeys
138
+ return obj.test !== undefined || obj.production !== undefined
139
+ }
140
+
141
+ export type Fee = {
142
+ description: string
143
+ amount: number
144
+ multiplier?: string
145
+ condition?: string
146
+ prefix?: string
147
+ }
148
+
149
+ export type FeeOptions = {
150
+ paymentReferenceFormat?: string
151
+ payReturnUrl?: string
152
+ allowSubmissionWithoutPayment: boolean
153
+ maxAttempts: number
154
+ customPayErrorMessage?: string
155
+ showPaymentSkippedWarningPage: boolean
156
+ }
157
+
158
+ /**
159
+ * `FormDefinition` is a typescript representation of `Schema`
160
+ */
161
+ export type FormDefinition = {
162
+ pages: Array<Page | RepeatingFieldPage>
163
+ conditions: ConditionRawData[]
164
+ lists: List[]
165
+ sections: Section[]
166
+ startPage?: Page['path'] | undefined
167
+ name?: string | undefined
168
+ feedback?: Feedback
169
+ phaseBanner?: PhaseBanner
170
+ fees: Fee[]
171
+ skipSummary?: boolean | undefined
172
+ outputs: Output[]
173
+ declaration?: string | undefined
174
+ metadata?: Record<string, any>
175
+ payApiKey?: string | MultipleApiKeys | undefined
176
+ specialPages?: SpecialPages
177
+ paymentReferenceFormat?: string
178
+ feeOptions: FeeOptions
179
+ }
@@ -0,0 +1,21 @@
1
+ export class FormConfiguration {
2
+ Key: string
3
+ DisplayName: string
4
+ LastModified: string | undefined
5
+ feedbackForm: boolean | undefined
6
+
7
+ constructor(
8
+ Key: string,
9
+ DisplayName?: string,
10
+ LastModified?: string,
11
+ feedbackForm?: boolean
12
+ ) {
13
+ if (!Key) {
14
+ throw Error('Form configuration must have a key')
15
+ }
16
+ this.Key = Key
17
+ this.DisplayName = DisplayName || Key
18
+ this.LastModified = LastModified
19
+ this.feedbackForm = feedbackForm || false
20
+ }
21
+ }
@@ -0,0 +1 @@
1
+ export { FormConfiguration } from './form-configuration'
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ export { Schema, componentSchema } from './schema'
2
+ export { ConditionRawData, ConditionsWrapper } from './data-model'
3
+ export { Logger } from './utils/logger'
4
+ export { FormConfiguration } from './form'
5
+ export { ComponentTypes, ConditionalComponentTypes } from './components'
6
+ export * from './components/types'
7
+ export * from './conditions'
8
+ export * from './utils/helpers'
9
+ export * from './migration'
10
+ export * from './data-model/types'
11
+ export { whichMigrations } from './migration/whichMigrations'
@@ -0,0 +1 @@
1
+ export { whichMigrations } from './whichMigrations'
@@ -0,0 +1,29 @@
1
+ import { MigrationScript } from './types'
2
+
3
+ function needsUpgrade(data) {
4
+ return !!(data.pages ?? [])
5
+ .flatMap((page) => page.components)
6
+ .find((component) => component.options?.list)
7
+ }
8
+
9
+ export function migrate(data): MigrationScript {
10
+ if (!needsUpgrade(data)) {
11
+ return { ...data, version: 2 }
12
+ }
13
+ const { pages } = data
14
+ const newPages = pages.flatMap((page) => {
15
+ return page.components.map((component) => {
16
+ if (!component.options?.list) {
17
+ return component
18
+ }
19
+ const { list, ...rest } = component.options
20
+ return { ...component, list, options: { ...rest } }
21
+ })
22
+ })
23
+
24
+ return {
25
+ ...data,
26
+ pages: newPages,
27
+ version: 2
28
+ }
29
+ }
@@ -0,0 +1,105 @@
1
+ import { MigrationScript } from './types'
2
+ import { nanoid } from '../utils/helpers'
3
+
4
+ /**
5
+ * @private
6
+ * StaticItem is a deprecated Type.
7
+ * It should only be used for aiding migration scripts.
8
+ */
9
+ type StaticItem = {
10
+ label: string
11
+ value: string | number | boolean
12
+ hint?: string
13
+ condition?: string
14
+ }
15
+
16
+ /**
17
+ * @private
18
+ * StaticComponentValues is a deprecated Type.
19
+ * It should only be used for aiding migration scripts.
20
+ */
21
+ type StaticComponentValues = {
22
+ list: any
23
+ type: 'static' | 'listRef'
24
+ valueType: string | number
25
+ items: StaticItem[]
26
+ }
27
+
28
+ type Item = {
29
+ title: string
30
+ value: any
31
+ conditions?: any
32
+ hint?: string
33
+ }
34
+
35
+ function recastItem({ label, value, condition, hint }: StaticItem) {
36
+ const item: Item = {
37
+ title: label,
38
+ value
39
+ }
40
+
41
+ condition && (item.conditions = condition)
42
+ hint && (item.hint = hint)
43
+ return item
44
+ }
45
+
46
+ function addListId(component: { values: StaticComponentValues }) {
47
+ if (!component.values) {
48
+ return component
49
+ }
50
+ const { values } = component
51
+ return {
52
+ ...component,
53
+ list: values.type === 'listRef' ? values.list : nanoid()
54
+ }
55
+ }
56
+
57
+ function migratePage(page) {
58
+ return {
59
+ ...page,
60
+ components: page.components.map(addListId)
61
+ }
62
+ }
63
+
64
+ function removeValues(page) {
65
+ return {
66
+ ...page,
67
+ components: page.components.map((component) => {
68
+ const { values, ...rest } = component
69
+ return {
70
+ ...rest
71
+ }
72
+ })
73
+ }
74
+ }
75
+
76
+ function needsUpgrade(data) {
77
+ return !!data.pages
78
+ .flatMap((page) => page.components)
79
+ .find((component) => component.values)
80
+ }
81
+
82
+ export function migrate(data): MigrationScript {
83
+ if (!needsUpgrade(data)) {
84
+ return { ...data, version: 2 }
85
+ }
86
+ const pages = data.pages.map(migratePage)
87
+ const componentsWithList = pages.flatMap((page) =>
88
+ page.components.filter((c) => c.values?.items)
89
+ )
90
+
91
+ const valuesAsLists = componentsWithList.map((component) => {
92
+ return {
93
+ title: component.title,
94
+ name: component.list,
95
+ items: component.values.items.map((item) => recastItem(item))
96
+ }
97
+ })
98
+
99
+ return {
100
+ ...data,
101
+ pages: pages.map(removeValues),
102
+ lists: [...(data.lists ?? []), ...valuesAsLists],
103
+ version: 2
104
+ }
105
+ }
@@ -0,0 +1 @@
1
+ export type MigrationScript = (data: Object) => Object
@@ -0,0 +1,23 @@
1
+ import { migrate as V0_TO_V2 } from './migration.0-2'
2
+ import { migrate as V1_TO_V2 } from './migration.1-2'
3
+ import { MigrationScript } from './types'
4
+
5
+ /**
6
+ * Returns which migrations that should be run against your Object with the given version
7
+ * @param version
8
+ */
9
+ export function whichMigrations(version: number) {
10
+ const migrations = new Set<MigrationScript>()
11
+ switch (version) {
12
+ case 0:
13
+ migrations.add(V0_TO_V2)
14
+ /**
15
+ * we are skipping v1 entirely. If we weren't you would do migrations.add([V1_TO_V2, V2_TO_V3]) for example.
16
+ */
17
+ break
18
+ case 1:
19
+ migrations.add(V1_TO_V2)
20
+ break
21
+ }
22
+ return migrations
23
+ }
@@ -0,0 +1 @@
1
+ export { Schema, componentSchema } from './schema'