diff --git a/Examples/Examples/TodoListView.swift b/Examples/Examples/TodoListView.swift index b4017d09..d167c46c 100644 --- a/Examples/Examples/TodoListView.swift +++ b/Examples/Examples/TodoListView.swift @@ -80,8 +80,8 @@ struct TodoListView: View { .task { do { error = nil - todos = IdentifiedArrayOf( - uniqueElements: try await supabase.database.from("todos") + todos = try await IdentifiedArrayOf( + uniqueElements: supabase.database.from("todos") .select() .execute() .value as [Todo] diff --git a/Sources/Supabase/Deprecations.swift b/Sources/Supabase/Deprecations.swift new file mode 100644 index 00000000..e67b4d79 --- /dev/null +++ b/Sources/Supabase/Deprecations.swift @@ -0,0 +1,28 @@ +import Foundation + +extension SupabaseClient { + @available( + *, + deprecated, + message: "Deprecated initializer, use init(supabaseURL:supabaseKey:options) instead." + ) + public convenience init( + supabaseURL: URL, + supabaseKey: String, + schema: String = "public", + headers: [String: String] = [:], + httpClient: HTTPClient = HTTPClient() + ) { + self.init( + supabaseURL: supabaseURL, + supabaseKey: supabaseKey, + options: SupabaseClientOptions( + db: SupabaseClientOptions.DatabaseOptions(schema: schema), + global: SupabaseClientOptions.GlobalOptions( + headers: headers, + httpClient: httpClient + ) + ) + ) + } +} diff --git a/Sources/Supabase/SupabaseClient.swift b/Sources/Supabase/SupabaseClient.swift index 9860f3d7..981ce4da 100644 --- a/Sources/Supabase/SupabaseClient.swift +++ b/Sources/Supabase/SupabaseClient.swift @@ -56,32 +56,26 @@ public class SupabaseClient { private var defaultHeaders: [String: String] - /// Init `Supabase` with the provided parameters. - /// - Parameters: - /// - supabaseURL: Unique Supabase project url - /// - supabaseKey: Supabase anonymous API Key - /// - schema: Database schema name, defaults to `public` - /// - headers: Optional headers for initializing the client. + /// Create a new client. public init( supabaseURL: URL, supabaseKey: String, - schema: String = "public", - headers: [String: String] = [:], - httpClient: HTTPClient = HTTPClient() + options: SupabaseClientOptions = .init() ) { self.supabaseURL = supabaseURL self.supabaseKey = supabaseKey - self.schema = schema - self.httpClient = httpClient + schema = options.db.schema + httpClient = options.global.httpClient defaultHeaders = [ "X-Client-Info": "supabase-swift/\(version)", "apikey": supabaseKey, - ].merging(headers) { _, new in new } + ].merging(options.global.headers) { _, new in new } auth = GoTrueClient( url: supabaseURL.appendingPathComponent("/auth/v1"), - headers: defaultHeaders + headers: defaultHeaders, + localStorage: options.auth.storage ) let isPlatform = diff --git a/Sources/Supabase/Types.swift b/Sources/Supabase/Types.swift new file mode 100644 index 00000000..82cba4f4 --- /dev/null +++ b/Sources/Supabase/Types.swift @@ -0,0 +1,47 @@ +import Foundation +import GoTrue + +public struct SupabaseClientOptions { + public let db: DatabaseOptions + public let auth: AuthOptions + public let global: GlobalOptions + + public struct DatabaseOptions { + /// The Postgres schema which your tables belong to. Must be on the list of exposed schemas in + /// Supabase. Defaults to `public`. + public let schema: String + + public init(schema: String = "public") { + self.schema = schema + } + } + + public struct AuthOptions { + /// A storage provider. Used to store the logged-in session. + public let storage: GoTrueLocalStorage? + + public init(storage: GoTrueLocalStorage? = nil) { + self.storage = storage + } + } + + public struct GlobalOptions { + public let headers: [String: String] + public let httpClient: SupabaseClient.HTTPClient + + public init(headers: [String: String] = [:], httpClient: SupabaseClient.HTTPClient = .init()) { + self.headers = headers + self.httpClient = httpClient + } + } + + public init( + db: DatabaseOptions = .init(), + auth: AuthOptions = .init(), + global: GlobalOptions = .init() + ) { + self.db = db + self.auth = auth + self.global = global + } +} diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4c9b50c1..74a03dd5 100644 --- a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -68,8 +68,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/supabase-community/storage-swift.git", "state" : { - "revision" : "04703e499ca258899d7ad45717efe75b8ddc09ab", - "version" : "0.1.0" + "revision" : "6081d81a59f5b5abb6ec7ae1eacf4bff41e6ec8b", + "version" : "0.1.1" } }, { @@ -77,8 +77,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-case-paths", "state" : { - "revision" : "f623901b4bcc97f59c36704f81583f169b228e51", - "version" : "0.13.0" + "revision" : "870133b7b2387df136ad301ec67b2e864b51dda1", + "version" : "0.14.0" } }, { @@ -95,8 +95,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-custom-dump", "state" : { - "revision" : "dd86159e25c749873f144577e5d18309bf57534f", - "version" : "0.8.0" + "revision" : "de8ba65649e7ee317b9daf27dd5eebf34bd4be57", + "version" : "0.9.1" } }, { @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swiftui-navigation.git", "state" : { - "revision" : "270a754308f5440be52fc295242eb7031638bd15", - "version" : "0.6.1" + "revision" : "0a0e1b321d70ee6a464ecfe6b0136d9eff77ebfc", + "version" : "0.7.0" } }, {