Skip to content
Merged
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
3 changes: 1 addition & 2 deletions book/book.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[book]
language = "en"
multilingual = false
src = "src"
title = "Lens Book"

[output.html]
git-repository-url = "https://github.com/samply/lens/tree/develop/book"
git-repository-icon = "fa-github"
git-repository-icon = "fab-github"
edit-url-template = "https://github.com/samply/lens/edit/develop/book/{path}"
10 changes: 6 additions & 4 deletions src/stores/catalogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,22 @@ export const getCriteriaFromKey = (
};

/**
* Set the catalogue. A warning is logged to the browser console if the catalogue does not match the JSON schema.
* Set the catalogue. A warning is logged to the browser console if the catalogue does not match the JSON schema. Note that the function makes a deep copy of the catalogue so modifying the original object has no effect.
*/
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);
}
10 changes: 6 additions & 4 deletions src/stores/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import optionsSchema from "../../schema/options.schema.json";
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.
* Set the options. A warning is logged to the browser console if the options do not match the JSON schema. Note that the function makes a deep copy of the options so modifying the original object has no effect.
*/
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);
}
9 changes: 6 additions & 3 deletions src/stores/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ export function getQueryStore(): QueryItem[][] {
return get(queryStore);
}

/**
* Set the query store. Note that the function makes a deep copy of the query store so modifying the original object has no effect.
*/
export function setQueryStore(query: QueryItem[][]): void {
queryStore.set(query);
queryStore.set(structuredClone(query));
}

/**
Expand Down Expand Up @@ -216,10 +219,10 @@ function findObjectsWithSameName(objectsArray: QueryItem[]): QueryItem[] {
}

/**
* Adds an item to the currently active query group
* Adds an item to the currently active query group. Note that the function makes a deep copy of the query item so modifying the original object has no effect.
* @param queryObject - the object to be added to the store
*/
export const addItemToActiveQueryGroup = (queryObject: QueryItem): void => {
const groupIndex = get(activeQueryGroupIndex);
addItemToQuery(queryObject, groupIndex);
addItemToQuery(structuredClone(queryObject), groupIndex);
};