npm.io
0.0.86 • Published 2 years ago

oute-services-flow-utility-sdk

Licence
Version
0.0.86
Deps
3
Size
168 kB
Vulns
0
Weekly
0

This module expose helper functions

  • Initialization
  var flow_utility_instance = require("oute-services-flow-utility-sdk")
  • Clean unwanted keys from json
  data = {
    key_config: {},
    a: 1
  }
  unwanted_keys = ["key_config", "task_obj"]
  result = flow_utility_instance.cleanUnwantedKeys(data, unwanted_keys)
  • Evaluate fx block
  state = {
    "1707301123322": {
      status_code: 200
    }
  }
  fx_block = {
    "type": "fx",
    "blocks": []
  }
  flow_utility_instance.fxBlock(state, fx_block)
  • Evaluate variable
  data = {
    "a": {
      "b": 1
    }
  }
  flatten_key = "\#{{a.b}}#"
  case_type = null
  nested_evaluation = true //This will decide if need to nest for the eval, default is false
  flow_utility_instance.getValue(data, flatten_key, case_type)
  • Resolve value based on type
  data = {
    "a": {
      "b": 1
    }
  }
  value = { "type": "fx", "blocks": [ { "type": "PRIMITIVES", "value": "7" }]}
  default_value = 9
  type = "INT"
  key = "id"
  case_type = null //lower, upper, caseless
  flow_utility_instance.resolveValue(data, key, value, type, default_value, case_type)
  • Parse and validate flow inputs
  input = {
    "key": "start_var1",
    "value": "sdf==>",
    "default": null,
    "type": "STRING",
    "required": false,
    "regex": null,
    "location": null
  }
  flow_utility_instance.parseAndValidate(input)
  • get default value based on type
  type = "ARRAY"
  flow_utility_instance.getDefaultValueByType(type)
  • Parse flow inputs/outputs and generate the object
  state = {
    headers: {a: 1, "content-type": "application/json"},
    body: {b: 2}
  }
  inputs = [
    {
      "key": "start_var1",
      "value": "\#{{body.b}}#",
      "default": null,
      "type": "STRING",
      "required": false,
      "regex": null,
      "location": null
    }
  ]
  update_key_by_alias = false
  flow_utility_instance.parseIO(state, inputs, update_key_by_alias)
  • Generate state from request
  req = {
    headers: {a: 1, "content-type": "application/json"},
    body: {b: 2}
  }
  inputs = [
    {
      "key": "start_var1",
      "value": "\#{{body.b}}#",
      "default": null,
      "type": "STRING",
      "required": false,
      "regex": null,
      "location": null
    }
  ]
  variables = {a: 234}
  result = flow_utility_instance.requestToStateTF(req, inputs, variables)
  • Parse db filter for orm
  state = {}
  filter = {}
  orm_type = "sequelize"
  db_type = "postgres"
  operators = Op //Sequelize operators
  flow_utility_instance.generateWhereClause(state, filter, orm_type, db_type, operators)
  • generate order by for orm
  state = {}
  inputs = [{"column": "key", "sort_by": "ASCENDING"}]
  orm_type = "sequelize"
  db_type = "postgres"
  flow_utility_instance.generateOrderByClause(state, inputs, orm_type, db_type)
  • generate group by for orm
  state = {}
  inputs = [{"column": "key"}]
  orm_type = "sequelize"
  db_type = "postgres"
  flow_utility_instance.generateGroupByClause(state, inputs, orm_type, db_type)
  • get values using dot anotation
  state = {
    "a": {
      "b": [1]
    }
  }
  flatten_key = "a.b.0"
  case_type = "caseless"
  flow_utility_instance.getValueByFlattenKeys(state, flatten_key, case_type)