Skip to content

Commit 8582a29

Browse files
author
Guilherme Souza
committed
Run swift-format
1 parent 2eef548 commit 8582a29

File tree

3 files changed

+181
-178
lines changed

3 files changed

+181
-178
lines changed

Package.swift

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,37 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "Supabase",
8-
platforms: [
9-
.macOS(.v10_15),
10-
.iOS(.v11),
11-
.tvOS(.v11),
12-
.watchOS(.v3)
13-
],
14-
products: [
15-
.library(
16-
name: "Supabase",
17-
targets: ["Supabase"]
18-
)
19-
],
20-
dependencies: [
21-
.package(name: "GoTrue", url: "https://github.com/supabase/gotrue-swift.git", .branch("main")),
22-
.package(name: "SupabaseStorage", url: "https://github.com/supabase/storage-swift.git", .branch("main")),
23-
.package(name: "Realtime", url: "https://github.com/supabase/realtime-swift.git", .branch("main")),
24-
.package(name: "PostgREST", url: "https://github.com/supabase/postgrest-swift", .exact("0.0.1")),
25-
],
26-
targets: [
27-
.target(
28-
name: "Supabase",
29-
dependencies: ["GoTrue", "SupabaseStorage", "Realtime", "PostgREST"]
30-
),
31-
.testTarget(
32-
name: "SupabaseTests",
33-
dependencies: ["Supabase"]
34-
),
35-
]
7+
name: "Supabase",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v11),
11+
.tvOS(.v11),
12+
.watchOS(.v3),
13+
],
14+
products: [
15+
.library(
16+
name: "Supabase",
17+
targets: ["Supabase"]
18+
)
19+
],
20+
dependencies: [
21+
.package(name: "GoTrue", url: "https://github.com/supabase/gotrue-swift.git", .branch("main")),
22+
.package(
23+
name: "SupabaseStorage", url: "https://github.com/supabase/storage-swift.git", .branch("main")
24+
),
25+
.package(
26+
name: "Realtime", url: "https://github.com/supabase/realtime-swift.git", .branch("main")),
27+
.package(
28+
name: "PostgREST", url: "https://github.com/supabase/postgrest-swift", .exact("0.0.1")),
29+
],
30+
targets: [
31+
.target(
32+
name: "Supabase",
33+
dependencies: ["GoTrue", "SupabaseStorage", "Realtime", "PostgREST"]
34+
),
35+
.testTarget(
36+
name: "SupabaseTests",
37+
dependencies: ["Supabase"]
38+
),
39+
]
3640
)

Sources/Supabase/SupabaseClient.swift

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,76 @@ import PostgREST
33
import Realtime
44
import SupabaseStorage
55

