Skip to content

Datastore.nucleus

Sebastien Filion edited this page Jun 14, 2018 · 2 revisions

Global


Class: NucleusDatastore

Class: NucleusDatastore

Creates a Redis client. The constructor returns a Proxy that interfaces the class and a Promise that resolves once the server is connected.

NucleusDatastore.addItemToHashFieldByName(itemKey, itemField, item, hashList)

Adds an item to a hash given a field and its key. HMSET key field value

Parameters

itemKey: String, Adds an item to a hash given a field and its key. HMSET key field value

itemField: String, Adds an item to a hash given a field and its key. HMSET key field value

item: *, Adds an item to a hash given a field and its key. HMSET key field value

hashList: Array, Adds an item to a hash given a field and its key. HMSET key field value

Returns: Promise.<*>

NucleusDatastore.addItemToListByName(itemKey, item, itemList)

Adds an item to a list given its key. LPUSH key value

Parameters

itemKey: String, Adds an item to a list given its key. LPUSH key value

item: *, Adds an item to a list given its key. LPUSH key value

itemList: Array, Adds an item to a list given its key. LPUSH key value

Returns: Promise.<*>

NucleusDatastore.addItemToSetByName(itemKey, item)

Adds an item to a set. SADD key value

Parameters

itemKey: String, Adds an item to a set. SADD key value

item: String, Adds an item to a set. SADD key value

Returns: Promise.<*>

NucleusDatastore.addTripleToHexastore(itemKey, subject, predicate, object)

Adds a triple to a hexastore.

Parameters

itemKey: String, Adds a triple to a hexastore.

subject: String, Adds a triple to a hexastore.

predicate: String, Adds a triple to a hexastore.

object: String, Adds a triple to a hexastore.

Returns: Promise.<void>

NucleusDatastore.createItem(itemKey, item)

Creates an item. SET key value

Parameters

itemKey: String, Creates an item. SET key value

item: *, Creates an item. SET key value

Returns: Promise.<*>

NucleusDatastore.destroy()

Destroys the Redis connection.

Returns: Promise

NucleusDatastore.duplicateConnection(datastoreName)

Duplicates the connection.

Parameters

datastoreName: String, Duplicates the connection.

Returns: NucleusDatastore

NucleusDatastore.evaluateLUAScript(LUAscript, argumentList)

Evaluates a LUA script.

Parameters

LUAscript: String, Evaluates a LUA script.

argumentList: Array, Evaluates a LUA script.

Returns: Promise.<*>

NucleusDatastore.executeHandlerCallbackForChannelName(channelName, $event)

Executes all handler callback for a given channel name.

Parameters

channelName: String, Executes all handler callback for a given channel name.

$event: NucleusEvent, Executes all handler callback for a given channel name.

Returns: Promise

NucleusDatastore.itemIsMemberOfSet(itemKey, item)

Verifies if an item is part of a given item set.

Parameters

itemKey: String, Verifies if an item is part of a given item set.

item: String, Verifies if an item is part of a given item set.

Returns: Promise.<Object>

NucleusDatastore.handleEventByChannelName(channelName, handlerCallback)

Handles event published to a specific channel given a handler callback.

Parameters

channelName: String, Handles event published to a specific channel given a handler callback.

handlerCallback: function, Handles event published to a specific channel given a handler callback.

Returns: Promise.<Object>

NucleusDatastore.handleRedisEvent(argumentList)

Handles Redis event.

Parameters

argumentList: Array.<String>, Handles Redis event.

NucleusDatastore.removeAllTriplesFromHexastoreByVector(itemKey, vector)

Removes a triple from a hexastore given the subject vector. This will remove every relationship where the given vector is subject or object.

Parameters

itemKey: String, Removes a triple from a hexastore given the subject vector. This will remove every relationship where the given vector is subject or object.

vector: String, Removes a triple from a hexastore given the subject vector. This will remove every relationship where the given vector is subject or object.

Returns: Promise.<void>

NucleusDatastore.removeItemByName(itemKey)

