Intro
Installable via npm install --save interface-datastore, it can also be used directly in the browser.
Download
The source is available for download from GitHub. Alternatively, you can install using npm:
$ npm install --save interface-datastore
You can then require() interface-datastore as normal:
const interfaceDatastore = require('interface-datastore')
In the Browser
Interface-datastore should work in any ES2015 environment out of the box.
Usage:
<script type="text/javascript" src="index.js"></script>
The portable versions of interface-datastore, including index.js and index.min.js, are included in the /dist folder. Interface-datastore can also be found on unkpkg.com under
Key
A Key represents the unique identifier of an object. Our Key scheme is inspired by file systems and Google App Engine key model. Keys are meant to be unique across a system. Keys are hierarchical, incorporating more and more specific namespaces. Thus keys can be deemed 'children' or 'ancestors' of other keys:
new Key('/Comedy')new Key('/Comedy/MontyPython')Also, every namespace can be parametrized to embed relevant object information. For example, the Keyname(most specific namespace) could include the object type:new Key('/Comedy/MontyPython/Actor:JohnCleese')new Key('/Comedy/MontyPython/Sketch:CheeseShop')new Key('/Comedy/MontyPython/Sketch:CheeseShop/Character:Mousebender')
Parameters
s: any:clean: any:
static
instance
Key.prototype.toString
toString(encoding: string): stringConvert to the string representation
Parameters
encoding: string (='utf8'):
Returns
Key.prototype.less
less(key: Key): boolCheck if the given key is sorted lower than ourself.
Parameters
key: Key:
Returns
bool
Key.prototype.reverse
reverse(): KeyReturns the key with all parts in reversed order.
Returns
Example
new Key('/Comedy/MontyPython/Actor:JohnCleese').reverse()
// => Key('/Actor:JohnCleese/MontyPython/Comedy')Key.prototype.baseNamespace
baseNamespace(): stringReturns the "base" namespace of this key.
Returns
Example
new Key('/Comedy/MontyPython/Actor:JohnCleese').baseNamespace()
// => 'Actor:JohnCleese'Key.prototype.list
list(): Array<string>Returns the list representation of this key.
Example
new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
// => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']Key.prototype.type
type(): stringReturns the "type" of this key (value of last namespace).
Returns
Example
new Key('/Comedy/MontyPython/Actor:JohnCleese').type()
// => 'Actor'Key.prototype.name
name(): stringReturns the "name" of this key (field of last namespace).
Returns
Example
new Key('/Comedy/MontyPython/Actor:JohnCleese').name()
// => 'JohnCleese'Key.prototype.instance
instance(s: string): KeyReturns an "instance" of this type key (appends value to namespace).
Parameters
s: string:
Returns
Example
new Key('/Comedy/MontyPython/Actor').instance('JohnClesse')
// => Key('/Comedy/MontyPython/Actor:JohnCleese')Key.prototype.path
path(): KeyReturns the "path" of this key (parent + type).
Returns
Example
new Key('/Comedy/MontyPython/Actor:JohnCleese').path()
// => Key('/Comedy/MontyPython/Actor')Key.prototype.parent
parent(): KeyReturns the parent Key of this Key.
Returns
Example
new Key("/Comedy/MontyPython/Actor:JohnCleese").parent()
// => Key("/Comedy/MontyPython")Key.prototype.child
child(key: Key): KeyReturns the child Key of this Key.
Parameters
key: Key:
Returns
Example
new Key('/Comedy/MontyPython').child(new Key('Actor:JohnCleese'))
// => Key('/Comedy/MontyPython/Actor:JohnCleese')Key.prototype.isAncestorOf
isAncestorOf(other: Key): boolReturns whether this key is a prefix of other
Parameters
other: Key:
Returns
bool
Example
new Key('/Comedy').isAncestorOf('/Comedy/MontyPython')
// => true