@defra/forms-model 3.0.569 → 3.0.571
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/dist/module/form/form-definition/index.js +20 -1
 - package/dist/module/form/form-definition/index.js.map +1 -1
 - package/dist/module/form/form-manager/types.js +5 -0
 - package/dist/module/form/form-manager/types.js.map +1 -1
 - package/dist/module/pages/helpers.js +0 -21
 - package/dist/module/pages/helpers.js.map +1 -1
 - package/dist/module/pages/index.js +1 -1
 - package/dist/module/pages/index.js.map +1 -1
 - package/dist/types/form/form-definition/index.d.ts +2 -1
 - package/dist/types/form/form-definition/index.d.ts.map +1 -1
 - package/dist/types/form/form-manager/types.d.ts +1 -0
 - package/dist/types/form/form-manager/types.d.ts.map +1 -1
 - package/dist/types/pages/helpers.d.ts +0 -6
 - package/dist/types/pages/helpers.d.ts.map +1 -1
 - package/dist/types/pages/index.d.ts +1 -1
 - package/dist/types/pages/index.d.ts.map +1 -1
 - package/package.json +1 -1
 - package/schemas/component-schema-v2.json +27 -0
 - package/schemas/component-schema.json +27 -0
 - package/schemas/form-definition-schema.json +81 -0
 - package/schemas/form-definition-v2-schema.json +135 -0
 - package/schemas/list-schema-v2.json +54 -0
 - package/schemas/list-schema.json +54 -0
 - package/schemas/page-schema-v2.json +81 -0
 - package/schemas/page-schema.json +27 -0
 - package/src/form/form-definition/index.ts +28 -1
 - package/src/form/form-manager/types.ts +5 -0
 - package/src/pages/helpers.ts +0 -21
 - package/src/pages/index.ts +0 -1
 
    
        package/schemas/page-schema.json
    CHANGED
    
    | 
         @@ -181,6 +181,33 @@ 
     | 
|
| 
       181 
181 
     | 
    
         
             
                            "type": "number",
         
     | 
| 
       182 
182 
     | 
    
         
             
                            "description": "Exact length required for validation",
         
     | 
| 
       183 
183 
     | 
    
         
             
                            "title": "Length"
         
     | 
| 
      
 184 
     | 
    
         
            +
                          },
         
     | 
| 
      
 185 
     | 
    
         
            +
                          "regex": {
         
     | 
| 
      
 186 
     | 
    
         
            +
                            "type": [
         
     | 
| 
      
 187 
     | 
    
         
            +
                              "array",
         
     | 
| 
      
 188 
     | 
    
         
            +
                              "boolean",
         
     | 
| 
      
 189 
     | 
    
         
            +
                              "number",
         
     | 
| 
      
 190 
     | 
    
         
            +
                              "object",
         
     | 
| 
      
 191 
     | 
    
         
            +
                              "string",
         
     | 
| 
      
 192 
     | 
    
         
            +
                              "null"
         
     | 
| 
      
 193 
     | 
    
         
            +
                            ],
         
     | 
| 
      
 194 
     | 
    
         
            +
                            "oneOf": [
         
     | 
| 
      
 195 
     | 
    
         
            +
                              {
         
     | 
| 
      
 196 
     | 
    
         
            +
                                "type": "string",
         
     | 
| 
      
 197 
     | 
    
         
            +
                                "description": "Regex expression for validation of user field content",
         
     | 
| 
      
 198 
     | 
    
         
            +
                                "title": "Regex (string)"
         
     | 
| 
      
 199 
     | 
    
         
            +
                              },
         
     | 
| 
      
 200 
     | 
    
         
            +
                              {
         
     | 
| 
      
 201 
     | 
    
         
            +
                                "type": "string",
         
     | 
| 
      
 202 
     | 
    
         
            +
                                "title": "Regex (string)"
         
     | 
| 
      
 203 
     | 
    
         
            +
                              }
         
     | 
| 
      
 204 
     | 
    
         
            +
                            ],
         
     | 
| 
      
 205 
     | 
    
         
            +
                            "title": "Regex",
         
     | 
| 
      
 206 
     | 
    
         
            +
                            "description": "The regex value.",
         
     | 
| 
      
 207 
     | 
    
         
            +
                            "oneOfTitles": [
         
     | 
| 
      
 208 
     | 
    
         
            +
                              "Regex (string)",
         
     | 
| 
      
 209 
     | 
    
         
            +
                              "Regex (string)"
         
     | 
| 
      
 210 
     | 
    
         
            +
                            ]
         
     | 
| 
       184 
211 
     | 
    
         
             
                          }
         
     | 
