Skip to content

Commit 7828cb0

Browse files
authored
Support replacing utilities in StreamChat (#27)
1 parent 2b7780e commit 7828cb0

File tree

8 files changed

+12
-29
lines changed

8 files changed

+12
-29
lines changed

Sources/StreamCore/Utils/Data+Gzip.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension Data {
3535
///
3636
/// - Returns: Gzip-compressed `Data` instance.
3737
/// - Throws: `GzipError`
38-
func gzipped() throws -> Data {
38+
public func gzipped() throws -> Data {
3939
guard !isEmpty else {
4040
return Data()
4141
}

Sources/StreamCore/Utils/HTTPUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Foundation
66

77
extension URLRequest {
8-
var queryItems: [URLQueryItem] {
8+
public var queryItems: [URLQueryItem] {
99
if let url,
1010
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false),
1111
let queryItems = urlComponents.queryItems {
@@ -16,7 +16,7 @@ extension URLRequest {
1616
}
1717

1818
extension Array where Element == URLQueryItem {
19-
var prettyPrinted: String {
19+
public var prettyPrinted: String {
2020
var message = ""
2121

2222
forEach { item in

Sources/StreamCore/Utils/RawJSON.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public indirect enum RawJSON: Codable, Hashable, Sendable {
1515
case array([RawJSON])
1616
case `nil`
1717

18-
static let double = number
18+
public static let double = number
1919

2020
public init(from decoder: Decoder) throws {
2121
let singleValueContainer = try decoder.singleValueContainer()
@@ -294,7 +294,7 @@ extension RawJSON {
294294
/// let price = customData["flight"]?["price"].numberValue
295295
/// let destination = customData["flight"]?["destination"].stringValue
296296
/// ```
297-
subscript(key: String) -> RawJSON? {
297+
public subscript(key: String) -> RawJSON? {
298298
get {
299299
guard case let .dictionary(dict) = self else {
300300
return nil
@@ -320,7 +320,7 @@ extension RawJSON {
320320
/// let customData = message.customData
321321
/// let secondFlightPrice = customData["flights"]?[1]?["price"] ?? 0
322322
/// ```
323-
subscript(index: Int) -> RawJSON? {
323+
public subscript(index: Int) -> RawJSON? {
324324
get {
325325
guard case let .array(array) = self else {
326326
return nil

Sources/StreamCore/Utils/StreamRuntimeCheck.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,4 @@ public enum StreamRuntimeCheck {
99
///
1010
/// When set to false, a message will be logged on console, but the assertion will not be thrown.
1111
public nonisolated(unsafe) static var assertionsEnabled = false
12-
13-
/// For *internal use* only
14-
///
15-
/// Established the maximum depth of relationships to fetch when performing a mapping
16-
///
17-
/// Eg.
18-
/// Relationship: Message ---> QuotedMessage ---> QuotedMessage ---X--- NIL
19-
/// Relationship: Channel ---> Message ---> QuotedMessage ---X--- NIL
20-
/// Depth: 0 1 2 3
21-
nonisolated(unsafe) static var _backgroundMappingRelationshipsMaxDepth = 2
22-
23-
/// For *internal use* only
24-
///
25-
/// Returns true if the maximum depth of relationships to fetch when performing a mapping is not yet met
26-
static func _canFetchRelationship(currentDepth: Int) -> Bool {
27-
currentDepth <= _backgroundMappingRelationshipsMaxDepth
28-
}
29-
30-
/// For *internal use* only
31-
///
32-
/// Core Data prefetches data used for creating immutable model objects (faulting is disabled).
33-
public nonisolated(unsafe) static var _isDatabasePrefetchingEnabled = false
3412
}

Sources/StreamCore/Utils/StringExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension String {
5353
}
5454

5555
extension StringProtocol {
56-
func ranges<S: StringProtocol>(of string: S, options: String.CompareOptions = []) -> [Range<String.Index>] {
56+
public func ranges<S: StringProtocol>(of string: S, options: String.CompareOptions = []) -> [Range<String.Index>] {
5757
var result: [Range<Index>] = []
5858
var startIndex = startIndex
5959
while startIndex < endIndex, let range = self[startIndex...].range(of: string, options: options) {

Sources/StreamCore/Utils/Timers.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public protocol TimerControl {
5555
}
5656

5757
extension DispatchWorkItem: TimerControl {}
58+
extension DispatchWorkItem: @retroactive @unchecked Sendable {}
5859

5960
/// Default real-world implementations of timers.
6061
public struct DefaultTimer: StreamTimer {
@@ -116,7 +117,11 @@ private class RepeatingTimer: RepeatingTimerControl, @unchecked Sendable {
116117

117118
private let queue = DispatchQueue(label: "io.getstream.repeating-timer")
118119
private var state: State = .suspended
120+
#if compiler(>=6.1)
119121
private let timer: DispatchSourceTimer
122+
#else
123+
private nonisolated(unsafe) let timer: DispatchSourceTimer
124+
#endif
120125

121126
init(timeInterval: TimeInterval, queue: DispatchQueue, onFire: @escaping () -> Void) {
122127
timer = DispatchSource.makeTimerSource(queue: queue)

0 commit comments

Comments
 (0)