NPM module - izara-shared: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 108: Line 108:
## objectVertexId: ''objectVertexId''
## objectVertexId: ''objectVertexId''


== graphSharedLib.createVersionedDataVertexLabel ==
== graphSharedLib.createVersionedDataVertexTag ==


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">
/**
/**
  * Creates standardized versionedDataVertexLabel
  * Creates standardized versionedDataVertexLabel
  * @param {string} subjectVertexLabel
  * @param {string} subjectVertexTag
  * @param {string} versionedDataTag
  * @param {string} versionedDataTag
  *
  *
Line 120: Line 120:
</syntaxhighlight>
</syntaxhighlight>


# let ''versionedDataVertexLabel'' = ''subjectVertexLabel'' + ''versionedDataTag''
# let ''versionedDataVertexTag'' = ''subjectVertexTag'' + ''versionedDataTag''
# return ''versionedDataVertexLabel''
# return ''versionedDataVertexTag''
 
== graphSharedLib.createVersionedDataEdgeLabel ==
 
<syntaxhighlight lang="JavaScript">
/**
* Creates standardized versionedDataEdgeLabel
* @param {string} ''versionedDataTag''
*
* @returns {string} versionedDataEdgeLabel
*/
</syntaxhighlight>
 
# return [[NPM module - izara-shared#graphSharedLib]].hasEdgeLabelPrefix + ''versionedDataTag''


== graphSharedLib.getVerticesByVertexLabel ==
== graphSharedLib.getVerticesByVertexLabel ==
Line 172: Line 185:
# return ''vertex''
# return ''vertex''


== graphSharedLib.getVertexOutEdges ==
== graphSharedLib.getVertexOutEdgesByVertexId ==


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">
Line 188: Line 201:
# ..
# ..


== graphSharedLib.getVertexOutEdgesAndVertices ==
== graphSharedLib.getVertexOutEdgesByVertexTagAndVertexUniqueId ==
 
<syntaxhighlight lang="JavaScript">
/**
* Returns all edges, allowing label and property filters
* @param {string} graphServiceName
* @param {string} subjectVertexTag
* @param {string} subjectVertexUniqueId
* @param {string} [edgeLabel=""]
* @param {object} [edgeProperties={}]
*
* @returns {string} vertexId
*/
</syntaxhighlight>
 
# const ''vertexId'' = [[NPM module - izara-shared#graphSharedLib.createVertexId]]
## vertexTag: ''subjectVertexTag''
## vertexUniqueId: ''subjectVertexUniqueId''
# const ''edges'' = invoke [[#graphSharedLib.getVertexOutEdgesByVertexId]]
## graphServiceName: ''graphServiceName''
## vertexId: ''vertexId''
## edgeLabel: ''edgeLabel''
## edgeProperties: ''edgeProperties''
# return ''edges''
 
== graphSharedLib.getVertexOutEdgesAndVerticesByVertexId ==


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">
Line 204: Line 242:


# ..
# ..
== graphSharedLib.getVertexOutEdgesAndVerticesByVertexTagAndVertexUniqueId ==
<syntaxhighlight lang="JavaScript">
/**
* Find related vertices and their connecting edges, including properties, allowing label and property filters
* @param {string} graphServiceName
* @param {string} subjectVertexTag
* @param {string} subjectVertexUniqueId
* @param {string} [edgeLabel=""] - edge label to filter edges by
* @param {object} [edgeProperties={}] - edge properties to filter by, is an array of key > value pairs
* @param {object} [vertexProperties={}] - object vertex properties to filter by, is an array of key > value pairs
*
* @returns {Object[]} array of vertices and the connecting edges
*/
</syntaxhighlight>
# const ''vertexId'' = [[NPM module - izara-shared#graphSharedLib.createVertexId]]
## vertexTag: ''subjectVertexTag''
## vertexUniqueId: ''subjectVertexUniqueId''
# const ''vertexAndEdges'' = invoke [[#graphSharedLib.getVertexOutEdgesAndVerticesByVertexId]]
## graphServiceName: ''graphServiceName''
## vertexId: ''vertexId''
## edgeLabel: ''edgeLabel''
## edgeProperties: ''edgeProperties''
# return ''vertexAndEdges''


== graphSharedLib.getObjectVertexByEdgeId ==
== graphSharedLib.getObjectVertexByEdgeId ==
Line 232: Line 296:


# .. needs to filter edge by currently active versioned data..
# .. needs to filter edge by currently active versioned data..
# ... work through queries to get the current versioned data


# // will need versionedDataEdgeLabel to find edges that are versioned data
#const versionedDataEdgeLabel = [[#createVersionedDataEdgeLabel]]
## versionedDataTag: ''versionedDataTag''


== graphSharedLib.getCurrentVersionedData ==
== graphSharedLib.getCurrentVersionedDataByVertexTagAndVertexUniqueId ==


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">
Line 248: Line 316:
</syntaxhighlight>
</syntaxhighlight>


