mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-31 05:52:43 +00:00
refactor: replace rfdc with native structuredClone
This commit is contained in:
@@ -92,8 +92,8 @@ describe('e2e Connector', function () {
|
||||
if (
|
||||
request.url.toString() === `http://localhost${bulkAddRoute.getUrlPath({UID: 'foo'}).toString()}`
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
storedThings.set((request.body as any).uid, JSON.parse(JSON.stringify(request.body)));
|
||||
const thing = request.body as SCThings;
|
||||
storedThings.set(thing.uid, structuredClone(thing));
|
||||
|
||||
return {
|
||||
body: {},
|
||||
@@ -143,7 +143,6 @@ describe('e2e Connector', function () {
|
||||
},
|
||||
);
|
||||
|
||||
// tslint:disable-next-line: max-line-length
|
||||
await e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: './node_modules/@openstapps/core/test/resources',
|
||||
@@ -151,7 +150,6 @@ describe('e2e Connector', function () {
|
||||
|
||||
failOnLookup = true;
|
||||
failOnCompare = false;
|
||||
// tslint:disable-next-line: max-line-length
|
||||
await e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: './node_modules/@openstapps/core/test/resources',
|
||||
@@ -161,7 +159,6 @@ describe('e2e Connector', function () {
|
||||
|
||||
failOnLookup = false;
|
||||
failOnCompare = true;
|
||||
// tslint:disable-next-line: max-line-length
|
||||
await e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: './node_modules/@openstapps/core/test/resources',
|
||||
@@ -178,7 +175,6 @@ describe('e2e Connector', function () {
|
||||
};
|
||||
});
|
||||
|
||||
// tslint:disable-next-line: max-line-length
|
||||
return e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: './node_modules/@openstapps/core/test/resources',
|
||||
|
||||
@@ -76,8 +76,9 @@ export class ConnectorClient extends Client {
|
||||
* @param thing Thing to remove references from
|
||||
*/
|
||||
static removeReferences<THING extends SCThings>(thing: THING): SCAssociatedThingWithoutReferences<THING> {
|
||||
const thingWithoutReferences = JSON.parse(JSON.stringify(thing));
|
||||
const thingWithoutReferences = structuredClone(thing);
|
||||
|
||||
// @ts-expect-error it still thinks it's a thing with references
|
||||
delete thingWithoutReferences.origin;
|
||||
|
||||
// iterate over all properties
|
||||
@@ -134,7 +135,7 @@ export class ConnectorClient extends Client {
|
||||
}
|
||||
}
|
||||
|
||||
return thingWithoutReferences as SCAssociatedThingWithoutReferences<THING>;
|
||||
return thingWithoutReferences as unknown as SCAssociatedThingWithoutReferences<THING>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -378,7 +378,7 @@ describe('ConnectorClient', function () {
|
||||
);
|
||||
|
||||
for (const testInstance of testInstances) {
|
||||
const checkInstance = JSON.parse(JSON.stringify(testInstance));
|
||||
const checkInstance = structuredClone(testInstance);
|
||||
const testInstanceWithoutReferences = ConnectorClient.removeReferences(testInstance);
|
||||
|
||||
expect(doesContainThings(testInstanceWithoutReferences)).to.be.equal(
|
||||
|
||||
@@ -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:*",
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -68,10 +68,10 @@ export class LightweightProjectWithIndex {
|
||||
|
||||
return (deep ?? true) && isLightweightClass(object)
|
||||
? this.applyInheritance(object)
|
||||
: JSON.parse(JSON.stringify(object));
|
||||
: structuredClone(object);
|
||||
},
|
||||
),
|
||||
JSON.parse(JSON.stringify(classLike)),
|
||||
structuredClone(classLike),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user