@defra/forms-engine-plugin 5.0.0-alpha.11 → 5.0.0-alpha.13
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/.public/javascripts/shared.min.js +1 -1
- package/.public/javascripts/shared.min.js.map +1 -1
- package/.server/client/javascripts/geospatial-map.d.ts +153 -5
- package/.server/client/javascripts/geospatial-map.js +147 -46
- package/.server/client/javascripts/geospatial-map.js.map +1 -1
- package/.server/client/javascripts/location-map.d.ts +38 -0
- package/.server/client/javascripts/location-map.js +42 -2
- package/.server/client/javascripts/location-map.js.map +1 -1
- package/.server/client/javascripts/map-constants.d.ts +3 -0
- package/.server/client/javascripts/map-constants.js +4 -0
- package/.server/client/javascripts/map-constants.js.map +1 -0
- package/.server/client/javascripts/map.d.ts +4 -0
- package/.server/client/javascripts/map.js +5 -0
- package/.server/client/javascripts/map.js.map +1 -1
- package/.server/server/plugins/engine/__stubs__/definitions.d.ts +29 -0
- package/.server/server/plugins/engine/__stubs__/definitions.js +125 -0
- package/.server/server/plugins/engine/__stubs__/definitions.js.map +1 -0
- package/.server/server/plugins/engine/components/CheckboxesField.d.ts +20 -2
- package/.server/server/plugins/engine/components/CheckboxesField.js +24 -12
- package/.server/server/plugins/engine/components/CheckboxesField.js.map +1 -1
- package/.server/server/plugins/engine/components/EastingNorthingField.d.ts +4 -0
- package/.server/server/plugins/engine/components/EastingNorthingField.js +1 -1
- package/.server/server/plugins/engine/components/EastingNorthingField.js.map +1 -1
- package/.server/server/plugins/engine/components/FileUploadField.d.ts +10 -1
- package/.server/server/plugins/engine/components/FileUploadField.js +18 -6
- package/.server/server/plugins/engine/components/FileUploadField.js.map +1 -1
- package/.server/server/plugins/engine/components/GeospatialField.d.ts +22 -0
- package/.server/server/plugins/engine/components/GeospatialField.js +33 -9
- package/.server/server/plugins/engine/components/GeospatialField.js.map +1 -1
- package/.server/server/plugins/engine/components/LatLongField.d.ts +4 -0
- package/.server/server/plugins/engine/components/LocationFieldBase.js +7 -1
- package/.server/server/plugins/engine/components/LocationFieldBase.js.map +1 -1
- package/.server/server/plugins/engine/components/LocationFieldHelpers.d.ts +4 -0
- package/.server/server/plugins/engine/components/LocationFieldHelpers.js +9 -2
- package/.server/server/plugins/engine/components/LocationFieldHelpers.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/components.js +2 -1
- package/.server/server/plugins/engine/components/helpers/components.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/geospatial.d.ts +5 -0
- package/.server/server/plugins/engine/components/helpers/geospatial.js +25 -16
- package/.server/server/plugins/engine/components/helpers/geospatial.js.map +1 -1
- package/.server/server/plugins/engine/errors.d.ts +49 -0
- package/.server/server/plugins/engine/errors.js +75 -0
- package/.server/server/plugins/engine/errors.js.map +1 -0
- package/.server/server/plugins/engine/form-availability.d.ts +3 -2
- package/.server/server/plugins/engine/form-availability.js +3 -2
- package/.server/server/plugins/engine/form-availability.js.map +1 -1
- package/.server/server/plugins/engine/form-context.js +2 -2
- package/.server/server/plugins/engine/form-context.js.map +1 -1
- package/.server/server/plugins/engine/i18n/buildValidationMessages.d.ts +1 -1
- package/.server/server/plugins/engine/i18n/buildValidationMessages.js +30 -9
- package/.server/server/plugins/engine/i18n/buildValidationMessages.js.map +1 -1
- package/.server/server/plugins/engine/i18n/translations/cy.json +117 -11
- package/.server/server/plugins/engine/i18n/translations/en-GB.json +80 -11
- package/.server/server/plugins/engine/i18n/types.d.ts +1 -0
- package/.server/server/plugins/engine/i18n/types.js.map +1 -1
- package/.server/server/plugins/engine/models/FormModel.js +10 -2
- package/.server/server/plugins/engine/models/FormModel.js.map +1 -1
- package/.server/server/plugins/engine/models/unavailable-view-model.d.ts +11 -2
- package/.server/server/plugins/engine/models/unavailable-view-model.js +23 -4
- package/.server/server/plugins/engine/models/unavailable-view-model.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/helpers/pages.js +2 -1
- package/.server/server/plugins/engine/pageControllers/helpers/pages.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/validationOptions.d.ts +1 -1
- package/.server/server/plugins/engine/pageControllers/validationOptions.js +1 -1
- package/.server/server/plugins/engine/pageControllers/validationOptions.js.map +1 -1
- package/.server/server/plugins/engine/unavailable-response.js +5 -2
- package/.server/server/plugins/engine/unavailable-response.js.map +1 -1
- package/.server/server/plugins/engine/views/components/_location-field-base.html +2 -1
- package/.server/server/plugins/engine/views/components/geospatialfield.html +1 -0
- package/.server/server/plugins/engine/views/components/osgridreffield.html +3 -1
- package/.server/server/plugins/engine/views/unavailable.html +14 -11
- package/package.json +1 -1
- package/src/client/javascripts/geospatial-map.js +169 -47
- package/src/client/javascripts/location-map.js +50 -2
- package/src/client/javascripts/map-constants.js +3 -0
- package/src/client/javascripts/map.js +5 -0
- package/src/server/plugins/engine/__stubs__/definitions.ts +155 -0
- package/src/server/plugins/engine/components/CheckboxesField.ts +34 -13
- package/src/server/plugins/engine/components/EastingNorthingField.ts +1 -1
- package/src/server/plugins/engine/components/FileUploadField.ts +26 -6
- package/src/server/plugins/engine/components/GeospatialField.ts +44 -11
- package/src/server/plugins/engine/components/LocationFieldBase.ts +7 -1
- package/src/server/plugins/engine/components/LocationFieldHelpers.ts +9 -2
- package/src/server/plugins/engine/components/helpers/components.ts +2 -1
- package/src/server/plugins/engine/components/helpers/geospatial.ts +32 -22
- package/src/server/plugins/engine/errors.ts +78 -0
- package/src/server/plugins/engine/form-availability.ts +8 -2
- package/src/server/plugins/engine/form-context.ts +4 -2
- package/src/server/plugins/engine/i18n/buildValidationMessages.ts +15 -10
- package/src/server/plugins/engine/i18n/translations/cy.json +117 -11
- package/src/server/plugins/engine/i18n/translations/en-GB.json +80 -11
- package/src/server/plugins/engine/i18n/types.ts +1 -0
- package/src/server/plugins/engine/models/FormModel.ts +12 -2
- package/src/server/plugins/engine/models/unavailable-view-model.ts +26 -5
- package/src/server/plugins/engine/pageControllers/helpers/pages.ts +2 -1
- package/src/server/plugins/engine/pageControllers/validationOptions.ts +2 -2
- package/src/server/plugins/engine/unavailable-response.ts +6 -2
- package/src/server/plugins/engine/views/components/_location-field-base.html +2 -1
- package/src/server/plugins/engine/views/components/geospatialfield.html +1 -0
- package/src/server/plugins/engine/views/components/osgridreffield.html +3 -1
- package/src/server/plugins/engine/views/unavailable.html +14 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-context.js","names":["Boom","isEqual","PREVIEW_PATH_PREFIX","assertFormAvailable","checkEmailAddressForLiveFormSubmission","getCacheService","FormModel","TerminalPageController","defaultServices","FormStatus","resolveLanguage","getFormModel","slug","state","options","services","formsService","isPreview","isPreviewState","formState","resolveState","metadata","getFormMetadata","definition","getFormDefinition","id","notFound","basePath","buildBasePath","routePrefix","ordnanceSurveyApiKey","formId","controllers","getFormContext","server","yar","Live","formModel","resolveFormModel","cacheService","summaryRequest","app","method","params","path","query","url","URL","cachedState","getState","$$__referenceNumber","language","translator","createTranslator","errors","stateMetadata","models","Map","cache","cacheKey","entry","get","updatedAt","notificationEmail","realm","modifiers","route","prefix","model","set","base","replace","startsWith","slice","getFirstJourneyPage","context","relevantPages","undefined","lastPageReached","at","penultimatePageReached"],"sources":["../../../../src/server/plugins/engine/form-context.ts"],"sourcesContent":["import Boom from '@hapi/boom'\nimport { type Request, type Server } from '@hapi/hapi'\nimport { isEqual } from 'date-fns'\n\nimport { PREVIEW_PATH_PREFIX } from '~/src/server/constants.js'\nimport { assertFormAvailable } from '~/src/server/plugins/engine/form-availability.js'\nimport {\n checkEmailAddressForLiveFormSubmission,\n getCacheService\n} from '~/src/server/plugins/engine/helpers.js'\nimport { FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageController } from '~/src/server/plugins/engine/pageControllers/PageController.js'\nimport { TerminalPageController } from '~/src/server/plugins/engine/pageControllers/index.js'\nimport * as defaultServices from '~/src/server/plugins/engine/services/index.js'\nimport {\n type AnyFormRequest,\n type AnyRequest,\n type FormContext,\n type FormContextRequest,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { FormStatus } from '~/src/server/routes/types.js'\nimport { type Services } from '~/src/server/types.js'\nimport { resolveLanguage } from '~/src/server/utils/utils.js'\n\ntype JourneyState = FormStatus | 'preview'\n\nexport interface FormModelOptions {\n services?: Services\n controllers?: Record<string, typeof PageController>\n basePath?: string\n ordnanceSurveyApiKey?: string\n formId?: string\n routePrefix?: string\n isPreview?: boolean\n}\n\nexport interface FormContextOptions extends FormModelOptions {\n errors?: FormSubmissionError[]\n language?: string\n}\n\ntype SummaryRequest = FormContextRequest & {\n yar: Request['yar']\n}\n\nexport async function getFormModel(\n slug: string,\n state: JourneyState,\n options: FormModelOptions = {}\n) {\n const services = options.services ?? defaultServices\n const { formsService } = services\n const isPreview = isPreviewState(state, options)\n const formState = resolveState(state)\n\n const metadata = await formsService.getFormMetadata(slug)\n assertFormAvailable(metadata, formState, isPreview)\n\n const definition = await formsService.getFormDefinition(\n metadata.id,\n formState\n )\n\n if (!definition) {\n throw Boom.notFound(\n `No definition found for form metadata ${metadata.id} (${slug}) ${state}`\n )\n }\n\n return new FormModel(\n definition,\n {\n basePath:\n options.basePath ??\n buildBasePath(options.routePrefix ?? '', slug, formState, isPreview),\n ordnanceSurveyApiKey: options.ordnanceSurveyApiKey,\n formId: options.formId ?? metadata.id\n },\n services,\n options.controllers\n )\n}\n\nexport async function getFormContext(\n { server, yar }: Pick<Request, 'server' | 'yar'>,\n slug: string,\n state: JourneyState = FormStatus.Live,\n options: FormContextOptions = {}\n): Promise<FormContext> {\n const formModel = await resolveFormModel(server, slug, state, options)\n\n const cacheService = getCacheService(server)\n\n const summaryRequest: SummaryRequest = {\n app: {},\n method: 'get',\n params: {\n path: 'summary',\n slug,\n ...(isPreviewState(state, options) && {\n state: resolveState(state)\n })\n },\n path: `/${formModel.basePath}/summary`,\n query: {},\n url: new URL(\n `/${formModel.basePath}/summary`,\n 'https://form-context.local'\n ),\n server,\n yar\n }\n\n const cachedState = await cacheService.getState(\n summaryRequest as unknown as AnyRequest\n )\n\n const formState = {\n ...cachedState,\n $$__referenceNumber: cachedState.$$__referenceNumber\n } as unknown as FormSubmissionState\n\n const language = resolveLanguage(summaryRequest as unknown as AnyFormRequest)\n const translator = formModel.createTranslator(language)\n\n return formModel.getFormContext(\n summaryRequest,\n formState,\n options.errors ?? [],\n translator\n )\n}\n\nexport async function resolveFormModel(\n server: Server,\n slug: string,\n state: JourneyState,\n options: FormModelOptions = {}\n) {\n const services = options.services ?? defaultServices\n const { formsService } = services\n\n const metadata = await formsService.getFormMetadata(slug)\n const formState = resolveState(state)\n const isPreview = options.isPreview ?? isPreviewState(state, options)\n assertFormAvailable(metadata, formState, isPreview)\n const stateMetadata = metadata[formState]\n\n if (!stateMetadata) {\n throw Boom.notFound(\n `No '${formState}' state for form metadata ${metadata.id}`\n )\n }\n\n // The models cache is created lazily per server instance\n server.app.models ??= new Map<string, { model: FormModel; updatedAt: Date }>()\n\n const cache = server.app.models\n\n const cacheKey = `${metadata.id}_${formState}_${isPreview}`\n let entry = cache.get(cacheKey)\n\n if (!entry || !isEqual(entry.updatedAt, stateMetadata.updatedAt)) {\n const definition = await formsService.getFormDefinition(\n metadata.id,\n formState\n )\n\n if (!definition) {\n throw Boom.notFound(\n `No definition found for form metadata ${metadata.id} (${slug}) ${state}`\n )\n }\n\n checkEmailAddressForLiveFormSubmission(\n metadata.notificationEmail,\n isPreview\n )\n\n const routePrefix =\n options.routePrefix ?? server.realm.modifiers.route.prefix\n\n const model = new FormModel(\n definition,\n {\n basePath:\n options.basePath ??\n buildBasePath(routePrefix, slug, formState, isPreview),\n ordnanceSurveyApiKey: options.ordnanceSurveyApiKey,\n formId: options.formId ?? metadata.id\n },\n services,\n options.controllers\n )\n\n entry = { model, updatedAt: stateMetadata.updatedAt }\n cache.set(cacheKey, entry)\n }\n\n return entry.model\n}\n\nfunction buildBasePath(\n routePrefix: string,\n slug: string,\n state: FormStatus,\n isPreview: boolean\n) {\n const base = (\n isPreview\n ? `${routePrefix}${PREVIEW_PATH_PREFIX}/${state}/${slug}`\n : `${routePrefix}/${slug}`\n ).replace(/\\/{2,}/g, '/')\n\n return base.startsWith('/') ? base.slice(1) : base\n}\n\nexport function getFirstJourneyPage(\n context?: Pick<FormContext, 'relevantPages'>\n) {\n if (!context?.relevantPages) {\n return undefined\n }\n\n const lastPageReached = context.relevantPages.at(-1)\n const penultimatePageReached = context.relevantPages.at(-2)\n\n if (\n lastPageReached instanceof TerminalPageController &&\n penultimatePageReached\n ) {\n return penultimatePageReached\n }\n\n return lastPageReached\n}\n\nfunction resolveState(state: JourneyState): FormStatus {\n return state === 'preview' ? FormStatus.Live : state\n}\n\nfunction isPreviewState(\n state: JourneyState,\n options: FormModelOptions = {}\n): boolean {\n return options.isPreview ?? state === 'preview'\n}\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,YAAY;AAE7B,SAASC,OAAO,QAAQ,UAAU;AAElC,SAASC,mBAAmB;AAC5B,SAASC,mBAAmB;AAC5B,SACEC,sCAAsC,EACtCC,eAAe;AAEjB,SAASC,SAAS;AAElB,SAASC,sBAAsB;AAC/B,OAAO,KAAKC,eAAe;AAS3B,SAASC,UAAU;AAEnB,SAASC,eAAe;AAuBxB,OAAO,eAAeC,YAAYA,CAChCC,IAAY,EACZC,KAAmB,EACnBC,OAAyB,GAAG,CAAC,CAAC,EAC9B;EACA,MAAMC,QAAQ,GAAGD,OAAO,CAACC,QAAQ,IAAIP,eAAe;EACpD,MAAM;IAAEQ;EAAa,CAAC,GAAGD,QAAQ;EACjC,MAAME,SAAS,GAAGC,cAAc,CAACL,KAAK,EAAEC,OAAO,CAAC;EAChD,MAAMK,SAAS,GAAGC,YAAY,CAACP,KAAK,CAAC;EAErC,MAAMQ,QAAQ,GAAG,MAAML,YAAY,CAACM,eAAe,CAACV,IAAI,CAAC;EACzDT,mBAAmB,CAACkB,QAAQ,EAAEF,SAAS,EAAEF,SAAS,CAAC;EAEnD,MAAMM,UAAU,GAAG,MAAMP,YAAY,CAACQ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EA,OAAOA,KAAK,CAACQ,KAAK;AACpB;AAEA,SAASxC,aAAaA,CACpBC,WAAmB,EACnBjB,IAAY,EACZC,KAAiB,EACjBI,SAAkB,EAClB;EACA,MAAMqD,IAAI,GAAG,CACXrD,SAAS,GACL,GAAGY,WAAW,GAAG3B,mBAAmB,IAAIW,KAAK,IAAID,IAAI,EAAE,GACvD,GAAGiB,WAAW,IAAIjB,IAAI,EAAE,EAC5B2D,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;EAEzB,OAAOD,IAAI,CAACE,UAAU,CAAC,GAAG,CAAC,GAAGF,IAAI,CAACG,KAAK,CAAC,CAAC,CAAC,GAAGH,IAAI;AACpD;AAEA,OAAO,SAASI,mBAAmBA,CACjCC,OAA4C,EAC5C;EACA,IAAI,CAACA,OAAO,EAAEC,aAAa,EAAE;IAC3B,OAAOC,SAAS;EAClB;EAEA,MAAMC,eAAe,GAAGH,OAAO,CAACC,aAAa,CAACG,EAAE,CAAC,CAAC,CAAC,CAAC;EACpD,MAAMC,sBAAsB,GAAGL,OAAO,CAACC,aAAa,CAACG,EAAE,CAAC,CAAC,CAAC,CAAC;EAE3D,IACED,eAAe,YAAYvE,sBAAsB,IACjDyE,sBAAsB,EACtB;IACA,OAAOA,sBAAsB;EAC/B;EAEA,OAAOF,eAAe;AACxB;AAEA,SAAS1D,YAAYA,CAACP,KAAmB,EAAc;EACrD,OAAOA,KAAK,KAAK,SAAS,GAAGJ,UAAU,CAAC2B,IAAI,GAAGvB,KAAK;AACtD;AAEA,SAASK,cAAcA,CACrBL,KAAmB,EACnBC,OAAyB,GAAG,CAAC,CAAC,EACrB;EACT,OAAOA,OAAO,CAACG,SAAS,IAAIJ,KAAK,KAAK,SAAS;AACjD","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"form-context.js","names":["Boom","isEqual","PREVIEW_PATH_PREFIX","assertFormAvailable","checkEmailAddressForLiveFormSubmission","getCacheService","FormModel","TerminalPageController","defaultServices","FormStatus","resolveLanguage","getFormModel","slug","state","options","services","formsService","isPreview","isPreviewState","formState","resolveState","metadata","getFormMetadata","definition","getFormDefinition","id","notFound","basePath","buildBasePath","routePrefix","ordnanceSurveyApiKey","formId","controllers","getFormContext","server","yar","Live","formModel","resolveFormModel","cacheService","summaryRequest","app","method","params","path","query","url","URL","cachedState","getState","$$__referenceNumber","language","translator","createTranslator","errors","stateMetadata","models","Map","cache","cacheKey","entry","get","updatedAt","notificationEmail","realm","modifiers","route","prefix","model","set","def","base","replace","startsWith","slice","getFirstJourneyPage","context","relevantPages","undefined","lastPageReached","at","penultimatePageReached"],"sources":["../../../../src/server/plugins/engine/form-context.ts"],"sourcesContent":["import Boom from '@hapi/boom'\nimport { type Request, type Server } from '@hapi/hapi'\nimport { isEqual } from 'date-fns'\n\nimport { PREVIEW_PATH_PREFIX } from '~/src/server/constants.js'\nimport { assertFormAvailable } from '~/src/server/plugins/engine/form-availability.js'\nimport {\n checkEmailAddressForLiveFormSubmission,\n getCacheService\n} from '~/src/server/plugins/engine/helpers.js'\nimport { FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageController } from '~/src/server/plugins/engine/pageControllers/PageController.js'\nimport { TerminalPageController } from '~/src/server/plugins/engine/pageControllers/index.js'\nimport * as defaultServices from '~/src/server/plugins/engine/services/index.js'\nimport {\n type AnyFormRequest,\n type AnyRequest,\n type FormContext,\n type FormContextRequest,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { FormStatus } from '~/src/server/routes/types.js'\nimport { type Services } from '~/src/server/types.js'\nimport { resolveLanguage } from '~/src/server/utils/utils.js'\n\ntype JourneyState = FormStatus | 'preview'\n\nexport interface FormModelOptions {\n services?: Services\n controllers?: Record<string, typeof PageController>\n basePath?: string\n ordnanceSurveyApiKey?: string\n formId?: string\n routePrefix?: string\n isPreview?: boolean\n}\n\nexport interface FormContextOptions extends FormModelOptions {\n errors?: FormSubmissionError[]\n language?: string\n}\n\ntype SummaryRequest = FormContextRequest & {\n yar: Request['yar']\n}\n\nexport async function getFormModel(\n slug: string,\n state: JourneyState,\n options: FormModelOptions = {}\n) {\n const services = options.services ?? defaultServices\n const { formsService } = services\n const isPreview = isPreviewState(state, options)\n const formState = resolveState(state)\n\n const metadata = await formsService.getFormMetadata(slug)\n\n const definition = await formsService.getFormDefinition(\n metadata.id,\n formState\n )\n\n assertFormAvailable(metadata, definition, formState, isPreview)\n\n if (!definition) {\n throw Boom.notFound(\n `No definition found for form metadata ${metadata.id} (${slug}) ${state}`\n )\n }\n\n return new FormModel(\n definition,\n {\n basePath:\n options.basePath ??\n buildBasePath(options.routePrefix ?? '', slug, formState, isPreview),\n ordnanceSurveyApiKey: options.ordnanceSurveyApiKey,\n formId: options.formId ?? metadata.id\n },\n services,\n options.controllers\n )\n}\n\nexport async function getFormContext(\n { server, yar }: Pick<Request, 'server' | 'yar'>,\n slug: string,\n state: JourneyState = FormStatus.Live,\n options: FormContextOptions = {}\n): Promise<FormContext> {\n const formModel = await resolveFormModel(server, slug, state, options)\n\n const cacheService = getCacheService(server)\n\n const summaryRequest: SummaryRequest = {\n app: {},\n method: 'get',\n params: {\n path: 'summary',\n slug,\n ...(isPreviewState(state, options) && {\n state: resolveState(state)\n })\n },\n path: `/${formModel.basePath}/summary`,\n query: {},\n url: new URL(\n `/${formModel.basePath}/summary`,\n 'https://form-context.local'\n ),\n server,\n yar\n }\n\n const cachedState = await cacheService.getState(\n summaryRequest as unknown as AnyRequest\n )\n\n const formState = {\n ...cachedState,\n $$__referenceNumber: cachedState.$$__referenceNumber\n } as unknown as FormSubmissionState\n\n const language = resolveLanguage(summaryRequest as unknown as AnyFormRequest)\n const translator = formModel.createTranslator(language)\n\n return formModel.getFormContext(\n summaryRequest,\n formState,\n options.errors ?? [],\n translator\n )\n}\n\nexport async function resolveFormModel(\n server: Server,\n slug: string,\n state: JourneyState,\n options: FormModelOptions = {}\n) {\n const services = options.services ?? defaultServices\n const { formsService } = services\n\n const metadata = await formsService.getFormMetadata(slug)\n const formState = resolveState(state)\n const isPreview = options.isPreview ?? isPreviewState(state, options)\n const stateMetadata = metadata[formState]\n\n if (!stateMetadata) {\n throw Boom.notFound(\n `No '${formState}' state for form metadata ${metadata.id}`\n )\n }\n\n // The models cache is created lazily per server instance\n server.app.models ??= new Map<string, { model: FormModel; updatedAt: Date }>()\n\n const cache = server.app.models\n\n const cacheKey = `${metadata.id}_${formState}_${isPreview}`\n let entry = cache.get(cacheKey)\n\n if (!entry || !isEqual(entry.updatedAt, stateMetadata.updatedAt)) {\n const definition = await formsService.getFormDefinition(\n metadata.id,\n formState\n )\n\n if (!definition) {\n throw Boom.notFound(\n `No definition found for form metadata ${metadata.id} (${slug}) ${state}`\n )\n }\n\n checkEmailAddressForLiveFormSubmission(\n metadata.notificationEmail,\n isPreview\n )\n\n const routePrefix =\n options.routePrefix ?? server.realm.modifiers.route.prefix\n\n const model = new FormModel(\n definition,\n {\n basePath:\n options.basePath ??\n buildBasePath(routePrefix, slug, formState, isPreview),\n ordnanceSurveyApiKey: options.ordnanceSurveyApiKey,\n formId: options.formId ?? metadata.id\n },\n services,\n options.controllers\n )\n\n entry = { model, updatedAt: stateMetadata.updatedAt }\n cache.set(cacheKey, entry)\n }\n\n assertFormAvailable(metadata, entry.model.def, formState, isPreview)\n\n return entry.model\n}\n\nfunction buildBasePath(\n routePrefix: string,\n slug: string,\n state: FormStatus,\n isPreview: boolean\n) {\n const base = (\n isPreview\n ? `${routePrefix}${PREVIEW_PATH_PREFIX}/${state}/${slug}`\n : `${routePrefix}/${slug}`\n ).replace(/\\/{2,}/g, '/')\n\n return base.startsWith('/') ? base.slice(1) : base\n}\n\nexport function getFirstJourneyPage(\n context?: Pick<FormContext, 'relevantPages'>\n) {\n if (!context?.relevantPages) {\n return undefined\n }\n\n const lastPageReached = context.relevantPages.at(-1)\n const penultimatePageReached = context.relevantPages.at(-2)\n\n if (\n lastPageReached instanceof TerminalPageController &&\n penultimatePageReached\n ) {\n return penultimatePageReached\n }\n\n return lastPageReached\n}\n\nfunction resolveState(state: JourneyState): FormStatus {\n return state === 'preview' ? FormStatus.Live : state\n}\n\nfunction isPreviewState(\n state: JourneyState,\n options: FormModelOptions = {}\n): boolean {\n return options.isPreview ?? state === 'preview'\n}\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,YAAY;AAE7B,SAASC,OAAO,QAAQ,UAAU;AAElC,SAASC,mBAAmB;AAC5B,SAASC,mBAAmB;AAC5B,SACEC,sCAAsC,EACtCC,eAAe;AAEjB,SAASC,SAAS;AAElB,SAASC,sBAAsB;AAC/B,OAAO,KAAKC,eAAe;AAS3B,SAASC,UAAU;AAEnB,SAASC,eAAe;AAuBxB,OAAO,eAAeC,YAAYA,CAChCC,IAAY,EACZC,KAAmB,EACnBC,OAAyB,GAAG,CAAC,CAAC,EAC9B;EACA,MAAMC,QAAQ,GAAGD,OAAO,CAACC,QAAQ,IAAIP,eAAe;EACpD,MAAM;IAAEQ;EAAa,CAAC,GAAGD,QAAQ;EACjC,MAAME,SAAS,GAAGC,cAAc,CAACL,KAAK,EAAEC,OAAO,CAAC;EAChD,MAAMK,SAAS,GAAGC,YAAY,CAACP,KAAK,CAAC;EAErC,MAAMQ,QAAQ,GAAG,MAAML,YAAY,CAACM,eAAe,CAACV,IAAI,CAAC;EAEzD,MAAMW,UAAU,GAAG,MAAMP,YAAY,CAACQ,iBAAiB,CACrDH,QAAQ,CAACI,EAAE,EACXN,SACF,CAAC;EAEDhB,mBAAmB,CAACkB,QAAQ,EAAEE,UAAU,EAAEJ,SAAS,EAAEF,SAAS,CAAC;EAE/D,IAAI,CAACM,UAAU,EAAE;IACf,MAAMvB,IAAI,CAAC0B,QAAQ,CACjB,yCAAyCL,QAAQ,CAACI,EAAE,KAAKb,IAAI,KAAKC,KAAK,EACzE,CAAC;EACH;EAEA,OAAO,IAAIP,SAAS,CAClBiB,UAAU,EACV;IACEI,QAAQ,EACNb,OAAO,CAACa,QAAQ,IAChBC,aAAa,CAACd,OAAO,CAACe,WA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C5B4D,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;EAEzB,OAAOD,IAAI,CAACE,UAAU,CAAC,GAAG,CAAC,GAAGF,IAAI,CAACG,KAAK,CAAC,CAAC,CAAC,GAAGH,IAAI;AACpD;AAEA,OAAO,SAASI,mBAAmBA,CACjCC,OAA4C,EAC5C;EACA,IAAI,CAACA,OAAO,EAAEC,aAAa,EAAE;IAC3B,OAAOC,SAAS;EAClB;EAEA,MAAMC,eAAe,GAAGH,OAAO,CAACC,aAAa,CAACG,EAAE,CAAC,CAAC,CAAC,CAAC;EACpD,MAAMC,sBAAsB,GAAGL,OAAO,CAACC,aAAa,CAACG,EAAE,CAAC,CAAC,CAAC,CAAC;EAE3D,IACED,eAAe,YAAYxE,sBAAsB,IACjD0E,sBAAsB,EACtB;IACA,OAAOA,sBAAsB;EAC/B;EAEA,OAAOF,eAAe;AACxB;AAEA,SAAS3D,YAAYA,CAACP,KAAmB,EAAc;EACrD,OAAOA,KAAK,KAAK,SAAS,GAAGJ,UAAU,CAAC2B,IAAI,GAAGvB,KAAK;AACtD;AAEA,SAASK,cAAcA,CACrBL,KAAmB,EACnBC,OAAyB,GAAG,CAAC,CAAC,EACrB;EACT,OAAOA,OAAO,CAACG,SAAS,IAAIJ,KAAK,KAAK,SAAS;AACjD","ignoreList":[]}
|
|
@@ -7,7 +7,7 @@ import { type JoiExpression } from 'joi';
|
|
|
7
7
|
* because Joi cannot resolve custom functions from a plain string.
|
|
8
8
|
* Plain strings with only built-in tokens ({{#label}}, {{#limit}}) work without wrapping.
|
|
9
9
|
*/
|
|
10
|
-
export declare function buildValidationMessages(t: (key: string) => string): {
|
|
10
|
+
export declare function buildValidationMessages(t: (key: string, options?: Record<string, unknown>) => string): {
|
|
11
11
|
required: JoiExpression;
|
|
12
12
|
selectRequired: JoiExpression;
|
|
13
13
|
pattern: JoiExpression;
|
|
@@ -39,15 +39,36 @@ export function buildValidationMessages(t) {
|
|
|
39
39
|
dateMin: t('components.dateField.validation.dateMin'),
|
|
40
40
|
dateMax: t('components.dateField.validation.dateMax'),
|
|
41
41
|
unicode: t('validation.unicode'),
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
// These generic templates are shared across fields with differing limits, so a
|
|
43
|
+
// fixed singular count is used here — components needing accurate singular/plural
|
|
44
|
+
// text (e.g. FileUploadField) build their own per-instance messages instead.
|
|
45
|
+
arrayMin: t('validation.arrayMin', {
|
|
46
|
+
count: 1
|
|
47
|
+
}),
|
|
48
|
+
arrayMax: t('validation.arrayMax', {
|
|
49
|
+
count: 1
|
|
50
|
+
}),
|
|
51
|
+
arrayLength: t('validation.arrayLength', {
|
|
52
|
+
count: 1
|
|
53
|
+
}),
|
|
54
|
+
featuresMin: t('validation.featuresMin', {
|
|
55
|
+
count: 1
|
|
56
|
+
}),
|
|
57
|
+
featuresMax: t('validation.featuresMax', {
|
|
58
|
+
count: 1
|
|
59
|
+
}),
|
|
60
|
+
featuresLength: t('validation.featuresLength', {
|
|
61
|
+
count: 1
|
|
62
|
+
}),
|
|
63
|
+
filesMin: t('validation.filesMin', {
|
|
64
|
+
count: 1
|
|
65
|
+
}),
|
|
66
|
+
filesMax: t('validation.filesMax', {
|
|
67
|
+
count: 1
|
|
68
|
+
}),
|
|
69
|
+
filesLength: t('validation.filesLength', {
|
|
70
|
+
count: 1
|
|
71
|
+
})
|
|
51
72
|
};
|
|
52
73
|
}
|
|
53
74
|
//# sourceMappingURL=buildValidationMessages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildValidationMessages.js","names":["joi","lowerFirstPreserveProperNouns","opts","functions","lowerFirst","buildValidationMessages","t","required","expression","selectRequired","pattern","format","declarationRequired","objectRequired","objectMissing","selectYesNoRequired","max","min","minMax","number","numberPrecision","numberInteger","numberMin","numberMax","maxWords","dateFormat","dateMin","dateMax","unicode","arrayMin","arrayMax","arrayLength","featuresMin","featuresMax","featuresLength","filesMin","filesMax","filesLength"],"sources":["../../../../../src/server/plugins/engine/i18n/buildValidationMessages.ts"],"sourcesContent":["import joi, { type JoiExpression, type ReferenceOptions } from 'joi'\n\nimport { lowerFirstPreserveProperNouns } from '~/src/server/plugins/engine/components/helpers/index.js'\n\nconst opts = {\n functions: {\n lowerFirst: lowerFirstPreserveProperNouns\n }\n} as ReferenceOptions\n\n/**\n * Builds a set of translated Joi message templates for a given language.\n * Called once per FormModel at construction time.\n *\n * Strings containing {{lowerFirst(#label)}} must be wrapped in joi.expression()\n * because Joi cannot resolve custom functions from a plain string.\n * Plain strings with only built-in tokens ({{#label}}, {{#limit}}) work without wrapping.\n */\nexport function buildValidationMessages(t: (key: string) => string) {\n return {\n // Expressions — contain lowerFirst custom function\n required: joi.expression(t('validation.required'), opts) as JoiExpression,\n selectRequired: joi.expression(\n t('validation.selectRequired'),\n opts\n ) as JoiExpression,\n pattern: joi.expression(t('validation.pattern'), opts) as JoiExpression,\n format: joi.expression(t('validation.format'), opts) as JoiExpression,\n declarationRequired: joi.expression(\n t('components.declarationField.validation.declarationRequired'),\n opts\n ) as JoiExpression,\n objectRequired: joi.expression(\n t('validation.objectRequired'),\n opts\n ) as JoiExpression,\n objectMissing: joi.expression(\n t('validation.objectMissing'),\n opts\n ) as JoiExpression,\n\n // Plain Joi template strings — no lowerFirst\n selectYesNoRequired: t(\n 'components.yesNoField.validation.selectYesNoRequired'\n ),\n max: t('validation.max'),\n min: t('validation.min'),\n minMax: t('validation.minMax'),\n number: t('validation.number'),\n numberPrecision: t('validation.numberPrecision'),\n numberInteger: t('validation.numberInteger'),\n numberMin: t('validation.numberMin'),\n numberMax: t('validation.numberMax'),\n maxWords: t('validation.maxWords'),\n dateFormat: t('components.dateField.validation.dateFormat'),\n dateMin: t('components.dateField.validation.dateMin'),\n dateMax: t('components.dateField.validation.dateMax'),\n\n unicode: t('validation.unicode'),\n arrayMin: t('validation.arrayMin'),\n arrayMax: t('validation.arrayMax'),\n arrayLength: t('validation.arrayLength'),\n featuresMin: t('validation.featuresMin'),\n featuresMax: t('validation.featuresMax'),\n featuresLength: t('validation.featuresLength'),\n filesMin: t('validation.filesMin'),\n filesMax: t('validation.filesMax'),\n filesLength: t('validation.filesLength')\n }\n}\n\nexport type ValidationMessages = ReturnType<typeof buildValidationMessages>\n"],"mappings":"AAAA,OAAOA,GAAG,MAAqD,KAAK;AAEpE,SAASC,6BAA6B;AAEtC,MAAMC,IAAI,GAAG;EACXC,SAAS,EAAE;IACTC,UAAU,EAAEH;EACd;AACF,CAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,uBAAuBA,
|
|
1
|
+
{"version":3,"file":"buildValidationMessages.js","names":["joi","lowerFirstPreserveProperNouns","opts","functions","lowerFirst","buildValidationMessages","t","required","expression","selectRequired","pattern","format","declarationRequired","objectRequired","objectMissing","selectYesNoRequired","max","min","minMax","number","numberPrecision","numberInteger","numberMin","numberMax","maxWords","dateFormat","dateMin","dateMax","unicode","arrayMin","count","arrayMax","arrayLength","featuresMin","featuresMax","featuresLength","filesMin","filesMax","filesLength"],"sources":["../../../../../src/server/plugins/engine/i18n/buildValidationMessages.ts"],"sourcesContent":["import joi, { type JoiExpression, type ReferenceOptions } from 'joi'\n\nimport { lowerFirstPreserveProperNouns } from '~/src/server/plugins/engine/components/helpers/index.js'\n\nconst opts = {\n functions: {\n lowerFirst: lowerFirstPreserveProperNouns\n }\n} as ReferenceOptions\n\n/**\n * Builds a set of translated Joi message templates for a given language.\n * Called once per FormModel at construction time.\n *\n * Strings containing {{lowerFirst(#label)}} must be wrapped in joi.expression()\n * because Joi cannot resolve custom functions from a plain string.\n * Plain strings with only built-in tokens ({{#label}}, {{#limit}}) work without wrapping.\n */\nexport function buildValidationMessages(\n t: (key: string, options?: Record<string, unknown>) => string\n) {\n return {\n // Expressions — contain lowerFirst custom function\n required: joi.expression(t('validation.required'), opts) as JoiExpression,\n selectRequired: joi.expression(\n t('validation.selectRequired'),\n opts\n ) as JoiExpression,\n pattern: joi.expression(t('validation.pattern'), opts) as JoiExpression,\n format: joi.expression(t('validation.format'), opts) as JoiExpression,\n declarationRequired: joi.expression(\n t('components.declarationField.validation.declarationRequired'),\n opts\n ) as JoiExpression,\n objectRequired: joi.expression(\n t('validation.objectRequired'),\n opts\n ) as JoiExpression,\n objectMissing: joi.expression(\n t('validation.objectMissing'),\n opts\n ) as JoiExpression,\n\n // Plain Joi template strings — no lowerFirst\n selectYesNoRequired: t(\n 'components.yesNoField.validation.selectYesNoRequired'\n ),\n max: t('validation.max'),\n min: t('validation.min'),\n minMax: t('validation.minMax'),\n number: t('validation.number'),\n numberPrecision: t('validation.numberPrecision'),\n numberInteger: t('validation.numberInteger'),\n numberMin: t('validation.numberMin'),\n numberMax: t('validation.numberMax'),\n maxWords: t('validation.maxWords'),\n dateFormat: t('components.dateField.validation.dateFormat'),\n dateMin: t('components.dateField.validation.dateMin'),\n dateMax: t('components.dateField.validation.dateMax'),\n\n unicode: t('validation.unicode'),\n // These generic templates are shared across fields with differing limits, so a\n // fixed singular count is used here — components needing accurate singular/plural\n // text (e.g. FileUploadField) build their own per-instance messages instead.\n arrayMin: t('validation.arrayMin', { count: 1 }),\n arrayMax: t('validation.arrayMax', { count: 1 }),\n arrayLength: t('validation.arrayLength', { count: 1 }),\n featuresMin: t('validation.featuresMin', { count: 1 }),\n featuresMax: t('validation.featuresMax', { count: 1 }),\n featuresLength: t('validation.featuresLength', { count: 1 }),\n filesMin: t('validation.filesMin', { count: 1 }),\n filesMax: t('validation.filesMax', { count: 1 }),\n filesLength: t('validation.filesLength', { count: 1 })\n }\n}\n\nexport type ValidationMessages = ReturnType<typeof buildValidationMessages>\n"],"mappings":"AAAA,OAAOA,GAAG,MAAqD,KAAK;AAEpE,SAASC,6BAA6B;AAEtC,MAAMC,IAAI,GAAG;EACXC,SAAS,EAAE;IACTC,UAAU,EAAEH;EACd;AACF,CAAqB;;A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AC,CAAC,qBAAqB,CAAC;IAClCmB,UAAU,EAAEnB,CAAC,CAAC,4CAA4C,CAAC;IAC3DoB,OAAO,EAAEpB,CAAC,CAAC,yCAAyC,CAAC;IACrDqB,OAAO,EAAErB,CAAC,CAAC,yCAAyC,CAAC;IAErDsB,OAAO,EAAEtB,CAAC,CAAC,oBAAoB,CAAC;IAChC;IACA;IACA;IACAuB,QAAQ,EAAEvB,CAAC,CAAC,qBAAqB,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC,CAAC;IAChDC,QAAQ,EAAEzB,CAAC,CAAC,qBAAqB,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC,CAAC;IAChDE,WAAW,EAAE1B,CAAC,CAAC,wBAAwB,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC,CAAC;IACtDG,WAAW,EAAE3B,CAAC,CAAC,wBAAwB,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC,CAAC;IACtDI,WAAW,EAAE5B,CAAC,CAAC,wBAAwB,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC,CAAC;IACtDK,cAAc,EAAE7B,CAAC,CAAC,2BAA2B,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC,CAAC;IAC5DM,QAAQ,EAAE9B,CAAC,CAAC,qBAAqB,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC,CAAC;IAChDO,QAAQ,EAAE/B,CAAC,CAAC,qBAAqB,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC,CAAC;IAChDQ,WAAW,EAAEhC,CAAC,CAAC,wBAAwB,EAAE;MAAEwB,KAAK,EAAE;IAAE,CAAC;EACvD,CAAC;AACH","ignoreList":[]}
|
|
@@ -16,15 +16,61 @@
|
|
|
16
16
|
"numberMax": "Rhaid i {{#label}} fod yn {{#limit}} neu is",
|
|
17
17
|
"maxWords": "Rhaid i {{#label}} fod yn {{#limit}} o eiriau neu lai",
|
|
18
18
|
"unicode": "Mae {{#label}} yn cynnwys nodau annilys, er enghraifft, dashes hirion",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
19
|
+
"arrayMin_zero": "Dewiswch o leiaf 1 opsiwn o'r rhestr",
|
|
20
|
+
"arrayMin_one": "Dewiswch o leiaf {{#limit}} opsiwn o'r rhestr",
|
|
21
|
+
"arrayMin_two": "Dewiswch o leiaf ddau opsiwn o'r rhestr",
|
|
22
|
+
"arrayMin_few": "Dewiswch o leiaf {{#limit}} opsiwn o'r rhestr",
|
|
23
|
+
"arrayMin_many": "Dewiswch o leiaf {{#limit}} opsiwn o'r rhestr",
|
|
24
|
+
"arrayMin_other": "Dewiswch o leiaf {{#limit}} opsiwn o'r rhestr",
|
|
25
|
+
"arrayMax_zero": "Dim ond {{#limit}} opsiynau y gellir eu dewis o'r rhestr",
|
|
26
|
+
"arrayMax_one": "Dim ond {{#limit}} opsiwn y gellir ei ddewis o'r rhestr",
|
|
27
|
+
"arrayMax_two": "Dim ond dwy opsiwn y gellir eu dewis o'r rhestr",
|
|
28
|
+
"arrayMax_few": "Dim ond {{#limit}} opsiwn y gellir eu dewis o'r rhestr",
|
|
29
|
+
"arrayMax_many": "Dim ond {{#limit}} opsiwn y gellir eu dewis o'r rhestr",
|
|
30
|
+
"arrayMax_other": "Dim ond {{#limit}} opsiwn y gellir eu dewis o'r rhestr",
|
|
31
|
+
"arrayLength_zero": "Dewiswch 0 opsiwn yn unig o'r rhestr",
|
|
32
|
+
"arrayLength_one": "Dewiswch un opsiwn yn unig o'r rhestr",
|
|
33
|
+
"arrayLength_two": "Dewiswch {{#limit}} opsiwn yn unig o'r rhestr",
|
|
34
|
+
"arrayLength_few": "Dewiswch {{#limit}} opsiwn yn unig o'r rhestr",
|
|
35
|
+
"arrayLength_many": "Dewiswch {{#limit}} opsiwn yn unig o'r rhestr",
|
|
36
|
+
"arrayLength_other": "Dewiswch {{#limit}} opsiwn yn unig o'r rhestr",
|
|
37
|
+
|
|
38
|
+
"featuresMin_zero": "Diffiniwch o leiaf {{#limit}} nodwedd",
|
|
39
|
+
"featuresMin_one": "Diffiniwch o leiaf un nodwedd",
|
|
40
|
+
"featuresMin_two": "Diffiniwch o leiaf {{#limit}} nodwedd",
|
|
41
|
+
"featuresMin_few": "Diffiniwch o leiaf {{#limit}} nodwedd",
|
|
42
|
+
"featuresMin_many": "Diffiniwch o leiaf {{#limit}} nodwedd",
|
|
43
|
+
"featuresMin_other": "Diffiniwch o leiaf {{#limit}} nodwedd",
|
|
44
|
+
"featuresMax_zero": "Dim ond {{#limit}} nodwedd y gellir eu diffinio",
|
|
45
|
+
"featuresMax_one": "Dim ond {{#limit}} nodwedd y gellir ei diffinio",
|
|
46
|
+
"featuresMax_two": "Dim ond {{#limit}} nodwedd y gellir eu diffinio",
|
|
47
|
+
"featuresMax_few": "Dim ond {{#limit}} nodwedd y gellir eu diffinio",
|
|
48
|
+
"featuresMax_many": "Dim ond {{#limit}} nodwedd y gellir eu diffinio",
|
|
49
|
+
"featuresMax_other": "Dim ond {{#limit}} nodwedd y gellir eu diffinio",
|
|
50
|
+
"featuresLength_zero": "Diffiniwch yn union {{#limit}} nodwedd",
|
|
51
|
+
"featuresLength_one": "Diffiniwch un nodwedd yn union",
|
|
52
|
+
"featuresLength_two": "Diffiniwch nodweddion {{#limit}} yn union",
|
|
53
|
+
"featuresLength_few": "Diffiniwch nodweddion {{#limit}} yn union",
|
|
54
|
+
"featuresLength_many": "Diffiniwch nodweddion {{#limit}} yn union",
|
|
55
|
+
"featuresLength_other": "Diffiniwch nodweddion {{#limit}} yn union",
|
|
56
|
+
"filesMin_zero": "Rhaid i chi uwchlwytho {{#limit}} ffeil neu fwy",
|
|
57
|
+
"filesMin_one": "Rhaid i chi uwchlwytho un ffeil neu fwy",
|
|
58
|
+
"filesMin_two": "Rhaid i chi uwchlwytho {{#limit}} o ffeiliau neu fwy",
|
|
59
|
+
"filesMin_few": "Rhaid i chi uwchlwytho {{#limit}} o ffeiliau neu fwy",
|
|
60
|
+
"filesMin_many": "Rhaid i chi uwchlwytho {{#limit}} o ffeiliau neu fwy",
|
|
61
|
+
"filesMin_other": "Rhaid i chi uwchlwytho {{#limit}} o ffeiliau neu fwy",
|
|
62
|
+
"filesMax_zero": "Dim ond {{#limit}} ffeil neu lai y gallwch eu huwchlwytho",
|
|
63
|
+
"filesMax_one": "Dim ond un ffeil neu lai y gallwch ei huwchlwytho",
|
|
64
|
+
"filesMax_two": "Dim ond {{#limit}} o ffeiliau neu lai y gallwch eu huwchlwytho",
|
|
65
|
+
"filesMax_few": "Dim ond {{#limit}} o ffeiliau neu lai y gallwch eu huwchlwytho",
|
|
66
|
+
"filesMax_many": "Dim ond {{#limit}} o ffeiliau neu lai y gallwch eu huwchlwytho",
|
|
67
|
+
"filesMax_other": "Dim ond {{#limit}} o ffeiliau neu lai y gallwch eu huwchlwytho",
|
|
68
|
+
"filesLength_zero": "Rhaid i chi uwchlwytho union {{#limit}} ffeil",
|
|
69
|
+
"filesLength_one": "Rhaid i chi uwchlwytho union un ffeil",
|
|
70
|
+
"filesLength_two": "Rhaid i chi uwchlwytho'n union {{#limit}} o ffeiliau",
|
|
71
|
+
"filesLength_few": "Rhaid i chi uwchlwytho'n union {{#limit}} o ffeiliau",
|
|
72
|
+
"filesLength_many": "Rhaid i chi uwchlwytho'n union {{#limit}} o ffeiliau",
|
|
73
|
+
"filesLength_other": "Rhaid i chi uwchlwytho'n union {{#limit}} o ffeiliau"
|
|
28
74
|
},
|
|
29
75
|
|
|
30
76
|
"errors": {
|
|
@@ -44,7 +90,7 @@
|
|
|
44
90
|
"and": "a",
|
|
45
91
|
"england": "Lloegr",
|
|
46
92
|
"wales": "Cymru",
|
|
47
|
-
"
|
|
93
|
+
"northern-ireland": "Gogledd Iwerddon",
|
|
48
94
|
"scotland": "Yr Alban",
|
|
49
95
|
"sendFeedback": "Anfon adborth"
|
|
50
96
|
},
|
|
@@ -161,6 +207,16 @@
|
|
|
161
207
|
"bannerForce": "Rhagolwg o ffurflen [[previewMode]] yw hon. Peidiwch â rhoi gwybodaeth bersonol.",
|
|
162
208
|
"bannerText": "Dyma ragolwg o dudalen ffurflen [[previewMode]] rydych chi'n ei golygu.",
|
|
163
209
|
"previousPages": "Mae'n dibynnu ar atebion o dudalennau cynharach yn y ffurflen. Yn y fersiwn fyw, bydd angen i ddefnyddwyr gwblhau'r cwestiynau hynny yn gyntaf."
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
"formUnavailable": {
|
|
213
|
+
"title": "Mae'n ddrwg gennyf, nid yw'r ffurflen hon ar gael",
|
|
214
|
+
"subHeading": "Nid yw '[[formTitle]]' ar gael mwyach.",
|
|
215
|
+
"contactDetailsHeading": "Manylion cyswllt ar gyfer [[organisationName]]",
|
|
216
|
+
"telephone": "Ffôn",
|
|
217
|
+
"callCharges": "Dysgwch am gostau galwadau",
|
|
218
|
+
"email": "E-bost",
|
|
219
|
+
"onlineContactForm": "Ffurflen gyswllt ar-lein"
|
|
164
220
|
}
|
|
165
221
|
},
|
|
166
222
|
|
|
@@ -267,7 +323,16 @@
|
|
|
267
323
|
},
|
|
268
324
|
|
|
269
325
|
"locationFieldBase": {
|
|
270
|
-
"howToFind": "Sut i ddod o hyd i fanylion lleoliad"
|
|
326
|
+
"howToFind": "Sut i ddod o hyd i fanylion lleoliad",
|
|
327
|
+
"map": {
|
|
328
|
+
"helpPanel": {
|
|
329
|
+
"label": "Sut i ddefnyddio'r map hwn",
|
|
330
|
+
"point1": "Chwilio am sir, lle neu god post",
|
|
331
|
+
"point2": "Defnyddiwch yr eiconau + a - i chwyddo i mewn ac allan",
|
|
332
|
+
"point3": "Defnyddiwch lyfliwr neu allweddlon i ganolbwyntio'r pwynt yn y lleoliad",
|
|
333
|
+
"point4": "Cliciwch i ychwanegu'r lleoliad i'r map"
|
|
334
|
+
}
|
|
335
|
+
}
|
|
271
336
|
},
|
|
272
337
|
|
|
273
338
|
"yesNoField": {
|
|
@@ -294,6 +359,47 @@
|
|
|
294
359
|
"added_few": "Ychwanegwyd [[count]] lleoliad",
|
|
295
360
|
"added_many": "Ychwanegwyd [[count]] o leoliadau",
|
|
296
361
|
"added_other": "Ychwanegwyd [[count]] lleoliad",
|
|
362
|
+
"map": {
|
|
363
|
+
"helpPanel": {
|
|
364
|
+
"label": "Sut i ddefnyddio'r map hwn",
|
|
365
|
+
"ledeIntro": "Gallwch ychwanegu",
|
|
366
|
+
"ledeOutro": "i'r map.",
|
|
367
|
+
"lineText": "llinell",
|
|
368
|
+
"shapeText": "siâp",
|
|
369
|
+
"lineOrShapeText": "llinell neu siâp",
|
|
370
|
+
"typesPhrasePoint": "pwyntiau",
|
|
371
|
+
"typesPhraseLine": "lliniau",
|
|
372
|
+
"typesPhraseShape": "siâpiau",
|
|
373
|
+
"typesPhraseOr": "neu",
|
|
374
|
+
"point1": "Chwilio am sir, lle neu god post",
|
|
375
|
+
"point2": "Defnyddiwch yr eiconau + a - i chwyddo i mewn ac allan",
|
|
376
|
+
"point3": "Cliciwch ddwywaith, neu dewiswch 'Wedi gorffen', pan fyddwch wedi",
|
|
377
|
+
"point4": "Rhowch enw i'r lleoliad"
|
|
378
|
+
},
|
|
379
|
+
"typeDescriptions": {
|
|
380
|
+
"point": "Pwynt",
|
|
381
|
+
"line": "Llinell",
|
|
382
|
+
"polygon": "Siâp"
|
|
383
|
+
},
|
|
384
|
+
"buttons": {
|
|
385
|
+
"point": "Ychwanegu pwynt",
|
|
386
|
+
"line": "Ychwanegu llinell",
|
|
387
|
+
"polygon": "Ychwanegu siâp"
|
|
388
|
+
},
|
|
389
|
+
"itemLabel1": "Lleoliad",
|
|
390
|
+
"itemLabel2": "disgrifiad",
|
|
391
|
+
"itemUpdateLink": "Diweddaru",
|
|
392
|
+
"itemDeleteLink": "Dileu",
|
|
393
|
+
"itemFocusLink": "Dangos",
|
|
394
|
+
"itemVisuallyHidden": "lleoliad",
|
|
395
|
+
"details": {
|
|
396
|
+
"summary": "Cyfesurynnau",
|
|
397
|
+
"type": "Math",
|
|
398
|
+
"centroidGridReference": "Canol cyfeirnod grid",
|
|
399
|
+
"firstPointGridReference": "Cyfeirnod grid y pwynt cyntaf",
|
|
400
|
+
"detailedCoordinates": "Cyfesurynnau manwl"
|
|
401
|
+
}
|
|
402
|
+
},
|
|
297
403
|
"validation": {
|
|
298
404
|
"descriptionRequired": "Rhowch ddisgrifiad ar gyfer lleoliad [[count]]",
|
|
299
405
|
"wrongCountry": "Rhaid i leoliad [[count]] fod y tu mewn i [[country]]"
|
|
@@ -16,15 +16,24 @@
|
|
|
16
16
|
"numberMax": "{{#label}} must be {{#limit}} or lower",
|
|
17
17
|
"maxWords": "{{#label}} must be {{#limit}} words or fewer",
|
|
18
18
|
"unicode": "{{#label}} includes invalid characters, for example, long dashes",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
19
|
+
"arrayMin_one": "Select at least {{#limit}} option from the list",
|
|
20
|
+
"arrayMin_other": "Select at least {{#limit}} options from the list",
|
|
21
|
+
"arrayMax_one": "Only {{#limit}} option can be selected from the list",
|
|
22
|
+
"arrayMax_other": "Only {{#limit}} options can be selected from the list",
|
|
23
|
+
"arrayLength_one": "Select only {{#limit}} option from the list",
|
|
24
|
+
"arrayLength_other": "Select only {{#limit}} options from the list",
|
|
25
|
+
"featuresMin_one": "Define at least {{#limit}} feature",
|
|
26
|
+
"featuresMin_other": "Define at least {{#limit}} features",
|
|
27
|
+
"featuresMax_one": "Only {{#limit}} feature can be defined",
|
|
28
|
+
"featuresMax_other": "Only {{#limit}} features can be defined",
|
|
29
|
+
"featuresLength_one": "Define exactly {{#limit}} feature",
|
|
30
|
+
"featuresLength_other": "Define exactly {{#limit}} features",
|
|
31
|
+
"filesMin_one": "You must upload {{#limit}} file or more",
|
|
32
|
+
"filesMin_other": "You must upload {{#limit}} files or more",
|
|
33
|
+
"filesMax_one": "You can only upload {{#limit}} file or less",
|
|
34
|
+
"filesMax_other": "You can only upload {{#limit}} files or less",
|
|
35
|
+
"filesLength_one": "You must upload exactly {{#limit}} file",
|
|
36
|
+
"filesLength_other": "You must upload exactly {{#limit}} files"
|
|
28
37
|
},
|
|
29
38
|
|
|
30
39
|
"errors": {
|
|
@@ -44,7 +53,7 @@
|
|
|
44
53
|
"and": "and",
|
|
45
54
|
"england": "England",
|
|
46
55
|
"wales": "Wales",
|
|
47
|
-
"
|
|
56
|
+
"northern-ireland": "Northern Ireland",
|
|
48
57
|
"scotland": "Scotland",
|
|
49
58
|
"sendFeedback": "Send feedback"
|
|
50
59
|
},
|
|
@@ -145,6 +154,16 @@
|
|
|
145
154
|
"bannerForce": "This is a preview of a [[previewMode]] form. Do not enter personal information.",
|
|
146
155
|
"bannerText": "This is a preview of a [[previewMode]] form page you are editing.",
|
|
147
156
|
"previousPages": "It depends on answers from earlier pages in the form. In the live version, users will need to complete those questions first."
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
"formUnavailable": {
|
|
160
|
+
"title": "Sorry, this form is unavailable",
|
|
161
|
+
"subHeading": "'[[formTitle]]' is no longer available.",
|
|
162
|
+
"contactDetailsHeading": "Contact details for [[organisationName]]",
|
|
163
|
+
"telephone": "Telephone",
|
|
164
|
+
"callCharges": "Find out about call charges",
|
|
165
|
+
"email": "Email",
|
|
166
|
+
"onlineContactForm": "Online contact form"
|
|
148
167
|
}
|
|
149
168
|
},
|
|
150
169
|
|
|
@@ -247,7 +266,16 @@
|
|
|
247
266
|
},
|
|
248
267
|
|
|
249
268
|
"locationFieldBase": {
|
|
250
|
-
"howToFind": "How to find location details"
|
|
269
|
+
"howToFind": "How to find location details",
|
|
270
|
+
"map": {
|
|
271
|
+
"helpPanel": {
|
|
272
|
+
"label": "How to use this map",
|
|
273
|
+
"point1": "Search for a place or postcode",
|
|
274
|
+
"point2": "Use the + and - icons to zoom in and out",
|
|
275
|
+
"point3": "Use a mouse or keyboard to centre the point at the location",
|
|
276
|
+
"point4": "Click to add the location to the map"
|
|
277
|
+
}
|
|
278
|
+
}
|
|
251
279
|
},
|
|
252
280
|
|
|
253
281
|
"yesNoField": {
|
|
@@ -270,6 +298,47 @@
|
|
|
270
298
|
"geospatialField": {
|
|
271
299
|
"added_one": "Added [[count]] location",
|
|
272
300
|
"added_other": "Added [[count]] locations",
|
|
301
|
+
"map": {
|
|
302
|
+
"helpPanel": {
|
|
303
|
+
"label": "How to use this map",
|
|
304
|
+
"ledeIntro": "You can add",
|
|
305
|
+
"ledeOutro": "to the map.",
|
|
306
|
+
"lineText": "a line",
|
|
307
|
+
"shapeText": "a shape",
|
|
308
|
+
"lineOrShapeText": "a line or shape",
|
|
309
|
+
"typesPhrasePoint": "points",
|
|
310
|
+
"typesPhraseLine": "lines",
|
|
311
|
+
"typesPhraseShape": "shapes",
|
|
312
|
+
"typesPhraseOr": "or",
|
|
313
|
+
"point1": "Search for a county, place or postcode",
|
|
314
|
+
"point2": "Use the + and - icons to zoom in and out",
|
|
315
|
+
"point3": "Double‑click, or select 'Done', when you have finished drawing",
|
|
316
|
+
"point4": "Give the location a name"
|
|
317
|
+
},
|
|
318
|
+
"typeDescriptions": {
|
|
319
|
+
"point": "Point",
|
|
320
|
+
"line": "Line",
|
|
321
|
+
"polygon": "Shape"
|
|
322
|
+
},
|
|
323
|
+
"buttons": {
|
|
324
|
+
"point": "Add point",
|
|
325
|
+
"line": "Add line",
|
|
326
|
+
"polygon": "Add shape"
|
|
327
|
+
},
|
|
328
|
+
"itemLabel1": "Location",
|
|
329
|
+
"itemLabel2": "description",
|
|
330
|
+
"itemUpdateLink": "Update",
|
|
331
|
+
"itemDeleteLink": "Delete",
|
|
332
|
+
"itemFocusLink": "Show",
|
|
333
|
+
"itemVisuallyHidden": "location",
|
|
334
|
+
"details": {
|
|
335
|
+
"summary": "Coordinates",
|
|
336
|
+
"type": "Type",
|
|
337
|
+
"centroidGridReference": "Centre grid reference",
|
|
338
|
+
"firstPointGridReference": "First point grid reference",
|
|
339
|
+
"detailedCoordinates": "Detailed coordinates"
|
|
340
|
+
}
|
|
341
|
+
},
|
|
273
342
|
"validation": {
|
|
274
343
|
"descriptionRequired": "Enter description for location [[count]]",
|
|
275
344
|
"wrongCountry": "Location [[count]] must be within [[country]]"
|
|
@@ -15,6 +15,7 @@ export type FormDefinitionTranslations = Record<string, {
|
|
|
15
15
|
shortDescription: string;
|
|
16
16
|
errorDescription: string;
|
|
17
17
|
paymentDescription: string;
|
|
18
|
+
instructionText: string;
|
|
18
19
|
}>>;
|
|
19
20
|
sections: Record<string, Partial<Pick<Section, 'title'>>>;
|
|
20
21
|
listItems: Record<string, Partial<Pick<Item, 'text' | 'hint'>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../../../src/server/plugins/engine/i18n/types.ts"],"sourcesContent":["import {\n type ComponentDef,\n type Item,\n type Page,\n type Section\n} from '@defra/forms-model'\n\n/**\n * Structure of the `translations` block in a form definition.\n * Also used to derive the valid property keys for the typed tX functions.\n */\nexport type FormDefinitionTranslations = Record<\n string,\n {\n pages: Record<string, Partial<{ title: string; repeatTitle: string }>>\n // ComponentDef is a discriminated union; Pick across the full union is not feasible.\n // The four keys below are the complete set of translatable component properties.\n components: Record<\n string,\n Partial<{\n title: string\n hint: string\n content: string\n shortDescription: string\n errorDescription: string\n paymentDescription: string\n }>\n >\n sections: Record<string, Partial<Pick<Section, 'title'>>>\n listItems: Record<string, Partial<Pick<Item, 'text' | 'hint'>>>\n form: Record<string, string>\n }\n>\n\ntype EntityTranslations = FormDefinitionTranslations[string]\n\n/**\n * Scoped translator returned by model.createTranslator(language).\n * t — plugin namespace (UI strings, buttons, errors, sub-field labels)\n * tForm — form namespace: form attributes, currently only form name\n * tPage — form namespace: page titles\n * tComponent — form namespace: component titles, hints, shortDescriptions\n * tSection — form namespace: section titles\n * tListItem — form namespace: list item text\n * language - current language\n */\nexport interface Translator {\n t: (key: string, opts?: Record<string, unknown>) => string\n tForm: (prop: string) => string\n tPage: (page: Page, prop: keyof EntityTranslations['pages'][string]) => string\n tComponent: (\n component: ComponentDef,\n prop: keyof EntityTranslations['components'][string]\n ) => string\n tSection: (\n section: Section,\n prop: keyof EntityTranslations['sections'][string]\n ) => string\n tListItem: (\n item: Item,\n prop: keyof EntityTranslations['listItems'][string]\n ) => string\n language: string\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../../src/server/plugins/engine/i18n/types.ts"],"sourcesContent":["import {\n type ComponentDef,\n type Item,\n type Page,\n type Section\n} from '@defra/forms-model'\n\n/**\n * Structure of the `translations` block in a form definition.\n * Also used to derive the valid property keys for the typed tX functions.\n */\nexport type FormDefinitionTranslations = Record<\n string,\n {\n pages: Record<string, Partial<{ title: string; repeatTitle: string }>>\n // ComponentDef is a discriminated union; Pick across the full union is not feasible.\n // The four keys below are the complete set of translatable component properties.\n components: Record<\n string,\n Partial<{\n title: string\n hint: string\n content: string\n shortDescription: string\n errorDescription: string\n paymentDescription: string\n instructionText: string\n }>\n >\n sections: Record<string, Partial<Pick<Section, 'title'>>>\n listItems: Record<string, Partial<Pick<Item, 'text' | 'hint'>>>\n form: Record<string, string>\n }\n>\n\ntype EntityTranslations = FormDefinitionTranslations[string]\n\n/**\n * Scoped translator returned by model.createTranslator(language).\n * t — plugin namespace (UI strings, buttons, errors, sub-field labels)\n * tForm — form namespace: form attributes, currently only form name\n * tPage — form namespace: page titles\n * tComponent — form namespace: component titles, hints, shortDescriptions\n * tSection — form namespace: section titles\n * tListItem — form namespace: list item text\n * language - current language\n */\nexport interface Translator {\n t: (key: string, opts?: Record<string, unknown>) => string\n tForm: (prop: string) => string\n tPage: (page: Page, prop: keyof EntityTranslations['pages'][string]) => string\n tComponent: (\n component: ComponentDef,\n prop: keyof EntityTranslations['components'][string]\n ) => string\n tSection: (\n section: Section,\n prop: keyof EntityTranslations['sections'][string]\n ) => string\n tListItem: (\n item: Item,\n prop: keyof EntityTranslations['listItems'][string]\n ) => string\n language: string\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -7,6 +7,7 @@ import { EN_GB } from "../../../constants.js";
|
|
|
7
7
|
import "../components/YesNoField.js";
|
|
8
8
|
import { hasListFormField } from "../components/helpers/components.js";
|
|
9
9
|
import { todayAsDateOnly } from "../date-helper.js";
|
|
10
|
+
import { ConditionBuildError, SchemaValidationError } from "../errors.js";
|
|
10
11
|
import { findPage, getError, getPage } from "../helpers.js";
|
|
11
12
|
import { loadFormTranslations } from "../i18n/createFormTranslator.js";
|
|
12
13
|
import { createTranslator } from "../i18n/createTranslator.js";
|
|
@@ -54,7 +55,7 @@ export class FormModel {
|
|
|
54
55
|
abortEarly: false
|
|
55
56
|
});
|
|
56
57
|
if (result.error) {
|
|
57
|
-
throw result.error;
|
|
58
|
+
throw new SchemaValidationError(result.error);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
// Make a clone of the shallow copy returned
|
|
@@ -180,7 +181,14 @@ export class FormModel {
|
|
|
180
181
|
displayName,
|
|
181
182
|
value
|
|
182
183
|
} = condition;
|
|
183
|
-
|
|
184
|
+
let expr;
|
|
185
|
+
try {
|
|
186
|
+
expr = this.toConditionExpression(value, parser);
|
|
187
|
+
} catch (cause) {
|
|
188
|
+
throw new ConditionBuildError(displayName, {
|
|
189
|
+
cause
|
|
190
|
+
});
|
|
191
|
+
}
|
|
184
192
|
const fn = evaluationState => {
|
|
185
193
|
const ctx = this.toConditionContext(evaluationState, this.conditions);
|
|
186
194
|
try {
|