| 
       185 
212 
     | 
    
         
             
                        },
         
     | 
| 
       186 
213 
     | 
    
         
             
                        "additionalProperties": true,
         
     | 
| 
         @@ -444,6 +444,21 @@ export const conditionWrapperSchemaV2 = Joi.object<ConditionWrapperV2>() 
     | 
|
| 
       444 
444 
     | 
    
         
             
              })
         
     | 
| 
       445 
445 
     | 
    
         
             
              .description('Condition schema for V2 forms')
         
     | 
| 
       446 
446 
     | 
    
         | 
| 
      
 447 
     | 
    
         
            +
            export const regexCustomValidator = (
         
     | 
| 
      
 448 
     | 
    
         
            +
              value: string,
         
     | 
| 
      
 449 
     | 
    
         
            +
              helpers: CustomHelpers<string>
         
     | 
| 
      
 450 
     | 
    
         
            +
            ) => {
         
     | 
| 
      
 451 
     | 
    
         
            +
              try {
         
     | 
| 
      
 452 
     | 
    
         
            +
                const _regex = new RegExp(value)
         
     | 
| 
      
 453 
     | 
    
         
            +
              } catch {
         
     | 
| 
      
 454 
     | 
    
         
            +
                return helpers.error('custom.incompatible', {
         
     | 
| 
      
 455 
     | 
    
         
            +
                  errorType: FormDefinitionErrorType.Incompatible,
         
     | 
| 
      
 456 
     | 
    
         
            +
                  errorCode: FormDefinitionError.IncompatibleQuestionRegex
         
     | 
| 
      
 457 
     | 
    
         
            +
                })
         
     | 
| 
      
 458 
     | 
    
         
            +
              }
         
     | 
| 
      
 459 
     | 
    
         
            +
              return value
         
     | 
| 
      
 460 
     | 
    
         
            +
            }
         
     | 
| 
      
 461 
     | 
    
         
            +
             
     | 
| 
       447 
462 
     | 
    
         
             
            export const componentSchema = Joi.object<ComponentDef>()
         
     | 
| 
       448 
463 
     | 
    
         
             
              .description('Form component definition specifying UI element behavior')
         
     | 
| 
       449 
464 
     | 
    
         
             
              .keys({
         
     | 
| 
         @@ -531,7 +546,19 @@ export const componentSchema = Joi.object<ComponentDef>() 
     | 
|
| 
       531 
546 
     | 
    
         
             
                    .description('Maximum value or length for validation'),
         
     | 
| 
       532 
547 
     | 
    
         
             
                  length: Joi.number()
         
     | 
| 
       533 
548 
     | 
    
         
             
                    .empty('')
         
     | 
| 
       534 
     | 
    
         
            -
                    .description('Exact length required for validation')
         
     | 
| 
      
 549 
     | 
    
         
            +
                    .description('Exact length required for validation'),
         
     | 
| 
      
 550 
     | 
    
         
            +
                  regex: Joi.when('type', {
         
     | 
| 
      
 551 
     | 
    
         
            +
                    is: Joi.string().valid(
         
     | 
| 
      
 552 
     | 
    
         
            +
                      ComponentType.TextField,
         
     | 
| 
      
 553 
     | 
    
         
            +
                      ComponentType.MultilineTextField
         
     | 
| 
      
 554 
     | 
    
         
            +
                    ),
         
     | 
| 
      
 555 
     | 
    
         
            +
                    then: Joi.string() // NOSONAR
         
     | 
| 
      
 556 
     | 
    
         
            +
                      .trim()
         
     | 
| 
      
 557 
     | 
    
         
            +
                      .optional()
         
     | 
| 
      
 558 
     | 
    
         
            +
                      .description('Regex expression for validation of user field content')
         
     | 
| 
      
 559 
     | 
    
         
            +
                      .custom(regexCustomValidator),
         
     | 
| 
      
 560 
     | 
    
         
            +
                    otherwise: Joi.string().allow('')
         
     | 
| 
      
 561 
     | 
    
         
            +
                  }).messages({ 'custom.incompatible': 'The regex expression is invalid' })
         
     | 
| 
       535 
562 
     | 
    
         
             
                })
         
     | 
| 
       536 