Removes an item given its key. DEL key

Parameters

itemKey: String, Removes an item given its key. DEL key

Returns: Promise.<null>

NucleusDatastore.removeItemFromFieldByName(itemKey, itemField)

Removes an item from a hash given a field. HMDEL key field

Parameters

itemKey: String, Removes an item from a hash given a field. HMDEL key field

itemField: String, Removes an item from a hash given a field. HMDEL key field

Returns: Promise.<null>

NucleusDatastore.retrieveAllItemsFromHashByName(itemKey)

Retrieves all the items from a hash given its name. HGETALL key

Parameters

itemKey: , Retrieves all the items from a hash given its name. HGETALL key

Returns: Promise.<Array>

NucleusDatastore.retrieveItemByName(itemKey)

Retrieves an item given its key. GET key

Parameters

itemKey: String, Retrieves an item given its key. GET key

Returns: Promise.<*>

NucleusDatastore.retrieveItemFromHashFieldByName(itemKey, itemField, itemFieldList)

Remove an item from a hash given an item field. HMDEL key field

Parameters

itemKey: String, Remove an item from a hash given an item field. HMDEL key field

itemField: String, Remove an item from a hash given an item field. HMDEL key field

itemFieldList: Array.<String>, Remove an item from a hash given an item field. HMDEL key field

Returns: Promise.<*>

NucleusDatastore.retrieveItemFromListDeferred(itemKey)

Retrieves an item from a list but blocks the client if the list is empty. BRPOP key timeout

Parameters

itemKey: String, Retrieves an item from a list but blocks the client if the list is empty. BRPOP key timeout

Returns: Promise

NucleusDatastore.retrieveRelationshipListFromHexastore(itemName, subject, object)

Retrieves the relationship between a subject and an object from a hexastore.

Parameters

itemName: String, Retrieves the relationship between a subject and an object from a hexastore.

subject: String, Retrieves the relationship between a subject and an object from a hexastore.

object: String, Retrieves the relationship between a subject and an object from a hexastore.

Returns: Promise.<Array.<String>>

NucleusDatastore.retrieveVectorByIndexSchemeFromHexastore(itemName, indexingScheme, vectorA, vectorB)

Retrieves the any vector from any triple given the index scheme from a hexastore.

Parameters

itemName: String, Retrieves the any vector from any triple given the index scheme from a hexastore.

indexingScheme: String, Retrieves the any vector from any triple given the index scheme from a hexastore.

vectorA: String, Retrieves the any vector from any triple given the index scheme from a hexastore.

vectorB: String, Retrieves the any vector from any triple given the index scheme from a hexastore.

Returns: Promise.<Array.<String>>

Example:

async $datastore.addTripleToHexastore('ResourceRelationship', userID, 'isMember', userGroupID);
const relationshipList = async $datastore.retrieveVectorByIndexSchemeFromHexastore('ResourceRelationship', 'SOP', userID, userGroupID);

NucleusDatastore.subscribeToChannelName(channelName)

Subscribes the client to a channel given its name.

Parameters

channelName: String, Subscribes the client to a channel given its name.

Returns: Promise

NucleusDatastore.unsubscribeFromChannelName(channelName)

Unsubscribes the client from a channel given its name.

Parameters

channelName: String, Unsubscribes the client from a channel given its name.

Returns: Promise

NucleusDatastore.parseHashItem(itemList)

Parses a hash item list into an object.

Parameters

itemList: Array, Parses a hash item list into an object.

Returns: Object

NucleusDatastore.parseItem(item)

Parses an item to a native data type.

Parameters

item: String, Parses an item to a native data type.

Returns: *

NucleusDatastore.stringifyItem(item)

Stringifies a native data type.

Parameters

item: *, Stringifies a native data type.

Returns: String


Author: Sebastien Filion

Overview: Define the Nucleus Datastore class that wraps a Redis client.

NucleusDatastore

Kind: global class

new NucleusDatastore(datastoreName, options)

