levelgraph / levelgraph-jsonld

The Object Document Mapper for LevelGraph based on JSON-LD
113 stars 16 forks source link

del() cannot accept strings, but put() can #50

Closed BigBlueHat closed 7 years ago

BigBlueHat commented 7 years ago
var jld = {"@context": "https://schema.org/", "name": "BigBlueHat"};
db.jsonld.put(jld, console.log.bind(console));
db.jsonld.put(JSON.stringify(jld), console.log.bind(console));
// have the same result
db.jsonld.del(jld, console.log.bind(console)); // works
db.jsonld.del(JSON.stringify(jld), console.log.bind(console)); // doesn't...
//results in...

JsonLdError

{
  code: "loading document failed",
  url: "{"@context":{"@vocab":"http://xmlns.com/foaf/0.1/"},"@id":"http://bigbluehat.com/#","name":"BigBlueHat","knows":[{"@id":"http://manu.sporny.org#person","name":"Manu Sporny","homepage":"http://manu.sporny.org/"}]}",
  __proto__: {
    message: "URL could not be dereferenced; only "http" and "https" URLs are supported.",
    name: "jsonld.InvalidUrl",
    stack: "Error↵    at JsonLdError (http://localhost:8000/dist/index.js:20808:19)↵    at loader (http://localhost:8000/dist/index.js:20344:23)↵    at http://localhost:8000/dist/index.js:19809:8↵    at Function.jsonld.promisify (http://localhost:8000/dist/index.js:19808:10)↵    at jsonld.RequestQueue._loader (http://localhost:8000/dist/index.js:20337:21)↵    at http://localhost:8000/dist/index.js:19966:43↵    at jsonld.RequestQueue.add (http://localhost:8000/dist/index.js:19962:12)↵    at Object.jsonld.loadDocument [as documentLoader] (http://localhost:8000/dist/index.js:19670:24)↵    at http://localhost:8000/dist/index.js:18732:29↵    at Item.run (http://localhost:8000/dist/index.js:52966:14)"
  }
}

Apparently jsonld.js thinks any string is a URL, so input will need JSON.parse()'ing first.

jmatsushita commented 7 years ago

Good catch! Fix coming.

jmatsushita commented 7 years ago

Actually I can't reproduce the error. Neither with your jld var and the different one in the url key of the error. (Trying this in the console of the playground)

jmatsushita commented 7 years ago

Ah, just reproduced it finally. It fails with:

db.jsonld.del(JSON.stringify(jld), {preserve:true}, console.log.bind(console));