### interface-datastore

`1.0.0`
Need help reading this?

## 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 ECMAScript 2018 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

- https://unpkg.com/interface-datastore/dist/index.min.js
- https://unpkg.com/interface-datastore/dist/index.js

### Key

src/key.js

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')`

new Key(s: any, clean: any)
Parameters
s `(any)`
clean `(any)`
Static Members
▸ withNamespaces(list)
src/key.js

Constructs a key out of a namespace array.

withNamespaces(list: Array<string>): Key
Parameters
list `(Array<string>)`
Returns
`Key`:
Example

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

▸ random()
src/key.js

Returns a randomly (uuid) generated key.

random(): Key
Returns
`Key`:
Example

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

Instance Members
▸ toString(encoding)
src/key.js

Convert to the string representation

toString(encoding: string): string
Parameters
encoding `(string = `'utf8'`)`
Returns
`string`:
▸ toBuffer()
src/key.js

Return the buffer representation of the key

toBuffer(): Buffer
Returns
`Buffer`:
▸ toStringTag
src/key.js
toStringTag
Returns
`String`:
▸ clean()
src/key.js

Cleanup the current key

clean(): void
Returns
`void`:
▸ less(key)
src/key.js

Check if the given key is sorted lower than ourself.

less(key: Key): bool
Parameters
key `(Key)`
Returns
`bool`:
▸ reverse()
src/key.js

Returns the key with all parts in reversed order.

reverse(): Key
Returns
`Key`:
Example

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

▸ namespaces()
src/key.js

Returns the `namespaces` making up this Key.

namespaces(): Array<string>
Returns
`Array<string>`:
▸ baseNamespace()
src/key.js

Returns the "base" namespace of this key.

baseNamespace(): string
Returns
`string`:
Example

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

▸ list()
src/key.js

Returns the `list` representation of this key.

list(): Array<string>
Returns
`Array<string>`:
Example

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

▸ type()
src/key.js

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

type(): string
Returns
`string`:
Example

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

▸ name()
src/key.js

Returns the "name" of this key (field of last namespace).

name(): string
Returns
`string`:
Example

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

▸ instance(s)
src/key.js

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

instance(s: string): Key
Parameters
s `(string)`
Returns
`Key`:
Example

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

▸ path()
src/key.js

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

path(): Key
Returns
`Key`:
Example

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

▸ parent()
src/key.js

Returns the `parent` Key of this Key.

parent(): Key
Returns
`Key`:
Example

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

▸ child(key)
src/key.js

Returns the `child` Key of this Key.

child(key: Key): Key
Parameters
key `(Key)`
Returns
`Key`:
Example

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

▸ isAncestorOf(other)
src/key.js

Returns whether this key is a prefix of `other`

isAncestorOf(other: Key): bool
Parameters
other `(Key)`
Returns
`bool`:
Example

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

▸ isDecendantOf(other)
src/key.js

Returns whether this key is a contains another as prefix.

isDecendantOf(other: Key): bool
Parameters
other `(Key)`
Returns
`bool`:
Example

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

▸ isTopLevel()
src/key.js

Returns wether this key has only one namespace.

isTopLevel(): bool
Returns
`bool`:
▸ concat(keys)
src/key.js

Concats one or more Keys into one new Key.

concat(keys: Array<Key>): Key
Parameters
keys `(Array<Key>)`
Returns
`Key`:

### namespaceType

src/key.js

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

namespaceType(ns: string): string
Parameters
ns `(string)`
Returns
`string`:

### namespaceValue

src/key.js

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

namespaceValue(ns: string): string
Parameters
ns `(string)`
Returns
`string`:

### flatten

src/key.js

Flatten array of arrays (only one level)

flatten(arr: Array<Array>): any
Parameters
arr `(Array<Array>)`
Returns
`any`: