@planning-inspectorate/dynamic-forms 3.13.1 → 3.14.1

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 (29) hide show
  1. package/package.json +1 -1
  2. package/src/validator/address-validator.js +1 -1
  3. package/src/validator/base-validator.js +1 -1
  4. package/src/validator/conditional-required-validator.js +1 -1
  5. package/src/validator/cross-question-validator.js +1 -1
  6. package/src/validator/date-period-validator.js +1 -5
  7. package/src/validator/date-time-validator.js +1 -5
  8. package/src/validator/date-validator.js +46 -30
  9. package/src/validator/date-validator.test.js +103 -0
  10. package/src/validator/required-validator.js +1 -5
  11. package/src/validator/unit-option-entry-validator.js +1 -5
  12. package/types/src/validator/address-validator.d.ts +2 -2
  13. package/types/src/validator/address-validator.d.ts.map +1 -1
  14. package/types/src/validator/base-validator.d.ts +4 -2
  15. package/types/src/validator/base-validator.d.ts.map +1 -1
  16. package/types/src/validator/conditional-required-validator.d.ts +2 -2
  17. package/types/src/validator/conditional-required-validator.d.ts.map +1 -1
  18. package/types/src/validator/cross-question-validator.d.ts +2 -2
  19. package/types/src/validator/cross-question-validator.d.ts.map +1 -1
  20. package/types/src/validator/date-period-validator.d.ts +2 -6
  21. package/types/src/validator/date-period-validator.d.ts.map +1 -1
  22. package/types/src/validator/date-time-validator.d.ts +2 -6
  23. package/types/src/validator/date-time-validator.d.ts.map +1 -1
  24. package/types/src/validator/date-validator.d.ts +8 -10
  25. package/types/src/validator/date-validator.d.ts.map +1 -1
  26. package/types/src/validator/required-validator.d.ts +2 -6
  27. package/types/src/validator/required-validator.d.ts.map +1 -1
  28. package/types/src/validator/unit-option-entry-validator.d.ts +2 -6
  29. package/types/src/validator/unit-option-entry-validator.d.ts.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planning-inspectorate/dynamic-forms",
