Sometimes while writing the script for your component you'll need to manipulate the data types moving through the component. This Value API reference explains the syntax for doing so in Javascript and Python components. (The R Value API is in this R Component API article.) 


Functions that create Values

 

api.value(initializer)
api.value.import(initializer)
api.value.eval(expr)
api.value.boolean(initializer)
api.value.integer(initializer)
api.value.float(initializer)
api.value.string(initializer)
api.value.list(initializer)
api.value.multiset(initializer)
api.value.set(initializer)
api.value.entity(initializer)
api.value.tag(initializer)
api.value.nullable(initializer)
api.value.null(initializer)
api.value.type(t)
api.value.type.boolean()
api.value.type.integer()
api.value.type.float()
api.value.type.string()
api.value.type.collection(valueType)
api.value.type.list(valueType)
api.value.type.multiset(valueType)
api.value.type.set(valueType)
api.value.type.entity(attributes) 
api.value.type.tag()
api.value.type.nullable(valueType)
api.value.type.null()
api.value.type.type()
api.value.type.dynamic()


 


Member functions of Value

 

Value.toString(formatObj)
Value.toTypeString()
Value.toNumber()
Value.toBoolean()
Value.toArrayOfValues()
Value.toObjectOfValues()
Value.export(options)
Value.cast(type)
Value.transform(expr, options)
Value.getType()
Value.isBoolean()
Value.isInteger()
Value.isFloat()
Value.isString()
Value.isCollection()
Value.isList()
Value.isMultiset()
Value.isSet()
Value.isEntity()
Value.isTag()
Value.isNullable()
Value.isNull()
Value.isType()
Value.getAttributeInfo() // returns list of {name, type, typeString}
Value.getAttribute(attributeName)
Value.attr(attributeName)
Value.setAttribute(attributeName, attributeValue)
Value.hasAttribute(attributeName)
Value.addAttribute(attributeName, attributeValue)
Value.getAttributeType(attributeName)
Value.hasTag(tagName)
Value.tag(tagName)
Value.extend(entity)
Value.map(fn)
Value.mapWith(expr)
Value.filter(fn)
Value.filterWith(expr)
Value.reduce(fn, initialValue)
Value.append(v) 
Value.concat(v) 
Value.isEmpty()
// Value.sort()
// Value.getValueType()
Value.update(cond, assign) 
Value.select(cond, assign) 
Value.join(jointo, jointype, cond, assign)
Value.union(unionwith)
// Value.intersection()
// Value.difference()

// Parameter descriptions


 

Expressions

Where a parameter has the name expr, a string should be provided with the form of an expression that evaluates to the desired value.

Arithmetic operators: +, -, *, /, %
Logical operators: &&, ||, !
Comparison operators: ==, !=, >, >=, <, <=
Grouping operator: ()
Conditional operator: ? :
Attribute operator: . (gets attribute from entity)

integer literal: eg. 5
float literal: eg. 2.5
string literal: eg. "my string value"
entity literal: {<attrType> <attrName> : <attrValue>, ...}
list literal: [<value0>, <value1>, ...]
multiset literal: m[<value0>, <value1>, ...]
set literal: s[<value0>, <value1>, ...]


In the case of mapWith, the expression specifies the value that the collection entry is being mapped to. For filterWith, the expression should be a boolean determining whether the collection entry should be retained in the result or not. In both of these cases, the function can only be used on collections of entities, and expr will be evaluated in the context of the current entry. In other words, attributes of the current entry can be referenced with just the attribute name, eg. score + 25 is an expression that evaluates to 25 plus the value of the attribute "score" of the current entity.


fn

Map, filter, and reduce require functions that not evaluated directly in the context of an entity, but instead are given the entity (or other value) as an argument. The arguments are specified and separated from the function body with the | operator, e.g. player | player.score + 25 is a function that returns 25 plus the value of the attribute 'score' of an entity supplied to the function.


The fn supplied to reduce should take two arguments: the current value, and the current entry being reduced, e.g. listOfIntgers.reduce('sum, v | sum + v', 0) will sum the values in listOfIntegers


cond

The parameter cond appears in the entity collection manipulation functions update, select, and join. This should be an expression, as expr above, evaluating to a boolean. In the case of update, this determines which entities will have their values modified. For select, it determines which entities will be selected. For join this is the condition that the tables will be joined on.


assign

These entity collection functions all have an assign parameter as well. This is an expression that defines what the output data will look like, and should therefore generally be an entity expression:

{name: firstname + lastname, score: score}
{*, desc: name + " is describable"}
{*, /unneededField}