563 
     | 
    
         
             
                  .unknown(true)
         
     | 
| 
       537 
564 
     | 
    
         
             
                  .default({})
         
     | 
| 
         @@ -46,6 +46,7 @@ export enum FormDefinitionError { 
     | 
|
| 
       46 
46 
     | 
    
         
             
              RefConditionConditionId = 'ref_condition_condition_id',
         
     | 
| 
       47 
47 
     | 
    
         
             
              RefPageComponentList = 'ref_page_component_list',
         
     | 
| 
       48 
48 
     | 
    
         
             
              IncompatibleConditionComponentType = 'incompatible_condition_component_type',
         
     | 
| 
      
 49 
     | 
    
         
            +
              IncompatibleQuestionRegex = 'incompatible_question_regex',
         
     | 
| 
       49 
50 
     | 
    
         
             
              Other = 'other'
         
     | 
| 
       50 
51 
     | 
    
         
             
            }
         
     | 
| 
       51 
52 
     | 
    
         | 
| 
         @@ -142,6 +143,10 @@ export const formDefinitionErrors: FormDefinitionErrors = { 
     | 
|
| 
       142 
143 
     | 
    
         
             
                key: 'componentId',
         
     | 
| 
       143 
144 
     | 
    
         
             
                type: FormDefinitionErrorType.Incompatible
         
     | 
| 
       144 
145 
     | 
    
         
             
              },
         
     | 
| 
      
 146 
     | 
    
         
            +
              [FormDefinitionError.IncompatibleQuestionRegex]: {
         
     | 
| 
      
 147 
     | 
    
         
            +
                key: 'regex',
         
     | 
| 
      
 148 
     | 
    
         
            +
                type: FormDefinitionErrorType.Incompatible
         
     | 
| 
      
 149 
     | 
    
         
            +
              },
         
     | 
| 
       145 
150 
     | 
    
         
             
              [FormDefinitionError.Other]: {
         
     | 
| 
       146 
151 
     | 
    
         
             
                key: '',
         
     | 
| 
       147 
152 
     | 
    
         
             
                type: FormDefinitionErrorType.Type
         
     | 
    
        package/src/pages/helpers.ts
    CHANGED
    
    | 
         @@ -135,27 +135,6 @@ export function showRepeaterSettings(page: Page): boolean { 
     | 
|
| 
       135 
135 
     | 
    
         
             
              return true
         
     | 
| 
       136 
136 
     | 
    
         
             
            }
         
     | 
| 
       137 
137 
     | 
    
         | 
| 
       138 
     | 
    
         
            -
            /**
         
     | 
| 
       139 
     | 
    
         
            -
             * High level check for whether file upload component should be omitted
         
     | 
| 
       140 
     | 
    
         
            -
             * @param { Page | undefined } page
         
     | 
| 
       141 
     | 
    
         
            -
             * @returns {boolean}
         
     | 
| 
       142 
     | 
    
         
            -
             */
         
     | 
| 
       143 
     | 
    
         
            -
            export function omitFileUploadComponent(page: Page | undefined): boolean {
         
     | 
| 
       144 
     | 
    
         
            -
              if (page?.controller === ControllerType.Repeat) {
         
     | 
| 
       145 
     | 
    
         
            -
                return true
         
     | 
| 
       146 
     | 
    
         
            -
              }
         
     | 
| 
       147 
     | 
    
         
            -
              if (!hasComponents(page)) {
         
     | 
| 
       148 
     | 
    
         
            -
                return false
         
     | 
| 
       149 
     | 
    
         
            -
              }
         
     | 
| 
       150 
     | 
    
         
            -
              if (page.components.length > 1) {
         
     | 
| 
       151 
     | 
    
         
            -
                return true
         
     | 
| 
       152 
     | 
    
         
            -
              }
         
     | 
| 
       153 
     | 
    
         
            -
              if (includesFileUploadField(page.components)) {
         
     | 
| 
       154 
     | 
    
         
            -
                return true
         
     | 
| 
       155 
     | 
    
         
            -
              }
         
     | 
| 
       156 
     | 
    
         
            -
              return false
         
     | 
| 
       157 
     | 
    
         
            -
            }
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
138 
     | 
    
         
             
            /**
         
     | 
| 
       160 
139 
     | 
    
         
             
             * Gets page title, or title of first question (if no page title set)
         
     | 
| 
       161 
140 
     | 
    
         
             
             * @param {Page} page
         
     |