6-
/**
7-
The main class for accessing Supabase functionality
8-
9-
Initialize this class using `.init(supabaseURL: String, supabaseKey: String)`
10-
11-
There are four main classes contained by the `Supabase` class.
12-
1. `auth`
13-
2. `database`
14-
3. `realtime`
15-
4. `storage`
16-
Each class listed is available under `Supabase.{name}`, eg: `Supabase.auth`
17-
18-
For more usage information read the README.md
19-
*/
6+
/// The main class for accessing Supabase functionality
7+
///
8+
/// Initialize this class using `.init(supabaseURL: String, supabaseKey: String)`
9+
///
10+
/// There are four main classes contained by the `Supabase` class.
11+
/// 1. `auth`
12+
/// 2. `database`
13+
/// 3. `realtime`
14+
/// 4. `storage`
15+
/// Each class listed is available under `Supabase.{name}`, eg: `Supabase.auth`
16+
///
17+
/// For more usage information read the README.md
2018
public class SupabaseClient {
21-
private var supabaseUrl: String
22-
private var supabaseKey: String
23-
private var schema: String
24-
private var restUrl: String
25-
private var realtimeUrl: String
26-
private var authUrl: String
27-
private var storageUrl: String
19+
private var supabaseUrl: String
20+
private var supabaseKey: String
21+
private var schema: String
22+
private var restUrl: String
23+
private var realtimeUrl: String
24+
private var authUrl: String
25+
private var storageUrl: String
2826

29-
/// Auth client for Supabase
30-
public var auth: GoTrueClient
27+
/// Auth client for Supabase
28+
public var auth: GoTrueClient
3129

32-
/// Storage client for Supabase.
33-
public var storage: SupabaseStorageClient {
34-
var headers: [String: String] = defaultHeaders
35-
headers["Authorization"] = "Bearer \(auth.session?.accessToken ?? supabaseKey)"
36-
return SupabaseStorageClient(url: storageUrl, headers: headers)
37-
}
30+
/// Storage client for Supabase.
31+
public var storage: SupabaseStorageClient {
32+
var headers: [String: String] = defaultHeaders
33+
headers["Authorization"] = "Bearer \(auth.session?.accessToken ?? supabaseKey)"
34+
return SupabaseStorageClient(url: storageUrl, headers: headers)
35+
}
3836

39-
/// Database client for Supabase.
40-
public var database: PostgrestClient {
41-
var headers: [String: String] = defaultHeaders
42-
headers["Authorization"] = "Bearer \(auth.session?.accessToken ?? supabaseKey)"
43-
return PostgrestClient(url: restUrl, headers: headers, schema: schema)
44-
}
37+
/// Database client for Supabase.
38+
public var database: PostgrestClient {
39+
var headers: [String: String] = defaultHeaders
40+
headers["Authorization"] = "Bearer \(auth.session?.accessToken ?? supabaseKey)"
41+
return PostgrestClient(url: restUrl, headers: headers, schema: schema)
42+
}
4543

46-
/// Realtime client for Supabase
47-
public var realtime: RealtimeClient
44+
/// Realtime client for Supabase
45+
public var realtime: RealtimeClient
4846

49-
private var defaultHeaders: [String: String]
47+
private var defaultHeaders: [String: String]
5048

51-
/// Init `Supabase` with the provided parameters.
52-
/// - Parameters:
53-
/// - supabaseUrl: Unique Supabase project url
54-
/// - supabaseKey: Supabase anonymous API Key
55-
/// - schema: Database schema name, defaults to `public`
56-
/// - autoRefreshToken: Toggles whether `Supabase.auth` automatically refreshes auth tokens. Defaults to `true`
57-
public init(
58-
supabaseUrl: String,
59-
supabaseKey: String,
60-
schema: String = "public",
61-
autoRefreshToken: Bool = true
62-
) {
63-
self.supabaseUrl = supabaseUrl
64-
self.supabaseKey = supabaseKey
65-
self.schema = schema
66-
restUrl = "\(supabaseUrl)/rest/v1"
67-
realtimeUrl = "\(supabaseUrl)/realtime/v1"
68-
authUrl = "\(supabaseUrl)/auth/v1"
69-
storageUrl = "\(supabaseUrl)/storage/v1"
49+
/// Init `Supabase` with the provided parameters.
50+
/// - Parameters:
51+
/// - supabaseUrl: Unique Supabase project url
52+
/// - supabaseKey: Supabase anonymous API Key
53+
/// - schema: Database schema name, defaults to `public`
54+
/// - autoRefreshToken: Toggles whether `Supabase.auth` automatically refreshes auth tokens. Defaults to `true`
55+
public init(
56+
supabaseUrl: String,
57+
supabaseKey: String,
58+
schema: String = "public",
59+
autoRefreshToken: Bool = true
60+
) {
61+
self.supabaseUrl = supabaseUrl
62+
self.supabaseKey = supabaseKey
63+
self.schema = schema
64+
restUrl = "\(supabaseUrl)/rest/v1"
65+
realtimeUrl = "\(supabaseUrl)/realtime/v1"
66+
authUrl = "\(supabaseUrl)/auth/v1"
67+
storageUrl = "\(supabaseUrl)/storage/v1"
7068

71-
defaultHeaders = ["X-Client-Info": "supabase-swift/0.0.1", "apikey": supabaseKey]
69+
defaultHeaders = ["X-Client-Info": "supabase-swift/0.0.1", "apikey": supabaseKey]
7270

73-
auth = GoTrueClient(
74-
url: authUrl,
75-
headers: defaultHeaders,
76-
autoRefreshToken: autoRefreshToken
77-
)
78-
realtime = RealtimeClient(endPoint: realtimeUrl, params: defaultHeaders)
79-
}
71+
auth = GoTrueClient(
72+
url: authUrl,
73+
headers: defaultHeaders,
74+
autoRefreshToken: autoRefreshToken
75+
)
76+
realtime = RealtimeClient(endPoint: realtimeUrl, params: defaultHeaders)
77+
}
8078
}

Tests/SupabaseTests/SupabaseTests.swift

Lines changed: 85 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,94 @@ import XCTest
44
@testable import Supabase
55

