Neo DAO Functions

This document provides an overview of the Neo application's Data Access Object (DAO) functions. These functions work across different blocks, including Script blocks, Schema blocks, and Mongo blocks. They are crucial for managing the interaction between the application's business logic and the data sources.

Overview

DAO functions manage the logic for accessing and manipulating data. They offer a simplified and consistent way to interact with data from sources, such as API requests and MongoDB.

DAO Functions

The following DAO functions are provided in Neo:

getApiRequest

The getApiRequest function retrieves the API request made to the application. It returns the complete input request object, including the HTTP method, the requested URL, headers, and the request body.

Use cases

Scenario 1: Consider that you need to customise the response based on specific headers in the incoming API request.
Usage: Use getApiRequest() to access the request headers and determine how to customise the response.

Scenario 2: Consider you need to validate the data in the request body before processing it.
Usage: Use getApiRequest() to access the request body and validate the data against your business rules before performing any operations.

Syntax:const request = dao.getApiRequest();

Example Output

{ 
  method: "GET",
  url: "/api/data", 
  headers: { 
    "Authorization": "Bearer token"
  }, 
  body: {} 
}

getIn

The function getIn returns the input properties of the current block. These are the data or parameters that were passed to the block when it was executed.

Use cases

Scenario 1: Consider you need to transform or process data that is passed to a block.
Usage: Use getIn() to access the input properties, perform necessary transformations or calculations, and then use the results.

Scenario 2 : Consider you need to implement conditional logic based on the input properties.
Usage: Use getIn() to retrieve the input properties and apply conditional logic to execute different paths or actions depending on the values of parameters1 and parameter2.

Input syntax: const input = dao.getIn();

Output syntax

Example Output: 
{ 
  param1: "value1", 
  param2: "value2" 
}

getOut

The function getOut retrieves the output data produced by a specified block. The function lets you access the result produced by a specific block after it has been executed. By providing the block’s name, you can get the output data specific to that block. If you don’t provide a block name, getOut() returns the output data from the previous or parent block.

Use cases

Scenario 1: Consider you need to retrieve and use the results of a block that was executed earlier in the flow.
Usage: Use getOut() to get the output data from the specified block. If you don't provide a block name, the function retrieves the output from the previous or parent block.

Scenario 2: Consider you want to chain multiple blocks together where each block depends on the result of the previous one.
Usage : Use getOut() to access the output of the preceding block and feed this data into the next block for further processing.

Input syntax: const output = dao.getOut("blockName");
The block name is optional.

Output syntax

{ 
  status: 200, 
  body: 
  { 
    "key": "value" 
  } 
}

getBody

The function getBody() retrieves the body of the output response from a specified block. If the block name is not specified, it retrieves the body from the previous or parent block. If the output from that block is an array, the function returns undefined.

Use cases

Scenario 1: Consider you need to access the specific data contained in the response body of a block.
Usage: Use getBody() to retrieve the response body from either the specified block or the previous block if no block name is provided. .

Scenario 2: Consider you need to debug or troubleshoot issues by examining the response body of a block.
Usage: Use getBody() to access and inspect the response body. This allows you to identify any discrepancies or issues in the output data.

Input syntax: const responseBody = dao.getBody("blockName");
The block name is optional.

Output syntax

{ 
  "key": "value" 
}

getMultiBody

The function getMultiBody() is used when a block returns an array of responses, each with its own body. This function retrieves all the individual bodies from these responses and returns them as an array. If the block name is not specified, it retrieves the body from the previous or parent block.

Use cases

Scenario 1: Consider you want to combine or analyse data from multiple response bodies returned by a block.
Usage: Use getMultiBody() to get an array of response bodies, then aggregate or analyse the data across all the responses.

Scenario 2: Consider you need to validate each response body in a collection of responses to ensure they meet specific criteria.
Usage: Use getMultiBody() to retrieve the array of response bodies, and then iterate through each one to apply validation checks.

Input syntax: const responseBodies = dao.getMultiBody("blockName");
The block name is optional.

Output syntax

[
  { 
    "data": "data1" 
  }, 
  { "data": "data2" 
  }
]

