Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • Key

Index

Constructors

constructor

  • new Key(s: string | Uint8Array, clean: undefined | boolean): Key
  • Parameters

    • s: string | Uint8Array
    • clean: undefined | boolean

    Returns Key

Properties

_buf

_buf: Uint8Array

Accessors

[Symbol.toStringTag]

  • get [Symbol.toStringTag](): string
  • Return string representation of the key

    Returns string

[symbol]

  • get [symbol](): boolean

Methods

baseNamespace

  • baseNamespace(): string
  • Returns the "base" namespace of this key.

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

    Returns string

child

  • Returns the child Key of this Key.

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

    Parameters

    • key: Key

      The child Key to add

    Returns Key

clean

  • clean(): void

concat

  • Concats one or more Keys into one new Key.

    Parameters

    • Rest ...keys: Key[]

      The array of keys to concatenate

    Returns Key

instance

  • instance(s: string): Key
  • Returns an "instance" of this type key (appends value to namespace).

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

    Parameters

    • s: string

      The string to append.

    Returns Key

isAncestorOf

  • isAncestorOf(other: Key): boolean
  • Returns whether this key is a prefix of other

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

    Parameters

    • other: Key

      The other key to test against

    Returns boolean

isDecendantOf

  • isDecendantOf(other: Key): boolean
  • Returns whether this key is a contains another as prefix.

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

    Parameters

    • other: Key

      The other Key to test against

    Returns boolean

isTopLevel

  • isTopLevel(): boolean
  • Checks if this key has only one namespace.

    Returns boolean

less

  • less(key: Key): boolean
  • Check if the given key is sorted lower than ourself.

    Parameters

    • key: Key

      The other Key to check against

    Returns boolean

list

  • list(): string[]
  • Returns the list representation of this key.

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

    Returns string[]

name

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

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

    Returns string

namespaces

  • namespaces(): string[]
  • Returns the namespaces making up this Key.

    Returns string[]

parent

  • parent(): Key
  • Returns the parent Key of this Key.

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

    Returns Key

path

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

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

    Returns Key

reverse

  • reverse(): Key
  • Returns the key with all parts in reversed order.

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

    Returns Key

toString

  • toString(encoding?: SupportedEncodings): string
  • Convert to the string representation

    Parameters

    • encoding: SupportedEncodings = 'utf8'

    Returns string

type

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

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

    Returns string

uint8Array

  • uint8Array(): Uint8Array
  • Return the Uint8Array representation of the key

    Returns Uint8Array

Static isKey

  • isKey(value: any): value is Key
  • Check if value is a Key instance

    Parameters

    • value: any

      Value to check

    Returns value is Key

Static random

  • random(): Key
  • Returns a randomly (uuid) generated key.

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

    Returns Key

Static withNamespaces

  • withNamespaces(list: string[]): Key
  • Constructs a key out of a namespace array.

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

    Parameters

    • list: string[]

      The array of namespaces

    Returns Key