66
final class SupabaseTests: XCTestCase {
7-
var supabase = SupabaseClient(supabaseUrl: SupabaseTests.supabaseUrl(), supabaseKey: SupabaseTests.supabaseKey())
8-
9-
static func supabaseUrl() -> String {
10-
if let token = ProcessInfo.processInfo.environment["supabaseUrl"] {
11-
return token
12-
} else {
13-
fatalError()
14-
}
7+
var supabase = SupabaseClient(
8+
supabaseUrl: SupabaseTests.supabaseUrl(), supabaseKey: SupabaseTests.supabaseKey())
9+
10+
static func supabaseUrl() -> String {
11+
if let token = ProcessInfo.processInfo.environment["supabaseUrl"] {
12+
return token
13+
} else {
14+
fatalError()
15+
}
16+
}
17+
18+
static func supabaseKey() -> String {
19+
if let url = ProcessInfo.processInfo.environment["supabaseKey"] {
20+
return url
21+
} else {
22+
fatalError()
1523
}
16-
17-
static func supabaseKey() -> String {
18-
if let url = ProcessInfo.processInfo.environment["supabaseKey"] {
19-
return url
20-
} else {
21-
fatalError()
22-
}
24+
}
25+
26+
func testSignIN() {
27+
let e = expectation(description: "testSignIN")
28+
29+
supabase.auth.signIn(email: "[email protected]", password: "secret") { result in
30+
switch result {
31+
case let .success(session):
32+
print(session)
33+
XCTAssertNotNil(session.accessToken)
34+
case let .failure(error):
35+
print(error.localizedDescription)
36+
XCTFail("testSignIN failed: \(error.localizedDescription)")
37+
}
38+
e.fulfill()
2339
}
24-
25-
func testSignIN() {
26-
let e = expectation(description: "testSignIN")
27-
28-
supabase.auth.signIn(email: "[email protected]", password: "secret") { result in
29-
switch result {
30-
case let .success(session):
31-
print(session)
32-
XCTAssertNotNil(session.accessToken)
33-
case let .failure(error):
34-
print(error.localizedDescription)
35-
XCTFail("testSignIN failed: \(error.localizedDescription)")
36-
}
37-
e.fulfill()
38-
}
39-
40-
waitForExpectations(timeout: 30) { error in
41-
if let error = error {
42-
XCTFail("testSignIN failed: \(error.localizedDescription)")
43-
}
44-
}
40+
41+
waitForExpectations(timeout: 30) { error in
42+
if let error = error {
43+
XCTFail("testSignIN failed: \(error.localizedDescription)")
44+
}
4545
}
46-
47-
func testListBuckets() {
48-
let e = expectation(description: "listBuckets")
49-
50-
supabase.storage.listBuckets { result in
51-
switch result {
52-
case let .success(buckets):
53-
XCTAssertEqual(buckets.count >= 0, true)
54-
case let .failure(error):
55-
print(error.localizedDescription)
56-
XCTFail("listBuckets failed: \(error.localizedDescription)")
57-
}
58-
e.fulfill()
59-
}
60-
61-
waitForExpectations(timeout: 30) { error in
62-
if let error = error {
63-
XCTFail("listBuckets failed: \(error.localizedDescription)")
64-
}
65-
}
46+
}
47+
48+
func testListBuckets() {
49+
let e = expectation(description: "listBuckets")
50+
51+
supabase.storage.listBuckets { result in
52+
switch result {
53+
case let .success(buckets):
54+
XCTAssertEqual(buckets.count >= 0, true)
55+
case let .failure(error):
56+
print(error.localizedDescription)
57+
XCTFail("listBuckets failed: \(error.localizedDescription)")
58+
}
59+
e.fulfill()
6660
}
67-
68-
func testUploadFile() {
69-
let e = expectation(description: "testUploadFile")
70-
let data = try! Data(
71-
contentsOf: URL(
72-
string: "https://raw.githubusercontent.com/satishbabariya/storage-swift/main/README.md")!)
73-
74-
let file = File(name: "README.md", data: data, fileName: "README.md", contentType: "text/html")
75-
76-
supabase.storage.from(id: "Demo").upload(
77-
path: "\(UUID().uuidString).md", file: file, fileOptions: FileOptions(cacheControl: "3600")
78-
) { result in
79-
switch result {
80-
case let .success(res):
81-
print(res)
82-
XCTAssertEqual(true, true)
83-
case let .failure(error):
84-
print(error.localizedDescription)
85-
XCTFail("testUploadFile failed: \(error.localizedDescription)")
86-
}
87-
e.fulfill()
88-
}
89-
90-
waitForExpectations(timeout: 30) { error in
91-
if let error = error {
92-
XCTFail("testUploadFile failed: \(error.localizedDescription)")
93-
}
94-
}
61+
62+
waitForExpectations(timeout: 30) { error in
63+
if let error = error {
64+
XCTFail("listBuckets failed: \(error.localizedDescription)")
65+
}
66+
}
67+
}
68+
69+
func testUploadFile() {
70+
let e = expectation(description: "testUploadFile")
71+
let data = try! Data(
72+
contentsOf: URL(
73+
string: "https://raw.githubusercontent.com/satishbabariya/storage-swift/main/README.md")!)
74+
75+
let file = File(name: "README.md", data: data, fileName: "README.md", contentType: "text/html")
76+
77+
supabase.storage.from(id: "Demo").upload(
78+
path: "\(UUID().uuidString).md", file: file, fileOptions: FileOptions(cacheControl: "3600")
79+
) { result in
80+
switch result {
81+
case let .success(res):
82+
print(res)
83+
XCTAssertEqual(true, true)
84+
case let .failure(error):
85+
print(error.localizedDescription)
86+
XCTFail("testUploadFile failed: \(error.localizedDescription)")
87+
}
88+
e.fulfill()
89+
}
90+
91+
waitForExpectations(timeout: 30) { error in
92+
if let error = error {
93+
XCTFail("testUploadFile failed: \(error.localizedDescription)")
94+
}
9595
}
96+
}
9697
}

0 commit comments

Comments
 (0)