getHeaders

The getHeaders() function is used to retrieve the headers from the output response of a specific block. Headers are key-value pairs that provide essential metadata about the response.

When you call getHeaders with a block name, the function returns an object containing all the headers associated with the output response of the specified block. If you don't specify a block name, it returns the headers of the previous or parent block by default.

Use cases

Scenario 1: Consider you need to determine the content type of a response to handle it appropriately, such as parsing JSON or XML data.
Usage: Use dao.getHeaders("blockName") to retrieve the Content-Type header from the response. This allows you to process the response data according to its type.

Scenario 2: Consider you need to verify that the response from a block includes a valid authorisation token before proceeding with sensitive operations.
Usage: Use dao.getHeaders("blockName") to retrieve the Authorisation header and validate the token. This ensures that the response is secure and authorised.

Input syntax: const headers = dao.getHeaders("blockName");
The block name is optional.

Example output :

 { 
   "Content-Type": "application/json", 
   "Authorization": "Bearer token" 
 }

getMultiHeaders

The getMultiHeaders function retrieves multiple sets of headers when a block's output is an array of responses. When a block returns multiple responses, each response has its own set of headers. ThegetMultiHeadersfunction gathers these headers and returns them as an array of header objects. Each object in the array represents the headers from one of the responses.

When you call getMultiHeaders with a block name, the function returns an object containing all the headers associated with the output response of the specified block. If you don't specify a block name, it returns the headers of the previous or parent block by default.

Use cases

Scenario 1: Consider you are processing a batch of API requests, and each request returns its own response. You need to examine the headers for each response, such as Content-Type or Authorisation.
Usage: Use getMultiHeaders() to retrieve the headers for all the responses at once. This allows you to analyse or log the headers for each request in the batch.

Scenario 2: Consider you need to perform different actions based on the headers returned by multiple responses, such as caching data only if the Cache-Control header is set or processing HTML responses differently from JSON responses.
Usage: Use getMultiHeaders() to access the headers from each response, enabling you to apply conditional logic based on the specific headers returned.

Input syntax: const multiHeaders = dao.getMultiHeaders("blockName");
The block name is optional.

Example output :

[
  { 
    "Content-Type": "application/json" 
  }, 
  { 
    "Content-Type": "text/html" 
  }
]

getStatus

The getStatus function retrieves the HTTP status code from the response generated by a specific block in your application. This status code reflects the result of the block's operation, such as success, error, or another outcome. If the block's output is an array, the function returns undefined.

When you call getStatus with a block name, the function returns the status code for that specific block. If you do not specify the block name, the function returns the status code from the previous or parent block's output.

Use cases

Scenario 1: Consider you need to implement custom error handling logic based on the status code returned by a block.
Usage: Use getStatus() to retrieve the status code from the block's output. This helps you determine the appropriate response or action based on the specific status code

Scenario 2: Consider you are executing multiple blocks in sequence, and the execution of a subsequent block depends on the success or failure (status code) of the previous block.
Usage: Use getStatus() to check the status code of the previous block. For example, if the status code is 200, whereas a different status code might trigger an alternative flow.

Input syntax: const statusCode = dao.getStatus("blockName");
The block name is optional.

Example Output: 200

getMultiStatus

The getMultiStatus function retrieves multiple status codes when a block's output consists of an array of responses. Each response in the array has its own status code, such as 200, 404, or 500. The getMultiStatus function collects these status codes from each response and returns them as an array.

When you call getMultiStatuswith a block name, the function returns the status code for that specific block. If you do not specify the block name, the function returns the status code from the previous or parent block's output.

Use cases

Scenario 1: Consider you are processing a batch of requests where each request returns a response with its own status code. You need to handle or log the status codes for all responses.
Usage: Use getMultiStatus() to retrieve the status codes for all responses in the batch.

Scenario 2: Consider you receive responses from multiple sources or services, and you need to make decisions based on the status codes from each response. For example, if any response indicates an error, you might want to trigger a specific action.
Usage: Use getMultiStatus() to access all status codes from the array of responses. This allows you to implement conditional logic based on the status codes, such as taking corrective actions if any response contains an error status.

