From 8818a4b5b4932d630fbd0daaee90158455b6fa3b Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 29 May 2024 19:51:57 +0000 Subject: [PATCH] Clone document on addStatic. --- CHANGELOG.md | 5 +++++ lib/JsonLdDocumentLoader.js | 5 +++-- package.json | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cca54a..175613a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # jsonld-document-loader +## 2.0.1 - + +### Changed +- addStatic deep clones documents to avoid mutation. + ## 2.0.0 - 2023-02-06 ### Changed diff --git a/lib/JsonLdDocumentLoader.js b/lib/JsonLdDocumentLoader.js index c073c75..fb212ad 100644 --- a/lib/JsonLdDocumentLoader.js +++ b/lib/JsonLdDocumentLoader.js @@ -1,6 +1,7 @@ /*! - * Copyright (c) 2019-2023 Digital Bazaar, Inc. All rights reserved. + * Copyright (c) 2019-2024 Digital Bazaar, Inc. All rights reserved. */ +import {klona} from 'klona'; export class JsonLdDocumentLoader { constructor() { @@ -15,7 +16,7 @@ export class JsonLdDocumentLoader { if(!_isObject(document)) { throw new TypeError('The second parameter (document) must be an object.'); } - this.documents.set(url, document); + this.documents.set(url, klona(document)); } /** diff --git a/package.json b/package.json index 71ab28c..33ebc7a 100644 --- a/package.json +++ b/package.json @@ -52,5 +52,8 @@ }, "engines": { "node": ">=16" + }, + "dependencies": { + "klona": "^2.0.6" } }