Creates a Redis client. The constructor returns a Proxy that interfaces the class and a Promise that resolves once the server is connected.

Param Type Default
datastoreName String Untitled
options Object
[options.index] Number 0
[options.port] Number 6379
[options.URL] String "localhost"

nucleusDatastore.addItemToHashFieldByName(itemKey, [itemField], [item], [...hashList]) ⇒ Promise.<*>

Adds an item to a hash given a field and its key. HMSET key field value

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
  • Will throw an error if the item field is missing or an empty string.
  • Will throw an error if an inconsistent list of item field and item is passed.
Param Type
itemKey String
[itemField] String
[item] *
[...hashList] Array

nucleusDatastore.addItemToListByName(itemKey, item, [itemList]) ⇒ Promise.<*>

Adds an item to a list given its key. LPUSH key value

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
Param Type
itemKey String
item *
[itemList] Array

nucleusDatastore.addItemToSetByName(itemKey, item) ⇒ Promise.<*>

Adds an item to a set. SADD key value

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
  • Will throw an error if the item is not a string.
Param Type
itemKey String
item String

nucleusDatastore.addTripleToHexastore(itemKey, subject, predicate, object) ⇒ Promise.<void>

Adds a triple to a hexastore.

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
  • Will throw an error if the subject is not a string.
  • Will throw an error if the predicate is not a string.
  • Will throw an error if the object is not a string.

See: Hexastore paper

Param Type
itemKey String
subject String
predicate String
object String

nucleusDatastore.createItem(itemKey, item) ⇒ Promise.<*>

Creates an item. SET key value

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
Param Type
itemKey String
item *

nucleusDatastore.destroy() ⇒ Promise

Destroys the Redis connection.

Kind: instance method of NucleusDatastore

nucleusDatastore.duplicateConnection([datastoreName]) ⇒ NucleusDatastore

Duplicates the connection.

Kind: instance method of NucleusDatastore

Param Type Default
[datastoreName] String `${this.name}Duplicate`

nucleusDatastore.evaluateLUAScript(LUAscript, ...argumentList) ⇒ Promise.<*>

Evaluates a LUA script.

Kind: instance method of NucleusDatastore

Param Type
LUAscript String
...argumentList Array

nucleusDatastore.executeHandlerCallbackForChannelName(channelName, $event) ⇒ Promise

Executes all handler callback for a given channel name.

Kind: instance method of NucleusDatastore

Param Type
channelName String
$event NucleusEvent

nucleusDatastore.itemIsMemberOfSet(itemKey, item) ⇒ Promise.<Object>

Verifies if an item is part of a given item set.

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
  • Will throw an error if the item is not a string.
Param Type
itemKey String
item String

nucleusDatastore.handleEventByChannelName(channelName, handlerCallback) ⇒ Promise.<Object>

Handles event published to a specific channel given a handler callback.

Kind: instance method of NucleusDatastore

Param Type
channelName String
handlerCallback function

nucleusDatastore.handleRedisEvent(...argumentList)

Handles Redis event.

Kind: instance method of NucleusDatastore

Param Type
...argumentList Array.<String>

nucleusDatastore.removeAllTriplesFromHexastoreByVector(itemKey, vector) ⇒ Promise.<void>

Removes a triple from a hexastore given the subject vector. This will remove every relationship where the given vector is subject or object.

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
  • Will throw an error if the vector is not a string.
Param Type
itemKey String
vector String

nucleusDatastore.removeItemByName(itemKey) ⇒ Promise.<null>

Removes an item given its key. DEL key

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
Param Type
itemKey String

nucleusDatastore.removeItemFromFieldByName(itemKey, itemField) ⇒ Promise.<null>

Removes an item from a hash given a field. HMDEL key field

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
  • Will throw an error if the item field is missing or an empty string.
Param Type
itemKey String
itemField String

nucleusDatastore.retrieveAllItemsFromHashByName(itemKey) ⇒ Promise.<Array>

Retrieves all the items from a hash given its name. HGETALL key

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
Param
itemKey