Input syntax: const statusCodes = dao.getMultiStatus("blockName");

Example output: [200, 404]

getQueryParams

The getQueryParams function retrieves the query parameters from the output response of a specified block. Query parameters are key-value pairs included in the URL of a request. If the block's output is an array, the function returns undefined.

When you specify a block name, getQueryParams returns the query parameters from that particular block. If you don't provide a block name, the function defaults to returning the query parameters from the output of the previous or parent block.

Use cases

Scenario 1: Consider that you need to analyse the query parameters used in a specific block to verify the correctness of the request.
Usage: Use getQueryParams() to retrieve the query parameters from the specified block's output and verify the same.

Scenario 2: Consider that you need to generate reports based on different search criteria or pagination settings specified in query parameters.
Usage: Use getQueryParams() to extract query parameters such as search terms or page numbers from the block's output.

Input syntax: const queryParams = dao.getQueryParams("blockName");
The block name is optional.

Example output

{ 
  "search": "query", 
   "page": "1" 
}

getMultiQueryParams

The getMultiQueryParams function returns an array of query parameters when a block's output includes multiple responses. It gathers the query parameters from each response and organizes them into an array of objects, with each object representing the query parameters from a single response.

If you specify a block name, getMultiQueryParams retrieves the query parameters from that particular block. If you don't specify a block name, it defaults to returning the query parameters from the previous or parent block's output.

Use cases

Scenario 1: Consider that you receive multiple paginated responses from a block, each with different page numbers or filters applied. You need to track or log these pagination details.
Usage: Use getMultiQueryParams() to extract the query parameters, such as page numbers and filters, from each response in the array. This allows you to manage or adjust pagination settings based on the query parameters used in the requests.

Scenario 2: You receive multiple search queries in a batch process and need to handle or analyse each query separately.
Usage: Use getMultiQueryParams() to retrieve the query parameters from each response in the array. This allows you to process or analyse the search queries individually, such as generating search results or reports for each query

Input syntax: const multiQueryParams = dao.getMultiQueryParams("blockName");
The block name is optional.

Example Output

[
  { 
    "search": "query1" 
  }, 
  { 
    "search": "query2" 
  }
]

getPathParams

The getPathParams function retrieves the path parameters from a specified block's output. If the output is an array, the function returns undefined.

When you specify a block name, getPathParams fetches the path parameters from that block. If you don't specify a block name, it retrieves the path parameters from the previous or parent block.

Use cases

Scenario 1: Consider you need to extract and validate a specific path parameter, like an ID, from a block's output before proceeding with further logic.
Usage: Use getPathParams() to retrieve the id from the block's output, allowing you to validate or use it in subsequent operations.

Scenario 2: Consider you are working with multiple API endpoints, and each requires different path parameters. You want to dynamically retrieve these parameters based on the current block's execution.
Usage: Use getPathParams() to access the path parameters of the relevant block, enabling you to manage routing or processing logic based on the retrieved parameters.

Input syntax: const pathParams = dao.getPathParams("blockName");
The block name is optional.

Example Output

{ 
  "id": "123" 
}

getMultiPathParams

The getMultiPathParams function retrieves an array of path parameters when a block's output consists of multiple responses. Each response in this array has its own set of path parameters. The getMultiPathParams function gathers these parameters from each response and returns them as an array of objects, where each object represents the path parameters from one of the responses.

When you specify a block name, the function getMultiPathParams fetches the path parameters from that particular block's output. If no block name is provided, it retrieves the path parameters from the previous or parent block.

Use cases

Scenario 1: Consider you are processing multiple API responses, each related to different resources identified by unique path parameters like id. You need to log or handle each resource individually.
Usage: Use getMultiPathParams() to retrieve the array of path parameters from each response. This helps manage or process each resource separately based on its unique identifier.

Scenario 2: Consider a scenario where your application aggregates data from multiple microservices, each returning a response with its own set of path parameters. You need to compile these parameters to generate a consolidated report or for further processing.
Usage: Use getMultiPathParams() to collect all path parameters from the responses. This helps you compile the necessary data or take actions based on the aggregated parameters.

