NPM module - izara-shared: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 88: Line 88:


# return ''vertexId'' + '_createdBy'
# return ''vertexId'' + '_createdBy'
== neptuneGraphSharedLib.createVersionedVertexEdge ==
<syntaxhighlight lang="JavaScript">
/**
* Creates an edge linking a subjectVertex to it's new versioned data vertex, and updates the old current vertex's "to" timestamp
* @param {string} graphServiceName
* @param {string} subjectVertexId
* @param {string} newVersionedDataVertexId
* @param {string} edgeLabel
*
*/
</syntaxhighlight>
# //get currently active versioned data edge, if exists, allow for an array in case race conditions previously caused two versions to be set as active
# const ''previouslyActiveVertices'' = invoke [[#neptuneGraphSharedLib.getVertexOutEdges]]
## graphServiceName: ''graphServiceName''
## subjectVertexId: ''subjectVertexId''
## edgeLabel: ''edgeLabel''
## edgeProperties:
### to: 0
# const ''timestamp'' = current timestamp
# publish message to ''graphServiceName'' MsgIn queue (msgTag: 'CreateEdge'):
## subjectVertexId: ''subjectVertexId''
## edgeLabel: ''edgeLabel''
## edgeId: ''subjectVertexId'' + '_' + ''edgeLabel'' + '_' + ''newVersionedDataVertexId''
## objectId: ''newVersionedDataVertexId''
## edgeProperties:
### from: ''timestamp''
### to: 0
# // update previously active versioned data
# for each ''previouslyActiveVertices''
## publish message to ''graphServiceName'' MsgIn queue (msgTag: 'UpdateEdgeProperties'):
### edgeId: ''previouslyActiveVertex''.id(?)
### edgeProperties:
#### to: ''timestamp''
# // link to user who created new versioned data
# const ''userVertexId'' = [[#neptuneGraphSharedLib.createUserVertex]]
## graphServiceName: ''graphServiceName''
## userId: ?_izContext.authorized/signedInUser..?
# const ''createdByEdgeId'' = [[#neptuneGraphSharedLib.createCreatedByEdgeId]]
## vertexId: ''newVersionedDataVertexId''
# publish message to ''graphServiceName'' MsgIn queue (msgTag: 'CreateEdge'):
## subjectVertexId: ''newVersionedDataVertexId''
## edgeLabel: 'createdBy'
## edgeId: ''createdByEdgeId''
## objectId: ''userVertexId''


== neptuneGraphSharedLib.getVerticesByVertexLabel ==
== neptuneGraphSharedLib.getVerticesByVertexLabel ==

Revision as of 03:51, 4 March 2021

Overview

Shared libraries

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
 */

neptuneGraphSharedLib

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

neptuneGraphSharedLib.createVertexId

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

neptuneGraphSharedLib.createUserVertex

/**
 * Standardize naming of user vertex and create vertex if not exist, will be used in almost all services
 * @param {string} graphServiceName
 * @param {string} userId
 *
 * @returns {string} userVertexId
 */
  1. const userVertexId = #neptuneGraphSharedLib.createVertexId
    1. vertexTag: 'user'
    2. userId
  2. publish message to graphServiceName MsgIn queue (msgTag: 'CreateVertex'):
    1. vertexId: userVertexId
    2. vertexLabel: 'user'
  3. return userVertexId

neptuneGraphSharedLib.createCreatedByEdgeId

/**
 * @param {string} vertexId
 *
 * @returns {string} createdByEdgeId
 */

Should only ever have one createdBy edge for a vertex so id is relatively simple

  1. return vertexId + '_createdBy'

neptuneGraphSharedLib.getVerticesByVertexLabel

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

neptuneGraphSharedLib.getVertexByVertexId

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

neptuneGraphSharedLib.getVertexOutEdges

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

neptuneGraphSharedLib.getVertexOutEdgesAndVertices

/**
 * 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. ..


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