# const ''subjectVertexId'' = [[NPM module - izara-shared#graphSharedLib.createVertexId]]
# const ''vertexId'' = [[NPM module - izara-shared#graphSharedLib.createVertexId]]
## vertexTag: ''vertexTag''
## vertexTag: ''vertexTag''
## vertexUniqueId: ''vertexUniqueId''
## vertexUniqueId: ''vertexUniqueId''
 
#const ''versionedDataVertexTag = [[#graphSharedLib.getCurrentVersionedDataByVertexId]]
#const ''versionedDataVertexLabel = [[#graphSharedLib.createVersionedDataVertexLabel]]
## graphServiceName: ''graphServiceName''
## subjectVertexLabel: ''vertexTag''
## vertexId: ''vertexId''
## versionedDataTag: ''versionedDataTag''
## versionedDataTag: ''versionedDataTag''

Revision as of 12:40, 6 March 2021

Overview

Shared libraries used across multiple izara projects

Repository

https://bitbucket.org/stb_working/izara-shared/src/master/

dynamodbSharedLib

Helper functions for interacting with DynamoDB resources.

dynamodbSharedLib.createStringSet

/**
 * Creates a string set element for use with documentClient
 * @param {string[]} stringSet
 *
 * @returns {string} String formatted as a string set for Dynamo
 */

configSharedLib

Helper functions for Config tables.

configSharedLib.getConfigValue

/**
 * @param {string} configTag
 * @param {string} configKey
 *
 * @returns {Object} returns the configValue for a single config record, or null if none found
 */

graphSharedLib

Helper functions for interacting with Neptune graph databases from any service.

constants

  • {string} userGraphTag ("user")
  • {string} createdByEdgeLabel ("createdBy")
  • {string} hasEdgeLabelPrefix ("has_")
  • {string} settingsVersionedDataTag ("Settings")

graphSharedLib.createVertexId

/**
 * Creates vertexId from vertexTag and unique id
 * @param {string} vertexTag - is the type of object
 * @param {string} vertexUniqueId
 *
 * @returns {string} vertexId
 */
  1. Concatenate vertexTag + "_" + vertexUniqueId

graphSharedLib.createEdgeIdFromVertexIds

/**
 * Creates standardized edgeId
 * @param {string} subjectVertexId
 * @param {string} edgeLabel
 * @param {string} [objectVertexId=""]
 *
 * @returns {string} edgeId
 */
  1. let edgeid = subjectVertexId + '_' + edgeLabel
  2. if(objectVertexId)
    1. edgeid = edgeid + '_' + objectVertexId
  3. return edgeid

graphSharedLib.createEdgeIdFromVertexTagsAndUniqueIds

/**
 * Creates standardized edgeId
 * @param {string} subjectVertexTag
 * @param {string} subjectVertexUniqueId
 * @param {string} edgeLabel
 * @param {string} [objectVertexTag=""]
 * @param {string} [objectVertexUniqueId=""]
 *
 * @returns {string} edgeId
 */
  1. const subjectVertexId = graphSharedLib.createVertexId
    1. vertexTag = subjectVertexTag
    2. uniqueId = subjectVertexUniqueId
  2. let objectVertexId = ""
  3. if(objectVertexTag)
    1. objectVertexId = graphSharedLib.createVertexId
      1. vertexTag = objectVertexTag
      2. uniqueId = objectVertexUniqueId
  4. return = graphSharedLib.createEdgeIdFromVertexIds
    1. subjectVertexId: subjectVertexId'
    2. edgeLabel: edgeLabel
    3. objectVertexId: objectVertexId

graphSharedLib.createVersionedDataVertexTag

/**
 * Creates standardized versionedDataVertexLabel
 * @param {string} subjectVertexTag
 * @param {string} versionedDataTag
 *
 * @returns {string} versionedDataVertexLabel
 */
  1. let versionedDataVertexTag = subjectVertexTag + versionedDataTag
  2. return versionedDataVertexTag

graphSharedLib.createVersionedDataEdgeLabel

/**
 * Creates standardized versionedDataEdgeLabel
 * @param {string} ''versionedDataTag''
 *
 * @returns {string} versionedDataEdgeLabel
 */
  1. return NPM module - izara-shared#graphSharedLib.hasEdgeLabelPrefix + versionedDataTag

graphSharedLib.getVerticesByVertexLabel

/**
 * Returns all vertices that match the vertex label for the given graph
 * @param {string} graphServiceName
 * @param {string} vertexLabel
 *
 * @returns {string} vertexId
 */
  1. ..

graphSharedLib.getVertexByVertexId

/**
 * Returns vertex that matched the vertex id
 * @param {string} graphServiceName
 * @param {string} vertexId
 *
 * @returns {string} vertexId
 */
  1. ..

graphSharedLib.getVertexByVertexTagAndVertexUniqueId

