@defra/forms-model 3.0.430 → 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.
- package/README.md +163 -1
- package/dist/module/common/pagination/index.js +2 -2
- package/dist/module/common/pagination/index.js.map +1 -1
- package/dist/module/common/search/index.js +4 -4
- package/dist/module/common/search/index.js.map +1 -1
- package/dist/module/common/sorting/index.js +2 -2
- package/dist/module/common/sorting/index.js.map +1 -1
- package/dist/module/form/form-definition/index.js +156 -156
- package/dist/module/form/form-definition/index.js.map +1 -1
- package/dist/module/form/form-editor/index.js +42 -42
- package/dist/module/form/form-editor/index.js.map +1 -1
- package/dist/module/form/form-manager/index.js +3 -3
- package/dist/module/form/form-manager/index.js.map +1 -1
- package/dist/module/form/form-metadata/index.js +34 -34
- package/dist/module/form/form-metadata/index.js.map +1 -1
- package/dist/module/form/form-submission/index.js +13 -13
- package/dist/module/form/form-submission/index.js.map +1 -1
- package/dist/module/types/joi-to-json.d.js +2 -0
- package/dist/module/types/joi-to-json.d.js.map +1 -0
- package/dist/types/common/pagination/index.d.ts.map +1 -1
- package/dist/types/common/search/index.d.ts.map +1 -1
- package/dist/types/common/sorting/index.d.ts.map +1 -1
- package/dist/types/form/form-definition/index.d.ts.map +1 -1
- package/dist/types/form/form-editor/index.d.ts +12 -12
- package/dist/types/form/form-editor/index.d.ts.map +1 -1
- package/dist/types/form/form-manager/index.d.ts.map +1 -1
- package/dist/types/form/form-metadata/index.d.ts.map +1 -1
- package/dist/types/form/form-submission/index.d.ts.map +1 -1
- package/package.json +6 -4
- package/scripts/generate-schemas.js +238 -0
- package/scripts/schema-modules/constants.js +39 -0
- package/scripts/schema-modules/schema-processors.js +109 -0
- package/scripts/schema-modules/schema-simplifiers.js +351 -0
- package/scripts/schema-modules/title-processors.js +327 -0
- package/scripts/schema-modules/types.js +21 -0
- package/scripts/schema-modules/utils.js +41 -0
- package/src/common/pagination/index.ts +8 -1
- package/src/common/search/index.ts +17 -3
- package/src/common/sorting/index.ts +8 -2
- package/src/form/form-definition/index.ts +567 -238
- package/src/form/form-editor/index.ts +202 -29
- package/src/form/form-manager/index.ts +11 -2
- package/src/form/form-metadata/index.ts +118 -40
- package/src/form/form-submission/index.ts +33 -10
- 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()
|
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()
|
11
|
-
|
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()
|
10
|
-
|
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
|
/**
|