From 277bfcd2cac5eccf74f70e085c0421c7db705487 Mon Sep 17 00:00:00 2001 From: SiranWeb Date: Mon, 14 Nov 2022 19:22:12 +0300 Subject: [PATCH] fix APBase toPlain --- src/models/apBase/APBase.model.ts | 23 ++++++++--------------- tsconfig.json | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/models/apBase/APBase.model.ts b/src/models/apBase/APBase.model.ts index f249302..8295871 100644 --- a/src/models/apBase/APBase.model.ts +++ b/src/models/apBase/APBase.model.ts @@ -6,20 +6,8 @@ export class APBase { public fields: T; protected constructor(fields: T) { - // TODO move ordering to toPlain - const obj = cloneObjDeep(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(fields), }; } @@ -37,12 +25,17 @@ export class APBase { } protected parseValue(value: any): any { - return value instanceof APBase ? value.toPlain() : value; + return value instanceof APBase ? value.toPlain() : value.toValue(); } public toPlain(): Record { const result = {} as Record; + 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 { public toJSON(): string { return JSON.stringify(this.toPlain()); } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index baddab4..5438e9c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "outDir": "./dist", "declaration": true, - "target": "es2016", + "target": "es2017", "module": "ES6", "moduleResolution": "Node", "esModuleInterop": true,