@defra/forms-model 3.0.99 → 3.0.100
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-metadata/index.js +3 -4
- package/dist/module/form/form-metadata/index.js.map +1 -1
- package/dist/module/utils/helpers.js +12 -0
- package/dist/module/utils/helpers.js.map +1 -1
- package/dist/types/form/form-metadata/index.d.ts.map +1 -1
- package/dist/types/utils/helpers.d.ts +5 -0
- package/dist/types/utils/helpers.d.ts.map +1 -1
- package/package.json +4 -1
- package/src/form/form-metadata/index.ts +1 -5
- package/src/utils/helpers.ts +10 -0
@@ -2,10 +2,9 @@ import Joi from 'joi';
|
|
2
2
|
export const organisations = ['Animal and Plant Health Agency – APHA', 'Centre for Environment, Fisheries and Aquaculture Science – Cefas', 'Defra', 'Environment Agency', 'Forestry Commission', 'Marine Management Organisation – MMO', 'Natural England', 'Rural Payments Agency – RPA', 'Veterinary Medicines Directorate – VMD'];
|
3
3
|
export const idSchema = Joi.string().hex().length(24).required();
|
4
4
|
export const titleSchema = Joi.string().max(250).trim().required();
|
5
|
-
export const slugSchema = Joi.string().
|
6
|
-
|
7
|
-
.
|
8
|
-
.required();
|
5
|
+
export const slugSchema = Joi.string().pattern(/^[a-z0-9-]+$/, {
|
6
|
+
name: 'letters, numbers and hyphens only'
|
7
|
+
}).required();
|
9
8
|
export const organisationSchema = Joi.string().valid(...organisations).required();
|
10
9
|
export const teamNameSchema = Joi.string().max(100).trim().required();
|
11
10
|
export const teamEmailSchema = Joi.string().email({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["Joi","organisations","idSchema","string","hex","length","required","titleSchema","max","trim","slugSchema","
|
1
|
+
{"version":3,"file":"index.js","names":["Joi","organisations","idSchema","string","hex","length","required","titleSchema","max","trim","slugSchema","pattern","name","organisationSchema","valid","teamNameSchema","teamEmailSchema","email","tlds","allow","authoredAtSchema","date","iso","authorIdSchema","uuid","authorDisplayNameSchema","formMetadataInputSchema","object","keys","title","organisation","teamName","teamEmail","formMetadataAuthorSchema","id","displayName","formMetadataStateSchema","createdAt","createdBy","updatedAt","updatedBy","formMetadataSchema","append","slug","draft","live"],"sources":["../../../../src/form/form-metadata/index.ts"],"sourcesContent":["import Joi from 'joi'\n\nimport {\n type FormMetadata,\n type FormMetadataInput,\n type FormMetadataState,\n type FormMetadataAuthor\n} from '~/src/form/form-metadata/types.js'\n\nexport const organisations = [\n 'Animal and Plant Health Agency – APHA',\n 'Centre for Environment, Fisheries and Aquaculture Science – Cefas',\n 'Defra',\n 'Environment Agency',\n 'Forestry Commission',\n 'Marine Management Organisation – MMO',\n 'Natural England',\n 'Rural Payments Agency – RPA',\n 'Veterinary Medicines Directorate – VMD'\n]\n\nexport const idSchema = Joi.string().hex().length(24).required()\nexport const titleSchema = Joi.string().max(250).trim().required()\nexport const slugSchema = Joi.string()\n .pattern(/^[a-z0-9-]+$/, { name: 'letters, numbers and hyphens only' })\n .required()\n\nexport const organisationSchema = Joi.string()\n .valid(...organisations)\n .required()\n\nexport const teamNameSchema = Joi.string().max(100).trim().required()\nexport const teamEmailSchema = Joi.string()\n .email({ tlds: { allow: ['uk'] } })\n .trim()\n .required()\n\nexport const authoredAtSchema = Joi.date().iso().required()\nexport const authorIdSchema = Joi.string().uuid().trim().required()\nexport const authorDisplayNameSchema = Joi.string().trim().required()\n\n/**\n * Joi schema for `FormMetadataInput` interface\n * @see {@link FormMetadataInput}\n */\nexport const formMetadataInputSchema = Joi.object<FormMetadataInput>()\n .keys({\n title: titleSchema,\n organisation: organisationSchema,\n teamName: teamNameSchema,\n teamEmail: teamEmailSchema\n })\n .required()\n\n/**\n * Joi schema for `FormMetadataAuthor` interface\n * @see {@link FormMetadataAuthor}\n */\nexport const formMetadataAuthorSchema = Joi.object<FormMetadataAuthor>()\n .keys({\n id: authorIdSchema,\n displayName: authorDisplayNameSchema\n })\n .required()\n\n/**\n * Joi schema for `FormMetadataState` interface\n * @see {@link FormMetadataState}\n */\nexport const formMetadataStateSchema = Joi.object<FormMetadataState>().keys({\n createdAt: authoredAtSchema,\n createdBy: formMetadataAuthorSchema,\n updatedAt: authoredAtSchema,\n updatedBy: formMetadataAuthorSchema\n})\n\n/**\n * Joi schema for `FormMetadata` interface\n * @see {@link FormMetadata}\n */\nexport const formMetadataSchema = formMetadataInputSchema.append<FormMetadata>({\n id: idSchema,\n slug: slugSchema,\n draft: formMetadataStateSchema.required(),\n live: formMetadataStateSchema\n})\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AASrB,OAAO,MAAMC,aAAa,GAAG,CAC3B,uCAAuC,EACvC,mEAAmE,EACnE,OAAO,EACP,oBAAoB,EACpB,qBAAqB,EACrB,sCAAsC,EACtC,iBAAiB,EACjB,6BAA6B,EAC7B,wCAAwC,CACzC;AAED,OAAO,MAAMC,QAAQ,GAAGF,GAAG,CAACG,MAAM,CAAC,CAAC,CAACC,GAAG,CAAC,CAAC,CAACC,MAAM,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC;AAChE,OAAO,MAAMC,WAAW,GAAGP,GAAG,CAACG,MAAM,CAAC,CAAC,CAACK,GAAG,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,CAAC,CAACH,QAAQ,CAAC,CAAC;AAClE,OAAO,MAAMI,UAAU,GAAGV,GAAG,CAACG,MAAM,CAAC,CAAC,CACnCQ,OAAO,CAAC,cAAc,EAAE;EAAEC,IAAI,EAAE;AAAoC,CAAC,CAAC,CACtEN,QAAQ,CAAC,CAAC;AAEb,OAAO,MAAMO,kBAAkB,GAAGb,GAAG,CAACG,MAAM,CAAC,CAAC,CAC3CW,KAAK,CAAC,GAAGb,aAAa,CAAC,CACvBK,QAAQ,CAAC,CAAC;AAEb,OAAO,MAAMS,cAAc,GAAGf,GAAG,CAACG,MAAM,CAAC,CAAC,CAACK,GAAG,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,CAAC,CAACH,QAAQ,CAAC,CAAC;AACrE,OA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gBAAgB;EAC3BoB,SAAS,EAAEP;AACb,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA,OAAO,MAAMQ,kBAAkB,GAAGf,uBAAuB,CAACgB,MAAM,CAAe;EAC7ER,EAAE,EAAEhC,QAAQ;EACZyC,IAAI,EAAEjC,UAAU;EAChBkC,KAAK,EAAER,uBAAuB,CAAC9B,QAAQ,CAAC,CAAC;EACzCuC,IAAI,EAAET;AACR,CAAC,CAAC","ignoreList":[]}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { customAlphabet } from 'nanoid';
|
2
|
+
import slug from 'slug';
|
2
3
|
export const serialiseAndDeserialise = obj => {
|
3
4
|
if (typeof obj === 'object' && obj !== null) {
|
4
5
|
return JSON.parse(JSON.stringify(obj));
|
@@ -23,5 +24,16 @@ export function filter(obj, predicate) {
|
|
23
24
|
}
|
24
25
|
return result;
|
25
26
|
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Replace spaces, en-dashes and em-dashes with hyphens
|
30
|
+
* before running through the slug package
|
31
|
+
*/
|
32
|
+
export function slugify(input = '') {
|
33
|
+
const string = input.trim().replace(/[\s–—]/g, '-');
|
34
|
+
return slug(string, {
|
35
|
+
lower: true
|
36
|
+
});
|
37
|
+
}
|
26
38
|
export const nanoid = customAlphabet('0123456789_abcdefghijklmnopqrstuvwxyz', 6);
|
27
39
|
//# sourceMappingURL=helpers.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.js","names":["customAlphabet","serialiseAndDeserialise","obj","JSON","parse","stringify","clone","filter","predicate","result","key","value","Object","entries","nanoid"],"sources":["../../../src/utils/helpers.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\n\nexport const serialiseAndDeserialise = <T>(obj: T): T => {\n if (typeof obj === 'object' && obj !== null) {\n return JSON.parse(JSON.stringify(obj))\n }\n\n return obj\n}\n\nexport const clone = <T>(obj: T & { clone?: () => T }): T => {\n if (obj) {\n if (typeof obj.clone === 'function') {\n return obj.clone()\n }\n\n return serialiseAndDeserialise<T>(obj)\n }\n return obj\n}\n\nexport function filter<T extends Record<string, unknown>>(\n obj: T,\n predicate: (value: any) => boolean\n): Partial<T> {\n const result = {}\n\n for (const [key, value] of Object.entries(obj)) {\n if (value && predicate(value)) {\n result[key] = value\n }\n }\n\n return result\n}\n\nexport const nanoid = customAlphabet('0123456789_abcdefghijklmnopqrstuvwxyz', 6)\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,QAAQ;
|
1
|
+
{"version":3,"file":"helpers.js","names":["customAlphabet","slug","serialiseAndDeserialise","obj","JSON","parse","stringify","clone","filter","predicate","result","key","value","Object","entries","slugify","input","string","trim","replace","lower","nanoid"],"sources":["../../../src/utils/helpers.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport slug from 'slug'\n\nexport const serialiseAndDeserialise = <T>(obj: T): T => {\n if (typeof obj === 'object' && obj !== null) {\n return JSON.parse(JSON.stringify(obj))\n }\n\n return obj\n}\n\nexport const clone = <T>(obj: T & { clone?: () => T }): T => {\n if (obj) {\n if (typeof obj.clone === 'function') {\n return obj.clone()\n }\n\n return serialiseAndDeserialise<T>(obj)\n }\n return obj\n}\n\nexport function filter<T extends Record<string, unknown>>(\n obj: T,\n predicate: (value: any) => boolean\n): Partial<T> {\n const result = {}\n\n for (const [key, value] of Object.entries(obj)) {\n if (value && predicate(value)) {\n result[key] = value\n }\n }\n\n return result\n}\n\n/**\n * Replace spaces, en-dashes and em-dashes with hyphens\n * before running through the slug package\n */\nexport function slugify(input = '') {\n const string = input.trim().replace(/[\\s–—]/g, '-')\n return slug(string, { lower: true })\n}\n\nexport const nanoid = customAlphabet('0123456789_abcdefghijklmnopqrstuvwxyz', 6)\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,QAAQ;AACvC,OAAOC,IAAI,MAAM,MAAM;AAEvB,OAAO,MAAMC,uBAAuB,GAAOC,GAAM,IAAQ;EACvD,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAIA,GAAG,KAAK,IAAI,EAAE;IAC3C,OAAOC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,SAAS,CAACH,GAAG,CAAC,CAAC;EACxC;EAEA,OAAOA,GAAG;AACZ,CAAC;AAED,OAAO,MAAMI,KAAK,GAAOJ,GAA4B,IAAQ;EAC3D,IAAIA,GAAG,EAAE;IACP,IAAI,OAAOA,GAAG,CAACI,KAAK,KAAK,UAAU,EAAE;MACnC,OAAOJ,GAAG,CAACI,KAAK,CAAC,CAAC;IACpB;IAEA,OAAOL,uBAAuB,CAAIC,GAAG,CAAC;EACxC;EACA,OAAOA,GAAG;AACZ,CAAC;AAED,OAAO,SAASK,MAAMA,CACpBL,GAAM,EACNM,SAAkC,EACtB;EACZ,MAAMC,MAAM,GAAG,CAAC,CAAC;EAEjB,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACX,GAAG,CAAC,EAAE;IAC9C,IAAIS,KAAK,IAAIH,SAAS,CAACG,KAAK,CAAC,EAAE;MAC7BF,MAAM,CAACC,GAAG,CAAC,GAAGC,KAAK;IACrB;EACF;EAEA,OAAOF,MAAM;AACf;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASK,OAAOA,CAACC,KAAK,GAAG,EAAE,EAAE;EAClC,MAAMC,MAAM,GAAGD,KAAK,CAACE,IAAI,CAAC,CAAC,CAACC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;EACnD,OAAOlB,IAAI,CAACgB,MAAM,EAAE;IAAEG,KAAK,EAAE;EAAK,CAAC,CAAC;AACtC;AAEA,OAAO,MAAMC,MAAM,GAAGrB,cAAc,CAAC,uCAAuC,EAAE,CAAC,CAAC","ignoreList":[]}
|
@@ -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,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,mCAAmC,CAAA;AAE1C,eAAO,MAAM,aAAa,UAUzB,CAAA;AAED,eAAO,MAAM,QAAQ,0BAA2C,CAAA;AAChE,eAAO,MAAM,WAAW,0BAA0C,CAAA;AAClE,eAAO,MAAM,UAAU,
|
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,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,mCAAmC,CAAA;AAE1C,eAAO,MAAM,aAAa,UAUzB,CAAA;AAED,eAAO,MAAM,QAAQ,0BAA2C,CAAA;AAChE,eAAO,MAAM,WAAW,0BAA0C,CAAA;AAClE,eAAO,MAAM,UAAU,0BAEV,CAAA;AAEb,eAAO,MAAM,kBAAkB,0BAElB,CAAA;AAEb,eAAO,MAAM,cAAc,0BAA0C,CAAA;AACrE,eAAO,MAAM,eAAe,0BAGf,CAAA;AAEb,eAAO,MAAM,gBAAgB,sBAA8B,CAAA;AAC3D,eAAO,MAAM,cAAc,0BAAwC,CAAA;AACnE,eAAO,MAAM,uBAAuB,0BAAiC,CAAA;AAErE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,qCAOvB,CAAA;AAEb;;;GAGG;AACH,eAAO,MAAM,wBAAwB,sCAKxB,CAAA;AAEb;;;GAGG;AACH,eAAO,MAAM,uBAAuB,qCAKlC,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,gCAK7B,CAAA"}
|
@@ -3,5 +3,10 @@ export declare const clone: <T>(obj: T & {
|
|
3
3
|
clone?: () => T;
|
4
4
|
}) => T;
|
5
5
|
export declare function filter<T extends Record<string, unknown>>(obj: T, predicate: (value: any) => boolean): Partial<T>;
|
6
|
+
/**
|
7
|
+
* Replace spaces, en-dashes and em-dashes with hyphens
|
8
|
+
* before running through the slug package
|
9
|
+
*/
|
10
|
+
export declare function slugify(input?: string): string;
|
6
11
|
export declare const nanoid: (size?: number | undefined) => string;
|
7
12
|
//# sourceMappingURL=helpers.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,WAAY,CAAC,KAAG,CAMnD,CAAA;AAED,eAAO,MAAM,KAAK,WAAY,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,KAAG,CASvD,CAAA;AAED,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtD,GAAG,EAAE,CAAC,EACN,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,GACjC,OAAO,CAAC,CAAC,CAAC,CAUZ;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,SAAK,UAGjC;AAED,eAAO,MAAM,MAAM,uCAA6D,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.100",
|
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": {
|
@@ -19,6 +19,9 @@
|
|
19
19
|
"test": "jest --color --coverage --verbose",
|
20
20
|
"test:watch": "jest --color --watch"
|
21
21
|
},
|
22
|
+
"dependencies": {
|
23
|
+
"slug": "^9.0.0"
|
24
|
+
},
|
22
25
|
"devDependencies": {
|
23
26
|
"joi": "^17.13.1",
|
24
27
|
"nanoid": "^3.3.7"
|
@@ -22,11 +22,7 @@ export const organisations = [
|
|
22
22
|
export const idSchema = Joi.string().hex().length(24).required()
|
23
23
|
export const titleSchema = Joi.string().max(250).trim().required()
|
24
24
|
export const slugSchema = Joi.string()
|
25
|
-
.
|
26
|
-
.trim()
|
27
|
-
.replace(/[\s–—]/g, '-') // replace spaces, en-dashes and em-dashes with hyphens
|
28
|
-
.replace(/[^a-z0-9-]/g, '') // remove non-matching characters except spaces
|
29
|
-
.replace(/-+/g, '-') // replace multiple hyphens with a single hyphen
|
25
|
+
.pattern(/^[a-z0-9-]+$/, { name: 'letters, numbers and hyphens only' })
|
30
26
|
.required()
|
31
27
|
|
32
28
|
export const organisationSchema = Joi.string()
|
package/src/utils/helpers.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { customAlphabet } from 'nanoid'
|
2
|
+
import slug from 'slug'
|
2
3
|
|
3
4
|
export const serialiseAndDeserialise = <T>(obj: T): T => {
|
4
5
|
if (typeof obj === 'object' && obj !== null) {
|
@@ -34,4 +35,13 @@ export function filter<T extends Record<string, unknown>>(
|
|
34
35
|
return result
|
35
36
|
}
|
36
37
|
|
38
|
+
/**
|
39
|
+
* Replace spaces, en-dashes and em-dashes with hyphens
|
40
|
+
* before running through the slug package
|
41
|
+
*/
|
42
|
+
export function slugify(input = '') {
|
43
|
+
const string = input.trim().replace(/[\s–—]/g, '-')
|
44
|
+
return slug(string, { lower: true })
|
45
|
+
}
|
46
|
+
|
37
47
|
export const nanoid = customAlphabet('0123456789_abcdefghijklmnopqrstuvwxyz', 6)
|