@defra/forms-engine-plugin 1.0.1 → 1.0.3

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.
Files changed (47) hide show
  1. package/.server/server/plugins/engine/configureEnginePlugin.d.ts +2 -1
  2. package/.server/server/plugins/engine/configureEnginePlugin.js +1 -1
  3. package/.server/server/plugins/engine/configureEnginePlugin.js.map +1 -1
  4. package/.server/server/plugins/engine/options.d.ts +7 -0
  5. package/.server/server/plugins/engine/options.js +36 -0
  6. package/.server/server/plugins/engine/options.js.map +1 -0
  7. package/.server/server/plugins/engine/options.test.js +33 -0
  8. package/.server/server/plugins/engine/options.test.js.map +1 -0
  9. package/.server/server/plugins/engine/plugin.d.ts +2 -30
  10. package/.server/server/plugins/engine/plugin.js +12 -596
  11. package/.server/server/plugins/engine/plugin.js.map +1 -1
  12. package/.server/server/plugins/engine/registrationOptions.d.ts +1 -0
  13. package/.server/server/plugins/engine/registrationOptions.js +2 -0
  14. package/.server/server/plugins/engine/registrationOptions.js.map +1 -0
  15. package/.server/server/plugins/engine/routes/file-upload.d.ts +4 -0
  16. package/.server/server/plugins/engine/routes/file-upload.js +41 -0
  17. package/.server/server/plugins/engine/routes/file-upload.js.map +1 -0
  18. package/.server/server/plugins/engine/routes/index.d.ts +7 -0
  19. package/.server/server/plugins/engine/routes/index.js +141 -0
  20. package/.server/server/plugins/engine/routes/index.js.map +1 -0
  21. package/.server/server/plugins/engine/routes/questions.d.ts +3 -0
  22. package/.server/server/plugins/engine/routes/questions.js +168 -0
  23. package/.server/server/plugins/engine/routes/questions.js.map +1 -0
  24. package/.server/server/plugins/engine/routes/repeaters/item-delete.d.ts +3 -0
  25. package/.server/server/plugins/engine/routes/repeaters/item-delete.js +106 -0
  26. package/.server/server/plugins/engine/routes/repeaters/item-delete.js.map +1 -0
  27. package/.server/server/plugins/engine/routes/repeaters/summary.d.ts +3 -0
  28. package/.server/server/plugins/engine/routes/repeaters/summary.js +98 -0
  29. package/.server/server/plugins/engine/routes/repeaters/summary.js.map +1 -0
  30. package/.server/server/plugins/engine/types.d.ts +19 -1
  31. package/.server/server/plugins/engine/types.js.map +1 -1
  32. package/.server/server/plugins/engine/vision.d.ts +12 -0
  33. package/.server/server/plugins/engine/vision.js +55 -0
  34. package/.server/server/plugins/engine/vision.js.map +1 -0
  35. package/package.json +1 -1
  36. package/src/server/plugins/engine/configureEnginePlugin.ts +3 -5
  37. package/src/server/plugins/engine/options.js +37 -0
  38. package/src/server/plugins/engine/options.test.js +34 -0
  39. package/src/server/plugins/engine/plugin.ts +30 -772
  40. package/src/server/plugins/engine/registrationOptions.ts +0 -0
  41. package/src/server/plugins/engine/routes/file-upload.ts +54 -0
  42. package/src/server/plugins/engine/routes/index.ts +187 -0
  43. package/src/server/plugins/engine/routes/questions.ts +208 -0
  44. package/src/server/plugins/engine/routes/repeaters/item-delete.ts +157 -0
  45. package/src/server/plugins/engine/routes/repeaters/summary.ts +137 -0
  46. package/src/server/plugins/engine/types.ts +26 -1
  47. package/src/server/plugins/engine/vision.ts +95 -0
@@ -1,5 +1,6 @@
1
1
  import { type FormDefinition } from '@defra/forms-model';
2
- import { plugin, type PluginOptions } from '~/src/server/plugins/engine/plugin.js';
2
+ import { plugin } from '~/src/server/plugins/engine/plugin.js';
3
+ import { type PluginOptions } from '~/src/server/plugins/engine/types.js';
3
4
  import { type RouteConfig } from '~/src/server/types.js';