Input syntax: const multiPathParams = dao.getMultiPathParams("blockName");
The block name is optional.

Example Output

 [
   { 
     "id": "123" 
   }, 
   { 
     "id": "456" 
   }
 ]

getError

The getError function is designed to retrieve the error object from the output of a specified block. This error object contains details such as an error message and an error code, which help identify and diagnose issues that occur during the execution of that block. When the block's output is an array of responses, the function returns undefined.

When you specify a block name as an argument, the function getError fetches the error object from that specific block. If you do not specify a block name, the function returns the error object from the previous or parent block.

Use cases

Scenario 1: Consider you need to debug a specific block that fails during execution.
Usage: Use getError() to retrieve the error object from that block. This allows you to see the error message and code, helping diagnose and fix the issue.

Scenario 2: Consider you have a workflow where different actions depend on whether a block succeeds or fails.
Usage: Use getError() to check if the specified block encountered an error. If the function returns an error object, implement custom error handling or logging based on the error details.

Input syntax: const error = dao.getError("blockName");
The block name is optional.



{ 
  "message": "An error occurred", "code": "500" 
}

getMultiError

The getMultiError function retrieves an array of error objects from the output response when a block's output consists of multiple responses. Each response in the array may have its own error object. The function collects all these error objects and returns them as an array.

When you specify a block name, getMultiError fetches the array of errors from that specific block's output. If you don't provide a block name, the function defaults to retrieving the errors from the output of the previous or parent block.

Use case

Scenario 1: Consider you are processing multiple API responses, each of which might contain its own error object. You need to collect and review all the errors to understand the issues across different responses.
Usage: Use getMultiError() to gather all error objects from each response in the array. This helps in aggregating error information for comprehensive troubleshooting or reporting.

Scenario 2: Consider you are implementing a batch processing system where each response could have its own error details. You need to handle errors for each item in the batch individually.
Usage: Use getMultiError() to retrieve and manage error details from all responses. This allows you to process errors for each response separately, such as logging them or triggering specific error handling workflows.

Input syntax: const errors = dao.getMultiError("blockName");
The block name is optional.

Example output

[
  { "message": "Error 1" }, 
  { "message": "Error 2" }
]

hasError

The hasError() function checks whether an error message exists in the output response of a specified block. It helps determine if the block encountered an error during execution. It returns a boolean value: true if an error message is present and false otherwise.

If you specify a block name, the function checks that specific block's output. If no block name is provided, it checks the output of the previous or parent block.

Use case

Scenario: Consider a conditional logic based on whether a block encounters an error during execution. For example, you may need to trigger error handling or execute alternative logic if an error occurs.
Usage: Use hasError() to check if the specified block generated an error. This enables you to create your logic according to the presence of errors, such as initiating an error handling routine if true.

Input syntax: const hasError = dao.hasError("blockName");
The block name is optional.

Output: True or False

getValidateError

The getValidateError function retrieves any validation errors present in the output response of a specified block. Validation errors occur when input data fails to meet specified criteria or constraints.

When you call getValidateError with a block name, it fetches the validation error details from that specific block's output. If you don't provide a block name, it returns the validation error details from the previous or parent block's output.

Use cases

Scenario 1: Consider a scenario where the validation for the query parameters has failed.
Usage: Use getValidateError() to retrieve the validation error details from the specified block.

Scenario 2: Consider that you are processing multiple blocks in a data validation pipeline, and you need to collect and review all validation errors that occur during execution.
Usage: Use getValidateError() to obtain validation errors from each block in the pipeline.

Input syntax: const validateError = dao.getValidateError('blockName');
The block name is optional.

Example output

{
  "status": false,
  "code": 400,
  "message": "billNumber must be unique",
  "path": "/body/billNumber"
}

hasValidateError

The hasValidateError function determines whether there are validation errors present in the output of a specified block. If you provide a block name, it checks for validation errors specific to that block. If no block name is given, it defaults to checking the previous or parent block's output.

The function returns a boolean value:

  • true: Indicates validation errors in the block's output.
  • false: Indicates no validation errors in the block's output.

