CombineWrapper

public final class CombineWrapper : WebcomWrapper, Hashable, CustomStringConvertible

The type that wraps DatasyncNode in order to enrich it with a Combine-based API.

See also the documentation section of WebcomWrapper for the corresponding wrapped type.

To use this type, import the following dependency in your code:

import WebcomCombine

Stored Properties

API

  • The DataNode instance that refers the same node as this instance.

    Declaration

    Swift

    public var dataNode: DataNode.CombineWrapper { get }
  • A reference to the parent of the node referred by this instance.

    The root node does not have a parent, so this property returns nil for the root node. For all other nodes, this property never returns nil.

    Note: With a reference to the root node, relativeNode(for: "..") returns a reference to the root node.

    Declaration

    Swift

    public var parent: CombineWrapper? { get }
  • Returns a reference to another node, relatively to the node referred by this instance.

    This method only returns nil when the path is ill-formed, that is when it contains forbidden characters. All nodes always exists: this method always returns a plain node reference when the path is syntactically valid.

    The path consists of segments separated by / (slash) characters. Each segment corresponds to a move in the database tree:

    • The starting point is the node corresponding to this instance.
    • The . segment is a no-operation.
    • The .. segment indicates to go one level up in the tree. When already at the root node, this is a no-operation.
    • The empty segment, when using a / at the beginning or at the end of the path, or when using several consecutive /, is a no-operation.
    • Any other valid segment indicates to go one level down towards the so-named child.

    If the path referred by this node is /foo/bar:

    • and path is equal to geek, /geek, geek/ or /geek/, the path of the resulting node is /foo/bar/geek,
    • and path is equal to ../geek/noob or /../geek//noob/. or ../geek/./noob/., the path of the resulting node is /foo/geek/noob,
    • and path is equal to ../geek/../..//../.., the resulting node is the root node.

    Note: With a reference to the root node, parent returns nil.

    Declaration

    Swift

    public func relativeNode(for path: String) -> CombineWrapper?

    Parameters

    path

    The relative path of the node to refer. It can start or not with a / (slash) character. It is always relative.

    Return Value

    A reference to the node corresponding to the relative path when it is valid, nil otherwise.

  • Returns a reference to a database node, relatively to a base node.

    This operator returns:

    node.relativeNode(for: path)
    

    Declaration

    Swift

    public static func / (node: CombineWrapper, path: String) -> CombineWrapper?

    Parameters

    node

    A reference to the base node.

    path

    The relative path of the node to refer. It can start or not with a / (slash) character. It is always relative.

    Return Value

    A node reference when the path is valid, nil otherwise.

  • Creates a reference to a new child of the node referred by this instance.

    The key of the new child is a unique identifier based on a timestamp. Such a key is also called a push identifier. The keys of several children created with this method are ordered chronologically. With this method, several users can add children to the same data node of a database at the same time without any write conflict.

    Note: More exactly, since from a theoretical point of view all nodes always exist, this method actually returns a reference to a node whose current value is JSON null.

    Declaration

    Swift

    public func createChild() -> CombineWrapper

    Return Value

    A reference to a new child of this node.

  • Gets the value of the node referred by this instance.

    The decodedValue() method can be used to get decoded values.

    Declaration

    Swift

    public func value() -> WebcomFuture<DatasyncValue>

    Return Value

    A future with the value of the referred node

  • value() Asynchronous

    Declaration

    Swift

    public func value() async throws -> DatasyncValue
  • Gets the value of the node referred by this instance.

    This method behaves like the value() method but it returns a future that gets a decoded value in case of success. When the value cannot be decoded, the future is rejected with an error having the WebcomError.SDKCode.decodingFailed code. If this behavior does not fit your needs, use the value() method and process the parameter as expected.

    The decoding is done using the WebcomApplication.jsonDecoder of the WebcomApplication from which this node derives.

    Declaration

    Swift

    public func decodedValue<T>() -> WebcomFuture<T> where T : Decodable

    Return Value

    A future with the decoded value of the referred node

  • decodedValue() Asynchronous

    Declaration

    Swift

    public func decodedValue<T>() async throws -> T where T : Decodable
  • Gets the value of the node referred by this instance.

    This method behaves like the value() method but it returns a future that gets a decoded value in case of success. When the value cannot be decoded, the future is rejected with an error having the WebcomError.SDKCode.decodingFailed code. If this behavior does not fit your needs, use the value() method and process the parameter as expected.

    The decoding is done using the WebcomApplication.jsonDecoder of the WebcomApplication from which this node derives.

    Declaration

    Swift

    public func decodedValue<T>(as type: T.Type) -> WebcomFuture<T> where T : Decodable

    Parameters

    type

    The target type for the decoding.

    Return Value

    A future with the decoded value of the referred node

  • decodedValue(as:) Asynchronous

    Declaration

    Swift

    public func decodedValue<T>(as type: T.Type) async throws -> T where T : Decodable
  • Clears the value of the node referred by this instance.

    Clearing the value is equivalent to setting a JSON null value. Therefore, calling this method is equivalent to call:

    set(nil, at: time, queue: queue, then: completionCallback)
    

    Declaration

    Swift

    @discardableResult
    public func clear(at time: DatasyncTime = .now) -> WebcomFuture<Void>

    Parameters

    time

    The time at which to perform the operation.

    Return Value

    A future with a void value.

  • clear(at:) Asynchronous

    Declaration

    Swift

    public func clear(at time: DatasyncTime = .now) async throws
  • Sets the value of the node referred by this instance.

    Note: In most cases, you should rather use the set(_:at:) overload that takes an Encodable parameter.

    All children of the referred node cleared before setting the new value. The merge(_:with:at:) method may be used to merge existing children with the ones of the value when it is a JSON object or array.

    Declaration

    Swift

    @discardableResult
    public func set(_ raw: WebcomMarkers.Raw, _ json: Any?, at time: DatasyncTime = .now) -> WebcomFuture<Void>

    Parameters

    raw

    Use the .raw value to disambiguate with the set(_:at:) overload that takes an Encodable parameter.

    json

    The value to set. It must be valid JSON (object, array, string, number, boolean or null). The null value can be specified with nil or NSNull().

    time

    The time at which to perform the operation.

    Return Value

    A future with a void value.

  • set(_:_:at:) Asynchronous

    Declaration

    Swift

    public func set(_ raw: WebcomMarkers.Raw, _ json: Any?, at time: DatasyncTime = .now) async throws
  • Sets the value of the node referred by this instance.

    All children of the referred node cleared before setting the new value. The merge(with:at:) method may be used to merge existing children with the ones of the value when it is a JSON object or array.

    Declaration

    Swift

    @discardableResult
    public func set(_ value: (some Encodable)?, at time: DatasyncTime = .now) -> WebcomFuture<Void>

    Parameters

    value

    The value to set. It will be encoded to JSON before being sent to the back-end, using the WebcomApplication.jsonEncoder of the WebcomApplication from which this node derives. The null value can be specified with nil or NSNull().

    time

    The time at which to perform the operation.

    Return Value

    A future with a void value.

  • set(_:at:) Asynchronous

    Declaration

    Swift

    public func set(_ value: (some Encodable)?, at time: DatasyncTime = .now) async throws
  • Sets the value of a node.

    This operator is equivalent to:

    _ = node.set(value)
    

    Declaration

    Swift

    public static func <- (node: CombineWrapper, value: (some Encodable)?)

    Parameters

    node

    A reference to the node whose value must be set.

    value

    The value to set.

  • <-(_:_:) Asynchronous

    Declaration

    Swift

    public static func <- (node: CombineWrapper, value: (some Encodable)?) async throws
  • Merges a value with the current value of the node referred by this instance.

    Note: In most cases, you should rather use the merge(with:at:) overload that takes an Encodable parameter.

    Unlike what happens with the set(_:_:at:):

    • json must be a valid JSON object,
    • existing direct children (i.e. the descendants at the first level of depth) that exist in the current value are preserved when json does not specify them.

    Declaration

    Swift

    @discardableResult
    public func merge(_ raw: WebcomMarkers.Raw, with json: [String : Any], at time: DatasyncTime = .now) -> WebcomFuture<Void>

    Parameters

    raw

    Use the .raw value to disambiguate with the merge(with:at:) overload that takes an Encodable parameter.

    json

    The value to merge with. It must be a valid JSON object.

    time

    The time at which to perform the operation.

    Return Value

    A future with a void value.

  • merge(_:with:at:) Asynchronous

    Declaration

    Swift

    public func merge(_ raw: WebcomMarkers.Raw, with json: [String : Any], at time: DatasyncTime = .now) async throws
  • Merges a value with the current value of the node referred by this instance.

    Unlike what happens with the set(_:at:):

    • value may not be nil,
    • the encoding of value to JSON must give a JSON object (or a JSON array but this is discouraged), or the method will fail,
    • existing direct children (i.e. the descendants at the first level of depth) that exist in the current value are preserved when value does not specify them.

    Declaration

    Swift

    @discardableResult
    public func merge(with value: some Encodable, at time: DatasyncTime = .now) -> WebcomFuture<Void>

    Parameters

    value

    The value to merge with. It will be encoded to JSON before being sent to the back-end, using the WebcomApplication.jsonEncoder of the WebcomApplication from which this node derives.

    time

    The time at which to perform the operation.

    Return Value

    A future with a void value.

  • merge(with:at:) Asynchronous

    Declaration

    Swift

    public func merge(with value: some Encodable, at time: DatasyncTime = .now) async throws
  • Adds a new child with the given value to the node referred by this instance.

    Note: In most cases, you should rather use the push(_:) overload that takes an Encodable parameter.

    This method creates a new child to the referred node and then it sets its value.

    When this method returns nil, completionCallback is called in failure with a WebcomError value indicating the reason of the failure. It may well happen that this method returns a non-nil node reference and the completionCallback is called in failure, for example if a security rule prevents writing the child.

    Declaration

    Swift

    @discardableResult
    public func push(_ raw: WebcomMarkers.Raw, _ json: Any?) -> WebcomFuture<CombineWrapper>

    Parameters

    raw

    Use the .raw value to disambiguate with the push(_:) overload that takes an Encodable parameter.

    json

    The value to set for the created child. It must be valid JSON (object, array, string, number, boolean or null). The null value can be specified with nil or NSNull().

    Return Value

    A future with a reference to the added child.

  • push(_:_:) Asynchronous

    Declaration

    Swift

    public func push(_ raw: WebcomMarkers.Raw, _ json: Any?) async throws -> DatasyncNode
  • Adds a new child with the given value to the node referred by this instance.

    This method creates a new child to the referred node and then it sets its value.

    When this method returns nil, completionCallback is called in failure with a WebcomError value indicating the reason of the failure. It may well happen that this method returns a non-nil node reference and the completionCallback is called in failure, for example if a security rule prevents writing the child.

    Declaration

    Swift

    @discardableResult
    public func push(_ value: (some Encodable)?) -> WebcomFuture<CombineWrapper>

    Parameters

    value

    The value to set for the created child. It will be encoded to JSON before being sent to the back-end, using the WebcomApplication.jsonEncoder of the WebcomApplication from which this node derives. The null value can be specified with nil or NSNull().

    Return Value

    A future with a reference to the added child.

  • push(_:) Asynchronous

    Declaration

    Swift

    public func push(_ value: (some Encodable)?) async throws -> DatasyncNode
  • Adds a new child to a node with the given value.

    This operator is equivalent to:

    node.push(value)
    

    Declaration

    Swift

    public static func += (node: CombineWrapper, value: (some Encodable)?)

    Parameters

    node

    A reference to the node to which a new child must be pushed.

    value

    The value to set for the created child.

  • Atomically increments (or decrements) the value of the node referred by this instance.

    When the node does not exist (in other words, when its initial value is null), the node is implicitly assumed having the startValue value and the increment step is added to that implicit value.

    When the node exists and its initial value is not a number, the operation fails.

    This operation is robust to concurrent increment operations. It is guaranteed that if n increment operations are performed at the same time, then the value of the node is incremented by n steps (in other words, none of the concurrent operations can overwrite another one).

    However, note that the returned value may not be synchronized with the actual value of the node, especially if other write operations are performed at the same time. You should rather use the subscribe(to:childrenConstraint:stores:file:line:queue:onEvent:onCompletion:) method to watch the actual value of the node.

    Declaration

    Swift

    public func increment(from startValue: NSNumber = 0, by step: NSNumber = 1) -> WebcomFuture<NSNumber>

    Parameters

    startValue

    The implicit initial value of the node when it does not exist.

    step

    The increment to add to the initial value to value the final value. To decrement, use a negative value.

    Return Value

    A future with the resulting value of the increment operation.

  • increment(from:by:) Asynchronous

    Declaration

    Swift

    public func increment(from startValue: NSNumber = 0, by step: NSNumber = 1) async throws -> NSNumber
  • Runs a transaction on the node referred by this instance.

    A transaction is a process that atomically sets a new value to the node depending on its initial value. In other words, the new value is computed from the initial value and it is sets only if the value of the node has not been modified in the meantime. If the value of the node just before setting the new value is no longer the initial value, then the transaction is run again.

    The transaction is specified with a function, which receives as its single parameter the initial value and returns an operation to execute. The operation may consist of setting a new value or clearing the value (which is equivalent to setting the null value). The operation may also indicate to abort the transaction.

    If the transaction consists in incrementing (or decrementing) the value of the referred node, you should rather use the increment(from:by:) method which is more efficient in this case.

    Declaration

    Swift

    @discardableResult
    public func runTransaction(_ function: @escaping DatasyncTransaction.Function) -> WebcomFuture<DatasyncTransaction.Result>

    Parameters

    function

    The function that computes the operation to execute from the initial value of the node.

    Return Value

    A future with the result of the transaction.

  • runTransaction(_:) Asynchronous

    Declaration

    Swift

    public func runTransaction(_ function: @escaping DatasyncTransaction.Function) async throws -> DatasyncTransaction.Result
  • Creates a publisher that produces a DatasyncEvent value each time the value of the referred node is modified.

    The decodedValuePublisher(for:childrenConstraint:file:line:) method can be used to directly get decoded values.

    Subscriptions made with the returned publisher must be stored explicitly to remain active, e.g. using the AnyCancellable.store(in:) method. Unlike callback-based subscriptions made with the DatasyncNode.subscribe(to:childrenConstraint:stores:file:line:queue:onEvent:onCompletion:) method, these subscriptions are not stored implicitly.

    Declaration

    Swift

    public func eventPublisher(for eventType: DatasyncEventType = .valueChange, childrenConstraint: DatasyncChildrenConstraint = .all, file: StaticString = #fileID, line: UInt = #line) -> AnyPublisher<DatasyncEvent, WebcomError>

    Parameters

    eventType

    The type of events to subscribe.

    childrenConstraint

    A constraint to filter the children of the referred node that are affected by the subscription

    file

    The file from which the method is called. This is used for debugging purposes.

    line

    The line from which the method is called. This is used for debugging purposes.

    Return Value

    A type-erased publisher that produces DatasyncEvent values and a WebcomError in case of revocation by the back-end.

  • Creates a publisher that produces a decoded value each time the value of the referred node is modified.

    This method behaves like the eventPublisher(for:childrenConstraint:file:line:) method but it returns a publisher that decodes the value. When the value of the referred node cannot be decoded, the returned publisher does not produce any value and it does not complete. Such a non-decodable value is simply ignored. If this behavior does not fit your needs, use the eventPublisher(for:childrenConstraint:file:line:) method and process the produced events as expected.

    Subscriptions made with the returned publisher must be stored explicitly to remain active, e.g. using the AnyCancellable.store(in:) method. Unlike callback-based subscriptions made with the DatasyncNode.subscribe(to:childrenConstraint:stores:file:line:queue:onEvent:onCompletion:) method, these subscriptions are not stored implicitly.

    Declaration

    Swift

    public func decodedValuePublisher<T>(for eventType: DatasyncEventType = .valueChange, childrenConstraint: DatasyncChildrenConstraint = .all, file: StaticString = #fileID, line: UInt = #line) -> AnyPublisher<T, WebcomError> where T : Decodable

    Parameters

    eventType

    The type of events to subscribe.

    childrenConstraint

    A constraint to filter the children of the referred node that are affected by the subscription.

    file

    The file from which the method is called. This is used for debugging purposes.

    line

    The line from which the method is called. This is used for debugging purposes.

    Return Value

    A type-erased publisher that produces decoded values and a WebcomError in case of revocation by the back-end.

  • Copies the value of the node referred by this instance to another node.

    All children of the destination node are cleared before setting its value.

    Declaration

    Swift

    public func copyValue(to destinationNode: DatasyncNode.CombineWrapper) -> WebcomFuture<DatasyncValue>

    Parameters

    destinationNode

    A reference to the node to set with the value of this node.

    Return Value

    A future with the copied value.

  • copyValue(to:) Asynchronous

    Declaration

    Swift

    public func copyValue(to destinationNode: DatasyncNode.CombineWrapper) async throws -> DatasyncValue
  • Copies the value of the node referred by this instance to another node.

    All children of the destination node are cleared before setting its value.

    Declaration

    Swift

    public func copyValue(to destinationPath: String) -> WebcomFuture<DatasyncValue>

    Parameters

    destinationPath

    The path of the node to set with the value of this node.

    Return Value

    A future with the copied value.

  • copyValue(to:) Asynchronous

    Declaration

    Swift

    public func copyValue(to destinationNode: String) async throws -> DatasyncValue