From a09bf131c23616ee80a3e3a323d8676887a1931b Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Fri, 24 May 2024 20:34:32 +0200 Subject: [PATCH] Fix build --- src/engines/SolidEngine.ts | 4 ++-- src/models/SolidModel.ts | 7 ++++--- src/models/SolidTypeIndex.ts | 4 +++- src/models/history/PropertyOperation.ts | 2 ++ src/models/relations/SolidContainsRelation.ts | 7 ++++++- src/models/relations/SolidIsContainedByRelation.ts | 7 ++++++- .../relations/mixins/SolidMultiModelDocumentRelation.ts | 7 ++++--- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/engines/SolidEngine.ts b/src/engines/SolidEngine.ts index 96c6ae9..af07def 100644 --- a/src/engines/SolidEngine.ts +++ b/src/engines/SolidEngine.ts @@ -1,4 +1,4 @@ -import { arrayFrom, arrayUnique, isObject, urlParentDirectory, urlRoot } from '@noeldemartin/utils'; +import { arrayFrom, arrayUnique, isObject, toString, urlParentDirectory, urlRoot } from '@noeldemartin/utils'; import { compactJsonLDGraph, quadsToJsonLD } from '@noeldemartin/solid-utils'; import { DocumentAlreadyExists, @@ -177,7 +177,7 @@ export class SolidEngine implements Engine { const rdfsClasses = this.extractJsonLDGraphTypes(filters); return filters.$in - ? await this.getDocumentsFromUrls(filters.$in, rdfsClasses) + ? await this.getDocumentsFromUrls(filters.$in.map(toString), rdfsClasses) : await this.client.getDocuments(collection, rdfsClasses.includes(IRI('ldp:Container'))); } diff --git a/src/models/SolidModel.ts b/src/models/SolidModel.ts index 8f9588f..ede2761 100644 --- a/src/models/SolidModel.ts +++ b/src/models/SolidModel.ts @@ -1222,13 +1222,14 @@ export class SolidModel extends SolidModelBase { return this.newInstance(attributes, true); }; - const resource = await RDFDocument.resourceFromJsonLDGraph(document as JsonLDGraph, resourceId || id); + const documentUrl = toString(id); + const resource = await RDFDocument.resourceFromJsonLDGraph(document as JsonLDGraph, resourceId || documentUrl); const model = await createModel(); - await model.loadDocumentModels(id, document); + await model.loadDocumentModels(documentUrl, document); return tap(model, m => { - m._sourceDocumentUrl = urlClean(id, { fragment: false }); + m._sourceDocumentUrl = urlClean(documentUrl, { fragment: false }); m._usesRdfAliases = this.static('rdfsClassesAliases').some( types => !types.some(type => !resource.isType(type)), ); diff --git a/src/models/SolidTypeIndex.ts b/src/models/SolidTypeIndex.ts index 526c2b7..a95b013 100644 --- a/src/models/SolidTypeIndex.ts +++ b/src/models/SolidTypeIndex.ts @@ -53,7 +53,9 @@ export default class SolidTypeIndex extends Model { return asyncFirst( containerRegistrations, - registration => (containerClass ?? SolidContainer).find(registration?.instanceContainer) as Promise, + async registration => registration?.instanceContainer + ? (containerClass ?? SolidContainer).find(registration.instanceContainer) as Promise + : null, ); } diff --git a/src/models/history/PropertyOperation.ts b/src/models/history/PropertyOperation.ts index 63c8033..4dbf607 100644 --- a/src/models/history/PropertyOperation.ts +++ b/src/models/history/PropertyOperation.ts @@ -4,6 +4,8 @@ import Model from './PropertyOperation.schema'; export default class PropertyOperation extends Model { + declare public property: string; + public apply(model: SolidModel): void { const field = model.static().getRdfPropertyField(this.property); diff --git a/src/models/relations/SolidContainsRelation.ts b/src/models/relations/SolidContainsRelation.ts index 15ee416..10ff3e7 100644 --- a/src/models/relations/SolidContainsRelation.ts +++ b/src/models/relations/SolidContainsRelation.ts @@ -19,7 +19,12 @@ export default class SolidContainsRelation< } public setForeignAttributes(related: Related): void { - if (!related.url || this.parent.resourceUrls.includes(related.getDocumentUrl())) { + const relatedDocumentUrl = related.getDocumentUrl(); + + if ( + !related.url || + (relatedDocumentUrl && this.parent.resourceUrls.includes(relatedDocumentUrl)) + ) { return; } diff --git a/src/models/relations/SolidIsContainedByRelation.ts b/src/models/relations/SolidIsContainedByRelation.ts index b9c07dd..e2d9340 100644 --- a/src/models/relations/SolidIsContainedByRelation.ts +++ b/src/models/relations/SolidIsContainedByRelation.ts @@ -21,7 +21,12 @@ export default class SolidIsContainedByRelation< } public setForeignAttributes(related: Related): void { - if (!this.parent.url || related.resourceUrls.includes(this.parent.getDocumentUrl())) { + const parentDocumentUrl = this.parent.getDocumentUrl(); + + if ( + !this.parent.url || + (parentDocumentUrl && related.resourceUrls.includes(parentDocumentUrl)) + ) { return; } diff --git a/src/models/relations/mixins/SolidMultiModelDocumentRelation.ts b/src/models/relations/mixins/SolidMultiModelDocumentRelation.ts index e38abd5..1ca8f6c 100644 --- a/src/models/relations/mixins/SolidMultiModelDocumentRelation.ts +++ b/src/models/relations/mixins/SolidMultiModelDocumentRelation.ts @@ -1,5 +1,5 @@ import { arrayUnique, tap } from '@noeldemartin/utils'; -import { MultiModelRelation } from 'soukai'; +import { MultiModelRelation, requireBootedModel } from 'soukai'; import type { Attributes, Key } from 'soukai'; import type { ClosureArgs } from '@noeldemartin/utils'; @@ -106,8 +106,9 @@ export default class SolidMultiModelDocumentRelation< await this.parent.save(); } - public detach(this: This, keyOrModel: string | Related): void { - const localKey = typeof keyOrModel === 'string' ? keyOrModel : keyOrModel.getAttribute(this.localKeyName); + public detach(this: This, keyOrModel: Key | Related): void { + const isRelated = (related: unknown): related is Related => related instanceof this.relatedClass; + const localKey = isRelated(keyOrModel) ? keyOrModel.getAttribute(this.localKeyName) : keyOrModel; const detachedModel = this.related?.find(model => model.getAttribute(this.localKeyName) === localKey); if (!detachedModel) {