NPM module - izara-shared: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
No edit summary
Line 64: Line 64:
  */
  */
</syntaxhighlight>
</syntaxhighlight>
Should only ever have one CreatedBy edge for a vertex so id is relatively simple


# return ''vertexId'' + '_CreatedBy'
# return ''vertexId'' + '_CreatedBy'

Revision as of 09:57, 3 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.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.createVersionedVertexEdge

/**
 * 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
 *
 */
  1. //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
  2. const previouslyActiveVertices = invoke #neptuneGraphSharedLib.getVertexOutEdges
    1. graphServiceName: graphServiceName
    2. subjectVertexId: subjectVertexId
    3. edgeLabel: edgeLabel
    4. edgeProperties:
      1. to: 0
  3. const timestamp = current timestamp
  4. publish message to graphServiceName MsgIn queue (msgTag: 'CreateEdge'):
    1. subjectVertexId: subjectVertexId
    2. edgeLabel: edgeLabel
    3. edgeId: subjectVertexId + '_' + edgeLabel + '_' + newVersionedDataVertexId
    4. objectId: newVersionedDataVertexId
    5. edgeProperties:
      1. from: timestamp
      2. to: 0
  5. // update previously active versioned data
  6. for each previouslyActiveVertices
    1. publish message to graphServiceName MsgIn queue (msgTag: 'UpdateEdgeProperties'):
      1. edgeId: previouslyActiveVertex.id(?)
      2. edgeProperties:
        1. to: timestamp
  7. // link to user who created new versioned data
  8. const userVertexId = #neptuneGraphSharedLib.createVertexId
    1. vertexTag: 'user'
    2. uniqueId: ?_izContext.authorized/signedInUser..?
  9. publish message to graphServiceName MsgIn queue (msgTag: 'CreateEdge'):
    1. subjectVertexId: subjectVertexId
    2. edgeLabel: edgeLabel
    3. edgeId: subjectVertexId + '_' + edgeLabel + '_' + newVersionedDataVertexId
    4. objectId: newVersionedDataVertexId
  10. const createdByEdgeId = #neptuneGraphSharedLib.createCreatedByEdgeId
    1. vertexId: newVersionedDataVertexId
  11. publish message to graphServiceName MsgIn queue (msgTag: 'CreateEdge'):
    1. subjectVertexId: newVersionedDataVertexId
    2. edgeLabel: 'createdBy'
    3. edgeId: createdByEdgeId
    4. objectId: userVertexId

neptuneGraphSharedLib.getVerticesByLabel

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

neptuneGraphSharedLib.getVertexById

/**
 * Returns all vertices that match the vertex label for the given graph
 * @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. ..