PersistDataValueSettingsBuilder

public class PersistDataValueSettingsBuilder : TransformationSettingsBuilder

Builder for creating a PersistDataValue transformation that stores a value from the dispatch payload (or a constant) into the data layer with a configurable expiry and update policy.

Example usage:

let settings = PersistDataValueSettingsBuilder(id: "persist-user-id")
    .persistFrom(.key("user_id"), to: .key("persisted_user_id"))
    .setExpiryPolicy(.forever)
    .setUpdatePolicy(.keepFirstValue)
    .setScope(.afterCollectors)
    .build()
  • Creates a new builder for a PersistDataValue transformation with the given unique id.

    Declaration

    Swift

    public init(id: String)

    Parameters

    id

    A unique identifier for this transformation instance.

  • Configures the transformation to persist a constant value to a specified destination of the data layer.

    This method sets up the transformation to store a fixed value at the specified destination path in the data layer. The value will be persisted according to the configured expiry and update policy settings. If not specified, defaults to .session expiry and .allowUpdate policy.

    Declaration

    Swift

    public func persistConstant(_ constant: DataInput, to destination: ReferenceContainer) -> Self

    Parameters

    constant

    The constant value to be persisted.

    destination

    A ReferenceContainer specifying where in the data layer to store the value. Can be a simple key or a nested path.

    Return Value

    The builder instance for method chaining.

  • Configures the transformation to persist a value from the Dispatch payload to a specified destination of the data layer.

    This method sets up the transformation to copy a value from an existing location in the payload (specified by the input ReferenceContainer) to the specified destination path in the data layer. The value will be persisted according to the configured expiry and update policy settings. If not specified, defaults to .session expiry and .allowUpdate policy.

    Declaration

    Swift

    public func persistFrom(_ input: ReferenceContainer, to destination: ReferenceContainer) -> Self

    Parameters

    input

    A ReferenceContainer specifying the source location in the ‘Dispatch’ payload from which to read the value to be persisted.

    destination

    A ReferenceContainer specifying where in the data layer to store the value. Can be a simple key or a nested path.

    Return Value

    The builder instance for method chaining.

  • Sets the expiry policy for the persisted data.

    This method configures how long the persisted value should remain in the data store before it expires and is automatically removed. The expiry policy determines the lifecycle of the stored data.

    If not called, the default expiry policy of .session will be used.

    Declaration

    Swift

    public func setExpiryPolicy(_ expiryPolicy: ExpiryPolicy) -> Self

    Parameters

    expiryPolicy

    The ExpiryPolicy to apply to the persisted data. Common values include .session (expires when the session ends), .forever (never expires), or .duration(timeFrame) for custom time-based expiry.

    Return Value

    The builder instance for method chaining.

  • Sets the update policy for the persisted data.

    This method configures how the transformation should behave when attempting to persist data to a destination that already contains a value. The update policy determines whether existing values can be overwritten or should be preserved.

    If not called, the default update policy of .allowUpdate will be used.

    Declaration

    Swift

    public func setUpdatePolicy(_ updatePolicy: UpdatePolicy) -> Self

    Parameters

    updatePolicy

    The UpdatePolicy policy to apply when the destination already contains data. Use .allowUpdate to overwrite existing values, or .keepFirstValue to preserve existing values and skip the persistence operation.

    Return Value

    The builder instance for method chaining.

  • Builds a DataObject from the current builder state. Writes whatever properties have been set to the configuration DataObject.

    Declaration

    Swift

    override public func build() -> DataObject