Repository navigation
DF-1509: Convert the foundation, server, engine helper and i18n modules to JavaScript with JSDoc - #507
DF-1509: Convert the foundation, server, engine helper and i18n modules to JavaScript with JSDoc#507alexluckett wants to merge 6 commits into
Conversation
…ules to JavaScript with JSDoc
The engine helpers, form context, date helper, form availability, reference numbers, registration options, unavailable response, validation helpers, vision setup and the definition stubs are now .js files typed with JSDoc and checked by tsc. getPage and findPage name PageControllerClass in their return type, so that the published types keep the alias. The tests that mock these modules and the page controllers README refer to the new .js paths.
ADDITIONAL_IDENTIFIER becomes a read-only object with a type of the same name, rather than a TypeScript enum. Its runtime value is the same, so the cache keys do not change; only the published type changes, as the v5 to v6 guide describes.
|
| * and appropriate namespaces for loading of form-specific translations later | ||
| * @param formEnGb | ||
| * @param {BaseTranslations} formEnGb | ||
| * @returns |
| type FormMetadata, | ||
| type SubmitResponsePayload | ||
| } from '@defra/forms-model' | ||
| import { addDays, format as dateFormat } from 'date-fns' |
There was a problem hiding this comment.
Were we going to remove the formatters since they're now in notify-listener? Do any plugin users make use of them?
| * Returns the "files" section of the response body | ||
| * @param item - the file upload item in the form | ||
| * @param {FileUploadFieldDetailitem} item - the file upload item in the form | ||
| * @returns the file upload data |
There was a problem hiding this comment.
Should we have a return type here?
| * Returns the "repeaters" section of the response body | ||
| * @param item - the repeater item | ||
| * @param {DetailItemRepeat} item - the repeater item | ||
| * @returns the repeater item |
There was a problem hiding this comment.
Looks good in terms of type replacements.
A large number of Sonar issues - do we address them as part of tech debt later, or just leave?
Quite a number of missing return types - not sure if you'd prefer to add them (generally missing when the TS had the return type missing).
This would have taken you weeks - without AI




Proposed change
Part of the TypeScript to JavaScript migration (v6), this PR is stacked on the tests PR and converts 52 source files to JavaScript with JSDoc types, in six commits: one for each area below, and a small second commit on the server area that names destructured parameters
param0, as the other converted files do.config, the logging helpers, thecrumb,errorPages,pulseandsessionplugins,schemas,utils,httpService, the services index, theindex,publicanddummy-apiroutes, andnotifyService;src/index,src/server/index,src/server/types, the engineplugin,configureEnginePluginandindex, and the engine routes;helpers,form-context,date-helper,form-availability,validationHelpers,referenceNumbers,registrationOptions,unavailable-response,visionand the__stubs__/definitionsfixture;cacheService.Key changes:
@importblock at the end of each file, annotations are now@type,@paramand@returns, and casts are JSDoc casts.Joi.string<T>()orrequest<BodyType>(…), so the result or the function is cast instead.config/index.jshas 17 of theseSchemaObjcasts.tscpublishes them in the same form as before.requestLoggerand the exported enginepluginhave a@type, which keeps them as constants rather than anamespace.getPageandfindPagehave@returns {PageControllerClass}, so the published type is the alias rather than a list of seven controller classes. The overloads ofgetPageHrefare now@overloadblocks with the same signatures.i18n/types.jspublishes a new type,FormDefinitionTranslation. A nested type contained a//comment, which a JSDoc type cannot hold, so the nested type has become a typedef of its own and the comment is now the description ofcomponents, word for word.outputFormatters/index.jsthe version keys have lost their quotes ('1': formatHumanV1is now1: formatHumanV1), as Prettier does for JavaScript. Object keys are always strings, sogetFormatter(audience, '1')still finds the same function.__stubs__/definitions.js, a line that started with a cast has been split into aconstand an assignment, because Prettier removes the parentheses of a JSDoc cast at the start of a line. The same object is assigned.helpers.tshad an@importcomment part-way through the file, which has been merged into the block at the end.src/server/types(FormsService,FormSubmissionService,Services,RouteConfig,OutputService), eight engine types (OfflineBoomData,GlobalScope,FormVersionMetadata,FormModelOptions,FormContextOptions,ExternalComponent,CompileOptions,EngineConfigurationObject) andTranslator.JourneyState,SummaryRequest,CompileOptions,EntityTranslations,BaseTranslations,Formatter,FileUploadFieldDetailitem(inmachine/v1) andPaymentOutput. The default exports oferrorPages,pulseandsessionappear as anamespace, but these files are not in the packageexportsmap.cacheServiceexportsADDITIONAL_IDENTIFIERas a read-only object with a type of the same name, rather than a TypeScript enum, because JavaScript has no enums. A string enum already compiles to an object with the same key and value, soADDITIONAL_IDENTIFIER.Confirmationis still':confirmation'and the keys written to the cache are unchanged. Breaking: as a type,ADDITIONAL_IDENTIFIERis now the union of its values, soADDITIONAL_IDENTIFIER.Confirmationcan no longer be used as a type on its own. The v5 to v6 guide describes this..js. Theserver:watch:devandserver:watch:debugscripts inpackage.jsonnow start./src/index.js, and the same change has been made to thejest.mockpaths in 23 test files,docs/features/configuration-based/page-events.mdandpageControllers/README.md. Thelogger-optionsandnotifytests have moved to.jswith their modules and are otherwise unchanged.Apart from the
__stubs__/definitions.jsfixture, the unquoted keys, theADDITIONAL_IDENTIFIERobject and the removedexport {}lines, the compiled code is identical tomain. The full test suite gives the same results as onmain(2,583 passed, 13 skipped).Jira ticket: DF-1509
Type of change
Checklist
README.mdanddocs/*(where appropriate, e.g. new features).npm run test).npm run lint).npm run format).