Data: Schema, Public Variables and Literals
  • 03 Sep 2024
  • 6 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Data: Schema, Public Variables and Literals

  • Dark
    Light
  • PDF

Article summary

We have included an Interactive Training to provide a more engaging and visual learning experience. End users are required to complete their training through the CSG University.


Xponent uses an internal Data Store during graph execution. This data store is used to keep track of all activities in the graph and holds data that is necessary for the processing.

Every node has at least one input or output location that refers to the data store. The data in Xponent falls into one of three distinct types: 

  1. Data Schema:
    • Data Schema in Xponent is represented as a JavaScript Object.
    • It is a temporary data structure that exists only for the duration of the execution of a single graph.
    • Data Schemas can be read from and written to by any node in the graph.
  2. Literal:
    • Literals in Xponent represent constant values.
    • They are typically used as inputs to nodes or as the return values from Return Nodes.
    • Unlike Data Schemas, Literals are static and do not change during the execution of the graph.
  3. Public Variable:
    • They exist independently of the Data Schema.
    • Public Variables can be read and written from any node in the graph. They come in two modes:
  • Persistent Public Variable: These public variables maintain their values throughout the entire deployment of a graph and across all listen events. They persist beyond individual transactions or operations and provide long-term data storage and sharing capabilities.
  • Transactional Public Variables: Transactional public variables are JavaScript objects that also exist outside of the schema. They can be read from and written from any node in the graph, but they have a more short-term or transaction-specific lifespan. Their data may be reset or changed with each transaction or operation within the graph.

When building a graph and choosing data locations for input and output to nodes the three options for choosing data are shown in the top right panel of the window. This panel can be rotated between the three views of 'Data Schema', 'Literals', and 'Public Variables' by using the tabs at the top of the panel:

Data Schema

The Data Schema can be thought of as a single JavaScript Object. The object can contain fields and other objects. It is represented as a hierarchical layout Child schemas can contain fields and other objects. Elements can be opened and folded using the down chevron and up chevron buttons. Graphs can read and write individual fields or whole records from the schema during execution.

It is not necessary to declare fields in the schema prior to graph execution but it is necessary if they are to be chosen as an input or output location for a node.

Adding a Single Field to the Schema

When you first start a new graph, the Schema section will be blank. New fields can be added to the schema using the Add Child Single Field to 'schema' button.

The Add Field dialogue will be shown:

After adding the field the Schema will look like this:

The 'newChild' field does not have any children of its own, so is shown with a single '>' rather than with up or down chevrons

Adding a Child Record via JSON to the Schema

A child record can be added to the schema by selecting the position at which the record is to be added and pressing the Add Record button. Records can be added at either the top level 'Schema' or somewhere further down the hierarchy.

The Add Child Record window appears and you can type or copy in any valid JavaScript Object Notation (JSON) record definition. Actual values are not necessary and can be junk data but not missing.

Missing values will return a JSON: SyntaxError message.

Error State:

There are many places where you can check that you have a valid JSON document - an easy-to-use one is JSON Lint. Note that this must be a valid standalone object and so must start and end with curly braces ({,}). 

After the addition of this record, the schema will now look like this:

Editing the Schema

Any record or field can be renamed by selecting the item and pressing the rename button.

Any record or field can be deleted by selecting the item and pressing the trash can button.

Schema is Created

Once you have created your schema, you will now be able to define the key values in the graph nodes for input/output/source. 

For Example: 

In a GET node, you can define your schema location tocustomer/email

Schema Scope

The scope of the schema is unique to a single execution of a graph. Schema is shared across the parent graph, sub-graphs, and loop nodes that make up a single transaction.

Schema locations referenced inside a managed graph node instance will share scope with other nodes if their nesting and naming is identical to schema locations in the project in which the managed graph is being used. 

:closed_lock_with_key:

In a future update, the schema for a managed graph may be separated from the project's schema.

However, because users of managed graphs may not have visibility into schema locations used by a managed graph, it is recommended to create a top-level schema location called "managed" or some other unique name and nest all other schema locations under this when creating a managed graph.

Literal Values

Literal values are any valid JavaScript object. This includes simple literal values such as strings, numeric values or more complex JavaScript objects.

For Example - Values:

  • String - "Hello World" 
  • Numeric -  3, 4.5 

Objects

JSON
{ "car" : { "make" : "Ford", "model" : "Mondeo", "engine" : "diesel" } }

Public Variables

Public Variables can hold any valid JavaScript object. Public variables are usually used to hold data that is necessary but not related to the entity being processed. This may be a temporary value or an access key.

For Example:

If the data should be part of the transaction and discarded at the end of the graph execution then it is better expressed as part of the schema.

Public variables can be initialized with values, unlike schema elements.

Creating a Public Variable

To create a public variable, use the Create New Public Variable button when the Public Variables window is selected.


This will bring up the Add Public Variables dialogue:

Public Variable Scope

Public Variables have a scope that can be persistent or transactional.

Transactional public variables: Transactional public variables' scope is limited to a single execution of a graph. After the graph execution completes, the value of the public variable is reset. Transactional public variables function very similarly to schema locations; however, unlike schema, you may specify an initial value.

Persistent public variables: Persistent public variables in a deployed graph share scope with all graphs deployed in the project within the same environment. Once a persistent public variable's value has been set, it will remain set as long as there is a graph deployed from the project within the environment. Once no graphs from the project and environment are deployed, the value of the public variable will remain set and available for a short period to allow any final graph executions to be completed successfully.

When used in a visual test, public variables do not share scope with other visual tests, nor do they share scope with public variables in the deployed graph.

Public variables that are used inside a managed graph do not share scope with public variables in the project in which the instance of the managed graph is being used. If two instances of the same managed graphs exist, the public variables of these managed graphs will have a shared scope. Under certain circumstances, the public variables of two different managed graphs created from the same source project may share scope, therefore, it is recommended to use a unique public variable for each managed graph.


See Also:


Is it helpful? React and share your comment

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence