Returning resolved data

Another step on the roadmap has been completed and removed! Holster will now resolve all data in and out. It previously just returned an object containing rels, now it resolves the ids and replaces the rel in the returned data with the full object. Luckily the code to do this was quite similar to the way ids are resolved when putting nodes, so both holster.get() and holster.put() should work with any arbitrarily nested data.

This change makes the underlying data completely opaque when using the Holster API, so data out is the same as data in:
holster.get("hello", console.log)

{
  "world!": {
    "things": "I want to add",
    "which": {
      "can": "also have nested objects"
    }
  }
}

Another interesting thing you can now do with Holster is see all your data. This is possible because of the above change, but you also need to know the top level keys to get. You can do that using the wire API to get the root node:
holster.wire.get({"#": "root"}, msg => console.log(Object.keys(msg.put.root)))

// Or use the above to display everything on disk
holster.wire.get({"#": "root"}, async msg => {
  // wire API returns meta data.
  delete msg.put.root._
  for (const key of Object.keys(msg.put.root)) {
    const value = await new Promise(resolve => holster.get(key, resolve))
    console.log(key, value)
  }
})
A few caveats, the wire API can be used to create top level nodes too, so this method will only show everything created with the Holster API. The Promise is required above because holster.get() controls the context until the callback is called, so this forces the loop to wait until the previous get has finished.
Add a comment