NPM module - izara-shared: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
No edit summary
Line 214: Line 214:
== constants ==
== constants ==


* {string} userGraphTag ("user")
* {string} userNodeLabel ("User")
* {string} createdByEdgeLabel ("createdBy")
* {string} userIdPropertyName ("userId")
* {string} hasEdgeLabelPrefix ("has_")
* {string} createdByRelationshipType ("createdBy")
* {string} settingsVersionedDataTag ("Settings")
* {string} hasRelationshipTypePrefix ("has")
* {string} currentRelationshipTypePrefix ("current")
* {string} versionedDataFromPropertyName ("from")
* {string} versionedDataFromPropertyName ("from")
* {string} versionedDataToPropertyName ("to")
* {string} versionedDataToPropertyName ("to")
* {string} originTimestamp ("originTimestamp")


== graphSharedLib.createVertexId ==
== graphSharedLib.createVersionedDataHasRelationshipType ==


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">
/**
/**
* Creates vertexId from vertexTag and unique id
  * @param {string} versionedDataLabel
  * @param {string} vertexTag - is the type of object
* @param {string} vertexUniqueId
  *
  *
  * @returns {string} vertexId
  * @returns {string} versionedDataHasRelationshipType
  */
  */
</syntaxhighlight>
</syntaxhighlight>


# Concatenate ''vertexTag'' + '_' + ''vertexUniqueId''
# Concatenate ''this.currentRelationshipTypePrefix'' + ''versionedDataLabel''


== graphSharedLib.createEdgeIdFromVertexIds ==
== graphSharedLib.createVersionedDataCurrentRelationshipType ==


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">
/**
/**
* Creates standardized edgeId
  * @param {string} versionedDataLabel
  * @param {string} subjectVertexId
* @param {string} edgeLabel
* @param {string} [objectVertexId=""]
  *
  *
  * @returns {string} edgeId
  * @returns {string} versionedDataHasRelationshipType
  */
  */
</syntaxhighlight>
</syntaxhighlight>


# let ''edgeid'' = ''subjectVertexId'' + '_' + ''edgeLabel''
# Concatenate ''this.currentRelationshipTypePrefix'' + ''versionedDataLabel''
# if(objectVertexId)
## ''edgeid'' = ''edgeid'' + '_' + ''objectVertexId''
# return ''edgeid''


== graphSharedLib.createEdgeIdFromVertexTagsAndUniqueIds ==
== graphSharedLib.getChildNodes ==


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">
/**
/**
* Creates standardized edgeId
  * @param {string[]} parentNodeIdentifierLabels                - array of labels
  * @param {string} subjectVertexTag
  * @param {object} parentNodeUniqueIdProperties      - node properties
  * @param {string} subjectVertexUniqueId
  * @param {string[]} relationshipTypes                - array of parent>child relationship types to find
  * @param {string} edgeLabel
  * @param {string[]} [versionedDataLabels=[]]         - array of versionDataTags to find results for each child node found
  * @param {string} [objectVertexTag=""]
* @param {string} [objectVertexUniqueId=""]
  *
  *
  * @returns {string} edgeId
  * @returns {object[]} - array of child nodes properties and relationship properties
  */
  */
</syntaxhighlight>
</syntaxhighlight>


# const ''subjectVertexId'' = graphSharedLib.createVertexId
# invoke sync [[2021-02-16 - Graph Handler - Functions#Node/GetChildNodes]]
## vertexTag = ''subjectVertexTag''
## uniqueId = ''subjectVertexUniqueId''
# let ''objectVertexId'' = ""
# if(objectVertexTag)
## ''objectVertexId'' = graphSharedLib.createVertexId
### vertexTag = ''objectVertexTag''
### uniqueId = ''objectVertexUniqueId''
# return = graphSharedLib.createEdgeIdFromVertexIds
## subjectVertexId: ''subjectVertexId'
## edgeLabel: ''edgeLabel''
## objectVertexId: ''objectVertexId''
 
== graphSharedLib.createVersionedDataVertexTag ==
 
<syntaxhighlight lang="JavaScript">
/**
* Creates standardized versionedDataVertexLabel
* @param {string} subjectVertexTag
* @param {string} versionedDataTag
*
* @returns {string} versionedDataVertexLabel
*/
</syntaxhighlight>
 
# let ''versionedDataVertexTag'' = ''subjectVertexTag'' + ''versionedDataTag''
# 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 ==
 
