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 xany value
- Source:
Returns:
an array
- Type
- array
-
<inner> calculateWithMathjs()
-
Calculate
exprusing variables incontext, with optionalspecobject specifyingunitsand/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 protocolProtocol objectsobject = {} - current objects
SCOPEobject = {} - current SCOPE
DATAarray = [] - current DATA table
patharray = [] - current processing path (usually a step ID, e.g. step 1.2 would be given by
[1, 2])filesobject = {} - 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 dataobject protocol data
namestring 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 predicatesArray 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 dataobject Data object with 'objects' property
patharray | string Name of the object value to lookup
dfltany 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 valueany 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 parsedobject the parsed parameters object, as passed into a command handler
dataobject protocol data
paramNamestring parameter name (which should reference an object)
propertyNamestring name of the object's property to retrieve
defaultValueany 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 oobject | 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 patharray [description]
parsedobject [description]
dataobject [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 patharray [description]
paramsobject [description]
dataobject [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 resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
dataobject protocol data
value0any 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:
valueandobjectName. Both properties are maps that reflect the structure of the given schema. Thevaluemap 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
objectNamemap contains any object names that were referenced; in contrast to thevaluemap (which is a tree of properties likeparams),objectNameis 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.accesseslist.Parameters:
Name Type Description paramsobject the parameters passed to the command
dataobject protocol data
schemaobject 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 resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
x0object the value to process
dataobject protocol data
- Source:
-
<inner> processLength(result, path, x, data)
-
Try to process a value as a length.
Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject 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
typewhose value is the given type.Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject protocol data
typestring type of object expected
allowArrayboolean 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 resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
valueany the value to process
fnCheckfunction a function that returns true if the value has the correct type
expectedTypeNamestring 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 resultobject the resulting object to return, containing objectName and value representations of params.
patharray 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
resultobject. Updatesdata.accessesif object lookups are performed.Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
paramsobject the part of the original parameters refered to by
pathschemaobject JSON Schema description, with roboliq extensions
dataobject 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 resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject protocol data
- Source:
-
<inner> processSource(result, path, x, data)
-
Try to process a value as a source reference.
Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject protocol data
- Source:
-
<inner> processSources(result, path, x, data)
-
Try to process a value as an array of source references.
Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject protocol data
- Source:
-
<inner> processString(result, path, params, data)
-
Try to process a value as a string.
Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
paramsobject the part of the original parameters refered to by
pathdataobject protocol data
- Source:
-
<inner> processTemperature(result, path, x, data)
-
Try to process a value as a temperature.
Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject protocol data
- Source:
-
<inner> processValue0AsEnum(result, path, value0, schema, data)
-
Try to process the value as an enum.
Parameters:
Name Type Description resultobject result structure for values and objectNames
patharray path in params
value0any the value to process
schemaobject schema
dataobject 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 resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
value0any the value to process
schemaobject JSON Schema description, with roboliq extensions
dataobject 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 resultobject result structure for values and objectNames
patharray path in params
value0any the value to process
schemaobject schema
dataobject 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 resultobject result structure for values and objectNames
patharray path in params
value0any the value to process
schemaobject schema
typesarray a list of types to try
dataobject protocol data
- Source:
-
<inner> processValueAsArray(result, path, value0, schema, data)
-
Try to process a value as an array.
Parameters:
Name Type Description resultobject result structure for values and objectNames
patharray path in params
value0any the value to process
schemaobject schema of the array items
dataobject protocol data
- Source:
-
<inner> processVolume(result, path, x, data)
-
Try to process a value as a volume.
Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject protocol data
- Source:
-
<inner> processWell(result, path, x, data)
-
Try to process a value as a well reference.
Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject protocol data
- Source:
-
<inner> processWells(result, path, x, data)
-
Try to process a value as an array of wells.
Parameters:
Name Type Description resultobject the resulting object to return, containing objectName and value representations of params.
patharray path in the original params object
xobject the value to process
dataobject 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 dataObject Command data
predicatesArray Array of llpl predicates
predicateNameString 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 dataObject Command data
predicatesArray Array of llpl predicates
queryExtractString 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 stepsarray | 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
stepsproperties - skip directives
Parameters:
Name Type Description xany the variable to perform substitutions on
dataobject 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: