refactor: replace rfdc with native structuredClone

This commit is contained in:
2024-04-03 11:14:47 +02:00
committed by Rainer Killinger
parent 622481a3c9
commit 53c3d0ba0c
13 changed files with 33 additions and 70 deletions

View File

@@ -49,8 +49,7 @@
"fast-deep-equal": "3.1.3",
"http-status-codes": "2.2.0",
"json-patch": "0.7.0",
"json-schema": "0.4.0",
"rfdc": "1.3.0"
"json-schema": "0.4.0"
},
"devDependencies": {
"@openstapps/easy-ast": "workspace:*",

View File

@@ -14,7 +14,6 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import equal from 'fast-deep-equal/es6/index.js';
import clone from 'rfdc';
import {SCLanguageCode} from './general/i18n.js';
import {isThing} from './guards.js';
import {SCClasses} from './meta.js';
@@ -223,7 +222,7 @@ export class SCThingTranslator {
return cachedInstance as T;
}
}
const translatedInstance = this.translateThingInPlaceDestructively(clone()(thing));
const translatedInstance = this.translateThingInPlaceDestructively(structuredClone(thing));
delete translatedInstance.translations;
this.cache.putObject(translatedInstance);
this.sourceCache.putObject(thing);
@@ -254,7 +253,7 @@ export class SCThingTranslator {
return this.deeptranslate((objectTranslatedFromCache as any)[key]);
}
}
const objectTranslated = this.translateThingInPlaceDestructively(clone()(object));
const objectTranslated = this.translateThingInPlaceDestructively(structuredClone(object));
this.cache.putObject(objectTranslated);
this.sourceCache.putObject(thing);

View File

@@ -13,7 +13,6 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {expect} from 'chai';
import clone from 'rfdc';
import {SCThingRemoteOrigin} from '../src/index.js';
import {SCDishMeta} from '../src/index.js';
import {SCThingTranslator} from '../src/index.js';
@@ -164,7 +163,7 @@ describe('Translator', function () {
it('should omit LRU cache with changed source', function () {
const translatorDE = new SCThingTranslator('de');
const dishCopy = clone()(dish);
const dishCopy = structuredClone(dish);
const translatedDish = translatorDE.translatedAccess(dish);
const destructivelyTranslatedDish = translatorDE.translate(dish);
@@ -224,7 +223,7 @@ describe('MetaTranslator', function () {
});
it('should translate thing without meta class', function () {
const dishCopy = clone()(dish);
const dishCopy = structuredClone(dish);
const typeNonExistent = eval("(x) => x + 'typeNonExistent';");
// this will assign a non-existent SCThingType to dishCopy
dishCopy.type = typeNonExistent();