<syntaxhighlight lang="JavaScript">
/**
* Returns all vertices that match the vertex label for the given graph
* @param {string} graphServiceName
* @param {string} vertexLabel
*
* @returns {string} vertexId
*/
</syntaxhighlight>
 
# ..
 
== graphSharedLib.getVertexByVertexId ==
 
<syntaxhighlight lang="JavaScript">
/**
* Returns vertex that matched the vertex id
* @param {string} graphServiceName
* @param {string} vertexId
*
* @returns {string} vertexId
*/
</syntaxhighlight>
 
# ..
 
== graphSharedLib.getVertexByVertexTagAndVertexUniqueId ==
 
<syntaxhighlight lang="JavaScript">
/**
* Returns vertex that matched the vertex id
* @param {string} graphServiceName
* @param {string} vertexTag
* @param {string} vertexUniqueId
*
* @returns {object} vertex
*/
</syntaxhighlight>
 
# const ''vertexId'' = [[NPM module - izara-shared#graphSharedLib.createVertexId]]
## vertexTag: ''vertexTag''
## vertexUniqueId: ''vertexUniqueId''
# const ''vertex'' = invoke [[#graphSharedLib.getVertexByVertexId]]
## graphServiceName: ''graphServiceName''
## vertexId: ''vertexId''
# return ''vertex''
 
== graphSharedLib.getVertexOutEdgesByVertexId ==
 
<syntaxhighlight lang="JavaScript">
/**
* Returns all edges, allowing label and property filters
* @param {string} graphServiceName
* @param {string} subjectVertexId
* @param {string} [edgeLabel=""]
* @param {object} [edgeProperties={}]
*
* @returns {string} vertexId
*/
</syntaxhighlight>
 
# ..
 
== 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">
/**
* 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
*/
</syntaxhighlight>
 
# ..
 
== 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.getVertexInEdgesAndVerticesByVertexId ==
 
<syntaxhighlight lang="JavaScript">
/**
* Find related vertices and their connecting edges, including properties, allowing label and property filters
* @param {string} graphServiceName
* @param {string} objectVertexId
* @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>
 
# ..
 
== graphSharedLib.getVertexInEdgesAndVerticesByVertexTagAndVertexUniqueId ==
 
<syntaxhighlight lang="JavaScript">
/**
* Find related vertices and their connecting edges, including properties, allowing label and property filters
* @param {string} graphServiceName
* @param {string} objectVertexTag
* @param {string} objectVertexUniqueId
* @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: ''objectVertexTag''
## vertexUniqueId: ''objectVertexUniqueId''
# const ''vertexAndEdges'' = invoke [[#graphSharedLib.getVertexOutEdgesAndVerticesByVertexId]]
## graphServiceName: ''graphServiceName''
## vertexId: ''vertexId''
## edgeLabel: ''edgeLabel''
## edgeProperties: ''edgeProperties''
# return ''vertexAndEdges''
 
== graphSharedLib.getObjectVertexByEdgeId ==
 
<syntaxhighlight lang="JavaScript">
/**
* Find the object/target vertex for a specific edgeId
* @param {string} graphServiceName
* @param {string} edgeId - edge label to filter edges by
*
* @returns {Object} vertex or null if not found
*/
</syntaxhighlight>
 
# ..
 
== graphSharedLib.getEdgeAndSubjectAndObjectByEdgeId ==
 
<syntaxhighlight lang="JavaScript">
/**
* Returns vertex that matched the vertex id
* @param {string} graphServiceName
* @param {string} edgeId
*
* @returns {object} edge/subject/object vertices
*/
</syntaxhighlight>
 
# ..
 
== graphSharedLib.getCurrentVersionedDataByVertexId ==
 
<syntaxhighlight lang="JavaScript">
/**
* @param {string} graphServiceName
* @param {string} vertexId
* @param {string} versionedDataTag
*
* @returns {Object} versionedData object
*/
</syntaxhighlight>
 
# .. 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.getCurrentVersionedDataByVertexTagAndVertexUniqueId ==
 
<syntaxhighlight lang="JavaScript">
/**
* @param {string} graphServiceName
* @param {string} vertexTag
* @param {string} vertexUniqueId
* @param {string} versionedDataTag
*
* @returns {string} versionedData object
*/
</syntaxhighlight>
 
# const ''vertexId'' = [[NPM module - izara-shared#graphSharedLib.createVertexId]]
## vertexTag: ''vertexTag''
## vertexUniqueId: ''vertexUniqueId''
#const ''versionedDataVertexTag = [[#graphSharedLib.getCurrentVersionedDataByVertexId]]
## graphServiceName: ''graphServiceName''
## vertexId: ''vertexId''
## versionedDataTag: ''versionedDataTag''


