Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/stores/catalogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
8 changes: 5 additions & 3 deletions src/stores/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ export const lensOptions = writable<LensOptions | undefined>();
/**
* 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);
}