From 7491b40b1d843a6cd56589a24de82b3751429518 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Tue, 31 Oct 2023 21:32:46 +0530 Subject: [PATCH] Added override option to ensureSDNASubjectClass to override SDNA --- core/src/perspectives/PerspectiveProxy.ts | 30 +++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/core/src/perspectives/PerspectiveProxy.ts b/core/src/perspectives/PerspectiveProxy.ts index 8a0d48263..db4004704 100644 --- a/core/src/perspectives/PerspectiveProxy.ts +++ b/core/src/perspectives/PerspectiveProxy.ts @@ -580,12 +580,32 @@ export class PerspectiveProxy { * If there is no such class, it gets the JS class's SDNA by calling its * static generateSDNA() function and adds it to the perspective's SDNA. */ - async ensureSDNASubjectClass(jsClass: any): Promise { - if((await this.subjectClassesByTemplate(new jsClass)).length > 0) { - return - } + async ensureSDNASubjectClass(jsClass: any, options?: { override: boolean }): Promise { + const subjectClass = await this.subjectClassesByTemplate(new jsClass) + if (!options?.override) { + if(subjectClass.length > 0) { + return + } + + await this.addSdna(jsClass.generateSDNA()) + } else { + let links = await this.get(new LinkQuery({ + source: "ad4m://self", + predicate: "ad4m://has_zome" + })) + + const link = links.find(l => { + if (l.data.target.includes(subjectClass[0])) { + return true + } + + return false; + }) - await this.addSdna(jsClass.generateSDNA()) + await this.remove(link); + + await this.addSdna(jsClass.generateSDNA()) + } } getNeighbourhoodProxy(): NeighbourhoodProxy {