4
5
  export declare const configureEnginePlugin: ({ formFileName, formFilePath, services, controllers }?: RouteConfig) => Promise<{
5
6
  plugin: typeof plugin;
@@ -2,9 +2,9 @@ import { join, parse } from 'node:path';
2
2
  import { FORM_PREFIX } from "../../constants.js";
3
3
  import { FormModel } from "./models/FormModel.js";
4
4
  import { plugin } from "./plugin.js";
5
- import { findPackageRoot } from "./plugin.js";
6
5
  import * as defaultServices from "./services/index.js";
7
6
  import { formsService } from "./services/localFormsService.js";
7
+ import { findPackageRoot } from "./vision.js";
8
8
  import { devtoolContext } from "../nunjucks/context.js";
9
9
  export const configureEnginePlugin = async ({
10
10
  formFileName,
@@ -1 +1 @@
1
- {"version":3,"file":"configureEnginePlugin.js","names":["join","parse","FORM_PREFIX","FormModel","plugin","findPackageRoot","defaultServices","formsService","devtoolContext","configureEnginePlugin","formFileName","formFilePath","services","controllers","model","definition","getForm","name","initialBasePath","basePath","options","cacheName","nunjucks","baseLayoutPath","paths","viewContext","importPath","ext","attributes","type","formImport","with","default"],"sources":["../../../../src/server/plugins/engine/configureEnginePlugin.ts"],"sourcesContent":["import { join, parse } from 'node:path'\n\nimport { type FormDefinition } from '@defra/forms-model'\n\nimport { FORM_PREFIX } from '~/src/server/constants.js'\nimport { FormModel } from '~/src/server/plugins/engine/models/FormModel.js'\nimport {\n plugin,\n type PluginOptions\n} from '~/src/server/plugins/engine/plugin.js'\nimport { findPackageRoot } from '~/src/server/plugins/engine/plugin.js'\nimport * as defaultServices from '~/src/server/plugins/engine/services/index.js'\nimport { formsService } from '~/src/server/plugins/engine/services/localFormsService.js'\nimport { devtoolContext } from '~/src/server/plugins/nunjucks/context.js'\nimport { type RouteConfig } from '~/src/server/types.js'\n\nexport const configureEnginePlugin = async ({\n formFileName,\n formFilePath,\n services,\n controllers\n}: RouteConfig = {}): Promise<{\n plugin: typeof plugin\n options: PluginOptions\n}> => {\n let model: FormModel | undefined\n\n if (formFileName && formFilePath) {\n const definition = await getForm(join(formFilePath, formFileName))\n const { name } = parse(formFileName)\n\n const initialBasePath = `${FORM_PREFIX}${name}`\n\n model = new FormModel(\n definition,\n { basePath: initialBasePath },\n services,\n controllers\n )\n }\n\n return {\n plugin,\n options: {\n model,\n services: services ?? {\n // services for testing, else use the disk loader option for running this service locally\n ...defaultServices,\n formsService: await formsService()\n },\n controllers,\n cacheName: 'session',\n nunjucks: {\n baseLayoutPath: 'dxt-devtool-baselayout.html',\n paths: [join(findPackageRoot(), 'src/server/devserver')] // custom layout to make it really clear this is not the same as the runner\n },\n viewContext: devtoolContext\n }\n }\n}\n\nexport async function getForm(importPath: string) {\n const { ext } = parse(importPath)\n\n const attributes: ImportAttributes = {\n type: ext === '.json' ? 'json' : 'module'\n }\n\n const formImport = import(importPath, { with: attributes }) as Promise<{\n default: FormDefinition\n }>\n\n const { default: definition } = await formImport\n return definition\n}\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,KAAK,QAAQ,WAAW;AAIvC,SAASC,WAAW;AACpB,SAASC,SAAS;AAClB,SACEC,MAAM;AAGR,SAASC,eAAe;AACxB,OAAO,KAAKC,eAAe;AAC3B,SAASC,YAAY;AACrB,SAASC,cAAc;AAGvB,OAAO,MAAMC,qBAAqB,GAAG,MAAAA,CAAO;EAC1CC,YAAY;EACZC,YAAY;EACZC,QAAQ;EACRC;AACW,CAAC,GAAG,CAAC,CAAC,KAGb;EACJ,IAAIC,KAA4B;EAEhC,IAAIJ,YAAY,IAAIC,YAAY,EAAE;IAChC,MAAMI,UAAU,GAAG,MAAMC,OAAO,CAAChB,IAAI,CAACW,YAAY,EAAED,YAAY,CAAC,CAAC;IAClE,MAAM;MAAEO;IAAK,CAAC,GAAGhB,KAAK,CAACS,YAAY,CAAC;IAEpC,MAAMQ,eAAe,GAAG,GAAGhB,WAAW,GAAGe,IAAI,EAAE;IAE/CH,KAAK,GAAG,IAAIX,SAAS,CACnBY,UAAU,EACV;MAAEI,QAAQ,EAAED;IAAgB,CAAC,EAC7BN,QAAQ,EACRC,WACF,CAAC;EACH;EAEA,OAAO;IACLT,MAAM;IACNgB,OAAO,EAAE;MACPN,KAAK;MACLF,QAAQ,EAAEA,QAAQ,IAAI;QACpB;QACA,GAAGN,eAAe;QAClBC,YAAY,EAAE,MAAMA,YAAY,CAAC;MACnC,CAAC;MACDM,WAAW;MACXQ,SAAS,EAAE,SAAS;MACpBC,QAAQ,EAAE;QACRC,cAAc,EAAE,6BAA6B;QAC7CC,KAAK,EAAE,CAACxB,IAAI,CAACK,eAAe,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC;MAC3D,CAAC;MACDoB,WAAW,EAAEjB;IACf;EACF,CAAC;AACH,CAAC;AAED,OAAO,eAAeQ,OAAOA,CAACU,UAAkB,EAAE;EAChD,MAAM;IAAEC;EAAI,CAAC,GAAG1B,KAAK,CAACyB,UAAU,CAAC;EAEjC,MAAME,UAA4B,GAAG;IACnCC,IAAI,EAAEF,GAAG,KAAK,OAAO,GAAG,MAAM,GAAG;EACnC,CAAC;EAED,MAAMG,UAAU,GAAG,MAAM,CAACJ,UAAU,EAAE;IAAEK,IAAI,EAAEH;EAAW,CAAC,CAExD;EAEF,MAAM;IAAEI,OAAO,EAAEjB;EAAW,CAAC,GAAG,MAAMe,UAAU;EAChD,OAAOf,UAAU;AACnB","ignoreList":[]}
1
+ {"version":3,"file":"configureEnginePlugin.js","names":["join","parse","FORM_PREFIX","FormModel","plugin","defaultServices","formsService","findPackageRoot","devtoolContext","configureEnginePlugin","formFileName","formFilePath","services","controllers","model","definition","getForm","name","initialBasePath","basePath","options","cacheName","nunjucks","baseLayoutPath","paths","viewContext","importPath","ext","attributes","type","formImport","with","default"],"sources":["../../../../src/server/plugins/engine/configureEnginePlugin.ts"],"sourcesContent":["import { join, parse } from 'node:path'\n\nimport { type FormDefinition } from '@defra/forms-model'\n\nimport { FORM_PREFIX } from '~/src/server/constants.js'\nimport { FormModel } from '~/src/server/plugins/engine/models/FormModel.js'\nimport { plugin } from '~/src/server/plugins/engine/plugin.js'\nimport * as defaultServices from '~/src/server/plugins/engine/services/index.js'\nimport { formsService } from '~/src/server/plugins/engine/services/localFormsService.js'\nimport { type PluginOptions } from '~/src/server/plugins/engine/types.js'\nimport { findPackageRoot } from '~/src/server/plugins/engine/vision.js'\nimport { devtoolContext } from '~/src/server/plugins/nunjucks/context.js'\nimport { type RouteConfig } from '~/src/server/types.js'\n\nexport const configureEnginePlugin = async ({\n formFileName,\n formFilePath,\n services,\n controllers\n}: RouteConfig = {}): Promise<{\n plugin: typeof plugin\n options: PluginOptions\n}> => {\n let model: FormModel | undefined\n\n if (formFileName && formFilePath) {\n const definition = await getForm(join(formFilePath, formFileName))\n const { name } = parse(formFileName)\n\n const initialBasePath = `${FORM_PREFIX}${name}`\n\n model = new FormModel(\n definition,\n { basePath: initialBasePath },\n services,\n controllers\n )\n }\n\n return {\n plugin,\n options: {\n model,\n services: services ?? {\n // services for testing, else use the disk loader option for running this service locally\n ...defaultServices,\n formsService: await formsService()\n },\n controllers,\n cacheName: 'session',\n nunjucks: {\n baseLayoutPath: 'dxt-devtool-baselayout.html',\n paths: [join(findPackageRoot(), 'src/server/devserver')] // custom layout to make it really clear this is not the same as the runner\n },\n viewContext: devtoolContext\n }\n }\n}\n\nexport async function getForm(importPath: string) {\n const { ext } = parse(importPath)\n\n const attributes: ImportAttributes = {\n type: ext === '.json' ? 'json' : 'module'\n }\n\n const formImport = import(importPath, { with: attributes }) as Promise<{\n default: FormDefinition\n }>\n\n const { default: definition } = await formImport\n return definition\n}\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,KAAK,QAAQ,WAAW;AAIvC,SAASC,WAAW;AACpB,SAASC,SAAS;AAClB,SAASC,MAAM;AACf,OAAO,KAAKC,eAAe;AAC3B,SAASC,YAAY;AAErB,SAASC,eAAe;AACxB,SAASC,cAAc;AAGvB,OAAO,MAAMC,qBAAqB,GAAG,MAAAA,CAAO;EAC1CC,YAAY;EACZC,YAAY;EACZC,QAAQ;EACRC;AACW,CAAC,GAAG,CAAC,CAAC,KAGb;EACJ,IAAIC,KAA4B;EAEhC,IAAIJ,YAAY,IAAIC,YAAY,EAAE;IAChC,MAAMI,UAAU,GAAG,MAAMC,OAAO,CAAChB,IAAI,CAACW,YAAY,EAAED,YAAY,CAAC,CAAC;IAClE,MAAM;MAAEO;IAAK,CAAC,GAAGhB,KAAK,CAACS,YAAY,CAAC;IAEpC,MAAMQ,eAAe,GAAG,GAAGhB,WAAW,GAAGe,IAAI,EAAE;IAE/CH,KAAK,GAAG,IAAIX,SAAS,CACnBY,UAAU,EACV;MAAEI,QAAQ,EAAED;IAAgB,CAAC,EAC7BN,QAAQ,EACRC,WACF,CAAC;EACH;EAEA,OAAO;IACLT,MAAM;IACNgB,OAAO,EAAE;MACPN,KAAK;MACLF,QAAQ,EAAEA,QAAQ,IAAI;QACpB;QACA,GAAGP,eAAe;QAClBC,YAAY,EAAE,MAAMA,YAAY,CAAC;MACnC,CAAC;MACDO,WAAW;MACXQ,SAAS,EAAE,SAAS;MACpBC,QAAQ,EAAE;QACRC,cAAc,EAAE,6BAA6B;QAC7CC,KAAK,EAAE,CAACxB,IAAI,CAACO,eAAe,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC;MAC3D,CAAC;MACDkB,WAAW,EAAEjB;IACf;EACF,CAAC;AACH,CAAC;AAED,OAAO,eAAeQ,OAAOA,CAACU,UAAkB,EAAE;EAChD,MAAM;IAAEC;EAAI,CAAC,GAAG1B,KAAK,CAACyB,UAAU,CAAC;EAEjC,MAAME,UAA4B,GAAG;IACnCC,IAAI,EAAEF,GAAG,KAAK,OAAO,GAAG,MAAM,GAAG;EACnC,CAAC;EAED,MAAMG,UAAU,GAAG,MAAM,CAACJ,UAAU,EAAE;IAAEK,IAAI,EAAEH;EAAW,CAAC,CAExD;EAEF,MAAM;IAAEI,OAAO,EAAEjB;EAAW,CAAC,GAAG,MAAMe,UAAU;EAChD,OAAOf,UAAU;AACnB","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Validates the plugin options against the schema and returns the validated value.
3
+ * @param {PluginOptions} options
4
+ * @returns {PluginOptions}
5
+ */
6
+ export function validatePluginOptions(options: PluginOptions): PluginOptions;
7
+ import type { PluginOptions } from '~/src/server/plugins/engine/types.js';
@@ -0,0 +1,36 @@
1
+ import Joi from 'joi';
2
+ const pluginRegistrationOptionsSchema = Joi.object({
3
+ model: Joi.object().optional(),
4
+ services: Joi.object().optional(),
5
+ controllers: Joi.object().pattern(Joi.string(), Joi.any()).optional(),
6
+ cacheName: Joi.string().optional(),
7
+ filters: Joi.object().pattern(Joi.string(), Joi.any()).optional(),
8
+ pluginPath: Joi.string().optional(),
9
+ nunjucks: Joi.object({
10
+ baseLayoutPath: Joi.string().required(),
11
+ paths: Joi.array().items(Joi.string()).required()
12
+ }).required(),
13
+ viewContext: Joi.function().required()
14
+ });
15
+
16
+ /**
17
+ * Validates the plugin options against the schema and returns the validated value.
18
+ * @param {PluginOptions} options
19
+ * @returns {PluginOptions}
20
+ */
21
+ export function validatePluginOptions(options) {
22
+ const result = pluginRegistrationOptionsSchema.validate(options, {
23
+ abortEarly: false
24
+ });
25
+ if (result.error) {
26
+ throw new Error('Invalid plugin options', result.error);
27
+ }
28
+
29
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
30
+ return result.value;
31
+ }
32
+
33
+ /**
34
+ * @import { PluginOptions } from '~/src/server/plugins/engine/types.js'
35
+ */
36
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","names":["Joi","pluginRegistrationOptionsSchema","object","model","optional","services","controllers","pattern","string","any","cacheName","filters","pluginPath","nunjucks","baseLayoutPath","required","paths","array","items","viewContext","function","validatePluginOptions","options","result","validate","abortEarly","error","Error","value"],"sources":["../../../../src/server/plugins/engine/options.js"],"sourcesContent":["import Joi from 'joi'\n\nconst pluginRegistrationOptionsSchema = Joi.object({\n model: Joi.object().optional(),\n services: Joi.object().optional(),\n controllers: Joi.object().pattern(Joi.string(), Joi.any()).optional(),\n cacheName: Joi.string().optional(),\n filters: Joi.object().pattern(Joi.string(), Joi.any()).optional(),\n pluginPath: Joi.string().optional(),\n nunjucks: Joi.object({\n baseLayoutPath: Joi.string().required(),\n paths: Joi.array().items(Joi.string()).required()\n }).required(),\n viewContext: Joi.function().required()\n})\n\n/**\n * Validates the plugin options against the schema and returns the validated value.\n * @param {PluginOptions} options\n * @returns {PluginOptions}\n */\nexport function validatePluginOptions(options) {\n const result = pluginRegistrationOptionsSchema.validate(options, {\n abortEarly: false\n })\n\n if (result.error) {\n throw new Error('Invalid plugin options', result.error)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result.value\n}\n\n/**\n * @import { PluginOptions } from '~/src/server/plugins/engine/types.js'\n */\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAErB,MAAMC,+BAA+B,GAAGD,GAAG,CAACE,MAAM,CAAC;EACjDC,KAAK,EAAEH,GAAG,CAACE,MAAM,CAAC,CAAC,CAACE,QAAQ,CAAC,CAAC;EAC9BC,QAAQ,EAAEL,GAAG,CAACE,MAAM,CAAC,CAAC,CAACE,QAAQ,CAAC,CAAC;EACjCE,WAAW,EAAEN,GAAG,CAACE,MAAM,CAAC,CAAC,CAACK,OAAO,CAACP,GAAG,CAACQ,MAAM,CAAC,CAAC,EAAER,GAAG,CAACS,GAAG,CAAC,CAAC,CAAC,CAACL,QAAQ,CAAC,CAAC;EACrEM,SAAS,EAAEV,GAAG,CAACQ,MAAM,CAAC,CAAC,CAACJ,QAAQ,CAAC,CAAC;EAClCO,OAAO,EAAEX,GAAG,CAACE,MAAM,CAAC,CAAC,CAACK,OAAO,CAACP,GAAG,CAACQ,MAAM,CAAC,CAAC,EAAER,GAAG,CAACS,GAAG,CAAC,CAAC,CAAC,CAACL,QAAQ,CAAC,CAAC;EACjEQ,UAAU,EAAEZ,GAAG,CAACQ,MAAM,CAAC,CAAC,CAACJ,QAAQ,CAAC,CAAC;EACnCS,QAAQ,EAAEb,GAAG,CAACE,MAAM,CAAC;IACnBY,cAAc,EAAEd,GAAG,CAACQ,MAAM,CAAC,CAAC,CAACO,QAAQ,CAAC,CAAC;IACvCC,KAAK,EAAEhB,GAAG,CAACiB,KAAK,CAAC,CAAC,CAACC,KAAK,CAAClB,GAAG,CAACQ,MAAM,CAAC,CAAC,CAAC,CAACO,QAAQ,CAAC;EAClD,CAAC,CAAC,CAACA,QAAQ,CAAC,CAAC;EACbI,WAAW,EAAEnB,GAAG,CAACoB,QAAQ,CAAC,CAAC,CAACL,QAAQ,CAAC;AACvC,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,qBAAqBA,CAACC,OAAO,EAAE;EAC7C,MAAMC,MAAM,GAAGtB,+BAA+B,CAACuB,QAAQ,CAACF,OAAO,EAAE;IAC/DG,UAAU,EAAE;EACd,CAAC,CAAC;EAEF,IAAIF,MAAM,CAACG,KAAK,EAAE;IAChB,MAAM,IAAIC,KAAK,CAAC,wBAAwB,EAAEJ,MAAM,CAACG,KAAK,CAAC;EACzD;;EAEA;EACA,OAAOH,MAAM,CAACK,KAAK;AACrB;;AAEA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ import { validatePluginOptions } from "./options.js";
2
+ describe('validatePluginOptions', () => {
3
+ it('returns the validated value for valid options', () => {
4
+ const validOptions = {
5
+ nunjucks: {
6
+ baseLayoutPath: 'dxt-devtool-baselayout.html',
7
+ paths: ['src/server/devserver'] // custom layout to make it really clear this is not the same as the runner
8
+ },
9
+ viewContext: () => {
10
+ return {
11
+ hello: 'world'
12
+ };
13
+ }
14
+ };
15
+ expect(validatePluginOptions(validOptions)).toEqual(validOptions);
16
+ });
17
+
18
+ /**
19
+ * tsc would usually check compliance with the type, but given a user might be using plain JS we still want a test
20
+ */
21
+ it('fails if a required attribute is missing', () => {
22
+ const invalidOptions = {
23
+ nunjucks: {
24
+ baseLayoutPath: 'dxt-devtool-baselayout.html',
25
+ paths: ['src/server/devserver'] // custom layout to make it really clear this is not the same as the runner
26
+ }
27
+ };
28
+
29
+ // @ts-expect-error -- add a test for JS users
30
+ expect(() => validatePluginOptions(invalidOptions)).toThrow('Invalid plugin options');
31
+ });
32
+ });
33
+ //# sourceMappingURL=options.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.test.js","names":["validatePluginOptions","describe","it","validOptions","nunjucks","baseLayoutPath","paths","viewContext","hello","expect","toEqual","invalidOptions","toThrow"],"sources":["../../../../src/server/plugins/engine/options.test.js"],"sourcesContent":["import { validatePluginOptions } from '~/src/server/plugins/engine/options.js'\n\ndescribe('validatePluginOptions', () => {\n it('returns the validated value for valid options', () => {\n const validOptions = {\n nunjucks: {\n baseLayoutPath: 'dxt-devtool-baselayout.html',\n paths: ['src/server/devserver'] // custom layout to make it really clear this is not the same as the runner\n },\n viewContext: () => {\n return { hello: 'world' }\n }\n }\n\n expect(validatePluginOptions(validOptions)).toEqual(validOptions)\n })\n\n /**\n * tsc would usually check compliance with the type, but given a user might be using plain JS we still want a test\n */\n it('fails if a required attribute is missing', () => {\n const invalidOptions = {\n nunjucks: {\n baseLayoutPath: 'dxt-devtool-baselayout.html',\n paths: ['src/server/devserver'] // custom layout to make it really clear this is not the same as the runner\n }\n }\n\n // @ts-expect-error -- add a test for JS users\n expect(() => validatePluginOptions(invalidOptions)).toThrow(\n 'Invalid plugin options'\n )\n })\n})\n"],"mappings":"AAAA,SAASA,qBAAqB;AAE9BC,QAAQ,CAAC,uBAAuB,EAAE,MAAM;EACtCC,EAAE,CAAC,+CAA+C,EAAE,MAAM;IACxD,MAAMC,YAAY,GAAG;MACnBC,QAAQ,EAAE;QACRC,cAAc,EAAE,6BAA6B;QAC7CC,KAAK,EAAE,CAAC,sBAAsB,CAAC,CAAC;MAClC,CAAC;MACDC,WAAW,EAAEA,CAAA,KAAM;QACjB,OAAO;UAAEC,KAAK,EAAE;QAAQ,CAAC;MAC3B;IACF,CAAC;IAEDC,MAAM,CAACT,qBAAqB,CAACG,YAAY,CAAC,CAAC,CAACO,OAAO,CAACP,YAAY,CAAC;EACnE,CAAC,CAAC;;EAEF;AACF;AACA;EACED,EAAE,CAAC,0CAA0C,EAAE,MAAM;IACnD,MAAMS,cAAc,GAAG;MACrBP,QAAQ,EAAE;QACRC,cAAc,EAAE,6BAA6B;QAC7CC,KAAK,EAAE,CAAC,sBAAsB,CAAC,CAAC;MAClC;IACF,CAAC;;IAED;IACAG,MAAM,CAAC,MAAMT,qBAAqB,CAACW,cAAc,CAAC,CAAC,CAACC,OAAO,CACzD,wBACF,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,36 +1,8 @@
1
- import { type PluginProperties, type Request, type Server } from '@hapi/hapi';
2
- import { type Environment } from 'nunjucks';
3
- import { FormModel } from '~/src/server/plugins/engine/models/index.js';
4
- import { type PageController } from '~/src/server/plugins/engine/pageControllers/PageController.js';
5
- import { type FilterFunction, type FormSubmissionState } from '~/src/server/plugins/engine/types.js';
6
- import { type FormRequest, type FormRequestPayload } from '~/src/server/routes/types.js';
7
- import { type Services } from '~/src/server/types.js';
8
- export declare function findPackageRoot(): string;
9
- export interface PluginOptions {
10
- model?: FormModel;
11
- services?: Services;
12
- controllers?: Record<string, typeof PageController>;
13
- cacheName?: string;
14
- keyGenerator?: (request: Request | FormRequest | FormRequestPayload) => string;
15
- sessionHydrator?: (request: Request | FormRequest | FormRequestPayload) => Promise<FormSubmissionState>;
16
- filters?: Record<string, FilterFunction>;
17
- pluginPath?: string;
18
- nunjucks: {
19
- baseLayoutPath: string;
20
- paths: string[];
21
- };
22
- viewContext: PluginProperties['forms-engine-plugin']['viewContext'];
23
- }
1
+ import { type Server } from '@hapi/hapi';
2
+ import { type PluginOptions } from '~/src/server/plugins/engine/types.js';
24
3
  export declare const plugin: {
25
4
  name: string;
26
5
  dependencies: string[];
27
6
  multiple: true;
28
7
  register(server: Server, options: PluginOptions): Promise<void>;
29
8
  };
30
- interface CompileOptions {
31
- environment: Environment;
32
- }
33
- export interface EngineConfigurationObject {
34
- compileOptions: CompileOptions;
35
- }
36
- export {};