@defra/forms-model 3.0.371 → 3.0.373

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.
@@ -6,10 +6,11 @@ import { PageTypes } from "./page-types.js";
6
6
  * Return component defaults by type
7
7
  */
8
8
  export function getPageDefaults(page) {
9
- const controller = controllerNameFromPath(page.controller ?? ControllerType.Page);
9
+ const nameOrPath = page?.controller ?? ControllerType.Page;
10
+ const controller = controllerNameFromPath(nameOrPath);
10
11
  const defaults = PageTypes.find(pageType => pageType.controller === controller);
11
12
  if (!defaults) {
12
- throw new Error(`Defaults not found for page type '${page.controller}'`);
13
+ throw new Error(`Defaults not found for page type '${nameOrPath}'`);
13
14
  }
14
15
  return structuredClone(defaults);
15
16
  }
@@ -18,28 +19,22 @@ export function getPageDefaults(page) {
18
19
  * Check page has components
19
20
  */
20
21
  export function hasComponents(page) {
21
- return isLinkablePage(page) && Array.isArray(page.components);
22
+ return hasNext(page) && Array.isArray(page.components);
22
23
  }
23
24
 
24
25
  /**
25
26
  * Check page has form components
26
27
  */
27
28
  export function hasFormComponents(page) {
28
- return isLinkablePage(page) && Array.isArray(page.components);
29
+ const controller = controllerNameFromPath(page?.controller);
30
+ return hasComponents(page) && controller !== ControllerType.Start;
29
31
  }
30
32
 
31
33
  /**
32
34
  * Check page has sections
33
35
  */
34
36
  export function hasSection(page) {
35
- return isLinkablePage(page) && typeof page.section === 'string';
36
- }
37
-
38
- /**
39
- * Check page has next link
40
- */
41
- export function hasNext(page) {
42
- return isLinkablePage(page);
37
+ return hasNext(page) && typeof page.section === 'string';
43
38
  }
44
39
 
45
40
  /**
@@ -50,9 +45,9 @@ export function isControllerName(nameOrPath) {
50
45
  }
51
46
 
52
47
  /**
53
- * Check page is linkable
48
+ * Check page has next link
54
49
  */
55
- export function isLinkablePage(page) {
50
+ export function hasNext(page) {
56
51
  if (!page || !('next' in page)) {
57
52
  return false;
58
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":["ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","controller","controllerNameFromPath","Page","defaults","find","pageType","Error","structuredClone","hasComponents","isLinkablePage","Array","isArray","components","hasFormComponents","hasSection","section","hasNext","isControllerName","nameOrPath","map","String","includes","Start","FileUpload","isQuestionPage","options","path","name"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageStart,\n type RequiredField\n} from '~/src/form/form-definition/types.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page: Pick<PageType, 'controller'>\n) {\n const controller = controllerNameFromPath(\n page.controller ?? ControllerType.Page\n )\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${page.controller}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return isLinkablePage(page) && Array.isArray(page.components)\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return isLinkablePage(page) && Array.isArray(page.components)\n}\n\n/**\n * Check page has sections\n */\nexport function hasSection(\n page: Partial<Page>\n): page is\n | RequiredField<PageStart, 'section'>\n | RequiredField<PageQuestion, 'section'>\n | RequiredField<PageFileUpload, 'section'> {\n return isLinkablePage(page) && typeof page.section === 'string'\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(page?: Partial<Page>) {\n return isLinkablePage(page)\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page is linkable\n */\nexport function isLinkablePage(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.FileUpload\n )\n}\n\n/**\n * Check page supports questions\n */\nexport function isQuestionPage(page?: Partial<Page>): page is PageQuestion {\n const controller = controllerNameFromPath(page?.controller)\n\n return (\n !controller ||\n controller === ControllerType.Page ||\n controller === ControllerType.FileUpload\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n"],"mappings":"AASA,SACEA,eAAe,EACfC,eAAe;AAEjB,SAASC,cAAc;AACvB,SAASC,SAAS;;AAElB;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,IAAkC,EAClC;EACA,MAAMC,UAAU,GAAGC,sBAAsB,CACvCF,IAAI,CAACC,UAAU,IAAIJ,cAAc,CAACM,IACpC,CAAC;EAED,MAAMC,QAAQ,GAAGN,SAAS,CAACO,IAAI,CAC5BC,QAAQ,IAAKA,QAAQ,CAACL,UAAU,KAAKA,UACxC,CAAC;EAED,IAAI,CAACG,QAAQ,EAAE;IACb,MAAM,IAAIG,KAAK,CAAC,qCAAqCP,IAAI,CAACC,UAAU,GAAG,CAAC;EAC1E;EAEA,OAAOO,eAAe,CAACJ,QAAQ,CAAC;AAClC;;AAEA;AACA;AACA;AACA,OAAO,SAASK,aAAaA,CAC3BT,IAAoB,EACmC;EACvD,OAAOU,cAAc,CAACV,IAAI,CAAC,IAAIW,KAAK,CAACC,OAAO,CAAC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c,CAAC2B,UAAU;AAE5C;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAAStB,sBAAsBA,CAACiB,UAAoC,EAAE;EAC3E,IAAID,gBAAgB,CAACC,UAAU,CAAC,EAAE;IAChC,OAAOA,UAAU;EACnB;EAEA,MAAMO,OAAO,GAAG9B,eAAe,CAACS,IAAI,CAAC,CAAC;IAAEsB;EAAK,CAAC,KAAKA,IAAI,KAAKR,UAAU,CAAC;EACvE,OAAOO,OAAO,EAAEE,IAAI;AACtB","ignoreList":[]}
1
+ {"version":3,"file":"helpers.js","names":["ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasFormComponents","Start","hasSection","section","isControllerName","map","String","includes","FileUpload","isQuestionPage","options","path","name"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageStart,\n type RequiredField\n} from '~/src/form/form-definition/types.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page?: Pick<PageType, 'controller'>\n) {\n const nameOrPath = page?.controller ?? ControllerType.Page\n const controller = controllerNameFromPath(nameOrPath)\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${nameOrPath}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return hasNext(page) && Array.isArray(page.components)\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is PageQuestion | PageFileUpload {\n const controller = controllerNameFromPath(page?.controller)\n return hasComponents(page) && controller !== ControllerType.Start\n}\n\n/**\n * Check page has sections\n */\nexport function hasSection(\n page?: Partial<Page>\n): page is\n | RequiredField<PageStart, 'section'>\n | RequiredField<PageQuestion, 'section'>\n | RequiredField<PageFileUpload, 'section'> {\n return hasNext(page) && typeof page.section === 'string'\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.FileUpload\n )\n}\n\n/**\n * Check page supports questions\n */\nexport function isQuestionPage(page?: Partial<Page>): page is PageQuestion {\n const controller = controllerNameFromPath(page?.controller)\n\n return (\n !controller ||\n controller === ControllerType.Page ||\n controller === ControllerType.FileUpload\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n"],"mappings":"AASA,SACEA,eAAe,EACfC,eAAe;AAEjB,SAASC,cAAc;AACvB,SAASC,SAAS;;AAElB;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,IAAmC,EACnC;EACA,MAAMC,UAAU,GAAGD,IAAI,EAAEE,UAAU,IAAIL,cAAc,CAACM,IAAI;EAC1D,MAAMD,UAAU,GAAGE,sBAAsB,CAACH,UAAU,CAAC;EAErD,MAAMI,QAAQ,GAAGP,SAAS,CAACQ,IAAI,CAC5BC,QAAQ,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KAAKL,cAAc,CAAC0B,UAAU;AAE5C;;AAEA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACxB,IAAoB,EAAwB;EACzE,MAAME,UAAU,GAAGE,sBAAsB,CAACJ,IAAI,EAAEE,UAAU,CAAC;EAE3D,OACE,CAACA,UAAU,IACXA,UAAU,KAAKL,cAAc,CAACM,IAAI,IAClCD,UAAU,KAAKL,cAAc,CAAC0B,UAAU;AAE5C;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASnB,sBAAsBA,CAACH,UAAoC,EAAE;EAC3E,IAAIkB,gBAAgB,CAAClB,UAAU,CAAC,EAAE;IAChC,OAAOA,UAAU;EACnB;EAEA,MAAMwB,OAAO,GAAG7B,eAAe,CAACU,IAAI,CAAC,CAAC;IAAEoB;EAAK,CAAC,KAAKA,IAAI,KAAKzB,UAAU,CAAC;EACvE,OAAOwB,OAAO,EAAEE,IAAI;AACtB","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  export { ControllerNames, ControllerTypes } from "./controller-types.js";
2
2
  export { PageTypes } from "./page-types.js";
3
- export { controllerNameFromPath, getPageDefaults, hasComponents, hasFormComponents, hasSection, hasNext, isControllerName, isLinkablePage, isQuestionPage } from "./helpers.js";
3
+ export { controllerNameFromPath, getPageDefaults, hasComponents, hasFormComponents, hasSection, hasNext, isControllerName, isQuestionPage } from "./helpers.js";
4
4
  export { ControllerPath, ControllerType } from "./enums.js";
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["ControllerNames","ControllerTypes","PageTypes","controllerNameFromPath","getPageDefaults","hasComponents","hasFormComponents","hasSection","hasNext","isControllerName","isLinkablePage","isQuestionPage","ControllerPath","ControllerType"],"sources":["../../../src/pages/index.ts"],"sourcesContent":["export {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\n\nexport { PageTypes } from '~/src/pages/page-types.js'\n\nexport {\n controllerNameFromPath,\n getPageDefaults,\n hasComponents,\n hasFormComponents,\n hasSection,\n hasNext,\n isControllerName,\n isLinkablePage,\n isQuestionPage\n} from '~/src/pages/helpers.js'\n\nexport { ControllerPath, ControllerType } from '~/src/pages/enums.js'\n"],"mappings":"AAAA,SACEA,eAAe,EACfC,eAAe;AAGjB,SAASC,SAAS;AAElB,SACEC,sBAAsB,EACtBC,eAAe,EACfC,aAAa,EACbC,iBAAiB,EACjBC,UAAU,EACVC,OAAO,EACPC,gBAAgB,EAChBC,cAAc,EACdC,cAAc;AAGhB,SAASC,cAAc,EAAEC,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["ControllerNames","ControllerTypes","PageTypes","controllerNameFromPath","getPageDefaults","hasComponents","hasFormComponents","hasSection","hasNext","isControllerName","isQuestionPage","ControllerPath","ControllerType"],"sources":["../../../src/pages/index.ts"],"sourcesContent":["export {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\n\nexport { PageTypes } from '~/src/pages/page-types.js'\n\nexport {\n controllerNameFromPath,\n getPageDefaults,\n hasComponents,\n hasFormComponents,\n hasSection,\n hasNext,\n isControllerName,\n isQuestionPage\n} from '~/src/pages/helpers.js'\n\nexport { ControllerPath, ControllerType } from '~/src/pages/enums.js'\n"],"mappings":"AAAA,SACEA,eAAe,EACfC,eAAe;AAGjB,SAASC,SAAS;AAElB,SACEC,sBAAsB,EACtBC,eAAe,EACfC,aAAa,EACbC,iBAAiB,EACjBC,UAAU,EACVC,OAAO,EACPC,gBAAgB,EAChBC,cAAc;AAGhB,SAASC,cAAc,EAAEC,cAAc","ignoreList":[]}
@@ -4,7 +4,7 @@ import { ControllerType } from '../pages/enums.js';
4
4
  /**
5
5
  * Return component defaults by type
6
6
  */
7
- export declare function getPageDefaults<PageType extends Page>(page: Pick<PageType, 'controller'>): PageType;
7
+ export declare function getPageDefaults<PageType extends Page>(page?: Pick<PageType, 'controller'>): PageType;
8
8
  /**
9
9
  * Check page has components
10
10
  */
@@ -14,25 +14,19 @@ export declare function hasComponents(page?: Partial<Page>): page is Extract<Pag
14
14
  /**
15
15
  * Check page has form components
16
16
  */
17
- export declare function hasFormComponents(page?: Partial<Page>): page is Extract<Page, {
18
- components: ComponentDef[];
19
- }>;
17
+ export declare function hasFormComponents(page?: Partial<Page>): page is PageQuestion | PageFileUpload;
20
18
  /**
21
19
  * Check page has sections
22
20
  */
23
- export declare function hasSection(page: Partial<Page>): page is RequiredField<PageStart, 'section'> | RequiredField<PageQuestion, 'section'> | RequiredField<PageFileUpload, 'section'>;
24
- /**
25
- * Check page has next link
26
- */
27
- export declare function hasNext(page?: Partial<Page>): page is PageStart | PageQuestion | PageFileUpload;
21
+ export declare function hasSection(page?: Partial<Page>): page is RequiredField<PageStart, 'section'> | RequiredField<PageQuestion, 'section'> | RequiredField<PageFileUpload, 'section'>;
28
22
  /**
29
23
  * Check for known page controller names
30
24
  */
31
25
  export declare function isControllerName(nameOrPath?: ControllerType | string): nameOrPath is ControllerType;
32
26
  /**
33
- * Check page is linkable
27
+ * Check page has next link
34
28
  */
35
- export declare function isLinkablePage(page?: Partial<Page>): page is Extract<Page, {
29
+ export declare function hasNext(page?: Partial<Page>): page is Extract<Page, {
36
30
  next: Link[];
37
31
  }>;
38
32
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/pages/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EACL,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAA;AAK5C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,IAAI,EACnD,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,GAcE,QAAQ,CAC7C;AAED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AI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,YAAY,CAQzE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,CAAC,EAAE,cAAc,GAAG,MAAM,8BAO1E"}
@@ -1,5 +1,5 @@
1
1
  export { ControllerNames, ControllerTypes } from '../pages/controller-types.js';
2
2
  export { PageTypes } from '../pages/page-types.js';
3
- export { controllerNameFromPath, getPageDefaults, hasComponents, hasFormComponents, hasSection, hasNext, isControllerName, isLinkablePage, isQuestionPage } from '../pages/helpers.js';
3
+ export { controllerNameFromPath, getPageDefaults, hasComponents, hasFormComponents, hasSection, hasNext, isControllerName, isQuestionPage } from '../pages/helpers.js';
4
4
  export { ControllerPath, ControllerType } from '../pages/enums.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,cAAc,EACf,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-model",
3
- "version": "3.0.371",
3
+ "version": "3.0.373",
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": {
@@ -25,7 +25,9 @@
25
25
  "slug": "^9.1.0"
26
26
  },
27
27
  "devDependencies": {
28
- "joi": "^17.13.3"
28
+ "@types/slug": "^5.0.9",
29
+ "joi": "^17.13.3",
30
+ "tsc-alias": "^1.8.10"
29
31
  },
30
32
  "peerDependencies": {
31
33
  "joi": "^17.0.0"
@@ -18,18 +18,17 @@ import { PageTypes } from '~/src/pages/page-types.js'
18
18
  * Return component defaults by type
19
19
  */
20
20
  export function getPageDefaults<PageType extends Page>(
21
- page: Pick<PageType, 'controller'>
21
+ page?: Pick<PageType, 'controller'>
22
22
  ) {
23
- const controller = controllerNameFromPath(
24
- page.controller ?? ControllerType.Page
25
- )
23
+ const nameOrPath = page?.controller ?? ControllerType.Page
24
+ const controller = controllerNameFromPath(nameOrPath)
26
25
 
27
26
  const defaults = PageTypes.find(
28
27
  (pageType) => pageType.controller === controller
29
28
  )
30
29
 
31
30
  if (!defaults) {
32
- throw new Error(`Defaults not found for page type '${page.controller}'`)
31
+ throw new Error(`Defaults not found for page type '${nameOrPath}'`)
33
32
  }
34
33
 
35
34
  return structuredClone(defaults) as PageType
@@ -41,7 +40,7 @@ export function getPageDefaults<PageType extends Page>(
41
40
  export function hasComponents(
42
41
  page?: Partial<Page>
43
42
  ): page is Extract<Page, { components: ComponentDef[] }> {
44
- return isLinkablePage(page) && Array.isArray(page.components)
43
+ return hasNext(page) && Array.isArray(page.components)
45
44
  }
46
45
 
47
46
  /**
@@ -49,27 +48,21 @@ export function hasComponents(
49
48
  */
50
49
  export function hasFormComponents(
51
50
  page?: Partial<Page>
52
- ): page is Extract<Page, { components: ComponentDef[] }> {
53
- return isLinkablePage(page) && Array.isArray(page.components)
51
+ ): page is PageQuestion | PageFileUpload {
52
+ const controller = controllerNameFromPath(page?.controller)
53
+ return hasComponents(page) && controller !== ControllerType.Start
54
54
  }
55
55
 
56
56
  /**
57
57
  * Check page has sections
58
58
  */
59
59
  export function hasSection(
60
- page: Partial<Page>
60
+ page?: Partial<Page>
61
61
  ): page is
62
62
  | RequiredField<PageStart, 'section'>
63
63
  | RequiredField<PageQuestion, 'section'>
64
64
  | RequiredField<PageFileUpload, 'section'> {
65
- return isLinkablePage(page) && typeof page.section === 'string'
66
- }
67
-
68
- /**
69
- * Check page has next link
70
- */
71
- export function hasNext(page?: Partial<Page>) {
72
- return isLinkablePage(page)
65
+ return hasNext(page) && typeof page.section === 'string'
73
66
  }
74
67
 
75
68
  /**
@@ -82,9 +75,9 @@ export function isControllerName(
82
75
  }
83
76
 
84
77
  /**
85
- * Check page is linkable
78
+ * Check page has next link
86
79
  */
87
- export function isLinkablePage(
80
+ export function hasNext(
88
81
  page?: Partial<Page>
89
82
  ): page is Extract<Page, { next: Link[] }> {
90
83
  if (!page || !('next' in page)) {
@@ -13,7 +13,6 @@ export {
13
13
  hasSection,
14
14
  hasNext,
15
15
  isControllerName,
16
- isLinkablePage,
17
16
  isQuestionPage
18
17
  } from '~/src/pages/helpers.js'
19
18