Skip to content

Releases: Semantu/lincd

v0.3.0

20 Sep 11:14
Compare
Choose a tag to compare

Full Changelog: v0.2.8...v0.3.0

Storage

Quads live in graphs, graphs live in stores
All quads live in a graph. And all graphs live in a store (implementing IQuadStore). Updates to graphs are automatically passed on to the right store. This can be configured with some of the methods laid out below.

defaultGraph
When a new node is created locally (using NamedNode.create()) it is a temporary node. All temporary nodes and their properties (so any quads with this node as subject or object) are stored in the default graph. The contents of the default graph are lost on a page refresh or system restart. The default graph is - by default - the only graph that is not stored in a permanent store.

default storage graph
When a temporary node is saved, all of it's properties (related quads) are sent to the default storage graph. You can set the default storage graph using Storage.setDefaultStorageGraph(), though it will often automatically be set if you set a default store.

default store
You can now set the default store for storage using Storage.setDefaultStore(store). This store will then be used when a new (temporary) node is saved using node.save() and for all property changes to existing non-temporary nodes (using for example node.set(x,y))

When you set the default store, Storage will internally request store.getDefaultGraph(). This graph will then be used as the default storage graph. And changes in that default storage graph are sent to the default store.

Storing shapes in a specific store or graph
You can now use Storage.storeShapesInGraph(graph,...shapeClasses) or Storeage.storeShapesInStore(store,...shapeClasses) to state that all instances of this shape should be stored in the indicated graph/store.

Note that if you use stores, Storage will internally use that stores' defaultGraph, and store the shapes in that graph, which then get sent over to the store. In other words Storeage.storeShapesInStore(store,...shapeClasses) is equivalent to
Storage.storeShapesInGraph(store.getDefaultGraph(),...shapeClasses)

A final note on storage: It is possible to let a IQuadStore store all the quads in the default graph, though this will include all the temporary nodes created, with temporary URI's (lincd://temp/...)

Shape validation

You can now test if nodes are valid instances of a certain shape. Using ShapeClass.validate(node).

Example:

@linkedShape
class Person extends Shape { 
   static targetClass:NamedNode = foaf.Person;
}

let personNode = NamedNode.create();
personNode.set(rdf.type,foaf.Person);

Person.validate(personNode);

Testing

The first LINCD test has been added for these storage features. For that, a JEST setup has been made