Skip to content

refactor: add private access control to lock isolated values #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/conventional-commits-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ALLOWED_CONVENTIONAL_COMMIT_PREFIXES = [
"chore",
"style",
"test",
"refactor",
];

const object = process.argv[2];
Expand Down Expand Up @@ -102,4 +103,4 @@ if (failed) {
process.exit(1);
}

process.exit(0);
process.exit(0);
2 changes: 1 addition & 1 deletion Sources/PostgREST/PostgrestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class PostgrestClient: Sendable {
}
}

let _configuration: LockIsolated<Configuration>
private let _configuration: LockIsolated<Configuration>
public var configuration: Configuration { _configuration.value }

/// Creates a PostgREST client with the specified configuration.
Expand Down
10 changes: 9 additions & 1 deletion Sources/Realtime/V2/CallbackManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ final class CallbackManager: @unchecked Sendable {
var callbacks: [RealtimeCallback] = []
}

let mutableState = LockIsolated(MutableState())
private let mutableState = LockIsolated(MutableState())

var serverChanges: [PostgresJoinConfig] {
mutableState.serverChanges
}

var callbacks: [RealtimeCallback] {
mutableState.callbacks
}

@discardableResult
func addBroadcastCallback(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Realtime/V2/WebSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class WebSocket: NSObject, URLSessionWebSocketDelegate, WebSocketClient, @
var stream: SocketStream?
}

let mutableState = LockIsolated(MutableState())
private let mutableState = LockIsolated(MutableState())

init(config: RealtimeClientV2.Configuration) {
realtimeURL = config.realtimeWebSocketURL
Expand Down
2 changes: 1 addition & 1 deletion Sources/_Helpers/EventEmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class ObservationToken: Sendable {
package final class EventEmitter<Event: Sendable>: Sendable {
public typealias Listener = @Sendable (Event) -> Void

let listeners = LockIsolated<[ObjectIdentifier: Listener]>([:])
private let listeners = LockIsolated<[ObjectIdentifier: Listener]>([:])
public let lastEvent: LockIsolated<Event>

let emitsLastEventWhenAttaching: Bool
Expand Down
8 changes: 4 additions & 4 deletions Tests/RealtimeTests/CallbackManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ final class CallbackManagerTests: XCTestCase {

XCTAssertEqual(callbackManager.addPresenceCallback { _ in }, 3)

XCTAssertEqual(callbackManager.mutableState.value.callbacks.count, 3)
XCTAssertEqual(callbackManager.callbacks.count, 3)

callbackManager.removeCallback(id: 2)
callbackManager.removeCallback(id: 3)

XCTAssertEqual(callbackManager.mutableState.value.callbacks.count, 1)
XCTAssertEqual(callbackManager.callbacks.count, 1)
XCTAssertFalse(
callbackManager.mutableState.value.callbacks
callbackManager.callbacks
.contains(where: { $0.id == 2 || $0.id == 3 })
)
}
Expand All @@ -62,7 +62,7 @@ final class CallbackManagerTests: XCTestCase {

callbackManager.setServerChanges(changes: changes)

XCTAssertEqual(callbackManager.mutableState.value.serverChanges, changes)
XCTAssertEqual(callbackManager.serverChanges, changes)
}

func testTriggerPostgresChanges() {
Expand Down
Loading