3
- "version": "3.13.1",
3
+ "version": "3.14.1",
4
4
  "description": "This package is for building GDS forms using a configuration-based approach.",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -41,7 +41,7 @@ export class AddressValidator extends BaseValidator {
41
41
 
42
42
  /**
43
43
  * validates response body using questionObj fieldname
44
- * @param {Question} questionObj
44
+ * @param {import('../questions/question.js').Question} questionObj
45
45
  */
46
46
  validate(questionObj) {
47
47
  const fieldName = questionObj.fieldName;
@@ -18,7 +18,7 @@ export class BaseValidator {
18
18
  * Validates response body against field validators.
19
19
  * Subclasses must override this method.
20
20
  * @abstract
21
- * @param {import('../questions/question-props.js').QuestionProps} questionObj - The question object containing the fieldName to validate.
21
+ * @param {{fieldName: string}} questionObj - The question object containing the fieldName to validate.
22
22
  * @param {import('../journey/journey-response.js').JourneyResponse} [journeyResponse] - The current journey response (optional).
23
23
  * @returns {import('express-validator').ValidationChain | import('express-validator').ValidationChain[]}
24
24
  */
@@ -31,7 +31,7 @@ export class ConditionalRequiredValidator extends BaseValidator {
31
31
 
32
32
  /**
33
33
  * validates the response body, checking the questionObj's fieldname
34
- * @param {Question} questionObj
34
+ * @param {import('../questions/options-question.js').OptionsQuestion} questionObj
35
35
  */
36
36
  validate(questionObj) {
37
37
  return questionObj.options.reduce((schema, option) => {
@@ -37,7 +37,7 @@ export class CrossQuestionValidator extends BaseValidator {
37
37
 
38
38
  /**
39
39
  * Validates response body against individual field validators.
40
- * @param {import('../questions/question-props.js').QuestionProps} questionObj - The question object containing the fieldName to validate.
40
+ * @param {import('../questions/question.js').Question} questionObj - The question object containing the fieldName to validate.
41
41
  * @param {import('../journey/journey-response.js').JourneyResponse} [journeyResponse={}] - The current journey response, used to access saved answers for validation.
42
42
  * @returns {import('express-validator').ValidationChain[]}
43
43
  */
@@ -6,10 +6,6 @@ import { enGB } from 'date-fns/locale';
6
6
  import BaseValidator from './base-validator.js';
7
7
  import { parseDateInput, startOfDay } from '../lib/date-utils.js';
8
8
 
9
- /**
10
- * @typedef {import('../components/date/question.js')} DateQuestion
11
- */
12
-
13
9
  /**
14
10
  * @typedef {Object} DateValidationSettings
15
11
  * @property {Boolean} ensureFuture
@@ -64,7 +60,7 @@ export class DatePeriodValidator extends BaseValidator {
64
60
 
65
61
  /**
66
62
  * validates the response body, checking the values sent for the date are valid
67
- * @param {DateQuestion} questionObj
63
+ * @param {import('../components/date/question.js').DateQuestion} questionObj
68
64
  */
69
65
  validate(questionObj) {
70
66
  const fieldName = questionObj.fieldName;
@@ -1,10 +1,6 @@
1
1
  import { body } from 'express-validator';
2
2
  import DateValidator from './date-validator.js';
3
3
 
4
- /**
5
- * @typedef {import('./question.js')} DateTimeQuestion
6
- */
7
-
8
4
  /**
9
5
  * enforces a user has entered a valid date
10
6
  * @class
@@ -32,7 +28,7 @@ export class DateTimeValidator extends DateValidator {
32
28
 
33
29
  /**
34
30
  * validates the response body, checking the values sent for the date are valid
35
- * @param {DateTimeQuestion} questionObj
31
+ * @param {import('../components/date-time/question.js').DateTimeQuestion} questionObj
36
32
  */
37
33
  validate(questionObj) {
38
34
  const fieldName = questionObj.fieldName;
@@ -1,19 +1,15 @@
1
1
  import { body } from 'express-validator';
2
-
3
2
  import { isAfter, isBefore, isValid, parse } from 'date-fns';
4
3
  import { enGB } from 'date-fns/locale';
5
4
 
6
5
  import BaseValidator from './base-validator.js';
7
6
  import { endOfDay, parseDateInput, startOfDay } from '../lib/date-utils.js';
8
7
 
9
- /**
10
- * @typedef {import('../components/date/question.js')} DateQuestion
11
- */
12
-
13
8
  /**
14
9
  * @typedef {Object} DateValidationSettings
15
- * @property {Boolean} ensureFuture
16
- * @property {Boolean} ensurePast
10
+ * @property {Boolean} [ensureFuture]
11
+ * @property {Boolean} [ensurePast]
12
+ * @property {Boolean} [optional]
17
13
  */
18
14
 
19
15
  /**
@@ -34,7 +30,8 @@ export class DateValidator extends BaseValidator {
34
30
  inputLabel,
35
31
  dateValidationSettings = {
36
32
  ensureFuture: false,
37
- ensurePast: false
33
+ ensurePast: false,
34
+ optional: false
38
35
  },
39
36
  errorMessages
40
37
  ) {
@@ -63,12 +60,12 @@ export class DateValidator extends BaseValidator {
63
60
  }
64
61
 
65
62
  isRequired() {
66
- return true;
63
+ return !this.dateValidationSettings.optional;
67
64
  }
68
65
 
69
66
  /**
70
67
  * validates the response body, checking the values sent for the date are valid
71
- * @param {DateQuestion} questionObj
68
+ * @param {import('../components/date/question.js').DateQuestion} questionObj
72
69
  */
73
70
  validate(questionObj) {
74
71
  const fieldName = questionObj.fieldName;
@@ -76,9 +73,21 @@ export class DateValidator extends BaseValidator {
76
73
  const monthInput = `${fieldName}_month`;
77
74
  const yearInput = `${fieldName}_year`;
78
75
 
76
+ /**
77
+ * Run before every check, if the correct param set then skip the validation
78
+ * when there is no data entered.
79
+ */
80
+ const shouldValidate = (value, { req }) => {
81
+ if (this.dateValidationSettings.optional === true) {
82
+ return !!(req.body[dayInput] || req.body[monthInput] || req.body[yearInput]);
83
+ }
84
+ return true;
85
+ };
86
+
79
87
  const rules = [
80
88
  // check all or some date inputs are not empty
81
89
  body(dayInput)
90
+ .if(shouldValidate)
82
91
  .notEmpty()
83
92
  .withMessage((_, { req }) => {
84
93
  if (!req.body[monthInput] && !req.body[yearInput]) {
@@ -96,6 +105,7 @@ export class DateValidator extends BaseValidator {
96
105
  return this.noDayErrorMessage;
97
106
  }),
98
107
  body(monthInput)
108
+ .if(shouldValidate)
99
109
  .notEmpty()
100
110
  .withMessage((_, { req }) => {
101
111
  if (req.body[dayInput] && !req.body[yearInput]) {
@@ -108,6 +118,7 @@ export class DateValidator extends BaseValidator {
108
118
  // empty error message returned
109
119
  }),
110
120
  body(yearInput)
121
+ .if(shouldValidate)
111
122
  .notEmpty()
112
123
  .withMessage((_, { req }) => {
113
124
  if (req.body[dayInput] && req.body[monthInput]) return this.noYearErrorMessage;
@@ -117,6 +128,7 @@ export class DateValidator extends BaseValidator {
117
128
 
118
129
  // check date values entered are within valid ranges
119
130
  body(dayInput)
131
+ .if(shouldValidate)
120
132
  .isInt({ min: 1, max: 31 })
121
133
  .withMessage(this.invalidDateErrorMessage)
122
134
  .bail()
@@ -135,38 +147,42 @@ export class DateValidator extends BaseValidator {
135
147
 
136
148
  return true;
137
149
  }),
138
- body(monthInput).isInt({ min: 1, max: 12 }).withMessage(this.invalidMonthErrorMessage),
139
- body(yearInput).isInt({ min: 1000, max: 9999 }).withMessage(this.invalidYearErrorMessage)
150
+ body(monthInput).if(shouldValidate).isInt({ min: 1, max: 12 }).withMessage(this.invalidMonthErrorMessage),
151
+ body(yearInput).if(shouldValidate).isInt({ min: 1000, max: 9999 }).withMessage(this.invalidYearErrorMessage)
140
152
  ];
141
153
 
142
154
  if (this.dateValidationSettings.ensurePast === true) {
143
155
  rules.push(
144
- body(dayInput).custom((value, { req }) => {
145
- const inputDate = parseDateInput({ day: value, month: req.body[monthInput], year: req.body[yearInput] });
156
+ body(dayInput)
157
+ .if(shouldValidate)
158
+ .custom((value, { req }) => {
159
+ const inputDate = parseDateInput({ day: value, month: req.body[monthInput], year: req.body[yearInput] });
146
160
 
147
- const today = endOfDay();
161
+ const today = endOfDay();
148
162
 
149
- if (isAfter(inputDate, today)) {
150
- throw new Error(this.futureDateErrorMessage);
151
- }
163
+ if (isAfter(inputDate, today)) {
164
+ throw new Error(this.futureDateErrorMessage);
165
+ }
152
166
 
153
- return true;
154
- })
167
+ return true;
168
+ })
155
169
  );
156
170
  }
157
171
 
158
172
  if (this.dateValidationSettings.ensureFuture === true) {
159
173
  rules.push(
160
- body(dayInput).custom((value, { req }) => {
161
- const inputDate = parseDateInput({ day: value, month: req.body[monthInput], year: req.body[yearInput] });
162
- const today = startOfDay();
163
-
164
- if (isBefore(inputDate, today)) {
165
- throw new Error(this.pastDateErrorMessage);
166
- }
167
-
168
- return true;
169
- })
174
+ body(dayInput)
175
+ .if(shouldValidate)
176
+ .custom((value, { req }) => {
177
+ const inputDate = parseDateInput({ day: value, month: req.body[monthInput], year: req.body[yearInput] });
178
+ const today = startOfDay();
179
+
180
+ if (isBefore(inputDate, today)) {
181
+ throw new Error(this.pastDateErrorMessage);
182
+ }
183
+
184
+ return true;
185
+ })
170
186
  );
171
187
  }
172
188
 
@@ -389,6 +389,109 @@ describe('./src/dynamic-forms/validator/date-validator.js', () => {
389
389
  assert.strictEqual(errors[`${question.fieldName}_month`].msg, errorMessages.invalidMonthErrorMessage);
390
390
  assert.strictEqual(errors[`${question.fieldName}_year`].msg, errorMessages.invalidYearErrorMessage);
391
391
  });
392
+
393
+ it('passes validation if optional is true and no fields are provided (undefined)', async () => {
394
+ const req = {
395
+ body: {
396
+ ['date-question_day']: undefined,
397
+ ['date-question_month']: undefined,
398
+ ['date-question_year']: undefined
399
+ }
400
+ };
401
+
402
+ const question = {
403
+ fieldName: 'date-question'
404
+ };
405
+
406
+ const errors = await _validationMappedErrors(req, question, 'the required date', undefined, {
407
+ optional: true
408
+ });
409
+
410
+ assert.strictEqual(Object.keys(errors).length, 0);
411
+ });
412
+
413
+ it('passes validation if optional is true and fields are empty strings', async () => {
414
+ const req = {
415
+ body: {
416
+ ['date-question_day']: '',
417
+ ['date-question_month']: '',
418
+ ['date-question_year']: ''
419
+ }
420
+ };
421
+
422
+ const question = {
423
+ fieldName: 'date-question'
424
+ };
425
+
426
+ const errors = await _validationMappedErrors(req, question, 'the required date', undefined, {
427
+ optional: true
428
+ });
429
+
430
+ assert.strictEqual(Object.keys(errors).length, 0);
431
+ });
432
+
433
+ it('throws error if optional is true but date is partially filled (missing day)', async () => {
434
+ const req = {
435
+ body: {
436
+ ['date-question_day']: '',
437
+ ['date-question_month']: '10',
438
+ ['date-question_year']: '2023'
439
+ }
440
+ };
441
+
442
+ const question = {
443
+ fieldName: 'date-question'
444
+ };
445
+
446
+ const errors = await _validationMappedErrors(req, question, 'the required date', undefined, {
447
+ optional: true
448
+ });
449
+
450
+ assert.strictEqual(Object.keys(errors).length, 1);
451
+ assert.strictEqual(errors[`${question.fieldName}_day`].msg, 'The required date must include a day');
452
+ });
453
+
454
+ it('throws error if optional is true but invalid values are provided', async () => {
455
+ const req = {
456
+ body: {
457
+ ['date-question_day']: '35',
458
+ ['date-question_month']: '10',
459
+ ['date-question_year']: '2023'
460
+ }
461
+ };
462
+
463
+ const question = {
464
+ fieldName: 'date-question'
465
+ };
466
+
467
+ const errors = await _validationMappedErrors(req, question, 'the required date', undefined, {
468
+ optional: true
469
+ });
470
+
471
+ assert.strictEqual(Object.keys(errors).length, 1);
472
+ assert.strictEqual(errors[`${question.fieldName}_day`].msg, 'The required date day must be a real day');
473
+ });
474
+
475
+ it('throws error if an object is passed without the optional key (undefined) and nothing is entered', async () => {
476
+ const req = {
477
+ body: {
478
+ ['date-question_day']: undefined,
479
+ ['date-question_month']: undefined,
480
+ ['date-question_year']: undefined
481
+ }
482
+ };
483
+
484
+ const question = {
485
+ fieldName: 'date-question'
486
+ };
487
+
488
+ const errors = await _validationMappedErrors(req, question, 'the required date', undefined, {
489
+ randomKey: true
490
+ });
491
+
492
+ assert.strictEqual(Object.keys(errors).length, 3);
493
+ assert.strictEqual(errors[`${question.fieldName}_day`].msg, 'Enter the required date');
494
+ });
392
495
  });
393
496
  });
394
497
 
@@ -2,10 +2,6 @@ import { body } from 'express-validator';
2
2
 
3
3
  import BaseValidator from './base-validator.js';
4
4
 
5
- /**
6
- * @typedef {import('../questions/question.js')} Question
7
- */
8
-
9
5
  /**
10
6
  * enforces a field is not empty
11
7
  * @class
@@ -30,7 +26,7 @@ export class RequiredValidator extends BaseValidator {
30
26
 
31
27
  /**
32
28
  * validates the response body, checking the questionObj's fieldname
33
- * @param {Question} questionObj
29
+ * @param {import('../questions/question.js').Question} questionObj
34
30
  */
35
31
  validate(questionObj) {
36
32
  return body(questionObj.fieldName).notEmpty().withMessage(this.errorMessage);
@@ -3,10 +3,6 @@ import { body } from 'express-validator';
3
3
  import BaseValidator from './base-validator.js';
4
4
  import { toArray } from '#src/lib/utils.js';
5
5
 
6
- /**
7
- * @typedef {import('../questions/question.js')} Question
8
- */
9
-
10
6
  /**
11
7
  * enforces a field is not empty when condition is satisfied
12
8
  * @class
@@ -34,7 +30,7 @@ export class UnitOptionEntryValidator extends BaseValidator {
34
30
 
35
31
  /**
36
32
  * validates the response body, checking the questionObj's fieldname
37
- * @param {Question} questionObj
33
+ * @param {import('../components/unit-option-entry/question.js').UnitOptionEntryQuestion} questionObj
38
34
  */
39
35
  validate(questionObj) {
40
36
  return questionObj.options.reduce((schema, option) => {
@@ -37,9 +37,9 @@ export class AddressValidator extends BaseValidator {
37
37
  } | undefined;
38
38
  /**
39
39
  * validates response body using questionObj fieldname
40
- * @param {Question} questionObj
40
+ * @param {import('../questions/question.js').Question} questionObj
41
41
  */
42
- validate(questionObj: Question): import("express-validator").ValidationChain[];
42
+ validate(questionObj: import("../questions/question.js").Question): import("express-validator").ValidationChain[];
43
43
  #private;
44
44
  }
45
45
  export default AddressValidator;
@@ -1 +1 @@
1
- {"version":3,"file":"address-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/address-validator.js"],"names":[],"mappings":"AAIO,4EAQN;AAGD,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,gCAAiC,GAAG,CAAC;AACrC,gCAAiC,CAAC,CAAC;AACnC,8BAA+B,GAAG,CAAC;AACnC,8BAA+B,CAAC,CAAC;AACjC,gCAAiC,CAAC,CAAC;AACnC,gCAAiC,CAAC,CAAC;AAEnC;;;GAGG;AACH;IACC;;;;OAIG;IACH,mBAFG;QAAqH,cAAc;0BAA5G,OAAO;0BAAgB,OAAO;sBAAY,OAAO;oBAAU,OAAO;sBAAY,OAAO;;KAAwB,EAKtI;IADA;sBAJyB,OAAO;sBAAgB,OAAO;kBAAY,OAAO;gBAAU,OAAO;kBAAY,OAAO;kBAIpE;IAG3C;;;OAGG;IACH,sBAFW,QAAQ,iDAYlB;;CAqGD;;0BA1JyB,qBAAqB"}
1
+ {"version":3,"file":"address-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/address-validator.js"],"names":[],"mappings":"AAIO,4EAQN;AAGD,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,gCAAiC,GAAG,CAAC;AACrC,gCAAiC,CAAC,CAAC;AACnC,8BAA+B,GAAG,CAAC;AACnC,8BAA+B,CAAC,CAAC;AACjC,gCAAiC,CAAC,CAAC;AACnC,gCAAiC,CAAC,CAAC;AAEnC;;;GAGG;AACH;IACC;;;;OAIG;IACH,mBAFG;QAAqH,cAAc;0BAA5G,OAAO;0BAAgB,OAAO;sBAAY,OAAO;oBAAU,OAAO;sBAAY,OAAO;;KAAwB,EAKtI;IADA;sBAJyB,OAAO;sBAAgB,OAAO;kBAAY,OAAO;gBAAU,OAAO;kBAAY,OAAO;kBAIpE;IAG3C;;;OAGG;IACH,sBAFW,OAAO,0BAA0B,EAAE,QAAQ,iDAYrD;;CAqGD;;0BA1JyB,qBAAqB"}
@@ -11,11 +11,13 @@ export class BaseValidator {
11
11
  * Validates response body against field validators.
12
12
  * Subclasses must override this method.
13
13
  * @abstract
14
- * @param {import('../questions/question-props.js').QuestionProps} questionObj - The question object containing the fieldName to validate.
14
+ * @param {{fieldName: string}} questionObj - The question object containing the fieldName to validate.
15
15
  * @param {import('../journey/journey-response.js').JourneyResponse} [journeyResponse] - The current journey response (optional).
16
16
  * @returns {import('express-validator').ValidationChain | import('express-validator').ValidationChain[]}
17
17
  */
18
- validate(questionObj: import("../questions/question-props.js").QuestionProps, journeyResponse?: import("../journey/journey-response.js").JourneyResponse): import("express-validator").ValidationChain | import("express-validator").ValidationChain[];
18
+ validate(questionObj: {
19
+ fieldName: string;
20
+ }, journeyResponse?: import("../journey/journey-response.js").JourneyResponse): import("express-validator").ValidationChain | import("express-validator").ValidationChain[];
19
21
  /**
20
22
  * Should the question that this validator is configured with be treated as a required question?
21
23
  *
@@ -1 +1 @@
1
- {"version":3,"file":"base-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/base-validator.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH;IACC;;OAEG;IACH,cAFU,MAAM,CAEH;IAQb;;;;;;;OAOG;IAEH,sBALW,OAAO,gCAAgC,EAAE,aAAa,oBACtD,OAAO,gCAAgC,EAAE,eAAe,GACtD,OAAO,mBAAmB,EAAE,eAAe,GAAG,OAAO,mBAAmB,EAAE,eAAe,EAAE,CAKvG;IAED;;;;;OAKG;IACH,sBAEC;CACD"}
1
+ {"version":3,"file":"base-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/base-validator.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH;IACC;;OAEG;IACH,cAFU,MAAM,CAEH;IAQb;;;;;;;OAOG;IAEH,sBALW;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,oBACnB,OAAO,gCAAgC,EAAE,eAAe,GACtD,OAAO,mBAAmB,EAAE,eAAe,GAAG,OAAO,mBAAmB,EAAE,eAAe,EAAE,CAKvG;IAED;;;;;OAKG;IACH,sBAEC;CACD"}
@@ -13,9 +13,9 @@ export class ConditionalRequiredValidator extends BaseValidator {
13
13
  constructor(errorMessage?: string);
14
14
  /**
15
15
  * validates the response body, checking the questionObj's fieldname
16
- * @param {Question} questionObj
16
+ * @param {import('../questions/options-question.js').OptionsQuestion} questionObj
17
17
  */
18
- validate(questionObj: Question): any;
18
+ validate(questionObj: import("../questions/options-question.js").OptionsQuestion): never[];
19
19
  getConditionalFieldName(questionObj: any, option: any): string;
20
20
  isValueIncluded(questionObj: any, value: any): import("express-validator").ValidationChain;
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"conditional-required-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/conditional-required-validator.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;GAGG;AACH;IAMC;;;OAGG;IACH,2BAFW,MAAM,EAQhB;IAED;;;OAGG;IACH,sBAFW,QAAQ,OAclB;IAED,+DAEC;IAED,2FAKC;CACD;;;0BAzDyB,qBAAqB"}
1
+ {"version":3,"file":"conditional-required-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/conditional-required-validator.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;GAGG;AACH;IAMC;;;OAGG;IACH,2BAFW,MAAM,EAQhB;IAED;;;OAGG;IACH,sBAFW,OAAO,kCAAkC,EAAE,eAAe,WAcpE;IAED,+DAEC;IAED,2FAKC;CACD;;;0BAzDyB,qBAAqB"}
@@ -23,11 +23,11 @@ export class CrossQuestionValidator extends BaseValidator {
23
23
  useBodyValues: boolean;
24
24
  /**
25
25
  * Validates response body against individual field validators.
26
- * @param {import('../questions/question-props.js').QuestionProps} questionObj - The question object containing the fieldName to validate.
26
+ * @param {import('../questions/question.js').Question} questionObj - The question object containing the fieldName to validate.
27
27
  * @param {import('../journey/journey-response.js').JourneyResponse} [journeyResponse={}] - The current journey response, used to access saved answers for validation.
28
28
  * @returns {import('express-validator').ValidationChain[]}
29
29
  */
30
- validate(questionObj: import("../questions/question-props.js").QuestionProps, journeyResponse?: import("../journey/journey-response.js").JourneyResponse): import("express-validator").ValidationChain[];
30
+ validate(questionObj: import("../questions/question.js").Question, journeyResponse?: import("../journey/journey-response.js").JourneyResponse): import("express-validator").ValidationChain[];
31
31
  }
32
32
  export default CrossQuestionValidator;
33
33
  import BaseValidator from './base-validator.js';
@@ -1 +1 @@
1
- {"version":3,"file":"cross-question-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/cross-question-validator.js"],"names":[],"mappings":"AAGA;;GAEG;AACH;IAQC;;;;;;;OAOG;IACH,yEANG;QAAuB,mBAAmB,EAAlC,MAAM;QACyE,kBAAkB,EAAjG,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,KAAK,OAAO,CAAC,GAAE,IAAI;QACrD,aAAa;KACtC,EAgBF;IA5BD,qBAAqB;IACrB,qBADW,MAAM,CACG;IACpB,+EAA+E;IAC/E,oBADW,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,KAAK,OAAO,CAAC,CACxD;IACnB,sBAAsB;IACtB,eADW,OAAO,CACJ;IAyBd;;;;;OAKG;IACH,sBAJW,OAAO,gCAAgC,EAAE,aAAa,oBACtD,OAAO,gCAAgC,EAAE,eAAe,GACtD,OAAO,mBAAmB,EAAE,eAAe,EAAE,CAqBzD;CACD;;0BA/DyB,qBAAqB"}
1
+ {"version":3,"file":"cross-question-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/cross-question-validator.js"],"names":[],"mappings":"AAGA;;GAEG;AACH;IAQC;;;;;;;OAOG;IACH,yEANG;QAAuB,mBAAmB,EAAlC,MAAM;QACyE,kBAAkB,EAAjG,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,KAAK,OAAO,CAAC,GAAE,IAAI;QACrD,aAAa;KACtC,EAgBF;IA5BD,qBAAqB;IACrB,qBADW,MAAM,CACG;IACpB,+EAA+E;IAC/E,oBADW,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,KAAK,OAAO,CAAC,CACxD;IACnB,sBAAsB;IACtB,eADW,OAAO,CACJ;IAyBd;;;;;OAKG;IACH,sBAJW,OAAO,0BAA0B,EAAE,QAAQ,oBAC3C,OAAO,gCAAgC,EAAE,eAAe,GACtD,OAAO,mBAAmB,EAAE,eAAe,EAAE,CAqBzD;CACD;;0BA/DyB,qBAAqB"}
@@ -1,6 +1,3 @@
1
- /**
2
- * @typedef {import('../components/date/question.js')} DateQuestion
3
- */
4
1
  /**
5
2
  * @typedef {Object} DateValidationSettings
6
3
  * @property {Boolean} ensureFuture
@@ -34,9 +31,9 @@ export class DatePeriodValidator extends BaseValidator {
34
31
  pastDateErrorMessage: any;
35
32
  /**
36
33
  * validates the response body, checking the values sent for the date are valid
37
- * @param {DateQuestion} questionObj
34
+ * @param {import('../components/date/question.js').DateQuestion} questionObj
38
35
  */
39
- validate(questionObj: DateQuestion): import("express-validator").ValidationChain[];
36
+ validate(questionObj: import("../components/date/question.js").DateQuestion): import("express-validator").ValidationChain[];
40
37
  rulesForNotEmptyInput({ dayInput, monthInput, yearInput }: {
41
38
  dayInput: any;
42
39
  monthInput: any;
@@ -55,7 +52,6 @@ export class DatePeriodValidator extends BaseValidator {
55
52
  #private;
56
53
  }
57
54
  export default DatePeriodValidator;
58
- export type DateQuestion = typeof import("../components/date/question.js");
59
55
  export type DateValidationSettings = {
60
56
  ensureFuture: boolean;
61
57
  ensurePast: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"date-period-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/date-period-validator.js"],"names":[],"mappings":"AAQA;;GAEG;AAEH;;;;GAIG;AAEH;;;GAGG;AACH;IAIC;;;;;OAKG;IACH,wBAJW,MAAM,2BACN,sBAAsB,kBACtB,MAAM,EAgChB;IAvCD,qCAAqC;IACrC,wBADW,sBAAsB,CACV;IAoBtB,uBAAmG;IACnG,uBAAmG;IACnG,yBAAyG;IACzG,wBAAsG;IACtG,4BAAkH;IAClH,2BAA+G;IAC/G,6BACuF;IACvF,6BACuF;IACvF,8BACyF;IACzF,6BACuF;IACvF,4BAAkH;IAClH,0BAA4G;IAK7G;;;OAGG;IACH,sBAFW,YAAY,iDAsBtB;IAED;;;;sDAuCC;IAED;;;;sDAwBC;IAED;;;;sDAuBC;;CA6BD;;;;;;;0BA5MyB,qBAAqB"}
1
+ {"version":3,"file":"date-period-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/date-period-validator.js"],"names":[],"mappings":"AAQA;;;;GAIG;AAEH;;;GAGG;AACH;IAIC;;;;;OAKG;IACH,wBAJW,MAAM,2BACN,sBAAsB,kBACtB,MAAM,EAgChB;IAvCD,qCAAqC;IACrC,wBADW,sBAAsB,CACV;IAoBtB,uBAAmG;IACnG,uBAAmG;IACnG,yBAAyG;IACzG,wBAAsG;IACtG,4BAAkH;IAClH,2BAA+G;IAC/G,6BACuF;IACvF,6BACuF;IACvF,8BACyF;IACzF,6BACuF;IACvF,4BAAkH;IAClH,0BAA4G;IAK7G;;;OAGG;IACH,sBAFW,OAAO,gCAAgC,EAAE,YAAY,iDAsB/D;IAED;;;;sDAuCC;IAED;;;;sDAwBC;IAED;;;;sDAuBC;;CA6BD;;;;;;0BAxMyB,qBAAqB"}
@@ -1,6 +1,3 @@
1
- /**
2
- * @typedef {import('./question.js')} DateTimeQuestion
3
- */
4
1
  /**
5
2
  * enforces a user has entered a valid date
6
3
  * @class
@@ -17,11 +14,10 @@ export class DateTimeValidator extends DateValidator {
17
14
  timeInputLabel: string;
18
15
  /**
19
16
  * validates the response body, checking the values sent for the date are valid
20
- * @param {DateTimeQuestion} questionObj
17
+ * @param {import('../components/date-time/question.js').DateTimeQuestion} questionObj
21
18
  */
22
- validate(questionObj: DateTimeQuestion): import("express-validator").ValidationChain[];
19
+ validate(questionObj: import("../components/date-time/question.js").DateTimeQuestion): import("express-validator").ValidationChain[];
23
20
  }
24
21
  export default DateTimeValidator;
25
- export type DateTimeQuestion = any;
26
22
  import DateValidator from './date-validator.js';
27
23
  //# sourceMappingURL=date-time-validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"date-time-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/date-time-validator.js"],"names":[],"mappings":"AAGA;;GAEG;AAEH;;;GAGG;AACH;IACC;;;;;;OAMG;IACH,4BALW,MAAM,mBACN,MAAM,2BACN,sBAAsB,sBACtB,MAAM,EAahB;IADA,uBAAoC;IAGrC;;;OAGG;IACH,sBAFW,gBAAgB,iDAsC1B;CACD;;;0BAxEyB,qBAAqB"}
1
+ {"version":3,"file":"date-time-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/date-time-validator.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH;IACC;;;;;;OAMG;IACH,4BALW,MAAM,mBACN,MAAM,2BACN,sBAAsB,sBACtB,MAAM,EAahB;IADA,uBAAoC;IAGrC;;;OAGG;IACH,sBAFW,OAAO,qCAAqC,EAAE,gBAAgB,iDAsCxE;CACD;;0BApEyB,qBAAqB"}
@@ -1,10 +1,8 @@
1
- /**
2
- * @typedef {import('../components/date/question.js')} DateQuestion
3
- */
4
1
  /**
5
2
  * @typedef {Object} DateValidationSettings
6
- * @property {Boolean} ensureFuture
7
- * @property {Boolean} ensurePast
3
+ * @property {Boolean} [ensureFuture]
4
+ * @property {Boolean} [ensurePast]
5
+ * @property {Boolean} [optional]
8
6
  */
9
7
  /**
10
8
  * enforces a user has entered a valid date
@@ -34,16 +32,16 @@ export class DateValidator extends BaseValidator {
34
32
  pastDateErrorMessage: any;
35
33
  /**
36
34
  * validates the response body, checking the values sent for the date are valid
37
- * @param {DateQuestion} questionObj
35
+ * @param {import('../components/date/question.js').DateQuestion} questionObj
38
36
  */
39
- validate(questionObj: DateQuestion): import("express-validator").ValidationChain[];
37
+ validate(questionObj: import("../components/date/question.js").DateQuestion): import("express-validator").ValidationChain[];
40
38
  #private;
41
39
  }
42
40
  export default DateValidator;
43
- export type DateQuestion = typeof import("../components/date/question.js");
44
41
  export type DateValidationSettings = {
45
- ensureFuture: boolean;
46
- ensurePast: boolean;
42
+ ensureFuture?: boolean | undefined;
43
+ ensurePast?: boolean | undefined;
44
+ optional?: boolean | undefined;
47
45
  };
48
46
  import BaseValidator from './base-validator.js';
49
47
  //# sourceMappingURL=date-validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"date-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/date-validator.js"],"names":[],"mappings":"AAQA;;GAEG;AAEH;;;;GAIG;AAEH;;;GAGG;AACH;IAIC;;;;;OAKG;IACH,wBAJW,MAAM,2BACN,sBAAsB,kBACtB,MAAM,EAgChB;IAvCD,qCAAqC;IACrC,wBADW,sBAAsB,CACV;IAoBtB,uBAAmG;IACnG,uBAAmG;IACnG,yBAAyG;IACzG,wBAAsG;IACtG,4BAAkH;IAClH,2BAA+G;IAC/G,6BACuF;IACvF,6BACuF;IACvF,8BACyF;IACzF,6BACuF;IACvF,4BAAkH;IAClH,0BAA4G;IAS7G;;;OAGG;IACH,sBAFW,YAAY,iDAuGtB;;CA6BD;;;;;;;0BArMyB,qBAAqB"}
1
+ {"version":3,"file":"date-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/date-validator.js"],"names":[],"mappings":"AAOA;;;;;GAKG;AAEH;;;GAGG;AACH;IAIC;;;;;OAKG;IACH,wBAJW,MAAM,2BACN,sBAAsB,kBACtB,MAAM,EAiChB;IAxCD,qCAAqC;IACrC,wBADW,sBAAsB,CACV;IAqBtB,uBAAmG;IACnG,uBAAmG;IACnG,yBAAyG;IACzG,wBAAsG;IACtG,4BAAkH;IAClH,2BAA+G;IAC/G,6BACuF;IACvF,6BACuF;IACvF,8BACyF;IACzF,6BACuF;IACvF,4BAAkH;IAClH,0BAA4G;IAS7G;;;OAGG;IACH,sBAFW,OAAO,gCAAgC,EAAE,YAAY,iDA0H/D;;CA6BD;;;;;;;0BAtNyB,qBAAqB"}
@@ -1,6 +1,3 @@
1
- /**
2
- * @typedef {import('../questions/question.js')} Question
3
- */
4
1
  /**
5
2
  * enforces a field is not empty
6
3
  * @class
@@ -13,11 +10,10 @@ export class RequiredValidator extends BaseValidator {
13
10
  constructor(errorMessage?: string);
14
11
  /**
15
12
  * validates the response body, checking the questionObj's fieldname
16
- * @param {Question} questionObj
13
+ * @param {import('../questions/question.js').Question} questionObj
17
14
  */
18
- validate(questionObj: Question): import("express-validator").ValidationChain;
15
+ validate(questionObj: import("../questions/question.js").Question): import("express-validator").ValidationChain;
19
16
  }
20
17
  export default RequiredValidator;
21
- export type Question = typeof import("../questions/question.js");
22
18
  import BaseValidator from './base-validator.js';
23
19
  //# sourceMappingURL=required-validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"required-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/required-validator.js"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;GAGG;AACH;IAMC;;;OAGG;IACH,2BAFW,MAAM,EAQhB;IAED;;;OAGG;IACH,sBAFW,QAAQ,+CAIlB;CAKD;;;0BAvCyB,qBAAqB"}
1
+ {"version":3,"file":"required-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/required-validator.js"],"names":[],"mappings":"AAIA;;;GAGG;AACH;IAMC;;;OAGG;IACH,2BAFW,MAAM,EAQhB;IAED;;;OAGG;IACH,sBAFW,OAAO,0BAA0B,EAAE,QAAQ,+CAIrD;CAKD;;0BAnCyB,qBAAqB"}
@@ -1,6 +1,3 @@
1
- /**
2
- * @typedef {import('../questions/question.js')} Question
3
- */
4
1
  /**
5
2
  * enforces a field is not empty when condition is satisfied
6
3
  * @class
@@ -30,12 +27,11 @@ export class UnitOptionEntryValidator extends BaseValidator {
30
27
  regexMessage: string;
31
28
  /**
32
29
  * validates the response body, checking the questionObj's fieldname
33
- * @param {Question} questionObj
30
+ * @param {import('../components/unit-option-entry/question.js').UnitOptionEntryQuestion} questionObj
34
31
  */
35
- validate(questionObj: Question): any;
32
+ validate(questionObj: import("../components/unit-option-entry/question.js").UnitOptionEntryQuestion): never[];
36
33
  isValueIncluded(questionObj: any, value: any): import("express-validator").ValidationChain;
37
34
  }
38
35
  export default UnitOptionEntryValidator;
39
- export type Question = typeof import("../questions/question.js");
40
36
  import BaseValidator from './base-validator.js';
41
37
  //# sourceMappingURL=unit-option-entry-validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unit-option-entry-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/unit-option-entry-validator.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;GAGG;AACH;IACC;;;;;;;;OAQG;IAEH,oEARG;QAAwB,YAAY;QACZ,IAAI;QACJ,GAAG;QACH,GAAG;QACJ,KAAK;QACJ,YAAY;KAAC,EAWvC;IALA,aAA2B;IAC3B,wBAAc;IACd,wBAAc;IACd,WAAkB;IAClB,qBAA0D;IAG3D;;;OAGG;IACH,sBAFW,QAAQ,OA4ClB;IAED,2FAKC;CACD;;;0BAtFyB,qBAAqB"}
1
+ {"version":3,"file":"unit-option-entry-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/unit-option-entry-validator.js"],"names":[],"mappings":"AAKA;;;GAGG;AACH;IACC;;;;;;;;OAQG;IAEH,oEARG;QAAwB,YAAY;QACZ,IAAI;QACJ,GAAG;QACH,GAAG;QACJ,KAAK;QACJ,YAAY;KAAC,EAWvC;IALA,aAA2B;IAC3B,wBAAc;IACd,wBAAc;IACd,WAAkB;IAClB,qBAA0D;IAG3D;;;OAGG;IACH,sBAFW,OAAO,6CAA6C,EAAE,uBAAuB,WA4CvF;IAED,2FAKC;CACD;;0BAlFyB,qBAAqB"}