-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathParseInstallation+combine.swift
143 lines (132 loc) · 7.17 KB
/
ParseInstallation+combine.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// ParseInstallation+combine.swift
// ParseSwift
//
// Created by Corey Baker on 1/29/21.
// Copyright © 2021 Parse Community. All rights reserved.
//
#if canImport(Combine)
import Foundation
import Combine
public extension ParseInstallation {
// MARK: Fetchable - Combine
/**
Fetches the `ParseInstallation` *aynchronously* with the current data from the server
and sets an error if one occurs. Publishes when complete.
- parameter includeKeys: The name(s) of the key(s) to include that are
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
`includeAll` for `Query`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- important: If an object fetched has the same objectId as current, it will automatically update the current.
- note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
desires a different policy, it should be inserted in `options`.
*/
func fetchPublisher(includeKeys: [String]? = nil,
options: API.Options = []) -> Future<Self, ParseError> {
Future { promise in
self.fetch(includeKeys: includeKeys,
options: options,
completion: promise)
}
}
// MARK: Savable - Combine
/**
Saves the `ParseInstallation` *asynchronously* and publishes when complete.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- important: If an object saved has the same objectId as current, it will automatically update the current.
*/
func savePublisher(isIgnoreCustomObjectIdConfig: Bool = false,
options: API.Options = []) -> Future<Self, ParseError> {
Future { promise in
self.save(isIgnoreCustomObjectIdConfig: isIgnoreCustomObjectIdConfig,
options: options,
completion: promise)
}
}
// MARK: Deletable - Combine
/**
Deletes the `ParseInstallation` *asynchronously* and publishes when complete.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- important: If an object deleted has the same objectId as current, it will automatically update the current.
*/
func deletePublisher(options: API.Options = []) -> Future<Void, ParseError> {
Future { promise in
self.delete(options: options, completion: promise)
}
}
}
// MARK: Batch Support - Combine
public extension Sequence where Element: ParseInstallation {
/**
Fetches a collection of installations *aynchronously* with the current data from the server and sets
an error if one occurs. Publishes when complete.
- parameter includeKeys: The name(s) of the key(s) to include that are
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
`includeAll` for `Query`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- important: If an object fetched has the same objectId as current, it will automatically update the current.
*/
func fetchAllPublisher(includeKeys: [String]? = nil,
options: API.Options = []) -> Future<[(Result<Self.Element, ParseError>)], ParseError> {
Future { promise in
self.fetchAll(includeKeys: includeKeys,
options: options,
completion: promise)
}
}
/**
Saves a collection of installations *asynchronously* and publishes when complete.
- parameter batchLimit: The maximum number of objects to send in each batch. If the items to be batched.
is greater than the `batchLimit`, the objects will be sent to the server in waves up to the `batchLimit`.
Defaults to 50.
- parameter transaction: Treat as an all-or-nothing operation. If some operation failure occurs that
prevents the transaction from completing, then none of the objects are committed to the Parse Server database.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- important: If an object saved has the same objectId as current, it will automatically update the current.
- warning: If `transaction = true`, then `batchLimit` will be automatically be set to the amount of the
objects in the transaction. The developer should ensure their respective Parse Servers can handle the limit or else
the transactions can fail.
*/
func saveAllPublisher(batchLimit limit: Int? = nil,
transaction: Bool = false,
isIgnoreCustomObjectIdConfig: Bool = false,
options: API.Options = []) -> Future<[(Result<Self.Element, ParseError>)], ParseError> {
Future { promise in
self.saveAll(batchLimit: limit,
transaction: transaction,
isIgnoreCustomObjectIdConfig: isIgnoreCustomObjectIdConfig,
options: options,
completion: promise)
}
}
/**
Deletes a collection of installations *asynchronously* and publishes when complete.
- parameter batchLimit: The maximum number of objects to send in each batch. If the items to be batched.
is greater than the `batchLimit`, the objects will be sent to the server in waves up to the `batchLimit`.
Defaults to 50.
- parameter transaction: Treat as an all-or-nothing operation. If some operation failure occurs that
prevents the transaction from completing, then none of the objects are committed to the Parse Server database.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- important: If an object deleted has the same objectId as current, it will automatically update the current.
- warning: If `transaction = true`, then `batchLimit` will be automatically be set to the amount of the
objects in the transaction. The developer should ensure their respective Parse Servers can handle the limit or else
the transactions can fail.
*/
func deleteAllPublisher(batchLimit limit: Int? = nil,
transaction: Bool = false,
options: API.Options = []) -> Future<[(Result<Void, ParseError>)], ParseError> {
Future { promise in
self.deleteAll(batchLimit: limit,
transaction: transaction,
options: options,
completion: promise)
}
}
}
#endif