= MsgCfgSharedLib =
= MsgCfgSharedLib =

Revision as of 14:01, 16 May 2021

Overview

Shared libraries used across multiple izara projects

Repository

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

CoreSharedLib

constants

  • {string} systemTextGraphTag ("systemText")
  • {string} systemTextServiceNameGraphTag ("systemTextServiceName")

LambdaSharedLib

Helper functions for interacting with Lambda resources.

LambdaSharedLib.lambdaFunctionName

/**
 * Executes a Get query to DynamoDB
 * @param {string} serviceName
 * @param {string} functionName
 *
 * @returns {string} deployed Lambda service name
 */
  • concatenate with env stage setting

DynamodbSharedLib

Helper functions for interacting with DynamoDB resources.

Idempotence

  • DynamodbSharedLib functions that have invoke queries with conditional expression can pass in a setting that says whether to throw on conditionalExpression failure
  • if for idempotent conditionalExpression error not want to throw, we want to keep processing as if the query passed like normal
  • default is to not throw, because in most cases we will be protecting for idempotent processing
  • if conditionalExpression is critical, eg not for idemptent test, then we throw, calling code can set whether to throw noRetryError or normal error that will trigger retries, calling code passes in a setting to do this, default is noRetryError

Notes

  • could add another setting that waits and retries on certain errors, within the one function call, could also set delay and how many retries
  • might not be needed as DynamoDocument library already has built in retry logic, errors might be an edge case that can be handled through normal throw/retry/dlq flow

dynamodbSharedLib.getItem

/**
 * Executes a GetItem query to DynamoDB
 * @param {string} tableName
 * @param {object} keyValues
 * @param {[object]} queryElements // eg returned only some attributes (ProjectionExpression)
 * @param {[object]} settings
 * @param {boolean} settings.errorOnNoRecordFound
 * @param {boolean} settings.retryOnErrorNoRecordFound
 * @returns {object} single record return value from the query, or Null if none found
 */
  • return the .Item property
  • if record not found Null will be returned unless errorOnNoRecordFound set to true which will throw error


errorOnNoRecordFound

  • if set truthy create an error that includes tableName and keyValues
  • noRetryError error is thrown unless retryOnErrorNoRecordFound is set truthy, then a normal error is thrown which will trigger retry code

other errors

  • other unhandled DynamoDB errors might include Dynamo throttling/failure
  • for these we throw a normal error so the request gets retried before passing to DLQ

dynamodbSharedLib.query

/**
 * Executes a Query on DynamoDB
 * @param {string} tableName
 * @param {object} partitionKeyValue
 * @param {[object]} queryElements
 * @param {[object]} queryElements.sortKeyConditions
 * @param {[object]} queryElements.ExclusiveStartKey
 * @param {[object]} settings
 * @param {numeric} settings.numPagesToRequest // not sure will use? Script will automatically request multiple pages of results
 *
 * @returns {object[], object} array of records from .Items in query result, and queryInfo object with properties such as LastEvaluatedKey
 */

errors

  • unhandled DynamoDB errors might include Dynamo throttling/failure
  • for these we throw a normal error so the request gets retried before passing to DLQ

dynamodbSharedLib.putItem

/**
 * Executes a PutItem query on DynamoDB
 * @param {string} tableName
 * @param {object} keyValues
 * @param {object} attributes
 * @param {[object]} queryElements 
 * @param {[object]} queryElements.conditionalExpressions
 * @param {[object]} settings
 * @param {numeric} settings.errorOnConditionalExpNotPass // if set then an error will be thrown, otherwise function returns with no error
 * @param {numeric} settings.retryOnErrorConditionalExpNotPass
 *
 * @returns {} .. maybe nothing
 */

errorOnConditionalExpNotPass

  • if set truthy create an error that includes tableName and keyValues, maybe conditionalExpressions or DynamoDB error if it describes not passing condition/s
  • noRetryError error is thrown unless retryOnErrorConditionalExpNotPass is set truthy, then a normal error is thrown which will trigger retry code

other errors

  • other unhandled DynamoDB errors might include Dynamo throttling/failure
  • for these we throw a normal error so the request gets retried before passing to DLQ

dynamodbSharedLib.updateItem

