diff --git a/src/stores/catalogue.ts b/src/stores/catalogue.ts index d691c891..88774cfd 100644 --- a/src/stores/catalogue.ts +++ b/src/stores/catalogue.ts @@ -324,18 +324,20 @@ export const getCriteriaFromKey = ( /** * Set the catalogue. A warning is logged to the browser console if the catalogue does not match the JSON schema. */ -export function setCatalogue(cat: Catalogue) { - catalogue.set(cat); +export function setCatalogue(newCatalogue: Catalogue) { + // Make a copy to avoid modifying the original object + const catalogueCopy = structuredClone(newCatalogue); const ajv = new Ajv({ allErrors: true, removeAdditional: true, }); addFormats(ajv); - const valid = ajv.validate(catalogueSchema, cat); + const valid = ajv.validate(catalogueSchema, catalogueCopy); if (!valid) { console.warn( "Catalogue does not conform with JSON schema: " + JSON.stringify(ajv.errors), ); } + catalogue.set(catalogueCopy); } diff --git a/src/stores/options.ts b/src/stores/options.ts index 613b399b..12e690e3 100644 --- a/src/stores/options.ts +++ b/src/stores/options.ts @@ -10,18 +10,20 @@ export const lensOptions = writable(); /** * Set the options. A warning is logged to the browser console if the options do not match the JSON schema. */ -export function setOptions(options: LensOptions) { - lensOptions.set(options); +export function setOptions(newOptions: LensOptions) { + // Make a copy to avoid modifying the original object + const optionsCopy = structuredClone(newOptions); const ajv = new Ajv({ allErrors: true, removeAdditional: true, }); addFormats(ajv); - const valid = ajv.validate(optionsSchema, options); + const valid = ajv.validate(optionsSchema, optionsCopy); if (!valid) { console.warn( "Options do not conform with JSON schema: " + JSON.stringify(ajv.errors), ); } + lensOptions.set(optionsCopy); }