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 Mappings options that are mapping a key from the payload to a destination in the result payload.

    See more

    Declaration

    Swift

    public class VariableOptions : MappingsBuilder
  • Some Mappings options that are mapping a constant value to a destination in the result payload.

    See more

    Declaration

    Swift

    public class ConstantOptions : MappingsBuilder
  • A ConstantOptions instance 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.

    See more

    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) -> VariableOptions

    Parameters

    key

    The source key from which to take the value to map.

    destination

    The destination path to a variable in the data layer.

    Return Value

    A VariableOptions mapping operation builder.

  • Creates a new mapping operation builder with the specified source and destination.

    Declaration

    Swift

    @discardableResult
    func mapFrom(_ path: JSONObjectPath, to destination: JSONObjectPath) -> VariableOptions

    Parameters

    path

    The source path from which to take the value to map.

    destination

    The destination path to a variable in the data layer.

    Return Value

    A VariableOptions mapping operation builder.

  • Creates a new mapping operation builder with the specified source and destination.

    Declaration

    Swift

    @discardableResult
    func mapFrom(_ path: JSONObjectPath, to destination: String) -> VariableOptions

    Parameters

    path

    The source path from which to take the value to map.

    destination

    The destination key to a variable in the data layer.

    Return Value

    A VariableOptions mapping operation builder.

  • Creates a new mapping operation builder with the specified source and destination.

    Declaration

    Swift

    @discardableResult
    func mapFrom(_ key: String, to destination: String) -> VariableOptions

    Parameters

    key

    The source key from which to take the value to map.

    destination

    The destination key to a variable in the data layer.

    Return Value

    A VariableOptions mapping operation builder.

  • Adds a mapping where the key is both the source and destination of the mapping.

    Declaration

    Swift

    @discardableResult
    func keep(_ key: String) -> VariableOptions

    Parameters

    key

    The key to take the value from and also the destination to place it in the mapped payload.

    Return Value

    A VariableOptions mapping operation builder.

  • Adds a mapping where the path is both the source and destination of the mapping.

    Declaration

    Swift

    @discardableResult
    func keep(_ path: JSONObjectPath) -> VariableOptions

    Parameters

    path

    The path to take the value from and also the destination to place it in the mapped payload.

    Return Value

    A VariableOptions mapping operation builder.

  • Adds a mapping where the value to map is given by the constant value and will be mapped to the given destination located/stored at some configured level of nesting as defined by the JSONObjectPath.

    Declaration

    Swift

    @discardableResult
    func mapConstant(_ value: DataInput, to destination: JSONObjectPath) -> ConstantOptions

    Return Value

    A ConstantOptions mapping operation builder.

  • Adds a mapping where the value to map is given by the constant value and will be mapped to the given destination located/stored in the root of the data layer..

    Declaration

    Swift

    @discardableResult
    func mapConstant(_ value: DataInput, to destination: String) -> ConstantOptions

    Return Value

    A ConstantOptions mapping operation builder.

  • Adds a mapping where the value to map is given by the constant name and will be mapped to the “command_name” key located in the root of the data layer.

    Declaration

    Swift

    @discardableResult
    func mapCommand(_ name: String) -> CommandOptions

    Parameters

    name

    The command name to map to the “command_name” property key.

    Return Value

    A CommandOptions mapping operation builder.