interface-datastore
0.7.0

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 unpkg.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 Key name (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

  1. s: any:  
  2. clean: any:  

static

Key.withNamespaces

withNamespaces(list: Array<string>): Key

Constructs a key out of a namespace array.

Parameters

  1. list: Array<string>:  

Returns

Example

Key.withNamespaces(['one', 'two'])
// => Key('/one/two')

Key.random

random(): Key

Returns a randomly (uuid) generated key.

Returns

Example

Key.random()
// => Key('/f98719ea086343f7b71f32ea9d9d521d')

instance

Key.prototype.toString

toString(encoding: string): string

Convert to the string representation

Parameters

  1. encoding: string (='utf8'):  

Returns

Key.prototype.toBuffer

toBuffer(): Buffer

Return the buffer representation of the key

Returns

Key.prototype.clean

clean(): void

Cleanup the current key

Returns

void

Key.prototype.less

less(key: Key): bool

Check if the given key is sorted lower than ourself.

Parameters

  1. key: Key:  

Returns

bool

Key.prototype.reverse

reverse(): Key

Returns the key with all parts in reversed order.

Returns

Example

new Key('/Comedy/MontyPython/Actor:JohnCleese').reverse()
// => Key('/Actor:JohnCleese/MontyPython/Comedy')

Key.prototype.namespaces

namespaces(): Array<string>

Returns the namespaces making up this Key.

Returns

Key.prototype.baseNamespace

baseNamespace(): string

Returns 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.

Returns

Example

new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
// => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']

Key.prototype.type

type(): string

Returns the "type" of this key (value of last namespace).

Returns

Example

new Key('/Comedy/MontyPython/Actor:JohnCleese').type()
// => 'Actor'

Key.prototype.name

name(): string

Returns 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): Key

Returns an "instance" of this type key (appends value to namespace).

Parameters

  1. s: string:  

Returns

Example

new Key('/Comedy/MontyPython/Actor').instance('JohnClesse')
// => Key('/Comedy/MontyPython/Actor:JohnCleese')

Key.prototype.path

path(): Key

Returns the "path" of this key (parent + type).

Returns

Example

new Key('/Comedy/MontyPython/Actor:JohnCleese').path()
// => Key('/Comedy/MontyPython/Actor')

Key.prototype.parent

parent(): Key

Returns the parent Key of this Key.

Returns

Example

new Key("/Comedy/MontyPython/Actor:JohnCleese").parent()
// => Key("/Comedy/MontyPython")

Key.prototype.child

child(key: Key): Key

Returns the child Key of this Key.

Parameters

  1. key: Key:  

Returns

Example

new Key('/Comedy/MontyPython').child(new Key('Actor:JohnCleese'))
// => Key('/Comedy/MontyPython/Actor:JohnCleese')

Key.prototype.isAncestorOf

isAncestorOf(other: Key): bool

Returns whether this key is a prefix of other

Parameters

  1. other: Key:  

Returns

bool

Example

new Key('/Comedy').isAncestorOf('/Comedy/MontyPython')
// => true

Key.prototype.isDecendantOf

isDecendantOf(other: Key): bool

Returns whether this key is a contains another as prefix.

Parameters

  1. other: Key:  

Returns

bool

Example

new Key('/Comedy/MontyPython').isDecendantOf('/Comedy')
// => true

Key.prototype.isTopLevel

isTopLevel(): bool

Returns wether this key has only one namespace.

Returns

bool

namespaceType

The first component of a namespace. foo in foo:bar

Parameters

  1. ns: string:  

Returns

namespaceValue

The last component of a namespace, baz in foo:bar:baz.

Parameters

  1. ns: string:  

Returns