Mappings
open class Mappings
The Mappings builder is used to build up key/destination mappings used when optionally
translating the full Dispatch payload to just the relevant data for any given Dispatcher.
Use the mapFrom method to supply the required source “key” and “destination” key, as
well as any optional “path” entries required to access keys in nested object.
Using the following payload DataObject as an example (shown as JSON)
{
"source" : "value",
"path": {
"to" : [{
"source": "nested value",
}]
}
}
Simple usage for keys in the top level DataObject would look like so:
mappings.mapFrom("source", to: "destination")
More complex versions requiring accessing keys that exist in nested objects and arrays would look like so:
mappings.mapFrom(JSONPath["path"]["to"][0]["source"],
to: JSONPath["path"]["to"]["destination"])
Use the keep utility method to create a mapping where the source key is the same as the destination.
Simple usage for keys in the top level DataObject would look like so:
mappings.keep("source")
More complex versions requiring accessing keys that exist in nested objects would look like so:
mappings.keep(JSONPath["path"]["to"][0]["source"])
The mapFrom and keep methods return a VariableOptions that allows for setting optional properties relevant to a mapping
like a ifValueEquals(:), to only perform the mapping if the value is equal to some specific string.
Use the mapConstant method to supply a constant “value” and “destination” key.
mappings.mapConstant("value", to: "destination")
More complex versions requiring accessing keys that exist in nested objects would look like so:
mappings.mapConstant(value, to: JSONPath["path"]["to"]["destination"])
The mapConstant method returns a ConstantOptions that allows for setting optional properties relevant to a mapping
like a ifValueIn(:equals:), to only perform the mapping if a value at the given key is equal to the given target.
-
Undocumented
Declaration
Swift
required public init() -
Some
See moreMappingsoptions that are mapping a key from the payload to a destination in the result payload.Declaration
Swift
public class VariableOptions : MappingsBuilder -
Some
See moreMappingsoptions that are mapping a constant value to a destination in the result payload.Declaration
Swift
public class ConstantOptions : MappingsBuilder -
A
See moreConstantOptionsinstance that is mapping a command name string to the “command_name” property in the result payload. Intended to be used for so called Remote Command Dispatchers.Declaration
Swift
public class CommandOptions : ConstantOptions -
Creates a new mapping operation builder with the specified source and destination.
Declaration
Swift
@discardableResult func mapFrom(_ key: String, to destination: JSONObjectPath) -> VariableOptionsParameters
keyThe source key from which to take the value to map.
destinationThe destination path to a variable in the data layer.
Return Value
A
VariableOptionsmapping operation builder. -
Creates a new mapping operation builder with the specified source and destination.
Declaration
Swift
@discardableResult func mapFrom(_ path: JSONObjectPath, to destination: JSONObjectPath) -> VariableOptionsParameters
pathThe source path from which to take the value to map.
destinationThe destination path to a variable in the data layer.
Return Value
A
VariableOptionsmapping operation builder. -
Creates a new mapping operation builder with the specified source and destination.
Declaration
Swift
@discardableResult func mapFrom(_ path: JSONObjectPath, to destination: String) -> VariableOptionsParameters
pathThe source path from which to take the value to map.
destinationThe destination key to a variable in the data layer.
Return Value
A
VariableOptionsmapping operation builder. -
Creates a new mapping operation builder with the specified source and destination.
Declaration
Swift
@discardableResult func mapFrom(_ key: String, to destination: String) -> VariableOptionsParameters
keyThe source key from which to take the value to map.
destinationThe destination key to a variable in the data layer.
Return Value
A
VariableOptionsmapping operation builder. -
Adds a mapping where the
keyis both the source and destination of the mapping.Declaration
Swift
@discardableResult func keep(_ key: String) -> VariableOptionsParameters
keyThe key to take the value from and also the destination to place it in the mapped payload.
Return Value
A
VariableOptionsmapping operation builder. -
Adds a mapping where the
pathis both the source and destination of the mapping.Declaration
Swift
@discardableResult func keep(_ path: JSONObjectPath) -> VariableOptionsParameters
pathThe path to take the value from and also the destination to place it in the mapped payload.
Return Value
A
VariableOptionsmapping operation builder. -
Adds a mapping where the value to map is given by the constant
valueand will be mapped to the givendestinationlocated/stored at some configured level of nesting as defined by theJSONObjectPath.Declaration
Swift
@discardableResult func mapConstant(_ value: DataInput, to destination: JSONObjectPath) -> ConstantOptionsReturn Value
A
ConstantOptionsmapping operation builder. -
Adds a mapping where the value to map is given by the constant
valueand will be mapped to the givendestinationlocated/stored in the root of the data layer..Declaration
Swift
@discardableResult func mapConstant(_ value: DataInput, to destination: String) -> ConstantOptionsReturn Value
A
ConstantOptionsmapping operation builder. -
Adds a mapping where the value to map is given by the constant
nameand will be mapped to the “command_name” key located in the root of the data layer.Declaration
Swift
@discardableResult func mapCommand(_ name: String) -> CommandOptionsParameters
nameThe command name to map to the “command_name” property key.
Return Value
A
CommandOptionsmapping operation builder.
View on GitHub