Skip to content

Commit 1838f09

Browse files
committed
Rename v2 types
1 parent 20534e0 commit 1838f09

16 files changed

+110
-185
lines changed

Examples/SlackClone/MessagesView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class MessagesViewModel {
3535
}
3636
}
3737

38-
private var realtimeChannelV2: RealtimeChannel?
38+
private var realtimeChannelV2: RealtimeChannelV2?
3939
private var observationTask: Task<Void, Never>?
4040

4141
func startObservingNewMessages() {

Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Realtime/CallbackManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class CallbackManager: @unchecked Sendable {
2121
@discardableResult
2222
func addBroadcastCallback(
2323
event: String,
24-
callback: @escaping @Sendable (_RealtimeMessage) -> Void
24+
callback: @escaping @Sendable (RealtimeMessageV2) -> Void
2525
) -> Int {
2626
mutableState.withValue {
2727
$0.id += 1
@@ -96,7 +96,7 @@ final class CallbackManager: @unchecked Sendable {
9696
}
9797
}
9898

99-
func triggerBroadcast(event: String, message: _RealtimeMessage) {
99+
func triggerBroadcast(event: String, message: RealtimeMessageV2) {
100100
let broadcastCallbacks = mutableState.callbacks.compactMap {
101101
if case let .broadcast(callback) = $0 {
102102
return callback
@@ -110,7 +110,7 @@ final class CallbackManager: @unchecked Sendable {
110110
func triggerPresenceDiffs(
111111
joins: [String: Presence],
112112
leaves: [String: Presence],
113-
rawMessage: _RealtimeMessage
113+
rawMessage: RealtimeMessageV2
114114
) {
115115
let presenceCallbacks = mutableState.callbacks.compactMap {
116116
if case let .presence(callback) = $0 {
@@ -139,7 +139,7 @@ struct PostgresCallback {
139139
struct BroadcastCallback {
140140
var id: Int
141141
var event: String
142-
var callback: @Sendable (_RealtimeMessage) -> Void
142+
var callback: @Sendable (RealtimeMessageV2) -> Void
143143
}
144144

145145
struct PresenceCallback {

Sources/Realtime/Channel.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct RealtimeChannelConfig: Sendable {
1515
public var presence: PresenceJoinConfig
1616
}
1717

18-
public final class RealtimeChannel: @unchecked Sendable {
18+
public final class RealtimeChannelV2: @unchecked Sendable {
1919
public enum Status {
2020
case unsubscribed
2121
case subscribing
@@ -87,7 +87,7 @@ public final class RealtimeChannel: @unchecked Sendable {
8787

8888
debug("subscribing to channel with body: \(joinConfig)")
8989

90-
try? await socket?.send(_RealtimeMessage(
90+
try? await socket?.send(RealtimeMessageV2(
9191
joinRef: nil,
9292
ref: socket?.makeRef().description ?? "",
9393
topic: topic,
@@ -101,7 +101,7 @@ public final class RealtimeChannel: @unchecked Sendable {
101101
debug("unsubscribing from channel \(topic)")
102102

103103
try await socket?.send(
104-
_RealtimeMessage(
104+
RealtimeMessageV2(
105105
joinRef: nil,
106106
ref: socket?.makeRef().description,
107107
topic: topic,
@@ -114,7 +114,7 @@ public final class RealtimeChannel: @unchecked Sendable {
114114
public func updateAuth(jwt: String) async throws {
115115
debug("Updating auth token for channel \(topic)")
116116
try await socket?.send(
117-
_RealtimeMessage(
117+
RealtimeMessageV2(
118118
joinRef: nil,
119119
ref: socket?.makeRef().description,
120120
topic: topic,
@@ -129,7 +129,7 @@ public final class RealtimeChannel: @unchecked Sendable {
129129
// TODO: use HTTP
130130
} else {
131131
try await socket?.send(
132-
_RealtimeMessage(
132+
RealtimeMessageV2(
133133
joinRef: nil,
134134
ref: socket?.makeRef().description,
135135
topic: topic,
@@ -151,7 +151,7 @@ public final class RealtimeChannel: @unchecked Sendable {
151151
)
152152
}
153153

154-
try await socket?.send(_RealtimeMessage(
154+
try await socket?.send(RealtimeMessageV2(
155155
joinRef: nil,
156156
ref: socket?.makeRef().description,
157157
topic: topic,
@@ -165,7 +165,7 @@ public final class RealtimeChannel: @unchecked Sendable {
165165
}
166166

167167
public func untrack() async throws {
168-
try await socket?.send(_RealtimeMessage(
168+
try await socket?.send(RealtimeMessageV2(
169169
joinRef: nil,
170170
ref: socket?.makeRef().description,
171171
topic: topic,
@@ -177,7 +177,7 @@ public final class RealtimeChannel: @unchecked Sendable {
177177
))
178178
}
179179

180-
func onMessage(_ message: _RealtimeMessage) async throws {
180+
func onMessage(_ message: RealtimeMessageV2) async throws {
181181
guard let eventType = message.eventType else {
182182
throw RealtimeError("Received message without event type: \(message)")
183183
}
@@ -331,8 +331,8 @@ public final class RealtimeChannel: @unchecked Sendable {
331331

332332
/// Listen for broadcast messages sent by other clients within the same channel under a specific
333333
/// `event`.
334-
public func broadcast(event: String) -> AsyncStream<_RealtimeMessage> {
335-
let (stream, continuation) = AsyncStream<_RealtimeMessage>.makeStream()
334+
public func broadcast(event: String) -> AsyncStream<RealtimeMessageV2> {
335+
let (stream, continuation) = AsyncStream<RealtimeMessageV2>.makeStream()
336336

337337
let id = callbackManager.addBroadcastCallback(event: event) {
338338
continuation.yield($0)

Sources/Realtime/Deprecated.swift

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,87 +9,3 @@ import Foundation
99

1010
@available(*, deprecated, renamed: "RealtimeMessage")
1111
public typealias Message = RealtimeMessage
12-
13-
extension RealtimeChannel {
14-
@available(
15-
*,
16-
deprecated,
17-
message: "Please use one of postgresChanges, presenceChange, or broadcast methods that returns an AsyncSequence instead."
18-
)
19-
@discardableResult
20-
public func on(
21-
_ event: String,
22-
filter: ChannelFilter,
23-
handler: @escaping (_RealtimeMessage) -> Void
24-
) -> RealtimeChannel {
25-
let stream: AsyncStream<HasRawMessage>
26-
27-
switch event.lowercased() {
28-
case "postgres_changes":
29-
switch filter.event?.uppercased() {
30-
case "UPDATE":
31-
stream = postgresChange(
32-
UpdateAction.self,
33-
schema: filter.schema ?? "public",
34-
table: filter.table!,
35-
filter: filter.filter
36-
)
37-
.map { $0 as HasRawMessage }
38-
.eraseToStream()
39-
case "INSERT":
40-
stream = postgresChange(
41-
InsertAction.self,
42-
schema: filter.schema ?? "public",
43-
table: filter.table!,
44-
filter: filter.filter
45-
)
46-
.map { $0 as HasRawMessage }
47-
.eraseToStream()
48-
case "DELETE":
49-
stream = postgresChange(
50-
DeleteAction.self,
51-
schema: filter.schema ?? "public",
52-
table: filter.table!,
53-
filter: filter.filter
54-
)
55-
.map { $0 as HasRawMessage }
56-
.eraseToStream()
57-
case "SELECT":
58-
stream = postgresChange(
59-
SelectAction.self,
60-
schema: filter.schema ?? "public",
61-
table: filter.table!,
62-
filter: filter.filter
63-
)
64-
.map { $0 as HasRawMessage }
65-
.eraseToStream()
66-
default:
67-
stream = postgresChange(
68-
AnyAction.self,
69-
schema: filter.schema ?? "public",
70-
table: filter.table!,
71-
filter: filter.filter
72-
)
73-
.map { $0 as HasRawMessage }
74-
.eraseToStream()
75-
}
76-
77-
case "presence":
78-
stream = presenceChange().map { $0 as HasRawMessage }.eraseToStream()
79-
case "broadcast":
80-
stream = broadcast(event: filter.event!).map { $0 as HasRawMessage }.eraseToStream()
81-
default:
82-
fatalError(
83-
"Unsupported event '\(event)'. Expected one of: postgres_changes, presence, or broadcast."
84-
)
85-
}
86-
87-
Task {
88-
for await action in stream {
89-
handler(action.rawMessage)
90-
}
91-
}
92-
93-
return self
94-
}
95-
}

Sources/Realtime/PostgresAction.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public protocol HasOldRecord {
2626
}
2727

2828
public protocol HasRawMessage {
29-
var rawMessage: _RealtimeMessage { get }
29+
var rawMessage: RealtimeMessageV2 { get }
3030
}
3131

3232
public struct InsertAction: PostgresAction, HasRecord, HasRawMessage {
@@ -35,7 +35,7 @@ public struct InsertAction: PostgresAction, HasRecord, HasRawMessage {
3535
public let columns: [Column]
3636
public let commitTimestamp: Date
3737
public let record: [String: AnyJSON]
38-
public let rawMessage: _RealtimeMessage
38+
public let rawMessage: RealtimeMessageV2
3939
}
4040

4141
public struct UpdateAction: PostgresAction, HasRecord, HasOldRecord, HasRawMessage {
@@ -44,7 +44,7 @@ public struct UpdateAction: PostgresAction, HasRecord, HasOldRecord, HasRawMessa
4444
public let columns: [Column]
4545
public let commitTimestamp: Date
4646
public let record, oldRecord: [String: AnyJSON]
47-
public let rawMessage: _RealtimeMessage
47+
public let rawMessage: RealtimeMessageV2
4848
}
4949

5050
public struct DeleteAction: PostgresAction, HasOldRecord, HasRawMessage {
@@ -53,7 +53,7 @@ public struct DeleteAction: PostgresAction, HasOldRecord, HasRawMessage {
5353
public let columns: [Column]
5454
public let commitTimestamp: Date
5555
public let oldRecord: [String: AnyJSON]
56-
public let rawMessage: _RealtimeMessage
56+
public let rawMessage: RealtimeMessageV2
5757
}
5858

5959
public struct SelectAction: PostgresAction, HasRecord, HasRawMessage {
@@ -62,7 +62,7 @@ public struct SelectAction: PostgresAction, HasRecord, HasRawMessage {
6262
public let columns: [Column]
6363
public let commitTimestamp: Date
6464
public let record: [String: AnyJSON]
65-
public let rawMessage: _RealtimeMessage
65+
public let rawMessage: RealtimeMessageV2
6666
}
6767

6868
public enum AnyAction: PostgresAction, HasRawMessage {
@@ -82,7 +82,7 @@ public enum AnyAction: PostgresAction, HasRawMessage {
8282
}
8383
}
8484

85-
public var rawMessage: _RealtimeMessage {
85+
public var rawMessage: RealtimeMessageV2 {
8686
wrappedAction.rawMessage
8787
}
8888
}

Sources/Realtime/Presence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public final class Presence {
163163

164164
// ----------------------------------------------------------------------
165165
/// The channel the Presence belongs to
166-
weak var channel: OldRealtimeChannel?
166+
weak var channel: RealtimeChannel?
167167

168168
/// Caller to callback hooks
169169
var caller: Caller
@@ -215,7 +215,7 @@ public final class Presence {
215215
onSync = callback
216216
}
217217

218-
public init(channel: OldRealtimeChannel, opts: Options = Options.defaults) {
218+
public init(channel: RealtimeChannel, opts: Options = Options.defaults) {
219219
state = [:]
220220
pendingDiffs = []
221221
self.channel = channel

Sources/Realtime/PresenceAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ public protocol PresenceAction: HasRawMessage {
2222
struct PresenceActionImpl: PresenceAction {
2323
var joins: [String: Presence]
2424
var leaves: [String: Presence]
25-
var rawMessage: _RealtimeMessage
25+
var rawMessage: RealtimeMessageV2
2626
}

Sources/Realtime/Push.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Foundation
2323
/// Represnts pushing data to a `Channel` through the `Socket`
2424
public class Push {
2525
/// The channel sending the Push
26-
public weak var channel: OldRealtimeChannel?
26+
public weak var channel: RealtimeChannel?
2727

2828
/// The event, for example `phx_join`
2929
public let event: String
@@ -62,7 +62,7 @@ public class Push {
6262
/// - parameter payload: Optional. The Payload to send, e.g. ["user_id": "abc123"]
6363
/// - parameter timeout: Optional. The push timeout. Default is 10.0s
6464
init(
65-
channel: OldRealtimeChannel,
65+
channel: RealtimeChannel,
6666
event: String,
6767
payload: Payload = [:],
6868
timeout: TimeInterval = Defaults.timeoutInterval

0 commit comments

Comments
 (0)