2021-02-16 - Graph Handler - Functions

From Izara Wiki
Jump to navigation Jump to search

Service - Graph Handler

Lambda Functions

Node/CreateNode

/**
 * Create a new node
 * @param {Object} _izContext                         - property of _izContext
 * @param {string[]} nodeLabels                       - array of labels
 * @param {object} nodeProperties                     - node properties
 * @param {string} createdByUserId                    - userId
 * @param {object} [createdByRelationshipProperties={}]        - properties of relationship
 * @param {string[]} [nodeIdentifierLabels=[]]  - array of Identifier labels for query
 * @param {object} [nodeUniqueIdPropertyNames=[]]   - array of PropertyNames for query
 *
 */

HdrSqs

logic

  1. invoke #nodeLib.createNode

Relationship/CreateRelationship

/**
 * Create a new relationship
 * @param {object} _izContext                             - izara logger and correlationIds 
 * @param {string[]} parentNodeIdentifierLabels           - array of parent node labels for qeury
 * @param {object} parentNodeUniqueIdProperties           - properties for query
 * @param {string[]} childNodeIdentifierLabels            - array of child node labels for qeury
 * @param {object} childNodeUniqueIdProperties		      - properties for query
 * @param {string} relationshipType         
 * @param {object} [relationshipProperties={}]
 *
 */

HdrSqs

logic

  1. invoke #relationshipLib.createRelationship

Node/CreateNodeWithVersionedData

/**
 * Create a new node and versioned data/s
 * @param {object} _izContext                       - izara logger and correlationIds
 * @param {string[]} parentNodeLabels               - array of parent node labels for qeury
 * @param {object} parentNodeProperties             - properties for query
 * @param {string[]} parentNodeIdentifierLabels     - array of parent node labels for qeury
 * @param {object} parentNodeUniqueIdPropertyNames  - properties for query
 * @param {string} createdByUserId                  - userId
 * @param {object[]} versionedData                  - array of versionedData to add
 * @param {string[]} versionedData.versionedDataLabel             - array of child node/versionData labels for qeury
 * @param {object} versionedData.versionedDataProperties          - properties for query
 * @param {object} [versionedData.createdByRelationshipProperties={}]      - properties of relationahip, default is {}
 * @param {numeric} originTimestamp                 - external timestamp for check unique node
 * @param {object} [createdByRelationshipProperties={}]      - properties of relationahip, default is {}
 *
 */

HdrSqs

logic

  1. invoke #nodeLib.createNodeWithVersionedData

Node/CreateVersionedData

/**
 * Create new versioned data for an existing node
 * @param {string[]} parentNodeIdentifierLabels
 * @param {object} parentNodeUniqueIdProperties
 * @param {string} createdByUserId
 * @param {string} versionedDataLabel
 * @param {object} [versionedDataProperties={}]
 * @param {numeric} [originTimestamp=0]
 * @param {object} [createdByRelationshipProperties={}]
 *
 */

HdrSqs

logic

  1. invoke #nodeLib.createVersionedDataNodeAndRelationships

Node/CreateChildNodeAndRelationship

/**
 * Create a new child node and relationship connecting to a parent node
 * @param {string[]} parentNodeIdentifierLabels
 * @param {object} parentNodeUniqueIdProperties
 * @param {string[]} childNodeLabels                         - array of labels
 * @param {object} childNodeProperties                       - node properties
 * @param {string} relationshipType                - type of relationship
 * @param {object} [relationshipProperties={}]          - properties of relationship
 * @param {string} [createdByUserId=""]                 - userId 
 * @param {string[]} [childNodeIdentifierLabels=[]]    - array of labels used to uniquely identify the new node
 * @param {string[]} [childNodeUniqueIdPropertyNames=[]]   - array of propertyNames used to uniquely identify the new node 
 * @param {object} [createdByRelationshipProperties={}]          - properties of relationship for createdBy user
 *
 */

HdrSqs

logic

  1. invoke #nodeLib.createNode
  2. create identifierLabels using #NodeLib.identifierLabelsFromLabelsAndIdentifierLabels
  3. create childNodeUniqueIdProperties using #nodeLib.uniqueIdPropertiesFromPropertiesAndPropertyNames
  4. invoke #relationshipLib.createRelationship

Node/CreateChildNodeWithVersionedData