nucleusDatastore.retrieveItemByName(itemKey) ⇒ Promise.<*>

Retrieves an item given its key. GET key

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
Param Type
itemKey String

nucleusDatastore.retrieveItemFromHashFieldByName(itemKey, [itemField], [...itemFieldList]) ⇒ Promise.<*>

Remove an item from a hash given an item field. HMDEL key field

Kind: instance method of NucleusDatastore
Throws:

  • Will throw an error if the item key is missing or an empty string.
  • Will throw an error if the item field is missing or an empty string.
Param Type
itemKey String
[itemField] String
[...itemFieldList] Array.<String>

nucleusDatastore.retrieveItemFromListDeferred(itemKey) ⇒ Promise

Retrieves an item from a list but blocks the client if the list is empty. BRPOP key timeout

Kind: instance method of NucleusDatastore

Param Type
itemKey String

nucleusDatastore.retrieveRelationshipListFromHexastore(itemName, subject, object) ⇒ Promise.<Array.<String>>

Retrieves the relationship between a subject and an object from a hexastore.

Kind: instance method of NucleusDatastore

Param Type
itemName String
subject String
object String

nucleusDatastore.retrieveVectorByIndexSchemeFromHexastore(itemName, indexingScheme, vectorA, vectorB) ⇒ Promise.<Array.<String>>

Retrieves the any vector from any triple given the index scheme from a hexastore.

Kind: instance method of NucleusDatastore
See: Hexastore paper

Param Type Default
itemName String
indexingScheme String SPO,SOP,OPS,OSP,PSO,POS
vectorA String
vectorB String

Example

async $datastore.addTripleToHexastore('ResourceRelationship', userID, 'isMember', userGroupID);
const relationshipList = async $datastore.retrieveVectorByIndexSchemeFromHexastore('ResourceRelationship', 'SOP', userID, userGroupID);

nucleusDatastore.searchItemInHashByName(itemKey, [fieldName], [fieldNameList]) ⇒ *

Searches for items in a hash given its name.

Kind: instance method of NucleusDatastore

Param Type
itemKey String
[fieldName] String
[fieldNameList] Array.<String>

Example

$datastore.searchItemInHashByName('UserSettings', 'localization');
$datastore.searchItemInHashByName('UserSettings', 'localization.defaultLanguageISO');
$datastore.searchItemInHashByName('UserSettings', ['localization', 'notifications');
$datastore.searchItemInHashByName('UserSettings', ['localization.defaultLanguageISO', 'notifications.channels.email']);

nucleusDatastore.subscribeToChannelName(channelName) ⇒ Promise

Subscribes the client to a channel given its name.

Kind: instance method of NucleusDatastore

Param Type
channelName String

nucleusDatastore.unsubscribeFromChannelName(channelName) ⇒ Promise

Unsubscribes the client from a channel given its name.

Kind: instance method of NucleusDatastore

Param Type
channelName String

NucleusDatastore.collapseObjectToDotNotation(object) ⇒ Object

Collaps an object to a dot notation object.

Kind: static method of NucleusDatastore

Param Type
object Object

Example

const collapsedObject = NucleusDatastore.collapseObjectToDotNotation({ a: { b: 'B' } });
collapsedObject['a.b'] === 'B';

NucleusDatastore.expandDotNotationObject(object) ⇒ Object

Expands a dot notation object.

Kind: static method of NucleusDatastore

Param Type
object Object

Example

const expandedObject = NucleusDatastore.expandDotNotationObject({ 'a.b': 'B' });
expandedObject.a.b === 'B';

NucleusDatastore.parseHashItem(itemList) ⇒ Object

Parses a hash item list into an object.

Kind: static method of NucleusDatastore

Param Type
itemList Array

NucleusDatastore.parseItem(item) ⇒ *

Parses an item to a native data type.

Kind: static method of NucleusDatastore

Param Type
item String

NucleusDatastore.stringifyItem(item) ⇒ String

Stringifies a native data type.

Kind: static method of NucleusDatastore

Param Type
item *
Clone this wiki locally