DataNode
public final class DataNode : Hashable, CustomStringConvertible
extension DataNode: WebcomCombinable
An object that represents a reference to a database node.
By abuse of language, the node reference is sometimes assimilate with the referred node itself. This does not usually preclude understanding. Just keep in mind that there may be several references for the same database node.
Instances are created using the DataService.node(for:) method of a DataService instance.
-
The absolute path of the node referred by this instance.
The path consists of the keys of the ancestors of this node, starting from the root of the tree, separated by
/(slash) characters. The last segment of the path is the key of this node. The before last segment of the path, if any, is the key of the parent of this node. The path always begins with a/. The path of the root node is"/".Declaration
Swift
public let path: String
-
A reference to the parent of the node referred by this instance.
The root node does not have a parent, so this property returns
nilfor the root node. For all other nodes, this property never returnsnil.Note: With a reference to the root node,
relativeNode(for: "..")returns a reference to the root node.Since
2.2.0Declaration
Swift
public var parent: DataNode? { get } -
Returns a reference to another node, relatively to the node referred by this instance.
This method always succeeds. If the
pathis ill-formed, it is the methods of the resulting instance that will fail.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 thepath, 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
pathis equal togeek,/geek,geek/or/geek/, the path of the resulting node is/foo/bar/geek, - and
pathis equal to../geek/noobor/../geek//noob/.or../geek/./noob/., the path of the resulting node is/foo/geek/noob, - and
pathis equal to../geek/../..//../.., the resulting node is the root node.
Note: With a reference to the root node,
parentreturnsnil.Since
2.2.0Declaration
Swift
public func relativeNode(for path: String) -> DataNodeParameters
pathThe 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. -
Returns a reference to a database node, relatively to a base node.
This operator returns:
node.relativeNode(for: path)Since
2.2.0Declaration
Swift
public static func / (node: DataNode, path: String) -> DataNodeParameters
nodeA reference to the base node.
pathThe 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.
-
Gets the value of the node referred by this instance.
The value is not returned synchronously, but a callback is called asynchronously with the value as its parameter.
The
decodedValue(session:queue:then:)method can be used to get decoded values. Thekeys(session:)method can be used to get only the keys of the children of the node.Declaration
Swift
public func value(session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: @escaping WebcomResult<DataValue>.Callback)Parameters
queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the application of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with the current value of the referred node. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure.sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used. -
Gets the value of the node referred by this instance.
The value is not returned synchronously, but a callback is called asynchronously with the value as its parameter.
This method behaves like the
value(session:queue:then:)method with a callback that receives a decoded value in case of success. When the value cannot be decoded, thecompletionCallbackis called with an error having theWebcomError.SDKCode.decodingFailedcode. If this behavior does not fit your needs, use thevalue(session:queue:then:)method and process the callback parameter as expected.The decoding is done using the
WebcomApplication.jsonDecoderof theWebcomApplicationfrom which this node derives.Declaration
Swift
public func decodedValue<T>(session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: @escaping WebcomResult<T>.Callback) where T : DecodableParameters
queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the manager of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with the decoded current value of the referred node. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure.sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used. -
Gets the keys of the children of the node referred by this instance.
When the node has no child, an empty array is got.
The keys are not returned synchronously, but a callback is called asynchronously with the value as its parameter.
The
value(session:queue:then:)method may be used to get the full value of the node.Since
2.2.0Declaration
Swift
public func childrenKeys(session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: @escaping WebcomResult<[WebcomKey]>.Callback)Parameters
sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used.queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the application of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with the keys of the children of the referred node. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure. -
Gets the keys of the children of the node referred by this instance.
Warning
This method was deprecated in version 2.2.0. UsechildrenKeys(session:queue:then:)instead.Declaration
Swift
@available(*, deprecated, renamed: "childrenKeys(session:queue:then:﹚") public func keys(session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: @escaping WebcomResult<[WebcomKey]>.Callback) -
Clears the value of the node referred by this instance.
Clearing the value is equivalent to setting a JSON
nullvalue. Therefore, calling this method is equivalent to call:set(nil, session: session, queue: queue, then: completionCallback)Declaration
Swift
public func clear(session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)Parameters
queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the application of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure.sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used. -
Sets the value of the node referred by this instance.
Note: In most cases, you should rather use the
set(_:session:queue:then:)overload that takes anEncodableparameter.All children of the referred node cleared before setting the new value. The
merge(_:with:session:queue:then:)method may be used to merge existing children with the ones of thevaluewhen it is a JSON object or array.Declaration
Swift
public func set(_ raw: WebcomMarkers.Raw, _ json: Any?, session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)Parameters
rawUse the
.rawvalue to disambiguate with theset(_:session:queue:then:)overload that takes anEncodableparameter.jsonThe value to set. It must be valid JSON (object, array, string, number, boolean or
null). Thenullvalue can be specified withnilorNSNull().queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the application of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure.sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used. -
Sets the value of the node referred by this instance.
All children of the referred node are cleared before setting the new value. The
merge(with:session:queue:then:)method may be used to merge existing children with the ones of thevaluewhen it is a JSON object or array.Declaration
Swift
public func set(_ value: (some Encodable)?, session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)Parameters
valueThe value to set. It will be encoded to JSON before being sent to the back-end, using the
WebcomApplication.jsonEncoderof theWebcomApplicationfrom which this node derives. Thenullvalue can be specified withnilorNSNull().queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the manager of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure.sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used. -
Sets the value of a node.
This operator is equivalent to:
node.set(value)Declaration
Swift
public static func <- (node: DataNode, value: (some Encodable)?)Parameters
nodeA reference to the node whose value must be set.
valueThe value to set.
-
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:session:queue:then:)overload that takes anEncodableparameter.Unlike what happens with the
set(_:_:session:queue:then:):jsonmust 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
jsondoes not specify them.
Declaration
Swift
public func merge(_ raw: WebcomMarkers.Raw, with json: [String : Any], session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)Parameters
rawUse the
.rawvalue to disambiguate with themerge(with:session:queue:then:)overload that takes anEncodableparameter.jsonThe value to merge with. It must be a valid JSON object.
queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the manager of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure.sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used. -
Merges a value with the current value of the node referred by this instance.
Unlike what happens with the
set(_:session:queue:then:):valuemay not benil,- the encoding of
valueto 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
valuedoes not specify them.
Declaration
Swift
public func merge(with value: (some Encodable)?, session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)Parameters
valueThe value to merge with. It will be encoded to JSON before being sent to the back-end, using the
WebcomApplication.jsonEncoderof theWebcomApplicationfrom which this node derives.queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the manager of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure.sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used. -
Subscribes to events related to the value of the referred node through remote notifications (push notifications).
This method requires that:
- the current user is authenticated,
Webcom.deviceTokenis set.
There can be at most one subscription of this type per node, per user and per device. Therefore, a new subscription of this type for the same node, the same user and the same device overwrites the first one.
The subscription is stored by the
DataServiceinstance, whether it succeeded or failed. TheDataService.unsubscribeFromAllThroughNotifications(session:queue:then:)method may be used to cancel all subscriptions that used notifications at the same time. TheDataService.updateDeviceTokenInAllSubscriptions(file:line:session:queue:then:)method may be used to update the device token of all subscriptions.Declaration
Swift
public func subscribeThroughNotifications(descriptor: DataSubscriptionDescriptor, file: StaticString = #fileID, line: UInt = #line, session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<DataSubscription>.Callback? = nil)Parameters
descriptorThe descriptor for the subscription.
fileThe file from which the method is called. This is used for debugging purposes.
lineThe line from which the method is called. This is used for debugging purposes.
sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used.queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the application of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a value representing the subscription. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure. -
Cancels the possible subscription through remote notifications (push notifications) for the referred node.
This method requires that the current user is authenticated.
When there is currently no subscription of this type for the referred node, the current user and the current device, this method is a no-operation.
Declaration
Swift
public func unsubscribeThroughNotifications(session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)Parameters
sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used.queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the application of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure. -
Subscribes to events related to the value of the referred node through a webhook.
This method requires that the current user is authenticated.
There can be at most one subscription of this type per node, per user and per device for a given
identifierand a givencontext. Therefore, a new subscription of this type for the same node, the same user, the same device, the sameidentifierand the samecontextoverwrites the first one.The subscription is stored by the
DataServiceinstance, whether it succeeded or failed. TheDataService.unsubscribeFromAllThroughWebhook(session:queue:then:)method may be used to cancel all subscriptions that used notifications at the same time.Declaration
Swift
public func subscribeThroughWebhook(_ identifier: String, context: String, descriptor: DataSubscriptionDescriptor, file: StaticString = #fileID, line: UInt = #line, session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<DataSubscription>.Callback? = nil)Parameters
identifierThe identifier of the webhook to subscribe to.
fileThe file from which the method is called. This is used for debugging purposes.
lineThe line from which the method is called. This is used for debugging purposes.
contextThe value to pass to the webhook when the value of the referred node is modified.
descriptorThe descriptor for the subscription.
sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used.queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the application of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a value representing the subscription. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure. -
Cancels the possible subscription through a webhook for the referred node.
This method requires that the current user is authenticated.
When there is currently no subscription of this type for the referred node, the current user, the current device, the same
identifierand the samecontext, this method is a no-operation.Declaration
Swift
public func unsubscribeThroughWebhook(_ identifier: String, context: String, session: URLSession? = nil, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)Parameters
identifierThe identifier of the webhook to unsubscribe from.
contextThe value passed to the webhook as it was set in the subscription.
sessionThe session used to send the request to the back-end. When
nil, the default session of the application of this instance is used.queueThe queue to which the provided callback dispatches. When
nil, the default callback queue of the application of this instance is used.completionCallbackThe closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a
WebcomErrorvalue indicating the reason of the failure.
-
Declaration
Swift
public static func == (left: DataNode, right: DataNode) -> Bool
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
Declaration
Swift
public var description: String { get }
-
The type that wraps
DataNodein order to enrich it with a Combine-based API.See also the documentation section of
WebcomWrapperfor the corresponding wrapped type.To use this type, import the following dependency in your code:
See moreimport WebcomCombineDeclaration
Swift
public final class CombineWrapper : WebcomWrapper, Hashable, CustomStringConvertible -
The wrapping instance, which has a Combine-based API.
Declaration
Swift
public var forCombine: CombineWrapper { get }