mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 19:22:51 +00:00
refactor: build system
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ValidationError} from '@openstapps/core-tools/lib/types/validator.js';
|
||||
import {ValidationError} from '@openstapps/core-tools';
|
||||
import {StatusCodes} from 'http-status-codes';
|
||||
import {SCError} from '../error.js';
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import equal = require('fast-deep-equal/es6');
|
||||
import clone = require('rfdc');
|
||||
import equal from 'fast-deep-equal/es6';
|
||||
import clone from 'rfdc';
|
||||
import {SCLanguageCode} from './general/i18n.js';
|
||||
import {isThing} from './guards.js';
|
||||
import {SCClasses} from './meta.js';
|
||||
@@ -92,12 +92,11 @@ export class SCThingTranslator {
|
||||
* @returns a T object allowing for access to translations or a translated value(s)
|
||||
*/
|
||||
private deeptranslate<T>(data: T): T {
|
||||
return typeof data === 'object' ? new Proxy(
|
||||
data as never,
|
||||
{
|
||||
get: (target, key) => this.deeptranslate(target[key as never]),
|
||||
},
|
||||
) as unknown as T : data;
|
||||
return typeof data === 'object'
|
||||
? (new Proxy(data as never, {
|
||||
get: (target, key) => this.deeptranslate(target[key as never]),
|
||||
}) as unknown as T)
|
||||
: data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,25 +253,22 @@ export class SCThingTranslator {
|
||||
* @returns an TSOCType<T> object allowing for access to translations or a translated value(s)
|
||||
*/
|
||||
public translatedAccess<T extends SCThing>(thing: T): T {
|
||||
return new Proxy(
|
||||
thing,
|
||||
{
|
||||
get: (target, key) => {
|
||||
const object: any = target;
|
||||
if (equal(this.sourceCache.get(thing), thing)) {
|
||||
const objectTranslatedFromCache = this.cache.get(thing);
|
||||
if (objectTranslatedFromCache !== undefined) {
|
||||
return this.deeptranslate((objectTranslatedFromCache as any)[key]);
|
||||
}
|
||||
return new Proxy(thing, {
|
||||
get: (target, key) => {
|
||||
const object: any = target;
|
||||
if (equal(this.sourceCache.get(thing), thing)) {
|
||||
const objectTranslatedFromCache = this.cache.get(thing);
|
||||
if (objectTranslatedFromCache !== undefined) {
|
||||
return this.deeptranslate((objectTranslatedFromCache as any)[key]);
|
||||
}
|
||||
const objectTranslated = this.translateThingInPlaceDestructively(clone()(object));
|
||||
this.cache.putObject(objectTranslated);
|
||||
this.sourceCache.putObject(thing);
|
||||
}
|
||||
const objectTranslated = this.translateThingInPlaceDestructively(clone()(object));
|
||||
this.cache.putObject(objectTranslated);
|
||||
this.sourceCache.putObject(thing);
|
||||
|
||||
return this.deeptranslate(objectTranslated[key]);
|
||||
},
|
||||
return this.deeptranslate(objectTranslated[key]);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user