/**
 * Returns vertex that matched the vertex id
 * @param {string} graphServiceName
 * @param {string} vertexTag
 * @param {string} vertexUniqueId
 *
 * @returns {string} vertexId
 */
  1. const vertexId = NPM module - izara-shared#graphSharedLib.createVertexId
    1. vertexTag: vertexTag
    2. vertexUniqueId: vertexUniqueId
  2. const vertex = invoke #graphSharedLib.getVertexByVertexId
    1. graphServiceName: graphServiceName
    2. vertexId: vertexId
  3. return vertex

graphSharedLib.getVertexOutEdgesByVertexId

/**
 * Returns all edges, allowing label and property filters
 * @param {string} graphServiceName
 * @param {string} subjectVertexId
 * @param {string} [edgeLabel=""]
 * @param {object} [edgeProperties={}]
 *
 * @returns {string} vertexId
 */
  1. ..

graphSharedLib.getVertexOutEdgesByVertexTagAndVertexUniqueId

/**
 * Returns all edges, allowing label and property filters
 * @param {string} graphServiceName
 * @param {string} subjectVertexTag
 * @param {string} subjectVertexUniqueId
 * @param {string} [edgeLabel=""]
 * @param {object} [edgeProperties={}]
 *
 * @returns {string} vertexId
 */
  1. const vertexId = NPM module - izara-shared#graphSharedLib.createVertexId
    1. vertexTag: subjectVertexTag
    2. vertexUniqueId: subjectVertexUniqueId
  2. const edges = invoke #graphSharedLib.getVertexOutEdgesByVertexId
    1. graphServiceName: graphServiceName
    2. vertexId: vertexId
    3. edgeLabel: edgeLabel
    4. edgeProperties: edgeProperties
  3. return edges

graphSharedLib.getVertexOutEdgesAndVerticesByVertexId

/**
 * Find related vertices and their connecting edges, including properties, allowing label and property filters
 * @param {string} graphServiceName
 * @param {string} subjectVertexId
 * @param {string} [edgeLabel=""] - edge label to filter edges by
 * @param {object} [edgeProperties={}] - edge properties to filter by, is an array of key > value pairs
 * @param {object} [vertexProperties={}] - object vertex properties to filter by, is an array of key > value pairs
 *
 * @returns {Object[]} array of vertices and the connecting edges
 */
  1. ..

graphSharedLib.getVertexOutEdgesAndVerticesByVertexTagAndVertexUniqueId

/**
 * Find related vertices and their connecting edges, including properties, allowing label and property filters
 * @param {string} graphServiceName
 * @param {string} subjectVertexTag
 * @param {string} subjectVertexUniqueId
 * @param {string} [edgeLabel=""] - edge label to filter edges by
 * @param {object} [edgeProperties={}] - edge properties to filter by, is an array of key > value pairs
 * @param {object} [vertexProperties={}] - object vertex properties to filter by, is an array of key > value pairs
 *
 * @returns {Object[]} array of vertices and the connecting edges
 */
  1. const vertexId = NPM module - izara-shared#graphSharedLib.createVertexId
    1. vertexTag: subjectVertexTag
    2. vertexUniqueId: subjectVertexUniqueId
  2. const vertexAndEdges = invoke #graphSharedLib.getVertexOutEdgesAndVerticesByVertexId
    1. graphServiceName: graphServiceName
    2. vertexId: vertexId
    3. edgeLabel: edgeLabel
    4. edgeProperties: edgeProperties
  3. return vertexAndEdges

graphSharedLib.getObjectVertexByEdgeId

/**
 * Find the object/target vertex for a specific edgeId
 * @param {string} edgeId - edge label to filter edges by
 *
 * @returns {Object} vertex or null if not found
 */
  1. ..

graphSharedLib.getCurrentVersionedDataByVertexId

/**
 * Find the object/target vertex for a specific edgeId
 * @param {string} graphServiceName
 * @param {string} vertexId
 * @param {string} versionedDataTag
 *
 * @returns {Object} vertex or null if not found
 */
  1. .. needs to filter edge by currently active versioned data..
  2. ... work through queries to get the current versioned data
  1. // will need versionedDataEdgeLabel to find edges that are versioned data
  2. const versionedDataEdgeLabel = #createVersionedDataEdgeLabel
    1. versionedDataTag: versionedDataTag

graphSharedLib.getCurrentVersionedDataByVertexTagAndVertexUniqueId

/**
 * Returns vertex that matched the vertex id
 * @param {string} graphServiceName
 * @param {string} vertexTag
 * @param {string} vertexUniqueId
 * @param {string} versionedDataTag
 *
 * @returns {string} vertexId
 */
  1. const vertexId = NPM module - izara-shared#graphSharedLib.createVertexId
    1. vertexTag: vertexTag
    2. vertexUniqueId: vertexUniqueId
  2. const versionedDataVertexTag = #graphSharedLib.getCurrentVersionedDataByVertexId
    1. graphServiceName: graphServiceName
    2. vertexId: vertexId
    3. versionedDataTag: versionedDataTag