/**
 * Create a new child node with versioned data and relationship connecting to a parent node
 * @param {string[]} parentNodeIdentifierLabels
 * @param {object} parentNodeUniqueIdProperties
 * @param {string[]} childNodeLabels                         - array of labels
 * @param {object} childNodeProperties                       - node properties
 * @param {string} relationshipType                - type of relationship
 * @param {object[]} versionedData                  - array of versionedData to add
 * @param {string[]} versionedData.versionedDataLabel             - array of child node/versionData labels for qeury
 * @param {object} versionedData.versionedDataProperties          - properties for query
 * @param {object} [versionedData.createdByRelationshipProperties={}]      - properties of relationahip, default is {}
 * @param {object} [relationshipProperties={}]          - properties of parent>child relationship
 * @param {string} [createdByUserId=""]                 - userId 
 * @param {string[]} [childNodeIdentifierLabels=[]]    - array of labels used to uniquely identify the new node
 * @param {string[]} [childNodeUniqueIdPropertyNames=[]]   - array of propertyNames used to uniquely identify the new node 
 * @param {object} [createdByRelationshipProperties={}]          - properties of relationship for createdBy user
 * @param {numeric} [originTimestamp=0]
 *
 */

HdrSqs

logic

  1. invoke #nodeLib.createNodeWithVersionedData
  2. create identifierLabels using #NodeLib.identifierLabelsFromLabelsAndIdentifierLabels
  3. create childNodeUniqueIdProperties using #nodeLib.uniqueIdPropertiesFromPropertiesAndPropertyNames
  4. invoke #relationshipLib.createRelationship to link parent and child nodes

Node/GetChildNodes

/**
 * Getting all child nodes for a parent node, including optionally child node versioned data
 * @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
 */

HdrInv

Relationship/ChangeRelationshipType

/**
 * Change relationship type, does this by removing the old relationship and replacing with a new relationship with the same properties
 * @param {string[]} parentNodeIdentifierLabels    - array of identified labels
 * @param {object} parentNodeUniqueIdProperties    - unique properties  
 * @param {string[]} childNodeIdentifierLabels     - array of identified labels
 * @param {object} childNodeUniqueIdProperties     - unique properties  
 * @param {string} oldRelationshipType                - type of relationship
 * @param {string} newRelationshipType                - type of relationship
 * @param {numeric} originTimestamp                 - external timestamp for check unique node
 * @param {string} [changedByUserId=""]                 - userId 
 * @param {object} [changedByRelationshipProperties={}]          - properties of changedBy relationship
 *
 */

HdrSqs

  1. invoke 2021-02-16 - Graph Handler - Functions#RelationshipLib.ChangeRelationshipType

Functions

nodeLib.createNode

