@defra/forms-model 3.0.429 → 3.0.431

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 (49) hide show
  1. package/README.md +163 -1
  2. package/dist/module/common/pagination/index.js +2 -2
  3. package/dist/module/common/pagination/index.js.map +1 -1
  4. package/dist/module/common/search/index.js +4 -4
  5. package/dist/module/common/search/index.js.map +1 -1
  6. package/dist/module/common/sorting/index.js +2 -2
  7. package/dist/module/common/sorting/index.js.map +1 -1
  8. package/dist/module/form/form-definition/index.js +156 -156
  9. package/dist/module/form/form-definition/index.js.map +1 -1
  10. package/dist/module/form/form-editor/index.js +47 -37
  11. package/dist/module/form/form-editor/index.js.map +1 -1
  12. package/dist/module/form/form-editor/types.js.map +1 -1
  13. package/dist/module/form/form-manager/index.js +3 -3
  14. package/dist/module/form/form-manager/index.js.map +1 -1
  15. package/dist/module/form/form-metadata/index.js +34 -34
  16. package/dist/module/form/form-metadata/index.js.map +1 -1
  17. package/dist/module/form/form-submission/index.js +13 -13
  18. package/dist/module/form/form-submission/index.js.map +1 -1
  19. package/dist/module/types/joi-to-json.d.js +2 -0
  20. package/dist/module/types/joi-to-json.d.js.map +1 -0
  21. package/dist/types/common/pagination/index.d.ts.map +1 -1
  22. package/dist/types/common/search/index.d.ts.map +1 -1
  23. package/dist/types/common/sorting/index.d.ts.map +1 -1
  24. package/dist/types/form/form-definition/index.d.ts.map +1 -1
  25. package/dist/types/form/form-editor/index.d.ts +17 -7
  26. package/dist/types/form/form-editor/index.d.ts.map +1 -1
  27. package/dist/types/form/form-editor/types.d.ts +45 -1
  28. package/dist/types/form/form-editor/types.d.ts.map +1 -1
  29. package/dist/types/form/form-manager/index.d.ts.map +1 -1
  30. package/dist/types/form/form-metadata/index.d.ts.map +1 -1
  31. package/dist/types/form/form-submission/index.d.ts.map +1 -1
  32. package/package.json +6 -4
  33. package/scripts/generate-schemas.js +238 -0
  34. package/scripts/schema-modules/constants.js +39 -0
  35. package/scripts/schema-modules/schema-processors.js +109 -0
  36. package/scripts/schema-modules/schema-simplifiers.js +351 -0
  37. package/scripts/schema-modules/title-processors.js +327 -0
  38. package/scripts/schema-modules/types.js +21 -0
  39. package/scripts/schema-modules/utils.js +41 -0
  40. package/src/common/pagination/index.ts +8 -1
  41. package/src/common/search/index.ts +17 -3
  42. package/src/common/sorting/index.ts +8 -2
  43. package/src/form/form-definition/index.ts +567 -238
  44. package/src/form/form-editor/index.ts +207 -24
  45. package/src/form/form-editor/types.ts +69 -0
  46. package/src/form/form-manager/index.ts +11 -2
  47. package/src/form/form-metadata/index.ts +118 -40
  48. package/src/form/form-submission/index.ts +33 -10
  49. package/src/types/joi-to-json.d.ts +15 -0
@@ -0,0 +1,41 @@
1
+ import fs from 'fs'
2
+
3
+ /**
4
+ * Ensures a directory exists
5
+ * @param {string} dir Directory path
6
+ */
7
+ export function ensureDirectoryExists(dir) {
8
+ if (!fs.existsSync(dir)) {
9
+ fs.mkdirSync(dir, { recursive: true })
10
+ }
11
+ }
12
+
13
+ /**
14
+ * Formats a kebab-case string to Title Case
15
+ * @param {string} str String to format
16
+ * @returns {string} Formatted string
17
+ */
18
+ export function toTitleCase(str) {
19
+ return str
20
+ .split('-')
21
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
22
+ .join(' ')
23
+ }
24
+
25
+ /**
26
+ * Format camelCase or snake_case to Title Case
27
+ * @param {string} str String to format
28
+ * @returns {string} Formatted string
29
+ */
30
+ export function formatPropertyName(str) {
31
+ return (
32
+ str
33
+ // camelCase to space-separated
34
+ .replace(/([A-Z])/g, ' $1')
35
+ // snake_case to space-separated
36
+ .replace(/_/g, ' ')
37
+ // Capitalize first letter
38
+ .replace(/^./, (first) => first.toUpperCase())
39
+ .trim()
40
+ )
41
+ }
@@ -6,7 +6,13 @@ import { type PaginationOptions } from '~/src/common/pagination/types.js'
6
6
  * Field definitions for pagination options.
7
7
  */
8
8
  export const paginationOptionFields = {
9
- page: Joi.number().positive().integer().default(1).min(1).optional(),
9
+ page: Joi.number()
10
+ .positive()
11
+ .integer()
12
+ .default(1)
13
+ .min(1)
14
+ .optional()
15
+ .description('Current page number, starting from 1'),
10
16
  perPage: Joi.number()
11
17
  .positive()
12
18
  .integer()
@@ -14,6 +20,7 @@ export const paginationOptionFields = {
14
20
  .min(1)
15
21
  .max(200)
16
22
  .optional()
23
+ .description('Number of items to display per page, between 1 and 200')
17
24
  }
18
25
 
19
26
  /**
@@ -7,18 +7,32 @@ import { organisations } from '~/src/form/form-metadata/index.js'
7
7
  * Field definitions for search options.
8
8
  */
9
9
  export const searchOptionFields = {
10
- title: Joi.string().trim().allow('').max(255).optional().default(''),
11
- author: Joi.string().trim().allow('').max(100).optional().default(''),
10
+ title: Joi.string()
11
+ .trim()
12
+ .allow('')
13
+ .max(255)
14
+ .optional()
15
+ .default('')
16
+ .description('Search by form title, empty string matches all'),
17
+ author: Joi.string()
18
+ .trim()
19
+ .allow('')
20
+ .max(100)
21
+ .optional()
22
+ .default('')
23
+ .description('Search by form author, empty string matches all'),
12
24
  organisations: Joi.array()
13
25
  .items(Joi.string().valid(...organisations))
14
26
  .single()
15
27
  .optional()
16
- .default([]),
28
+ .default([])
29
+ .description('Filter by organisation(s), empty array matches all'),
17
30
  status: Joi.array()
18
31
  .items(Joi.string().valid('draft', 'live'))
19
32
  .single()
20
33
  .optional()
21
34
  .default([])
35
+ .description('Filter by form status(es), empty array matches all')
22
36
  }
23
37
 
24
38
  /**
@@ -6,8 +6,14 @@ import { type SortingOptions } from '~/src/common/sorting/types.js'
6
6
  * Field definitions for sorting options.
7
7
  */
8
8
  export const sortingOptionFields = {
9
- sortBy: Joi.string().valid('updatedAt', 'title').optional(),
10
- order: Joi.string().valid('asc', 'desc').optional()
9
+ sortBy: Joi.string()
10
+ .valid('updatedAt', 'title')
11
+ .optional()
12
+ .description('Field to sort results by'),
13
+ order: Joi.string()
14
+ .valid('asc', 'desc')
15
+ .optional()
16
+ .description('Sort order (ascending or descending)')
11
17
  }
12
18
 
13
19
  /**