fix APBase toPlain

pull/4/head
SiranWeb 2022-11-14 19:22:12 +03:00
rodzic a3e2588365
commit 277bfcd2ca
2 zmienionych plików z 9 dodań i 16 usunięć

Wyświetl plik

@ -6,20 +6,8 @@ export class APBase<T extends WithContext> {
public fields: T;
protected constructor(fields: T) {
// TODO move ordering to toPlain
const obj = cloneObjDeep<T>(fields);
if ('@context' in obj) {
this.fields = {
'@context': obj['@context'],
} as T;
delete obj["@context"];
} else {
this.fields = {} as T;
}
this.fields = {
...this.fields,
...obj
...cloneObjDeep<T>(fields),
};
}
@ -37,12 +25,17 @@ export class APBase<T extends WithContext> {
}
protected parseValue(value: any): any {
return value instanceof APBase ? value.toPlain() : value;
return value instanceof APBase ? value.toPlain() : value.toValue();
}
public toPlain(): Record<string, any> {
const result = {} as Record<string, any>;
if ('@context' in this.fields) {
result['@context'] = this.fields['@context'];
}
for (const [key, value] of Object.entries(this.fields)) {
if (key === '@context') continue;
const isFunction = typeof value === 'function';
const isArray = Array.isArray(value);
const isNull = value === null;
@ -69,4 +62,4 @@ export class APBase<T extends WithContext> {
public toJSON(): string {
return JSON.stringify(this.toPlain());
}
}
}

Wyświetl plik

@ -2,7 +2,7 @@
"compilerOptions": {
"outDir": "./dist",
"declaration": true,
"target": "es2016",
"target": "es2017",
"module": "ES6",
"moduleResolution": "Node",
"esModuleInterop": true,