/**
 * Create a new node
 * @param {string[]} nodeLabels                         - array of labels
 * @param {object} nodeProperties                       - node properties
 * @param {string} [createdByUserId=""]                 - userId 
 * @param {object} [createdByRelationshipProperties={}]          - properties of relationship for createdBy user
 * @param {string[]} [nodeIdentifierLabels=[]]    - array of labels used to uniquely identify the new node
 * @param {string[]} [nodeUniqueIdPropertyNames=[]]   - array of propertyNames used to uniquely identify the new node
 *
 * @returns {string} node object of created node, or null if node already exists
 */
  • creates a new node and created by user node/relationship
  • nodeIdentifierLabels and nodeUniqueIdPropertyNames are used to check if a matching node with these settings already exist, if it does we update rather than create
  • if nodeIdentifierLabels or nodeUniqueIdPropertyNames is not set then the full list of nodeLabels / nodeProperties are considered as unique identifiers (protects against idempotence
  • if the node already exists any new labels will be applied, but new properties will not be set

nodeLib.createNodeWithVersionedData

/**
 * Create a new node, versioned data, and all associated relationship
 * @param {string[]} parentNodeLabels               - array of labels
 * @param {object} parentNodeProperties             - node properties
 * @param {string[]} parentNodeIdentifierLabels     - array of parent node labels for qeury
 * @param {object} parentNodeUniqueIdPropertyNames  - properties for query
 * @param {string} createdByUserId                  - userId 
 * @param {object[]} versionedData                  - array of versionedData to add
 * @param {string[]} versionedData.versionedDataLabel             - array of child node/versionData labels for qeury
 * @param {object} versionedData.versionedDataProperties          - properties for query
 * @param {object} [versionedData.createdByRelationshipProperties={}]      - properties of relationahip, default is {}
 * @param {numeric} originTimestamp                 - timestamp from external services
 * @param {object} [createdByRelationshipProperties={}]      - relationship properties, will including from, to and originTimestamp, default is empty object
 *
 * returns {object} - 
 */

logic

  1. invoke #nodeLib.createNode to create the parent node
  2. for each versionedData invoke #nodeLib.createVersionedDataNodeAndRelationships

nodeLib.createVersionedDataNodeAndRelationships

/**
 * Creates a new versioned data node and adds/updates associated relationships
 * @param {string} parentNodeIdentifierLabels
 * @param {string} parentNodeUniqueIdPropertyNames
 * @param {string} createdByUserId
 * @param {string} versionedDataLabel // 
 * @param {object} [versionedDataProperties={}]
 * @param {numeric} [originTimestamp=0] - if empty will use current timestamp
 * @param {object} [createdByRelationshipProperties={}]
 *
 */

nodeLib.combinedIdentifierLabelsIntoLabelArray

/**
 * Makes sure all identifier labels are also added to the node's label array
 * @param {string[]} nodeLabels
 * @param {string[]} nodeIdentifierLabels
 *
 * returns {string[]} - nodeLabels
 */
  • makes sure no duplicate labels in array

RelationshipLib.createRelationship

/**
 * Create a createRelationship
 * @param {string[]} parentNodeIdentifierLabels    - array of identified labels
 * @param {object} parentNodeUniqueIdProperties    - unique properties  
 * @param {string[]} childNodeIdentifierLabels     - array of identified labels
 * @param {object} childNodeUniqueIdProperties     - unique properties  
 * @param {string} relationshipType                - type of relationship
 * @param {object} [relationshipProperties]          - properties of relationship
 *
 */

RelationshipLib.createCreatedByRelationship

/**
 * Create a new relationship
 * @param {string} parentNodeIdentifierLabels          - array of identified labels
 * @param {string} parentNodeUniqueIdProperties        - unique properties  
 * @param {string} createdByUserId                     - userId
 * @param {object} createdByRelationshipProperties     - properties of createBy relationship
 *
 */
  • only creates if createdBy relationship does not already exist

RelationshipLib.createRelationshipIfTypeNotExist

/**
 * Create a new relationship if the parent node does not already have a relationship of this type
 * @param {string[]} parentNodeIdentifierLabels    - array of identified labels
 * @param {object} parentNodeUniqueIdProperties    - unique properties  
 * @param {string[]} childNodeIdentifierLabels     - array of identified labels
 * @param {object} childNodeUniqueIdProperties     - unique properties  
 * @param {string} relationshipType                - type of relationship
 * @param {object} relationshipProperties          - properties of relationship
 *
 */

RelationshipLib.createVersionedDataRelationships

/**
 * Create a new relationship
 * @param {string[]} parentNodeLabels                       - array of identified labels
 * @param {object} parentNodeProperties                     - unique properties  
 * @param {string[]} versionedDataLabel                     - array of identified labels
 * @param {object} versionedDataProperties                  - unique properties  
 * @param {string} versionedDataRelationshipType            - type of relationship
 * @param {numeric} originTimestamp                         - timestamo fron external services
 * @param {object} [versionDataRelationshipProperties={}]   - properties of relationship {from, to , originTimestamp}
 *
 */

RelationshipLib.ChangeRelationshipType

/**
 * Change relationship type, does this by removing the old relationship and replacing with a new relationship with the same properties
 * @param {string[]} parentNodeIdentifierLabels    - array of identified labels
 * @param {object} parentNodeUniqueIdProperties    - unique properties  
 * @param {string[]} childNodeIdentifierLabels     - array of identified labels
 * @param {object} childNodeUniqueIdProperties     - unique properties  
 * @param {string} oldRelationshipType                - type of relationship
 * @param {string} newRelationshipType                - type of relationship
 * @param {numeric} originTimestamp                 - external timestamp for check unique node
 * @param {string} [changedByUserId=""]                 - userId 
 * @param {object} [changedByRelationshipProperties={}]          - properties of changedBy relationship
 *
 */
  • if multiple relationships match, will replace all found
  • used for example to switch a relationship between enabled and disabled
  • changedBy relationship type comes from NPM module - izara-shared#constants
  • changedBy relationship saves properties for oldRelationshipType and newRelationshipType and originTimestamp