Use case

Scenario: Consider you need to implement conditional logic based on whether a block's output includes validation errors. For example, you might want to trigger an error message or prompt the user to correct their input if any validation errors are present.
Usage: Use hasValidateError() to check if the specified block contains validation errors.

Input syntax : const hasValidateError = dao.hasValidateError('blockName');
The block name is optional.

Output: True or False

getEffectiveHeaders

The getEffectiveHeaders function retrieves headers relevant to API request processing by filtering out non-essential headers. It focuses on headers starting with x-cap or those related to authorization. This function ensures you access crucial headers needed for authentication and interactions with the API gateway, including only the essential headers.

Use cases

Scenario 1: Consider you need to pass specific headers to an API gateway for proper request handling, such as custom headers for API management or authentication tokens.
Usage: Use getEffectiveHeaders() to retrieve only the relevant headers needed for the API request, such as x-cap headers or authorization tokens. This ensures you include all necessary information for authentication and API gateway processing, without extraneous headers that could interfere with the request.

Scenario 2: Consider you are debugging an issue with API requests and need to verify which headers are sent for authentication and tracking purposes.
Usage: Use getEffectiveHeaders() to extract and review the headers applied to the API request. This helps you confirm that the required x-cap headers and authorization tokens are present and correctly formatted.

Input syntax: const effectiveHeaders = dao.getEffectiveHeaders();

Example output

{ 
  'x-cap-header': 'value', 
    'authorization': 'Bearer token'
}

isSuccess

The isSuccess() is a boolean function used to determine whether a previous operation or transaction was successful. It helps control the logic flow within a system, particularly in error handling and decision-making processes.

isSuccess() checks if data retrieval or a transaction completes without errors. It returns true if successful; else it returns false. Using this function, you can implement conditional logic based on the success of previous operations and effectively handle errors. This function does not require any input parameters.

Use case

Scenario: Consider an airport check-in system, the system first verifies that it successfully retrieved a passenger's data without errors. Next, it checks the passenger’s details, like a valid ticket and ID.
Usage 1: isSuccess() && (getOut().body.validPassenger)

This relation checks if the operation was successful and the passenger data is valid. If both conditions are true, the subsequent code block will execute, indicating that it is safe to proceed with further operations.

Usage 2: isSuccess() && (!getOut().body.validPassenger)

In this case, the relation checks if the operation was successful but the passenger data is not valid. If these conditions are met, it might trigger an error-handling routine or a specific pathway to manage the invalid passenger scenario.

hasError()

The hasError() is a boolean function used to check if an operation or transaction encountered any errors. It returns true when an error occurs, allowing the system to detect issues and trigger error-handling processes. Using the function improves system reliability by allowing only error-specific blocks to execute after a failure.

hasError() does not require any input parameters.

DAO Methods Specific to Filters

getDataFlowOut

Retrieve the output from a specified data flow using the dagType parameter to indicate the type of data flow.

📘

dagType

  • The dagType is set to 'main' for the original or main data flow.
  • The dagType is set to '@PreMatching-P1/2/3' for pre-matching data flows.
  • The dagType is set to '@PostMatching-P1/2/3' for post-matching data flows.

getLatestDataFlowOut

Fetch the output from the latest execution of a data flow without needing any parameters.

doesDataFlowHaveError

Return a boolean that indicates whether the specified data flow encounters an error by specifying the dagType parameter.

doesLatestDataFlowHaveError

Return a boolean that indicates whether the latest data flow encounters an error, with no parameters required.

getDataFlowError

Retrieve the error from a specified data flow by using the dagType parameter to specify which DAG's error you want to fetch.

getLatestDataFlowError

Fetch the error from the latest DAG without needing any parameters.

getDataFlowBody

Retrieve the body of the specified data flow by using the dagType parameter to indicate which data flow body you want to access.

getLatestDataFlowBody

Fetch the body from the latest execution of a data flow without requiring any parameters.

getDataFlowMultiBody

Similar to getMultiBody , specify dagType in the parameters.

getLatestDataFlowMultiBody

Similar to getMultiBody .