@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.
- 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 +47 -37
- package/dist/module/form/form-editor/index.js.map +1 -1
- package/dist/module/form/form-editor/types.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 +17 -7
- package/dist/types/form/form-editor/index.d.ts.map +1 -1
- package/dist/types/form/form-editor/types.d.ts +45 -1
- package/dist/types/form/form-editor/types.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 +207 -24
- package/src/form/form-editor/types.ts +69 -0
- 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
@@ -15,15 +15,24 @@ export declare const nameSchema: Joi.StringSchema<string>;
|
|
15
15
|
export declare const questionSchema: Joi.StringSchema<string>;
|
16
16
|
export declare const hintTextSchema: Joi.StringSchema<string>;
|
17
17
|
export declare const questionOptionalSchema: Joi.StringSchema<string>;
|
18
|
+
export declare const exactFilesSchema: Joi.NumberSchema<number>;
|
19
|
+
export declare const minFilesSchema: Joi.NumberSchema<number>;
|
20
|
+
export declare const maxFilesSchema: Joi.NumberSchema<number>;
|
21
|
+
export declare const fileTypesSchema: Joi.ArraySchema<any[]>;
|
22
|
+
export declare const documentTypesSchema: Joi.ArraySchema<any[]>;
|
23
|
+
export declare const imageTypesSchema: Joi.ArraySchema<any[]>;
|
24
|
+
export declare const tabularDataTypesSchema: Joi.ArraySchema<any[]>;
|
25
|
+
export declare const enhancedActionSchema: Joi.StringSchema<string>;
|
26
|
+
export declare const radioIdSchema: Joi.StringSchema<string>;
|
27
|
+
export declare const radioLabelSchema: Joi.StringSchema<string>;
|
28
|
+
export declare const radioHintSchema: Joi.StringSchema<string>;
|
29
|
+
export declare const radioValueSchema: Joi.StringSchema<string>;
|
18
30
|
export declare const shortDescriptionSchema: Joi.StringSchema<string>;
|
19
31
|
export declare const pageHeadingAndGuidanceSchema: Joi.StringSchema<string>;
|
20
32
|
export declare const pageHeadingSchema: Joi.StringSchema<string>;
|
21
33
|
export declare const guidanceTextSchema: Joi.StringSchema<string>;
|
22
34
|
export declare const needDeclarationSchema: Joi.StringSchema<string>;
|
23
35
|
export declare const declarationTextSchema: Joi.StringSchema<string>;
|
24
|
-
export declare const exactFilesSchema: Joi.NumberSchema<number>;
|
25
|
-
export declare const minFilesSchema: Joi.NumberSchema<number>;
|
26
|
-
export declare const maxFilesSchema: Joi.NumberSchema<number>;
|
27
36
|
export declare const minSchema: Joi.NumberSchema<number>;
|
28
37
|
export declare const maxSchema: Joi.NumberSchema<number>;
|
29
38
|
export declare const minLengthSchema: Joi.NumberSchema<number>;
|
@@ -36,13 +45,10 @@ export declare const regexSchema: Joi.StringSchema<string>;
|
|
36
45
|
export declare const rowsSchema: Joi.NumberSchema<number>;
|
37
46
|
export declare const suffixSchema: Joi.StringSchema<string>;
|
38
47
|
export declare const classesSchema: Joi.StringSchema<string>;
|
39
|
-
export declare const fileTypesSchema: Joi.ArraySchema<any[]>;
|
40
|
-
export declare const documentTypesSchema: Joi.ArraySchema<any[]>;
|
41
|
-
export declare const imageTypesSchema: Joi.ArraySchema<any[]>;
|
42
|
-
export declare const tabularDataTypesSchema: Joi.ArraySchema<any[]>;
|
43
48
|
export declare const questionDetailsFullSchema: {
|
44
49
|
classesSchema: Joi.StringSchema<string>;
|
45
50
|
documentTypesSchema: Joi.ArraySchema<any[]>;
|
51
|
+
enhancedActionSchema: Joi.StringSchema<string>;
|
46
52
|
exactFilesSchema: Joi.NumberSchema<number>;
|
47
53
|
fileTypesSchema: Joi.ArraySchema<any[]>;
|
48
54
|
hintTextSchema: Joi.StringSchema<string>;
|
@@ -61,6 +67,10 @@ export declare const questionDetailsFullSchema: {
|
|
61
67
|
questionOptionalSchema: Joi.StringSchema<string>;
|
62
68
|
questionSchema: Joi.StringSchema<string>;
|
63
69
|
questionTypeFullSchema: Joi.StringSchema<string>;
|
70
|
+
radioHintSchema: Joi.StringSchema<string>;
|
71
|
+
radioIdSchema: Joi.StringSchema<string>;
|
72
|
+
radioLabelSchema: Joi.StringSchema<string>;
|
73
|
+
radioValueSchema: Joi.StringSchema<string>;
|
64
74
|
regexSchema: Joi.StringSchema<string>;
|
65
75
|
rowsSchema: Joi.NumberSchema<number>;
|
66
76
|
shortDescriptionSchema: Joi.StringSchema<string>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/form/form-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAGrB,OAAO,EACL,KAAK,mCAAmC,EACxC,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC7B,MAAM,iCAAiC,CAAA;AAExC,oBAAY,oBAAoB;IAC9B,qBAAqB,qBAAqB;IAC1C,YAAY,YAAY;IACxB,YAAY,YAAY;CACzB;AAED,eAAO,MAAM,cAAc,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/form/form-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAGrB,OAAO,EACL,KAAK,mCAAmC,EACxC,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC7B,MAAM,iCAAiC,CAAA;AAExC,oBAAY,oBAAoB;IAC9B,qBAAqB,qBAAqB;IAC1C,YAAY,YAAY;IACxB,YAAY,YAAY;CACzB;AAED,eAAO,MAAM,cAAc,0BAG6C,CAAA;AAExE,eAAO,MAAM,kBAAkB,0BAe2C,CAAA;AAE1E,eAAO,MAAM,sBAAsB,0BAiBmC,CAAA;AAEtE,eAAO,MAAM,sBAAsB,0BAOmB,CAAA;AAEtD,eAAO,MAAM,aAAa,0BAE0C,CAAA;AACpE,eAAO,MAAM,aAAa,0BAQ0B,CAAA;AAEpD,eAAO,MAAM,UAAU,0BAG0B,CAAA;AAEjD,eAAO,MAAM,cAAc,0BAG8B,CAAA;AAEzD,eAAO,MAAM,cAAc,0BAI0C,CAAA;AAErE,eAAO,MAAM,sBAAsB,0BAMhC,CAAA;AAEH,eAAO,MAAM,gBAAgB,0BAO1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+BrC,CAAA;AAED,eAAO,MAAM,uBAAuB;;;CAGnC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,yBAAyB,uCAGmC,CAAA;AAEzE,eAAO,MAAM,sCAAsC;;CAElD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,wCAAwC,uDAIO,CAAA;AAE5D,eAAO,MAAM,2BAA2B;;;;;CAKvC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,6BAA6B,2CAMrC,CAAA;AAEL,eAAO,MAAM,+BAA+B;;;;CAI3C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iCAAiC,+CAI8B,CAAA"}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { type ComponentDef } from '../../components/types.js';
|
1
2
|
/**
|
2
3
|
* Interface for `FormEditor` Joi schema
|
3
4
|
*/
|
@@ -138,12 +139,53 @@ export interface FormEditor {
|
|
138
139
|
* The types of tabular data files for upload
|
139
140
|
*/
|
140
141
|
tabularDataTypes: string[];
|
142
|
+
/**
|
143
|
+
* The action required from within a sub-section
|
144
|
+
*/
|
145
|
+
enhancedAction: string;
|
146
|
+
/**
|
147
|
+
* Placeholder for inserted section to handle adding/editing radios or checkboxes
|
148
|
+
*/
|
149
|
+
radiosOrCheckboxes: string;
|
150
|
+
/**
|
151
|
+
* The unique id of the radio item
|
152
|
+
*/
|
153
|
+
radioId: string;
|
154
|
+
/**
|
155
|
+
* The display text of the radio item
|
156
|
+
*/
|
157
|
+
radioLabel: string;
|
158
|
+
/**
|
159
|
+
* The hint of the radio item
|
160
|
+
*/
|
161
|
+
radioHint: string;
|
162
|
+
/**
|
163
|
+
* The value of the radio item
|
164
|
+
*/
|
165
|
+
radioValue: string;
|
141
166
|
}
|
142
167
|
export type FormEditorInputPage = Pick<FormEditor, 'pageType' | 'questionType' | 'writtenAnswerSub' | 'dateSub' | 'listSub'>;
|
143
168
|
export type FormEditorInputCheckAnswersSettings = Pick<FormEditor, 'needDeclaration' | 'declarationText'>;
|
144
|
-
export type FormEditorInputQuestion = Pick<FormEditor, 'questionType' | 'name' | 'question' | 'shortDescription' | 'hintText' | 'questionOptional' | 'minLength' | 'maxLength' | 'regex' | 'rows' | 'classes' | 'prefix' | 'suffix' | 'precision' | 'min' | 'max' | 'maxFuture' | 'maxPast' | 'exactFiles' | 'minFiles' | 'maxFiles' | 'fileTypes' | 'documentTypes' | 'imageTypes' | 'tabularDataTypes'>;
|
169
|
+
export type FormEditorInputQuestion = Pick<FormEditor, 'questionType' | 'name' | 'question' | 'shortDescription' | 'hintText' | 'questionOptional' | 'minLength' | 'maxLength' | 'regex' | 'rows' | 'classes' | 'prefix' | 'suffix' | 'precision' | 'min' | 'max' | 'maxFuture' | 'maxPast' | 'exactFiles' | 'minFiles' | 'maxFiles' | 'fileTypes' | 'documentTypes' | 'imageTypes' | 'tabularDataTypes' | 'enhancedAction' | 'radioId' | 'radioLabel' | 'radioHint' | 'radioValue'>;
|
145
170
|
export type FormEditorInputPageSettings = Pick<FormEditor, 'pageHeadingAndGuidance' | 'pageHeading' | 'guidanceText'>;
|
146
171
|
export type FormEditorInputGuidancePage = Pick<FormEditor, 'pageHeading' | 'guidanceText'>;
|
172
|
+
export type FormEditorInputQuestionDetails = Pick<FormEditorInputQuestion, 'question' | 'hintText' | 'shortDescription' | 'questionOptional' | 'questionType' | 'fileTypes' | 'documentTypes' | 'imageTypes' | 'tabularDataTypes' | 'enhancedAction' | 'radioId' | 'radioLabel' | 'radioHint' | 'radioValue'>;
|
173
|
+
export interface EnhancedActionState {
|
174
|
+
questionDetails: Partial<ComponentDef>;
|
175
|
+
state: {
|
176
|
+
radioId?: string;
|
177
|
+
radioLabel?: string;
|
178
|
+
radioHint?: string;
|
179
|
+
radioValue?: string;
|
180
|
+
expanded?: boolean;
|
181
|
+
};
|
182
|
+
listItems: {
|
183
|
+
label?: string;
|
184
|
+
hint?: string;
|
185
|
+
value?: string;
|
186
|
+
id?: string;
|
187
|
+
}[];
|
188
|
+
}
|
147
189
|
export interface GovukField {
|
148
190
|
id?: string;
|
149
191
|
name?: string;
|
@@ -174,6 +216,7 @@ export interface GovukField {
|
|
174
216
|
}[];
|
175
217
|
rows?: number;
|
176
218
|
type?: string;
|
219
|
+
customTemplate?: string;
|
177
220
|
}
|
178
221
|
export interface FormEditorGovukField {
|
179
222
|
question?: GovukField;
|
@@ -184,6 +227,7 @@ export interface FormEditorGovukField {
|
|
184
227
|
documentTypes?: GovukField;
|
185
228
|
imageTypes?: GovukField;
|
186
229
|
tabularDataTypes?: GovukField;
|
230
|
+
radiosOrCheckboxes?: GovukField;
|
187
231
|
errorMessage?: {
|
188
232
|
text: string;
|
189
233
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/form/form-editor/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAEhC;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,sBAAsB,EAAE,MAAM,CAAA;IAE9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,SAAS,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AM,eAAe,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/form/form-manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAKrB,eAAO,MAAM,eAAe,iGAezB,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/form/form-metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACvB,MAAM,mCAAmC,CAAA;AAE1C,eAAO,MAAM,aAAa,UAUzB,CAAA;AAED,eAAO,MAAM,QAAQ,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/form/form-metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACvB,MAAM,mCAAmC,CAAA;AAE1C,eAAO,MAAM,aAAa,UAUzB,CAAA;AAED,eAAO,MAAM,QAAQ,0BAMlB,CAAA;AAEH,eAAO,MAAM,WAAW,0BAI+B,CAAA;AAEvD,eAAO,MAAM,UAAU,0BAGqC,CAAA;AAE5D,eAAO,MAAM,kBAAkB,0BAG8B,CAAA;AAE7D,eAAO,MAAM,cAAc,0BAIgC,CAAA;AAE3D,eAAO,MAAM,eAAe,0BAIyC,CAAA;AAErE,eAAO,MAAM,WAAW,0BAEiC,CAAA;AAEzD,eAAO,MAAM,kBAAkB,0BAI2B,CAAA;AAE1D,eAAO,MAAM,uBAAuB,0BAGwB,CAAA;AAE5D,eAAO,MAAM,WAAW,4CAK+C,CAAA;AAEvE,eAAO,MAAM,eAAe,0BAMmB,CAAA;AAE/C,eAAO,MAAM,gBAAgB,0BAGiC,CAAA;AAE9D,eAAO,MAAM,YAAY,6CAK6C,CAAA;AAEtE,eAAO,MAAM,aAAa,uCAM+C,CAAA;AAEzE,eAAO,MAAM,wBAAwB,0BAEkC,CAAA;AAEvE,eAAO,MAAM,sBAAsB,0BAKsB,CAAA;AAEzD,eAAO,MAAM,8BAA8B,0BAMxC,CAAA;AAEH,eAAO,MAAM,gBAAgB,sBAGoC,CAAA;AAEjE,eAAO,MAAM,cAAc,0BAGuB,CAAA;AAElD,eAAO,MAAM,uBAAuB,0BAGe,CAAA;AAEnD,eAAO,MAAM,qBAAqB;;;;;;;;;CASjC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,qCAG+B,CAAA;AAEnE;;;GAGG;AACH,eAAO,MAAM,wBAAwB,sCAMkC,CAAA;AAEvE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,qCAaqC,CAAA;AAEzE;;;GAGG;AACH,eAAO,MAAM,kBAAkB,gCAiB5B,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/form/form-submission/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,qCAAqC,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/form/form-submission/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,qCAAqC,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,gCAW0B,CAAA;AAE7D;;;GAGG;AACH,eAAO,MAAM,yBAAyB,mCAayC,CAAA;AAE/E;;;GAGG;AACH,eAAO,MAAM,uBAAuB,iCAkB2C,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@defra/forms-model",
|
3
|
-
"version": "3.0.
|
3
|
+
"version": "3.0.431",
|
4
4
|
"description": "A hapi plugin providing the model for Defra forms",
|
5
5
|
"homepage": "https://github.com/DEFRA/forms-designer/tree/main/model#readme",
|
6
6
|
"repository": {
|
@@ -14,21 +14,23 @@
|
|
14
14
|
"main": "dist/module/index.js",
|
15
15
|
"types": "dist/types/index.d.ts",
|
16
16
|
"scripts": {
|
17
|
-
"build": "npm run build:types && npm run build:node",
|
17
|
+
"build": "npm run build:types && npm run build:node && npm run build:schemas",
|
18
18
|
"build:node": "babel --delete-dir-on-start --extensions \".ts\" --ignore \"**/*.test.*\" --copy-files --no-copy-ignored --source-maps --out-dir ./dist/module ./src",
|
19
19
|
"build:types": "tsc --build --force tsconfig.build.json && tsc-alias --project tsconfig.build.json",
|
20
|
+
"build:schemas": "node scripts/generate-schemas.js",
|
20
21
|
"test": "jest --color --coverage --verbose",
|
21
22
|
"test:watch": "jest --color --watch"
|
22
23
|
},
|
23
24
|
"dependencies": {
|
24
25
|
"marked": "^15.0.7",
|
26
|
+
"nanoid": "^5.0.7",
|
25
27
|
"slug": "^10.0.0",
|
26
|
-
"uuid": "^11.1.0"
|
27
|
-
"nanoid": "^5.0.7"
|
28
|
+
"uuid": "^11.1.0"
|
28
29
|
},
|
29
30
|
"devDependencies": {
|
30
31
|
"@types/slug": "^5.0.9",
|
31
32
|
"joi": "^17.13.3",
|
33
|
+
"joi-to-json": "^4.3.1",
|
32
34
|
"tsc-alias": "^1.8.11"
|
33
35
|
},
|
34
36
|
"peerDependencies": {
|
@@ -0,0 +1,238 @@
|
|
1
|
+
import fs from 'fs'
|
2
|
+
import path from 'path'
|
3
|
+
import parse from 'joi-to-json'
|
4
|
+
|
5
|
+
import { schemasDir } from './schema-modules/constants.js'
|
6
|
+
import { ensureDirectoryExists, toTitleCase } from './schema-modules/utils.js'
|
7
|
+
import { addTitles } from './schema-modules/title-processors.js'
|
8
|
+
import { simplifyForDocs } from './schema-modules/schema-simplifiers.js'
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Cleans the schemas directory by removing all existing JSON files
|
12
|
+
* @returns {number} Number of files cleaned
|
13
|
+
*/
|
14
|
+
export function cleanSchemaDirectory() {
|
15
|
+
console.log('Cleaning existing schema files...')
|
16
|
+
const existingFiles = fs
|
17
|
+
.readdirSync(schemasDir)
|
18
|
+
.filter((file) => file.endsWith('.json'))
|
19
|
+
|
20
|
+
for (const file of existingFiles) {
|
21
|
+
fs.unlinkSync(path.join(schemasDir, file))
|
22
|
+
}
|
23
|
+
|
24
|
+
console.log(`Cleaned ${existingFiles.length} existing schema files`)
|
25
|
+
return existingFiles.length
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Gets the schema map that defines which files should be generated
|
30
|
+
* @returns {Record<string, string>} Schema map with filename-to-schema-export mapping
|
31
|
+
*/
|
32
|
+
export function getSchemaMap() {
|
33
|
+
return {
|
34
|
+
// Form definition schemas
|
35
|
+
'form-definition-schema': 'formDefinitionSchema',
|
36
|
+
'form-definition-v2-payload-schema': 'formDefinitionV2PayloadSchema',
|
37
|
+
|
38
|
+
// Component schemas
|
39
|
+
'component-schema': 'componentSchema',
|
40
|
+
'component-schema-v2': 'componentSchemaV2',
|
41
|
+
|
42
|
+
// Page schemas
|
43
|
+
'page-schema': 'pageSchema',
|
44
|
+
'page-schema-v2': 'pageSchemaV2',
|
45
|
+
'page-schema-payload-v2': 'pageSchemaPayloadV2',
|
46
|
+
|
47
|
+
// List schemas
|
48
|
+
'list-schema': 'listSchema',
|
49
|
+
'list-schema-v2': 'listSchemaV2',
|
50
|
+
|
51
|
+
// Form metadata schemas
|
52
|
+
'form-metadata-schema': 'formMetadataSchema',
|
53
|
+
'form-metadata-author-schema': 'formMetadataAuthorSchema',
|
54
|
+
'form-metadata-input-schema': 'formMetadataInputSchema',
|
55
|
+
'form-metadata-state-schema': 'formMetadataStateSchema',
|
56
|
+
|
57
|
+
// Form metadata field schemas
|
58
|
+
'form-metadata-contact-schema': 'contactSchema',
|
59
|
+
'form-metadata-email-schema': 'emailSchema',
|
60
|
+
'form-metadata-online-schema': 'onlineSchema',
|
61
|
+
|
62
|
+
// Form editor schemas
|
63
|
+
'form-editor-input-page-schema': 'formEditorInputPageSchema',
|
64
|
+
'form-editor-input-check-answers-setting-schema':
|
65
|
+
'formEditorInputCheckAnswersSettingSchema',
|
66
|
+
'form-editor-input-question-schema': 'formEditorInputQuestionSchema',
|
67
|
+
'form-editor-input-page-settings-schema':
|
68
|
+
'formEditorInputPageSettingsSchema',
|
69
|
+
|
70
|
+
// Form editor field schemas
|
71
|
+
'page-type-schema': 'pageTypeSchema',
|
72
|
+
'question-type-schema': 'questionTypeSchema',
|
73
|
+
'question-type-full-schema': 'questionTypeFullSchema',
|
74
|
+
'written-answer-sub-schema': 'writtenAnswerSubSchema',
|
75
|
+
'date-sub-schema': 'dateSubSchema',
|
76
|
+
|
77
|
+
// Form submission schemas
|
78
|
+
'form-submit-payload-schema': 'formSubmitPayloadSchema',
|
79
|
+
'form-submit-record-schema': 'formSubmitRecordSchema',
|
80
|
+
'form-submit-recordset-schema': 'formSubmitRecordsetSchema',
|
81
|
+
|
82
|
+
// Form manager schemas
|
83
|
+
'patch-page-schema': 'patchPageSchema',
|
84
|
+
|
85
|
+
// Section schemas
|
86
|
+
'question-schema': 'questionSchema',
|
87
|
+
|
88
|
+
// Validation schemas
|
89
|
+
'min-schema': 'minSchema',
|
90
|
+
'max-schema': 'maxSchema',
|
91
|
+
'min-length-schema': 'minLengthSchema',
|
92
|
+
'max-length-schema': 'maxLengthSchema',
|
93
|
+
'max-future-schema': 'maxFutureSchema',
|
94
|
+
'max-past-schema': 'maxPastSchema',
|
95
|
+
|
96
|
+
// Common schemas
|
97
|
+
'search-options-schema': 'searchOptionsSchema',
|
98
|
+
'query-options-schema': 'queryOptionsSchema',
|
99
|
+
'pagination-options-schema': 'paginationOptionsSchema',
|
100
|
+
'sorting-options-schema': 'sortingOptionsSchema'
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Process a single schema and create its JSON Schema file
|
106
|
+
* @param {string} fileName - Output file name
|
107
|
+
* @param {string} schemaName - Schema export name in the model
|
108
|
+
* @param {Record<string, unknown>} model - The loaded model containing schemas
|
109
|
+
* @returns {boolean} Whether processing was successful
|
110
|
+
*/
|
111
|
+
export function processSchema(fileName, schemaName, model) {
|
112
|
+
try {
|
113
|
+
/** @type {unknown} */
|
114
|
+
const joiSchema = model[schemaName]
|
115
|
+
|
116
|
+
if (!joiSchema) {
|
117
|
+
return false
|
118
|
+
}
|
119
|
+
|
120
|
+
/** @type {import('./schema-modules/types.js').SchemaObject} */
|
121
|
+
let jsonSchema = parse(
|
122
|
+
/** @type {Schema} */ (joiSchema),
|
123
|
+
'json',
|
124
|
+
{},
|
125
|
+
{
|
126
|
+
includeSchemaDialect: true,
|
127
|
+
includeDescriptions: true
|
128
|
+
}
|
129
|
+
)
|
130
|
+
|
131
|
+
const title = toTitleCase(fileName)
|
132
|
+
if (!jsonSchema.title) {
|
133
|
+
jsonSchema.title = title
|
134
|
+
}
|
135
|
+
if (!jsonSchema.description) {
|
136
|
+
jsonSchema.description = `JSON Schema for validating ${title} in Defra forms`
|
137
|
+
}
|
138
|
+
|
139
|
+
if (!jsonSchema.$id) {
|
140
|
+
jsonSchema.$id = `@defra/forms-model/schemas/${fileName}.json`
|
141
|
+
}
|
142
|
+
|
143
|
+
addTitles(jsonSchema, '')
|
144
|
+
|
145
|
+
jsonSchema = simplifyForDocs(jsonSchema, '')
|
146
|
+
|
147
|
+
const outputPath = path.join(schemasDir, `${fileName}.json`)
|
148
|
+
fs.writeFileSync(outputPath, JSON.stringify(jsonSchema, null, 2))
|
149
|
+
return true
|
150
|
+
} catch (/** @type {unknown} */ err) {
|
151
|
+
const error = err instanceof Error ? err : new Error(String(err))
|
152
|
+
console.error(`✗ Failed to process ${fileName}: ${error.message}`)
|
153
|
+
return false
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Loads the model with all schemas
|
159
|
+
* @returns {Promise<Record<string, unknown>>} Loaded model
|
160
|
+
*/
|
161
|
+
async function loadModelSchemas() {
|
162
|
+
console.log('Loading model schemas...')
|
163
|
+
return import('../dist/module/index.js')
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Processes all schemas and generates JSON Schema files
|
168
|
+
* @param {Record<string, unknown>} model - The loaded model containing schemas
|
169
|
+
* @returns {{ successCount: number, errorCount: number }} Object containing success and error counts
|
170
|
+
*/
|
171
|
+
export function processAllSchemas(model) {
|
172
|
+
const schemaMap = getSchemaMap()
|
173
|
+
let successCount = 0
|
174
|
+
let errorCount = 0
|
175
|
+
|
176
|
+
for (const [fileName, schemaName] of Object.entries(schemaMap)) {
|
177
|
+
const success = processSchema(fileName, schemaName, model)
|
178
|
+
|
179
|
+
if (success) {
|
180
|
+
successCount++
|
181
|
+
} else {
|
182
|
+
errorCount++
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
return { successCount, errorCount }
|
187
|
+
}
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Generates schema files from Joi schemas
|
191
|
+
*/
|
192
|
+
export async function generateSchemas() {
|
193
|
+
try {
|
194
|
+
const model = await loadModelSchemas()
|
195
|
+
|
196
|
+
ensureDirectoryExists(schemasDir)
|
197
|
+
|
198
|
+
cleanSchemaDirectory()
|
199
|
+
|
200
|
+
const { successCount, errorCount } = processAllSchemas(model)
|
201
|
+
|
202
|
+
console.log('\nSchema generation complete!')
|
203
|
+
console.log(`✓ Successfully generated ${successCount} schemas`)
|
204
|
+
if (errorCount > 0) {
|
205
|
+
console.log(`✗ Failed to generate ${errorCount} schemas`)
|
206
|
+
}
|
207
|
+
|
208
|
+
return { successCount, errorCount }
|
209
|
+
} catch (err) {
|
210
|
+
const error = err instanceof Error ? err : new Error(String(err))
|
211
|
+
console.error(`\n✗ Schema generation failed: ${error.message}`)
|
212
|
+
throw error
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
// Only run when executed directly, not when imported as a module
|
217
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
218
|
+
;(async () => {
|
219
|
+
try {
|
220
|
+
await generateSchemas()
|
221
|
+
} catch (err) {
|
222
|
+
console.error('Schema generation failed:', err)
|
223
|
+
throw err
|
224
|
+
}
|
225
|
+
})().catch((err) => {
|
226
|
+
console.error('Unhandled error:', err)
|
227
|
+
// eslint-disable-next-line no-process-exit
|
228
|
+
process.exit(1)
|
229
|
+
})
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* @import { Schema } from 'joi'
|
234
|
+
*/
|
235
|
+
|
236
|
+
/**
|
237
|
+
* @import { SchemaObject } from './schema-modules/types.js'
|
238
|
+
*/
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import path from 'path'
|
2
|
+
import { fileURLToPath } from 'url'
|
3
|
+
|
4
|
+
export const currentDirname = path.dirname(fileURLToPath(import.meta.url))
|
5
|
+
export const schemasDir = path.resolve(currentDirname, '../../schemas')
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Condition type constants
|
9
|
+
*/
|
10
|
+
export const CONDITION_TYPES = {
|
11
|
+
DEFINITION: 'Condition Definition',
|
12
|
+
REFERENCE: 'Condition Reference',
|
13
|
+
NESTED_GROUP: 'Nested Condition Group'
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Value type constants
|
18
|
+
*/
|
19
|
+
export const VALUE_TYPES = {
|
20
|
+
STATIC: 'Static Value',
|
21
|
+
RELATIVE_DATE: 'Relative Date Value'
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Common description constants
|
26
|
+
*/
|
27
|
+
export const DESCRIPTIONS = {
|
28
|
+
NESTED_CONDITION_GROUP:
|
29
|
+
'A nested group of conditions that allows building complex logical expressions with multiple levels.'
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Path segment constants
|
34
|
+
*/
|
35
|
+
export const PATH_SEGMENTS = {
|
36
|
+
CONDITIONS: 'conditions',
|
37
|
+
ITEMS: 'items',
|
38
|
+
PROPERTIES: 'properties'
|
39
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import { CONDITION_TYPES, DESCRIPTIONS, VALUE_TYPES } from './constants.js'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Fixes titles for condition items in anyOfTitles
|
5
|
+
* @param {SchemaObject} obj - Schema to process
|
6
|
+
* @returns {boolean} True if changes were made
|
7
|
+
*/
|
8
|
+
export function fixConditionItems(obj) {
|
9
|
+
if (!obj.anyOfTitles?.includes('Conditions Item Variant 3')) {
|
10
|
+
return false
|
11
|
+
}
|
12
|
+
|
13
|
+
const EXPECTED_CONDITION_TYPES_COUNT = 3
|
14
|
+
|
15
|
+
obj.anyOfTitles = [
|
16
|
+
CONDITION_TYPES.DEFINITION,
|
17
|
+
CONDITION_TYPES.REFERENCE,
|
18
|
+
CONDITION_TYPES.NESTED_GROUP
|
19
|
+
]
|
20
|
+
|
21
|
+
if (obj.anyOf?.length === EXPECTED_CONDITION_TYPES_COUNT) {
|
22
|
+
if (obj.anyOf[0].properties?.field) {
|
23
|
+
obj.anyOf[0].title = CONDITION_TYPES.DEFINITION
|
24
|
+
}
|
25
|
+
if (obj.anyOf[1].properties?.conditionName) {
|
26
|
+
obj.anyOf[1].title = CONDITION_TYPES.REFERENCE
|
27
|
+
}
|
28
|
+
if (obj.anyOf[2].$ref?.includes('conditionGroupSchema')) {
|
29
|
+
obj.anyOf[2].title = CONDITION_TYPES.NESTED_GROUP
|
30
|
+
obj.anyOf[2].description = DESCRIPTIONS.NESTED_CONDITION_GROUP
|
31
|
+
}
|
32
|
+
}
|
33
|
+
return true
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Fixes titles for value objects in anyOfTitles
|
38
|
+
* @param {SchemaObject} obj - Schema to process
|
39
|
+
* @returns {boolean} True if changes were made
|
40
|
+
*/
|
41
|
+
export function fixValueObjects(obj) {
|
42
|
+
if (
|
43
|
+
obj.anyOfTitles?.length !== 2 ||
|
44
|
+
obj.anyOfTitles[0] !== 'Value (object)' ||
|
45
|
+
obj.anyOfTitles[1] !== 'Value (object)'
|
46
|
+
) {
|
47
|
+
return false
|
48
|
+
}
|
49
|
+
|
50
|
+
obj.anyOfTitles = [VALUE_TYPES.STATIC, VALUE_TYPES.RELATIVE_DATE]
|
51
|
+
|
52
|
+
if (obj.anyOf?.length === 2) {
|
53
|
+
if (obj.anyOf[0].properties?.value) {
|
54
|
+
obj.anyOf[0].title = VALUE_TYPES.STATIC
|
55
|
+
}
|
56
|
+
if (obj.anyOf[1].properties?.period) {
|
57
|
+
obj.anyOf[1].title = VALUE_TYPES.RELATIVE_DATE
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
return true
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Processes the anyOfTitles array in an object
|
66
|
+
* @param {SchemaObject} obj - Schema to process
|
67
|
+
*/
|
68
|
+
export function processAnyOfTitles(obj) {
|
69
|
+
if (!obj || typeof obj !== 'object') {
|
70
|
+
return
|
71
|
+
}
|
72
|
+
|
73
|
+
if (!Array.isArray(obj.anyOfTitles)) {
|
74
|
+
return
|
75
|
+
}
|
76
|
+
|
77
|
+
if (!fixConditionItems(obj)) {
|
78
|
+
fixValueObjects(obj)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Recursively fixes all condition titles and anyOfTitles throughout the schema
|
84
|
+
* regardless of their nesting level
|
85
|
+
* @param {SchemaObject} obj - The schema or subschema to fix
|
86
|
+
*/
|
87
|
+
export function fixConditionTitles(obj) {
|
88
|
+
if (!obj || typeof obj !== 'object') {
|
89
|
+
return
|
90
|
+
}
|
91
|
+
|
92
|
+
processAnyOfTitles(obj)
|
93
|
+
|
94
|
+
if (obj.title === 'Conditions Item Variant 3') {
|
95
|
+
obj.title = CONDITION_TYPES.NESTED_GROUP
|
96
|
+
obj.description = DESCRIPTIONS.NESTED_CONDITION_GROUP
|
97
|
+
}
|
98
|
+
|
99
|
+
Object.keys(obj).forEach((key) => {
|
100
|
+
const value = obj[key]
|
101
|
+
if (value && typeof value === 'object') {
|
102
|
+
fixConditionTitles(value)
|
103
|
+
}
|
104
|
+
})
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* @import { SchemaObject } from './types.js'
|
109
|
+
*/
|