o-development / ldo

Monorepo for Linked Data Objects (ldo)
MIT License
23 stars 5 forks source link

Helpers to change the Description Resource #48

Open elf-pavlik opened 1 month ago

elf-pavlik commented 1 month ago

I don't have a clear idea of the expected interface. Hopefully, I will be able to come up with some options.

Here are a few things to keep in mind:

An example of how I'm using it currently, blob is a File:

const { ok } = await session.rawFetch(fileId, {
  method: 'PUT',
  headers: { 'Content-Type': blob.type },
  body: blob
});

const descriptionIri = await session.discoverDescription(fileId)

const newFile = solidLdoDataset.usingType(FileShapeType)
  .fromSubject(fileId);

const resource = solidLdoDataset.getResource(descriptionIri);
const cFile = changeData(newFile, resource);
cFile.fileName = blob.name
cFile.format = blob.type

const fileResult = await commitData(cFile)

Given shape

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX solidshapes: <http://localhost:3000/shapetrees/shapes/>
PREFIX nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#>
PREFIX ma: <http://www.w3.org/ns/ma-ont#>

solidshapes:File {
  nfo:fileName xsd:string ;
  ma:format xsd:string
}

I always use opaque IRIs generated with randomUUID. I'm saving the original file name and using it when offering a download https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/download