/**
 * Executes an UpdateItem query on DynamoDB
 * @param {string} tableName
 * @param {object} keyValues
 * @param {object} attributes
 * @param {[object]} queryElements 
 * @param {[object]} queryElements.conditionalExpressions
 * @param {[object]} settings
 * @param {numeric} settings.errorOnConditionalExpNotPass // if set then an error will be thrown, otherwise function returns with no error
 * @param {numeric} settings.retryOnErrorConditionalExpNotPass
 *
 * @returns {} .. maybe nothing
 */

errorOnConditionalExpNotPass

  • if set truthy create an error that includes tableName and keyValues, maybe conditionalExpressions or DynamoDB error if it describes not passing condition/s
  • noRetryError error is thrown unless retryOnErrorConditionalExpNotPass is set truthy, then a normal error is thrown which will trigger retry code

other errors

  • other unhandled DynamoDB errors might include Dynamo throttling/failure
  • for these we throw a normal error so the request gets retried before passing to DLQ

dynamodbSharedLib.deleteItem

/**
 * Executes a DeleteItem query on DynamoDB
 * @param {string} tableName
 * @param {object} keyValues
 * @param {[object]} queryElements 
 * @param {[object]} queryElements.conditionalExpressions
 * @param {[object]} settings
 * @param {numeric} settings.errorOnConditionalExpNotPass // if set then an error will be thrown, otherwise function returns with no error
 * @param {numeric} settings.retryOnErrorConditionalExpNotPass
 *
 * @returns {} .. maybe nothing
 */

errorOnConditionalExpNotPass

  • if set truthy create an error that includes tableName and keyValues, maybe conditionalExpressions or DynamoDB error if it describes not passing condition/s
  • noRetryError error is thrown unless retryOnErrorConditionalExpNotPass is set truthy, then a normal error is thrown which will trigger retry code

other errors

  • other unhandled DynamoDB errors might include Dynamo throttling/failure
  • for these we throw a normal error so the request gets retried before passing to DLQ

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} userNodeLabel ("User")
  • {string} userIdPropertyName ("userId")
  • {string} createdByRelationshipType ("createdBy")
  • {string} hasRelationshipTypePrefix ("has")
  • {string} currentRelationshipTypePrefix ("current")
  • {string} versionedDataFromPropertyName ("from")
  • {string} versionedDataToPropertyName ("to")
  • {string} originTimestamp ("originTimestamp")

graphSharedLib.createVersionedDataHasRelationshipType

/**
 * @param {string} versionedDataLabel
 *
 * @returns {string} versionedDataHasRelationshipType
 */
  1. Concatenate this.currentRelationshipTypePrefix + versionedDataLabel

graphSharedLib.createVersionedDataCurrentRelationshipType

/**
 * @param {string} versionedDataLabel
 *
 * @returns {string} versionedDataHasRelationshipType
 */
  1. Concatenate this.currentRelationshipTypePrefix + versionedDataLabel

graphSharedLib.getChildNodes

/**
 * @param {string[]} parentNodeIdentifierLabels                 - array of labels
 * @param {object} parentNodeUniqueIdProperties       - node properties
 * @param {string[]} relationshipTypes                - array of parent>child relationship types to find
 * @param {string[]} [versionedDataLabels=[]]         - array of versionDataTags to find results for each child node found
 *
 * @returns {object[]}  - array of child nodes properties and relationship properties
 */
  1. invoke sync 2021-02-16 - Graph Handler - Functions#Node/GetChildNodes

MsgCfgSharedLib

Helper functions for interacting with Message Configs

MsgCfgLib.createMsgConfigId

/**
 * 
 * @param {string} serviceName
 * @param {string} topicName
 *
 * @returns {string} msgCfgId
 */
  • concatenate {serviceName} + "_" + {topicName}

MsgCfgLib.explodeMsgConfigId

/**
 * 
 * @param {string} msgCfgId
 *
 * @returns {string[]} serviceName, topicName
 */

AwsSharedLib

Generic functions for AWS

AwsSharedLib.getResourceNameFromArn

/**
 * 
 * @param {string} arn
 * @param {string} serviceName
 *
 * @returns {string} resourceName
 */
  • invoke AwsSharedLib.explodeArn to get fullResourceName
  • remove serviceName and env.iz_stage to from fullResourceName to return basic resourceName

AwsSharedLib.explodeArn

/**
 * 
 * @param {string} arn
 *
 * @returns {object} arnElements
 */
  • explodes the arn and returns the different elements
  • currently only need arnElements.fullResourceName


Working documents

Working_documents - NPM module - izara-shared