o-development / ldo

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

Strange error when committing data #50

Open pchampin opened 2 weeks ago

pchampin commented 2 weeks ago

TL;DR: I get a strange error "Container URIs are not allowed for custom data" when trying to commitData to a leaf...

Here is a snippet of code that I'm working on:

    // root is a Container

    // create a subfolder of root
    const bookName = "" + (new Date()).getUTCFullYear();
    const bookContainer = root.child(`${bookName}/`);
    const result1 = await bookContainer.createIfAbsent();
    if (result1.isError) {
      return { prepared: false, message: "Creating book folder: " + result1.message};
    }

    // create an index in the subfolder
    const bookIndex = bookContainer.child("index");
    const result2 = await bookIndex.createIfAbsent();
    if (result2.isError) {
      return { prepared: false, message: "Creating book index: " + result2.message};
    }

    const book = createData (
      BookShapeType,
      bookIndex.uri,
      bookIndex,
    );
    // book.type = { "@id": "Book" }; // <---- this line is creating the error
    book.label = bookName;
    const result3 = await commitData(book);
    if (result3.isError) {
      return "Populating book index: " + result3.message;
    }

This works ok, but I would like my index file to declare itself of type Book. So I uncomment the assignment book.type = ..., but then result3 is en error, and I return "Populating book index: Encountered multiple errors: Error: Container URIs are not allowed for custom data.".

The shape of Book looks like this:

<#Book> {
  a [ sl:Book ]
    // rdfs:comment "A book contains (implicitly) zero to many translations" ;
  rdfs:label xsd:string
    // rdfs:comment "The label/title of this book" ;
}