A collection of helper functions for command handlers.
- Source:
Methods
-
<inner> asArray(x)
-
Ensure that the value is an array. If the value is already an array, return it directly. If the value is undefined, return an empty array. Otherwise, return the value wrapped in an array.
Parameters:
Name Type Description x
any value
- Source:
Returns:
an array
- Type
- array
-
<inner> calculateWithMathjs()
-
Calculate
expr
using variables incontext
, with optionalspec
object specifyingunits
and/ordecimals
- Source:
-
<inner> createData(protocol, objects, SCOPE, DATA, path, files)
-
Create the 'data' object that gets passed into many commandHelper functions.
TODO: Rather than calling it 'data', we should probably rename it to 'context'.
Parameters:
Name Type Description protocol
Protocol objects
object = {} - current objects
SCOPE
object = {} - current SCOPE
DATA
array = [] - current DATA table
path
array = [] - current processing path (usually a step ID, e.g. step 1.2 would be given by
[1, 2]
)files
object = {} - map of filename to loaded filedata
- Source:
Returns:
the 'data' object that gets passed into many commandHelper functions
- Type
- object
-
<inner> dereferenceVariable(data, name)
-
Recursively lookup variable by name or path and return the final value.
Parameters:
Name Type Description data
object protocol data
name
string name or path of object to lookup in
data.objects
- Source:
Returns:
result of the lookup, if successful; otherwise undefined.
- Type
- any
-
<inner> fixPredicateUndefines(predicates)
-
Helper function for queryLogic() that replaces undefined property values with the name of the property prefixed by '?'.
Parameters:
Name Type Description predicates
Array Array of llpl predicates
- Source:
-
<inner> g(data, path, dflt)
-
Try to get a value from data.objects with the given name.
Parameters:
Name Type Description data
object Data object with 'objects' property
path
array | string Name of the object value to lookup
dflt
any default value to return
- Source:
Returns:
The value at the given path, if any
- Type
- Any
-
<inner> getCommon(value)
-
If value is an array and every element of the array is the same, return the first value of the array. Otherwise just return the value.
Parameters:
Name Type Description value
any value to inspect
- Source:
-
<inner> getParsedValue(parsed, data, paramName, propertyName, defaultValue)
-
Get a property value from an object in the parsed parameters. If no value could be found (and no default was given) then an exception will be thrown.
Parameters:
Name Type Description parsed
object the parsed parameters object, as passed into a command handler
data
object protocol data
paramName
string parameter name (which should reference an object)
propertyName
string name of the object's property to retrieve
defaultValue
any default value if property not found
- Source:
Returns:
the property value
- Type
- any
-
<inner> getStepKeys(o)
-
Return array of step keys in order. Any keys that begin with a number will be included, and they will be sorted in natural order.
Parameters:
Name Type Description o
object | array an object or array of steps
- Source:
Returns:
an ordered array of keys that represent steps
- Type
- array
-
<inner> lookupInputPath(path, parsed, data)
-
Lookup nested paths.
Parameters:
Name Type Description path
array [description]
parsed
object [description]
data
object [description]
- Source:
Returns:
[description]
- Type
- any
Example
* "object": gets parameter value. * "?object": optionally gets parameter value. * "object*": looks up object. * "object*location": looks up object, gets `location` property. * "object*location*": looks up object, gets `location` property, looks up location. * "object*location*type": looks up object, looks up its `location` property, gets type property. * "something**": double de-reference * "object*(someName)": looks up object, gets someName value, gets object's property with that value. (this is not currently implemented)
-
<inner> lookupPath(path, params, data)
-
Lookup nested paths.
Parameters:
Name Type Description path
array [description]
params
object [description]
data
object [description]
- Source:
Returns:
[description]
- Type
- any
Example
This example will first lookup `object` in `params`, then lookup the result in `data.objects`, then get the value of `model`, then lookup it value for `evowareName`: ``` [["@object", "model"], "evowareName"] ```
-
<inner> lookupValue0(result, path, data, value0)
-
Try to lookup value0 in objects set. This function is recursive - if the value refers to a variable, the variables value will also be dereferenced. When a variable is looked up, its also added to result.objectName[path].
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
data
object protocol data
value0
any The value from the user.
- Source:
Returns:
A new value, if value0 referred to something in data.objects.
- Type
- any
-
<inner> parseInputSpec()
-
Parse input spec and return object with the same properties as the spec, but with values looked up.
- Source:
-
<inner> parseParams(params, data, schema)
-
Parse command parameters according to a schema.
If parsing fails, an exception will be thrown.
Otherwise, the returned result contains two properties:
value
andobjectName
. Both properties are maps that reflect the structure of the given schema. Thevalue
map contains the parsed values -- object references are replaced by the actual object (indata
), quantities are replaced by mathjs objects, well specifications are replaced by an array of well references, etc.The
objectName
map contains any object names that were referenced; in contrast to thevalue
map (which is a tree of properties likeparams
),objectName
is a flat map, where the keys are string representations of the object paths (separated by '.'). Any object names that were looked up will also be added to thedata.accesses
list.Parameters:
Name Type Description params
object the parameters passed to the command
data
object protocol data
schema
object JSON Schema description, with roboliq type extensions
- Source:
Returns:
the parsed parameters, if successfully parsed.
- Type
- object
-
<inner> processDuration(result, path, x0, data)
-
Try to process a value as a time duration.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x0
object the value to process
data
object protocol data
- Source:
-
<inner> processLength(result, path, x, data)
-
Try to process a value as a length.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
- Source:
-
<inner> processObjectOfType(result, path, x, data, type, allowArray)
-
Tries to process and object with the given type, whereby this simply means checking that the value is a plain object with a property
type
whose value is the given type.Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
type
string type of object expected
allowArray
boolean false if we should not look into an array for an object
- Source:
-
<inner> processOneOfBasicType(result, path, value, fnCheck, expectedTypeName)
-
Accept either a single value whose type is checked with fnCheck(), or an array with each element equal to the first - in that case, set the result value to the first element of the array.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
value
any the value to process
fnCheck
function a function that returns true if the value has the correct type
expectedTypeName
string name of the expected type, for constructing the error message if fnCheck fails
- Source:
-
<inner> processOneOrArray(result, path)
-
Try to call fn on value0. If that works, return the value is made into a singleton array. Otherwise try to process value0 as an array. fn should accept parameters (result, path, value0) and set the value in result.value at the given path.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
- Source:
-
<inner> processParamsBySchema(result, path, params, schema, data)
-
Try to process the given params with the given schema.
Updates the
result
object. Updatesdata.accesses
if object lookups are performed.Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
params
object the part of the original parameters refered to by
path
schema
object JSON Schema description, with roboliq extensions
data
object protocol data
- Source:
-
<inner> processSiteOrStay(result, path, x, data)
-
Try to process a value as the keyword "stay" or as a Site reference.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
- Source:
-
<inner> processSource(result, path, x, data)
-
Try to process a value as a source reference.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
- Source:
-
<inner> processSources(result, path, x, data)
-
Try to process a value as an array of source references.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
- Source:
-
<inner> processString(result, path, params, data)
-
Try to process a value as a string.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
params
object the part of the original parameters refered to by
path
data
object protocol data
- Source:
-
<inner> processTemperature(result, path, x, data)
-
Try to process a value as a temperature.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
- Source:
-
<inner> processValue0AsEnum(result, path, value0, schema, data)
-
Try to process the value as an enum.
Parameters:
Name Type Description result
object result structure for values and objectNames
path
array path in params
value0
any the value to process
schema
object schema
data
object protocol data
- Source:
-
<inner> processValue0BySchema(result, path, value0, schema, data)
-
Try to convert value0 (a "raw" value, no yet looked up) to the given type.
If schema is undefined, return value.
If schema.enum: return processValue0AsEnum()
If schema.type is undefined but there are schema.properties, assume schema.type = "object".
If type is undefined or empty, return value.
If type is an array, try processing for each element of the array
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
value0
any the value to process
schema
object JSON Schema description, with roboliq extensions
data
object protocol data
- Source:
-
<inner> processValue0BySchemaType(result, path, value0, schema, data)
-
A sub-function of processValue0BySchema(). Try to process the value as a named type.
Parameters:
Name Type Description result
object result structure for values and objectNames
path
array path in params
value0
any the value to process
schema
object schema
data
object protocol data
- Source:
-
<inner> processValue0OnTypes(result, path, value0, schema, types, data)
-
A sub-function of processValue0BySchema(). Try to process the value as a named type.
Parameters:
Name Type Description result
object result structure for values and objectNames
path
array path in params
value0
any the value to process
schema
object schema
types
array a list of types to try
data
object protocol data
- Source:
-
<inner> processValueAsArray(result, path, value0, schema, data)
-
Try to process a value as an array.
Parameters:
Name Type Description result
object result structure for values and objectNames
path
array path in params
value0
any the value to process
schema
object schema of the array items
data
object protocol data
- Source:
-
<inner> processVolume(result, path, x, data)
-
Try to process a value as a volume.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
- Source:
-
<inner> processWell(result, path, x, data)
-
Try to process a value as a well reference.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
- Source:
-
<inner> processWells(result, path, x, data)
-
Try to process a value as an array of wells.
Parameters:
Name Type Description result
object the resulting object to return, containing objectName and value representations of params.
path
array path in the original params object
x
object the value to process
data
object protocol data
- Source:
-
<inner> queryLogic(data, predicates, predicateName)
-
Query the logic database with the given predicates. If solutions are found, choose one of the alternatives.
Parameters:
Name Type Description data
Object Command data
predicates
Array Array of llpl predicates
predicateName
String Name of the predicate we're interested in
- Source:
Returns:
- an array where the first item is the chosen solution, and the second item includes all alternatives. If no solution was found, then both items will be undefined.
- Type
- Array
-
<inner> queryLogicGeneral(data, predicates, queryExtract)
-
Query the logic database with the given predicates and return the values of interest.
Parameters:
Name Type Description data
Object Command data
predicates
Array Array of llpl predicates
queryExtract
String A jmespath query string to extract values of interest from the llpl result list
- Source:
Returns:
Array of objects holding valid values
- Type
- Array
-
<inner> stepify(steps)
-
Return an object that conforms to the expected format for steps.
Parameters:
Name Type Description steps
array | object input in format of an array of steps, a single step, or propertly formatted steps.
- Source:
Returns:
an object with only numeric keys, representing a sequence of steps.
- Type
- object
-
<inner> substituteDeep(x, data)
-
Recursively replace $-SCOPE, $$-DATA, and template strings in
x
.The recursion has the following exceptions:
- skip objects with any of these properties:
data
,@DATA
,@SCOPE
- skip
steps
properties - skip directives
Parameters:
Name Type Description x
any the variable to perform substitutions on
data
object protocol data
- Source:
Returns:
the value with possible substitutions
- Type
- any
- skip objects with any of these properties:
-
<inner> updateSCOPEDATA()
-
Process '@DATA', '@SCOPE', and 'data' properties for a step, The returned data table will be the first to exist of '@DATA', 'DATA', and 'objects.DATA' The returned scope will be the merger of data.objects.SCOPE, SCOPE, '@SCOPE', and common DATA values. and return updated {DATA, SCOPE}.
- Source: