From de59889ecb37408d3b5912cba77cde3cc4126ddd Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 28 Oct 2022 06:10:08 -0300 Subject: [PATCH 01/29] Point dependencies to RC branches --- .swift-version | 1 + .swiftformat | 11 ++++ Package.resolved | 81 ++++++++++++++++++++++++--- Package.swift | 11 ++-- Sources/Supabase/SupabaseClient.swift | 10 ++-- 5 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 .swift-version create mode 100644 .swiftformat diff --git a/.swift-version b/.swift-version new file mode 100644 index 00000000..2df33d76 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +5.6 diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 00000000..ae46a8c1 --- /dev/null +++ b/.swiftformat @@ -0,0 +1,11 @@ +--binarygrouping none +--decimalgrouping none +--hexgrouping none +--indent 2 +--octalgrouping none +--semicolons never +--wraparguments before-first +--wrapcollections before-first +--wrapparameters before-first +--extensionacl on-declarations +--maxwidth 100 diff --git a/Package.resolved b/Package.resolved index 70e97180..894d55b6 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,12 +1,77 @@ { - "pins" : [ - { - "identity" : "functions-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/supabase-community/functions-swift", - "state" : { - "revision" : "7d5dfce3673bb30bbb7e1fbb5e0afe01bbd92624", - "version" : "0.2.0" + "object": { + "pins": [ + { + "package": "functions-swift", + "repositoryURL": "https://github.com/supabase-community/functions-swift", + "state": { + "branch": "main", + "revision": "bdaf7b34ab7bc25b4aa8092fc384367d8ae7a11f", + "version": null + } + }, + { + "package": "Get", + "repositoryURL": "https://github.com/kean/Get", + "state": { + "branch": null, + "revision": "4750914f0fc8ae6c20a52d028b413d0cebce87fc", + "version": "2.1.4" + } + }, + { + "package": "GoTrue", + "repositoryURL": "https://github.com/supabase-community/gotrue-swift", + "state": { + "branch": "stable-release", + "revision": "772a5d42fce3a66c00ef5a52deddad0606fb8ba6", + "version": null + } + }, + { + "package": "KeychainAccess", + "repositoryURL": "https://github.com/kishikawakatsumi/KeychainAccess", + "state": { + "branch": null, + "revision": "84e546727d66f1adc5439debad16270d0fdd04e7", + "version": "4.2.2" + } + }, + { + "package": "PostgREST", + "repositoryURL": "https://github.com/supabase-community/postgrest-swift", + "state": { + "branch": "release-candidate", + "revision": "abf168adc50ab3fa4668842b1ae0589bb38feb0b", + "version": null + } + }, + { + "package": "Realtime", + "repositoryURL": "https://github.com/supabase-community/realtime-swift.git", + "state": { + "branch": null, + "revision": "0b985c687fe963f6bd818ff77a35c27247b98bb4", + "version": "0.0.2" + } + }, + { + "package": "SupabaseStorage", + "repositoryURL": "https://github.com/supabase-community/storage-swift.git", + "state": { + "branch": "main", + "revision": "04703e499ca258899d7ad45717efe75b8ddc09ab", + "version": null + } + }, + { + "package": "URLQueryEncoder", + "repositoryURL": "https://github.com/kean/URLQueryEncoder", + "state": { + "branch": null, + "revision": "4cc975d4d075d0e62699a796a08284e217d4ee93", + "version": "0.2.0" + } } }, { diff --git a/Package.swift b/Package.swift index ecc72329..043abeb2 100644 --- a/Package.swift +++ b/Package.swift @@ -19,11 +19,14 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/supabase-community/gotrue-swift", from: "0.1.0"), - .package(url: "https://github.com/supabase-community/storage-swift.git", from: "0.1.0"), + .package(url: "https://github.com/supabase-community/gotrue-swift", branch: "stable-release"), + .package(url: "https://github.com/supabase-community/storage-swift.git", branch: "main"), .package(url: "https://github.com/supabase-community/realtime-swift.git", from: "0.0.1"), - .package(url: "https://github.com/supabase-community/postgrest-swift", from: "1.0.0"), - .package(url: "https://github.com/supabase-community/functions-swift", from: "0.2.0"), + .package( + url: "https://github.com/supabase-community/postgrest-swift", + branch: "release-candidate" + ), + .package(url: "https://github.com/supabase-community/functions-swift", branch: "main"), ], targets: [ .target( diff --git a/Sources/Supabase/SupabaseClient.swift b/Sources/Supabase/SupabaseClient.swift index 6de08419..7a239fdb 100644 --- a/Sources/Supabase/SupabaseClient.swift +++ b/Sources/Supabase/SupabaseClient.swift @@ -50,7 +50,7 @@ public class SupabaseClient { FunctionsClient( url: functionsURL, headers: defaultHeaders, - apiClientDelegate: self + http: self ) } @@ -61,7 +61,6 @@ public class SupabaseClient { /// - supabaseURL: Unique Supabase project url /// - supabaseKey: Supabase anonymous API Key /// - schema: Database schema name, defaults to `public` - /// - headers: Optional headers for initializing the client. public init( supabaseURL: URL, supabaseKey: String, @@ -97,11 +96,14 @@ public class SupabaseClient { public struct HTTPClient { let storage: StorageHTTPClient + let functions: FunctionsHTTPClient public init( - storage: StorageHTTPClient? = nil + storage: StorageHTTPClient? = nil, + functions: FunctionsHTTPClient? = nil ) { self.storage = storage ?? DefaultStorageHTTPClient() + self.functions = functions ?? DefaultFunctionsHTTPClient() } } @@ -120,7 +122,7 @@ extension SupabaseClient: APIClientDelegate { } extension SupabaseClient { - func adapt(request: URLRequest) async -> URLRequest { + func adapt(request: URLRequest) async throws -> URLRequest { var request = request if let accessToken = try? await auth.session.accessToken { request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization") From 39e411cb4ce543c70bdba32ed7b2be532c957366 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Sat, 5 Nov 2022 08:31:29 -0300 Subject: [PATCH 02/29] Update dependencies --- Package.resolved | 8 ++++---- Sources/Supabase/SupabaseClient.swift | 12 +++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Package.resolved b/Package.resolved index 894d55b6..0c92c446 100644 --- a/Package.resolved +++ b/Package.resolved @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/kean/Get", "state": { "branch": null, - "revision": "4750914f0fc8ae6c20a52d028b413d0cebce87fc", - "version": "2.1.4" + "revision": "7209fdb015686fd90918b2037cb2039206405bd3", + "version": "2.1.5" } }, { @@ -24,7 +24,7 @@ "repositoryURL": "https://github.com/supabase-community/gotrue-swift", "state": { "branch": "stable-release", - "revision": "772a5d42fce3a66c00ef5a52deddad0606fb8ba6", + "revision": "7650c562f52b56e18fb8a682b6235ba74da64ab0", "version": null } }, @@ -42,7 +42,7 @@ "repositoryURL": "https://github.com/supabase-community/postgrest-swift", "state": { "branch": "release-candidate", - "revision": "abf168adc50ab3fa4668842b1ae0589bb38feb0b", + "revision": "911e6c17c0f9abc7f585d76138ffa276b78abca9", "version": null } }, diff --git a/Sources/Supabase/SupabaseClient.swift b/Sources/Supabase/SupabaseClient.swift index 7a239fdb..afffa87a 100644 --- a/Sources/Supabase/SupabaseClient.swift +++ b/Sources/Supabase/SupabaseClient.swift @@ -122,7 +122,7 @@ extension SupabaseClient: APIClientDelegate { } extension SupabaseClient { - func adapt(request: URLRequest) async throws -> URLRequest { + func adapt(request: URLRequest) async -> URLRequest { var request = request if let accessToken = try? await auth.session.accessToken { request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization") @@ -145,3 +145,13 @@ extension SupabaseClient: StorageHTTPClient { return try await httpClient.storage.upload(request, from: data) } } + +extension SupabaseClient: FunctionsHTTPClient { + public func execute( + _ request: URLRequest, + client: FunctionsClient + ) async throws -> (Data, HTTPURLResponse) { + let request = await adapt(request: request) + return try await httpClient.functions.execute(request, client: client) + } +} From cca34c55a661bd629e347b29dd66a74cc125d422 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Sat, 5 Nov 2022 10:05:05 -0300 Subject: [PATCH 03/29] Point to main branch --- Package.resolved | 4 ++-- Package.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.resolved b/Package.resolved index 0c92c446..4a95400e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -23,8 +23,8 @@ "package": "GoTrue", "repositoryURL": "https://github.com/supabase-community/gotrue-swift", "state": { - "branch": "stable-release", - "revision": "7650c562f52b56e18fb8a682b6235ba74da64ab0", + "branch": "main", + "revision": "7989dcbc5ee55451c4a4d43d0dce2c333389d3b4", "version": null } }, diff --git a/Package.swift b/Package.swift index 043abeb2..3ebd5442 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,7 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/supabase-community/gotrue-swift", branch: "stable-release"), + .package(url: "https://github.com/supabase-community/gotrue-swift", branch: "main"), .package(url: "https://github.com/supabase-community/storage-swift.git", branch: "main"), .package(url: "https://github.com/supabase-community/realtime-swift.git", from: "0.0.1"), .package( From cc056bf75b4d3e5ca95b9a69541bdff51142f6a2 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 7 Nov 2022 11:18:04 -0300 Subject: [PATCH 04/29] Update postgrest-swift --- Package.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.resolved b/Package.resolved index 4a95400e..27de6310 100644 --- a/Package.resolved +++ b/Package.resolved @@ -42,7 +42,7 @@ "repositoryURL": "https://github.com/supabase-community/postgrest-swift", "state": { "branch": "release-candidate", - "revision": "911e6c17c0f9abc7f585d76138ffa276b78abca9", + "revision": "71404de0aed2289137d7749addecd449804e32ad", "version": null } }, From 796e3b12574d9ca441ac1f5da7316dda5152170c Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Wed, 21 Dec 2022 07:57:06 -0300 Subject: [PATCH 05/29] Set postgrest to master --- Package.resolved | 8 ++++---- Package.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Package.resolved b/Package.resolved index 27de6310..5356d320 100644 --- a/Package.resolved +++ b/Package.resolved @@ -41,8 +41,8 @@ "package": "PostgREST", "repositoryURL": "https://github.com/supabase-community/postgrest-swift", "state": { - "branch": "release-candidate", - "revision": "71404de0aed2289137d7749addecd449804e32ad", + "branch": "master", + "revision": "02b1e40d89d2d265a148b1fbffe6b98df5a6c687", "version": null } }, @@ -69,8 +69,8 @@ "repositoryURL": "https://github.com/kean/URLQueryEncoder", "state": { "branch": null, - "revision": "4cc975d4d075d0e62699a796a08284e217d4ee93", - "version": "0.2.0" + "revision": "4ce950479707ea109f229d7230ec074a133b15d7", + "version": "0.2.1" } } }, diff --git a/Package.swift b/Package.swift index 3ebd5442..de0d738a 100644 --- a/Package.swift +++ b/Package.swift @@ -24,7 +24,7 @@ let package = Package( .package(url: "https://github.com/supabase-community/realtime-swift.git", from: "0.0.1"), .package( url: "https://github.com/supabase-community/postgrest-swift", - branch: "release-candidate" + branch: "master" ), .package(url: "https://github.com/supabase-community/functions-swift", branch: "main"), ], From 2b90ca7e82c387c9d25350079d68546358d95736 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Thu, 22 Dec 2022 10:07:28 -0300 Subject: [PATCH 06/29] Update functions-swift --- Package.resolved | 2 +- Sources/Supabase/SupabaseClient.swift | 17 ++--------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Package.resolved b/Package.resolved index 5356d320..2d70babd 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,7 +6,7 @@ "repositoryURL": "https://github.com/supabase-community/functions-swift", "state": { "branch": "main", - "revision": "bdaf7b34ab7bc25b4aa8092fc384367d8ae7a11f", + "revision": "b6e4ea9ba2ae333e60dbc259099807980644787c", "version": null } }, diff --git a/Sources/Supabase/SupabaseClient.swift b/Sources/Supabase/SupabaseClient.swift index afffa87a..f539b674 100644 --- a/Sources/Supabase/SupabaseClient.swift +++ b/Sources/Supabase/SupabaseClient.swift @@ -50,7 +50,7 @@ public class SupabaseClient { FunctionsClient( url: functionsURL, headers: defaultHeaders, - http: self + apiClientDelegate: self ) } @@ -96,14 +96,11 @@ public class SupabaseClient { public struct HTTPClient { let storage: StorageHTTPClient - let functions: FunctionsHTTPClient public init( - storage: StorageHTTPClient? = nil, - functions: FunctionsHTTPClient? = nil + storage: StorageHTTPClient? = nil ) { self.storage = storage ?? DefaultStorageHTTPClient() - self.functions = functions ?? DefaultFunctionsHTTPClient() } } @@ -145,13 +142,3 @@ extension SupabaseClient: StorageHTTPClient { return try await httpClient.storage.upload(request, from: data) } } - -extension SupabaseClient: FunctionsHTTPClient { - public func execute( - _ request: URLRequest, - client: FunctionsClient - ) async throws -> (Data, HTTPURLResponse) { - let request = await adapt(request: request) - return try await httpClient.functions.execute(request, client: client) - } -} From 3c25d6ed3e68398136241d1a6381e7eb43774121 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Thu, 22 Dec 2022 10:10:10 -0300 Subject: [PATCH 07/29] Fix functions-swift version --- Package.resolved | 6 +++--- Package.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Package.resolved b/Package.resolved index 2d70babd..a6a1981b 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,9 +5,9 @@ "package": "functions-swift", "repositoryURL": "https://github.com/supabase-community/functions-swift", "state": { - "branch": "main", - "revision": "b6e4ea9ba2ae333e60dbc259099807980644787c", - "version": null + "branch": null, + "revision": "7d5dfce3673bb30bbb7e1fbb5e0afe01bbd92624", + "version": "0.2.0" } }, { diff --git a/Package.swift b/Package.swift index de0d738a..58dce12d 100644 --- a/Package.swift +++ b/Package.swift @@ -26,7 +26,7 @@ let package = Package( url: "https://github.com/supabase-community/postgrest-swift", branch: "master" ), - .package(url: "https://github.com/supabase-community/functions-swift", branch: "main"), + .package(url: "https://github.com/supabase-community/functions-swift", from: "0.2.0"), ], targets: [ .target( From b4a8a5e66175c5314c59b2e423b1d528c547e5c7 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 06:37:03 -0300 Subject: [PATCH 08/29] Add examples project --- .gitignore | 4 +- Examples/Examples.xcodeproj/project.pbxproj | 393 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 63 +++ .../Examples/Assets.xcassets/Contents.json | 6 + Examples/Examples/AuthView.swift | 82 ++++ Examples/Examples/Examples.entitlements | 10 + Examples/Examples/ExamplesApp.swift | 38 ++ Examples/Examples/HomeView.swift | 31 ++ .../Preview Assets.xcassets/Contents.json | 6 + Examples/Examples/RootView.swift | 36 ++ Examples/Examples/_Secrets.swift | 6 + Package.resolved | 2 +- .../contents.xcworkspacedata | 10 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/swiftpm/Package.resolved | 79 ++++ 18 files changed, 798 insertions(+), 2 deletions(-) create mode 100644 Examples/Examples.xcodeproj/project.pbxproj create mode 100644 Examples/Examples.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Examples/Examples/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Examples/Examples/Assets.xcassets/Contents.json create mode 100644 Examples/Examples/AuthView.swift create mode 100644 Examples/Examples/Examples.entitlements create mode 100644 Examples/Examples/ExamplesApp.swift create mode 100644 Examples/Examples/HomeView.swift create mode 100644 Examples/Examples/Preview Content/Preview Assets.xcassets/Contents.json create mode 100644 Examples/Examples/RootView.swift create mode 100644 Examples/Examples/_Secrets.swift create mode 100644 supabase-swift.xcworkspace/contents.xcworkspacedata create mode 100644 supabase-swift.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved diff --git a/.gitignore b/.gitignore index 1d28cee2..8aacde9f 100644 --- a/.gitignore +++ b/.gitignore @@ -93,4 +93,6 @@ iOSInjectionProject/ /.build /Packages /*.xcodeproj -/.swiftpm \ No newline at end of file +/.swiftpm + +Secrets.swift diff --git a/Examples/Examples.xcodeproj/project.pbxproj b/Examples/Examples.xcodeproj/project.pbxproj new file mode 100644 index 00000000..a4265d68 --- /dev/null +++ b/Examples/Examples.xcodeproj/project.pbxproj @@ -0,0 +1,393 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 793895CA2954ABFF0044F2B8 /* ExamplesApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 793895C92954ABFF0044F2B8 /* ExamplesApp.swift */; }; + 793895CC2954ABFF0044F2B8 /* RootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 793895CB2954ABFF0044F2B8 /* RootView.swift */; }; + 793895CE2954AC000044F2B8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 793895CD2954AC000044F2B8 /* Assets.xcassets */; }; + 793895D22954AC000044F2B8 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 793895D12954AC000044F2B8 /* Preview Assets.xcassets */; }; + 7956405C2954AC3E0088A06F /* Supabase in Frameworks */ = {isa = PBXBuildFile; productRef = 7956405B2954AC3E0088A06F /* Supabase */; }; + 7956405E2954ADE00088A06F /* Secrets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7956405D2954ADE00088A06F /* Secrets.swift */; }; + 795640602954AE140088A06F /* AuthView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7956405F2954AE140088A06F /* AuthView.swift */; }; + 795640622955AD2B0088A06F /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 795640612955AD2B0088A06F /* HomeView.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 793895C62954ABFF0044F2B8 /* Examples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Examples.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 793895C92954ABFF0044F2B8 /* ExamplesApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExamplesApp.swift; sourceTree = ""; }; + 793895CB2954ABFF0044F2B8 /* RootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootView.swift; sourceTree = ""; }; + 793895CD2954AC000044F2B8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 793895CF2954AC000044F2B8 /* Examples.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Examples.entitlements; sourceTree = ""; }; + 793895D12954AC000044F2B8 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 7956405D2954ADE00088A06F /* Secrets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Secrets.swift; sourceTree = ""; }; + 7956405F2954AE140088A06F /* AuthView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthView.swift; sourceTree = ""; }; + 795640612955AD2B0088A06F /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = ""; }; + 795640632955ADFB0088A06F /* _Secrets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _Secrets.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 793895C32954ABFF0044F2B8 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 7956405C2954AC3E0088A06F /* Supabase in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 793895BD2954ABFF0044F2B8 = { + isa = PBXGroup; + children = ( + 793895C82954ABFF0044F2B8 /* Examples */, + 793895C72954ABFF0044F2B8 /* Products */, + 7956405A2954AC3E0088A06F /* Frameworks */, + ); + sourceTree = ""; + }; + 793895C72954ABFF0044F2B8 /* Products */ = { + isa = PBXGroup; + children = ( + 793895C62954ABFF0044F2B8 /* Examples.app */, + ); + name = Products; + sourceTree = ""; + }; + 793895C82954ABFF0044F2B8 /* Examples */ = { + isa = PBXGroup; + children = ( + 793895CD2954AC000044F2B8 /* Assets.xcassets */, + 7956405F2954AE140088A06F /* AuthView.swift */, + 793895CF2954AC000044F2B8 /* Examples.entitlements */, + 793895C92954ABFF0044F2B8 /* ExamplesApp.swift */, + 793895D02954AC000044F2B8 /* Preview Content */, + 793895CB2954ABFF0044F2B8 /* RootView.swift */, + 7956405D2954ADE00088A06F /* Secrets.swift */, + 795640612955AD2B0088A06F /* HomeView.swift */, + 795640632955ADFB0088A06F /* _Secrets.swift */, + ); + path = Examples; + sourceTree = ""; + }; + 793895D02954AC000044F2B8 /* Preview Content */ = { + isa = PBXGroup; + children = ( + 793895D12954AC000044F2B8 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; + 7956405A2954AC3E0088A06F /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 793895C52954ABFF0044F2B8 /* Examples */ = { + isa = PBXNativeTarget; + buildConfigurationList = 793895D52954AC000044F2B8 /* Build configuration list for PBXNativeTarget "Examples" */; + buildPhases = ( + 793895C22954ABFF0044F2B8 /* Sources */, + 793895C32954ABFF0044F2B8 /* Frameworks */, + 793895C42954ABFF0044F2B8 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Examples; + packageProductDependencies = ( + 7956405B2954AC3E0088A06F /* Supabase */, + ); + productName = Examples; + productReference = 793895C62954ABFF0044F2B8 /* Examples.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 793895BE2954ABFF0044F2B8 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1410; + LastUpgradeCheck = 1410; + TargetAttributes = { + 793895C52954ABFF0044F2B8 = { + CreatedOnToolsVersion = 14.1; + }; + }; + }; + buildConfigurationList = 793895C12954ABFF0044F2B8 /* Build configuration list for PBXProject "Examples" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 793895BD2954ABFF0044F2B8; + productRefGroup = 793895C72954ABFF0044F2B8 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 793895C52954ABFF0044F2B8 /* Examples */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 793895C42954ABFF0044F2B8 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 793895D22954AC000044F2B8 /* Preview Assets.xcassets in Resources */, + 793895CE2954AC000044F2B8 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 793895C22954ABFF0044F2B8 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 793895CC2954ABFF0044F2B8 /* RootView.swift in Sources */, + 7956405E2954ADE00088A06F /* Secrets.swift in Sources */, + 795640602954AE140088A06F /* AuthView.swift in Sources */, + 795640622955AD2B0088A06F /* HomeView.swift in Sources */, + 793895CA2954ABFF0044F2B8 /* ExamplesApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 793895D32954AC000044F2B8 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 793895D42954AC000044F2B8 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 793895D62954AC000044F2B8 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = Examples/Examples.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"Examples/Preview Content\""; + DEVELOPMENT_TEAM = ELTTE7K8TT; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16.1; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 13.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.supabase.Examples; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 793895D72954AC000044F2B8 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = Examples/Examples.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"Examples/Preview Content\""; + DEVELOPMENT_TEAM = ELTTE7K8TT; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16.1; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 13.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.supabase.Examples; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 793895C12954ABFF0044F2B8 /* Build configuration list for PBXProject "Examples" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 793895D32954AC000044F2B8 /* Debug */, + 793895D42954AC000044F2B8 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 793895D52954AC000044F2B8 /* Build configuration list for PBXNativeTarget "Examples" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 793895D62954AC000044F2B8 /* Debug */, + 793895D72954AC000044F2B8 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 7956405B2954AC3E0088A06F /* Supabase */ = { + isa = XCSwiftPackageProductDependency; + productName = Supabase; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 793895BE2954ABFF0044F2B8 /* Project object */; +} diff --git a/Examples/Examples.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Examples/Examples.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/Examples/Examples.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Examples/Examples/Assets.xcassets/AccentColor.colorset/Contents.json b/Examples/Examples/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000..eb878970 --- /dev/null +++ b/Examples/Examples/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json b/Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..532cd729 --- /dev/null +++ b/Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,63 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/Examples/Assets.xcassets/Contents.json b/Examples/Examples/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/Examples/Examples/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/Examples/AuthView.swift b/Examples/Examples/AuthView.swift new file mode 100644 index 00000000..acf6b56c --- /dev/null +++ b/Examples/Examples/AuthView.swift @@ -0,0 +1,82 @@ +// +// AuthView.swift +// Examples +// +// Created by Guilherme Souza on 22/12/22. +// + +import SwiftUI + +final class AuthController: ObservableObject { + +} + +struct AuthView: View { + enum Mode { + case signIn, signUp + } + + @StateObject var auth = AuthController() + + @State var email = "" + @State var password = "" + @State var mode: Mode = .signIn + @State var error: Error? + + var body: some View { + Form { + Section { + TextField("Email", text: $email) + .keyboardType(.emailAddress) + .textContentType(.emailAddress) + .autocorrectionDisabled() + .textInputAutocapitalization(.never) + SecureField("Password", text: $password) + .textContentType(.password) + .autocorrectionDisabled() + .textInputAutocapitalization(.never) + Button(mode == .signIn ? "Sign in" : "Sign up") { + Task { + await primaryActionButtonTapped() + } + } + + if let error { + Text(String(describing: error)) + .foregroundColor(.red) + .font(.footnote) + } + } + + Section { + Button(mode == .signIn ? "Don't have an account? Sign up." : "Already have an account? Sign in.") { + withAnimation { + mode = mode == .signIn ? .signUp : .signIn + } + } + } + } + } + + func primaryActionButtonTapped() async { + do { + error = nil + switch mode { + case .signIn: + try await supabase.auth.signIn(email: email, password: password) + case .signUp: + try await supabase.auth.signUp(email: email, password: password) + } + } catch { + withAnimation { + self.error = error + } + } + } +} + +struct AuthView_Previews: PreviewProvider { + static var previews: some View { + AuthView() + } +} diff --git a/Examples/Examples/Examples.entitlements b/Examples/Examples/Examples.entitlements new file mode 100644 index 00000000..f2ef3ae0 --- /dev/null +++ b/Examples/Examples/Examples.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/Examples/Examples/ExamplesApp.swift b/Examples/Examples/ExamplesApp.swift new file mode 100644 index 00000000..f9b1a93e --- /dev/null +++ b/Examples/Examples/ExamplesApp.swift @@ -0,0 +1,38 @@ +// +// ExamplesApp.swift +// Examples +// +// Created by Guilherme Souza on 22/12/22. +// + +import SwiftUI +import Supabase + +@main +struct ExamplesApp: App { + @State var supabaseInitialized = false + + var body: some Scene { + WindowGroup { + main + } + } + + @ViewBuilder + var main: some View { + if supabaseInitialized { + RootView() + } else { + ProgressView() + .task { + await supabase.auth.initialize() + supabaseInitialized = true + } + } + } +} + +let supabase = SupabaseClient( + supabaseURL: Secrets.supabaseURL, + supabaseKey: Secrets.supabaseAnonKey +) diff --git a/Examples/Examples/HomeView.swift b/Examples/Examples/HomeView.swift new file mode 100644 index 00000000..0b1ad661 --- /dev/null +++ b/Examples/Examples/HomeView.swift @@ -0,0 +1,31 @@ +// +// HomeView.swift +// Examples +// +// Created by Guilherme Souza on 23/12/22. +// + +import SwiftUI + +struct HomeView: View { + var body: some View { + NavigationStack { + Text("Hello, World!") + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button("Sign out") { + Task { + try! await supabase.auth.signOut() + } + } + } + } + } + } +} + +struct HomeView_Previews: PreviewProvider { + static var previews: some View { + HomeView() + } +} diff --git a/Examples/Examples/Preview Content/Preview Assets.xcassets/Contents.json b/Examples/Examples/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/Examples/Examples/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/Examples/RootView.swift b/Examples/Examples/RootView.swift new file mode 100644 index 00000000..b83f790c --- /dev/null +++ b/Examples/Examples/RootView.swift @@ -0,0 +1,36 @@ +// +// RootView.swift +// Examples +// +// Created by Guilherme Souza on 22/12/22. +// + +import SwiftUI +import GoTrue + +struct RootView: View { + @State var authEvent: AuthChangeEvent? + + var body: some View { + Group { + if authEvent == .signedOut { + AuthView() + } else { + HomeView() + } + } + .task { + for await event in supabase.auth.authEventChange { + withAnimation { + authEvent = event + } + } + } + } +} + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + RootView() + } +} diff --git a/Examples/Examples/_Secrets.swift b/Examples/Examples/_Secrets.swift new file mode 100644 index 00000000..a36e8dd6 --- /dev/null +++ b/Examples/Examples/_Secrets.swift @@ -0,0 +1,6 @@ +import Foundation + +enum Secrets { + static let supabaseURL = URL(string: "SUPABASE_URL")! + static let supabaseAnonKey = "SUPABASE_ANON_KEY" +} diff --git a/Package.resolved b/Package.resolved index a6a1981b..af3b4898 100644 --- a/Package.resolved +++ b/Package.resolved @@ -42,7 +42,7 @@ "repositoryURL": "https://github.com/supabase-community/postgrest-swift", "state": { "branch": "master", - "revision": "02b1e40d89d2d265a148b1fbffe6b98df5a6c687", + "revision": "fdf1505bae801be04e3741245f666ce24874532f", "version": null } }, diff --git a/supabase-swift.xcworkspace/contents.xcworkspacedata b/supabase-swift.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..d6fe7ad5 --- /dev/null +++ b/supabase-swift.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/supabase-swift.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/supabase-swift.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/supabase-swift.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000..47011e28 --- /dev/null +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,79 @@ +{ + "object": { + "pins": [ + { + "package": "functions-swift", + "repositoryURL": "https://github.com/supabase-community/functions-swift", + "state": { + "branch": null, + "revision": "7d5dfce3673bb30bbb7e1fbb5e0afe01bbd92624", + "version": "0.2.0" + } + }, + { + "package": "Get", + "repositoryURL": "https://github.com/kean/Get", + "state": { + "branch": null, + "revision": "7209fdb015686fd90918b2037cb2039206405bd3", + "version": "2.1.5" + } + }, + { + "package": "GoTrue", + "repositoryURL": "https://github.com/supabase-community/gotrue-swift", + "state": { + "branch": "main", + "revision": "7989dcbc5ee55451c4a4d43d0dce2c333389d3b4", + "version": null + } + }, + { + "package": "KeychainAccess", + "repositoryURL": "https://github.com/kishikawakatsumi/KeychainAccess", + "state": { + "branch": null, + "revision": "84e546727d66f1adc5439debad16270d0fdd04e7", + "version": "4.2.2" + } + }, + { + "package": "PostgREST", + "repositoryURL": "https://github.com/supabase-community/postgrest-swift", + "state": { + "branch": "master", + "revision": "fdf1505bae801be04e3741245f666ce24874532f", + "version": null + } + }, + { + "package": "Realtime", + "repositoryURL": "https://github.com/supabase-community/realtime-swift.git", + "state": { + "branch": null, + "revision": "0b985c687fe963f6bd818ff77a35c27247b98bb4", + "version": "0.0.2" + } + }, + { + "package": "SupabaseStorage", + "repositoryURL": "https://github.com/supabase-community/storage-swift.git", + "state": { + "branch": "main", + "revision": "04703e499ca258899d7ad45717efe75b8ddc09ab", + "version": null + } + }, + { + "package": "URLQueryEncoder", + "repositoryURL": "https://github.com/kean/URLQueryEncoder", + "state": { + "branch": null, + "revision": "4ce950479707ea109f229d7230ec074a133b15d7", + "version": "0.2.1" + } + } + ] + }, + "version": 1 +} From 4658cad805a216feffa2587c0d43bfa7c5742fe4 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 07:26:22 -0300 Subject: [PATCH 09/29] Add auth and todo list example --- Examples/Examples.xcodeproj/project.pbxproj | 51 +++++++ Examples/Examples/AuthView.swift | 9 +- Examples/Examples/ErrorText.swift | 28 ++++ Examples/Examples/ExamplesApp.swift | 4 +- Examples/Examples/HomeView.swift | 2 +- Examples/Examples/Models.swift | 42 ++++++ Examples/Examples/RootView.swift | 2 +- Examples/Examples/TodoListView.swift | 128 ++++++++++++++++++ Examples/supabase/.gitignore | 3 + Examples/supabase/config.toml | 71 ++++++++++ .../migrations/20221223094509_init.sql | 7 + Examples/supabase/seed.sql | 0 .../xcshareddata/swiftpm/Package.resolved | 54 ++++++++ 13 files changed, 393 insertions(+), 8 deletions(-) create mode 100644 Examples/Examples/ErrorText.swift create mode 100644 Examples/Examples/Models.swift create mode 100644 Examples/Examples/TodoListView.swift create mode 100644 Examples/supabase/.gitignore create mode 100644 Examples/supabase/config.toml create mode 100644 Examples/supabase/migrations/20221223094509_init.sql create mode 100644 Examples/supabase/seed.sql diff --git a/Examples/Examples.xcodeproj/project.pbxproj b/Examples/Examples.xcodeproj/project.pbxproj index a4265d68..a9bcc3fc 100644 --- a/Examples/Examples.xcodeproj/project.pbxproj +++ b/Examples/Examples.xcodeproj/project.pbxproj @@ -15,6 +15,11 @@ 7956405E2954ADE00088A06F /* Secrets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7956405D2954ADE00088A06F /* Secrets.swift */; }; 795640602954AE140088A06F /* AuthView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7956405F2954AE140088A06F /* AuthView.swift */; }; 795640622955AD2B0088A06F /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 795640612955AD2B0088A06F /* HomeView.swift */; }; + 795640662955AE9C0088A06F /* TodoListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 795640652955AE9C0088A06F /* TodoListView.swift */; }; + 795640682955AEB30088A06F /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = 795640672955AEB30088A06F /* Models.swift */; }; + 7956406A2955AFBD0088A06F /* ErrorText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 795640692955AFBD0088A06F /* ErrorText.swift */; }; + 7956406D2955B3500088A06F /* SwiftUINavigation in Frameworks */ = {isa = PBXBuildFile; productRef = 7956406C2955B3500088A06F /* SwiftUINavigation */; }; + 795640702955B5190088A06F /* IdentifiedCollections in Frameworks */ = {isa = PBXBuildFile; productRef = 7956406F2955B5190088A06F /* IdentifiedCollections */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -28,6 +33,9 @@ 7956405F2954AE140088A06F /* AuthView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthView.swift; sourceTree = ""; }; 795640612955AD2B0088A06F /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = ""; }; 795640632955ADFB0088A06F /* _Secrets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _Secrets.swift; sourceTree = ""; }; + 795640652955AE9C0088A06F /* TodoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoListView.swift; sourceTree = ""; }; + 795640672955AEB30088A06F /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = ""; }; + 795640692955AFBD0088A06F /* ErrorText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorText.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -35,6 +43,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 795640702955B5190088A06F /* IdentifiedCollections in Frameworks */, + 7956406D2955B3500088A06F /* SwiftUINavigation in Frameworks */, 7956405C2954AC3E0088A06F /* Supabase in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -71,6 +81,9 @@ 7956405D2954ADE00088A06F /* Secrets.swift */, 795640612955AD2B0088A06F /* HomeView.swift */, 795640632955ADFB0088A06F /* _Secrets.swift */, + 795640652955AE9C0088A06F /* TodoListView.swift */, + 795640672955AEB30088A06F /* Models.swift */, + 795640692955AFBD0088A06F /* ErrorText.swift */, ); path = Examples; sourceTree = ""; @@ -108,6 +121,8 @@ name = Examples; packageProductDependencies = ( 7956405B2954AC3E0088A06F /* Supabase */, + 7956406C2955B3500088A06F /* SwiftUINavigation */, + 7956406F2955B5190088A06F /* IdentifiedCollections */, ); productName = Examples; productReference = 793895C62954ABFF0044F2B8 /* Examples.app */; @@ -137,6 +152,10 @@ Base, ); mainGroup = 793895BD2954ABFF0044F2B8; + packageReferences = ( + 7956406B2955B3500088A06F /* XCRemoteSwiftPackageReference "swiftui-navigation" */, + 7956406E2955B5190088A06F /* XCRemoteSwiftPackageReference "swift-identified-collections" */, + ); productRefGroup = 793895C72954ABFF0044F2B8 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -164,7 +183,10 @@ buildActionMask = 2147483647; files = ( 793895CC2954ABFF0044F2B8 /* RootView.swift in Sources */, + 7956406A2955AFBD0088A06F /* ErrorText.swift in Sources */, 7956405E2954ADE00088A06F /* Secrets.swift in Sources */, + 795640682955AEB30088A06F /* Models.swift in Sources */, + 795640662955AE9C0088A06F /* TodoListView.swift in Sources */, 795640602954AE140088A06F /* AuthView.swift in Sources */, 795640622955AD2B0088A06F /* HomeView.swift in Sources */, 793895CA2954ABFF0044F2B8 /* ExamplesApp.swift in Sources */, @@ -382,11 +404,40 @@ }; /* End XCConfigurationList section */ +/* Begin XCRemoteSwiftPackageReference section */ + 7956406B2955B3500088A06F /* XCRemoteSwiftPackageReference "swiftui-navigation" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/pointfreeco/swiftui-navigation.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 0.4.5; + }; + }; + 7956406E2955B5190088A06F /* XCRemoteSwiftPackageReference "swift-identified-collections" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/pointfreeco/swift-identified-collections.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 0.5.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + /* Begin XCSwiftPackageProductDependency section */ 7956405B2954AC3E0088A06F /* Supabase */ = { isa = XCSwiftPackageProductDependency; productName = Supabase; }; + 7956406C2955B3500088A06F /* SwiftUINavigation */ = { + isa = XCSwiftPackageProductDependency; + package = 7956406B2955B3500088A06F /* XCRemoteSwiftPackageReference "swiftui-navigation" */; + productName = SwiftUINavigation; + }; + 7956406F2955B5190088A06F /* IdentifiedCollections */ = { + isa = XCSwiftPackageProductDependency; + package = 7956406E2955B5190088A06F /* XCRemoteSwiftPackageReference "swift-identified-collections" */; + productName = IdentifiedCollections; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 793895BE2954ABFF0044F2B8 /* Project object */; diff --git a/Examples/Examples/AuthView.swift b/Examples/Examples/AuthView.swift index acf6b56c..42d431d7 100644 --- a/Examples/Examples/AuthView.swift +++ b/Examples/Examples/AuthView.swift @@ -7,9 +7,7 @@ import SwiftUI -final class AuthController: ObservableObject { - -} +final class AuthController: ObservableObject {} struct AuthView: View { enum Mode { @@ -49,7 +47,10 @@ struct AuthView: View { } Section { - Button(mode == .signIn ? "Don't have an account? Sign up." : "Already have an account? Sign in.") { + Button( + mode == .signIn ? "Don't have an account? Sign up." : + "Already have an account? Sign in." + ) { withAnimation { mode = mode == .signIn ? .signUp : .signIn } diff --git a/Examples/Examples/ErrorText.swift b/Examples/Examples/ErrorText.swift new file mode 100644 index 00000000..98a4bb29 --- /dev/null +++ b/Examples/Examples/ErrorText.swift @@ -0,0 +1,28 @@ +// +// ErrorText.swift +// Examples +// +// Created by Guilherme Souza on 23/12/22. +// + +import SwiftUI + +struct ErrorText: View { + let error: Error + + init(_ error: Error) { + self.error = error + } + + var body: some View { + Text(String(describing: error)) + .foregroundColor(.red) + .font(.footnote) + } +} + +struct ErrorText_Previews: PreviewProvider { + static var previews: some View { + ErrorText(NSError()) + } +} diff --git a/Examples/Examples/ExamplesApp.swift b/Examples/Examples/ExamplesApp.swift index f9b1a93e..699bc98a 100644 --- a/Examples/Examples/ExamplesApp.swift +++ b/Examples/Examples/ExamplesApp.swift @@ -5,13 +5,13 @@ // Created by Guilherme Souza on 22/12/22. // -import SwiftUI import Supabase +import SwiftUI @main struct ExamplesApp: App { @State var supabaseInitialized = false - + var body: some Scene { WindowGroup { main diff --git a/Examples/Examples/HomeView.swift b/Examples/Examples/HomeView.swift index 0b1ad661..aff182ec 100644 --- a/Examples/Examples/HomeView.swift +++ b/Examples/Examples/HomeView.swift @@ -10,7 +10,7 @@ import SwiftUI struct HomeView: View { var body: some View { NavigationStack { - Text("Hello, World!") + TodoListView() .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Sign out") { diff --git a/Examples/Examples/Models.swift b/Examples/Examples/Models.swift new file mode 100644 index 00000000..6676ee58 --- /dev/null +++ b/Examples/Examples/Models.swift @@ -0,0 +1,42 @@ +// +// File.swift +// Examples +// +// Created by Guilherme Souza on 23/12/22. +// + +import Foundation + +struct Todo: Identifiable, Hashable, Decodable { + let id: UUID + var description: String + var isComplete: Bool + let createdAt: Date + + enum CodingKeys: String, CodingKey { + case id + case description + case isComplete = "is_complete" + case createdAt = "created_at" + } +} + +struct CreateTodoRequest: Encodable { + var description: String + var isComplete: Bool + + enum CodingKeys: String, CodingKey { + case description + case isComplete = "is_complete" + } +} + +struct UpdateTodoRequest: Encodable { + var description: String? + var isComplete: Bool? + + enum CodingKeys: String, CodingKey { + case description + case isComplete = "is_complete" + } +} diff --git a/Examples/Examples/RootView.swift b/Examples/Examples/RootView.swift index b83f790c..b5a1e30c 100644 --- a/Examples/Examples/RootView.swift +++ b/Examples/Examples/RootView.swift @@ -5,8 +5,8 @@ // Created by Guilherme Souza on 22/12/22. // -import SwiftUI import GoTrue +import SwiftUI struct RootView: View { @State var authEvent: AuthChangeEvent? diff --git a/Examples/Examples/TodoListView.swift b/Examples/Examples/TodoListView.swift new file mode 100644 index 00000000..3b6ec113 --- /dev/null +++ b/Examples/Examples/TodoListView.swift @@ -0,0 +1,128 @@ +// +// TodoListView.swift +// Examples +// +// Created by Guilherme Souza on 23/12/22. +// + +import IdentifiedCollections +import SwiftUI +import SwiftUINavigation + +struct TodoListView: View { + @State var todos: IdentifiedArrayOf = [] + @State var error: Error? + + @State var createTodoRequest: CreateTodoRequest? + + var body: some View { + List { + if let error { + ErrorText(error) + } + + IfLet($createTodoRequest) { $createTodoRequest in + Section { + TextField("Description", text: $createTodoRequest.description) + Button("Save") { + Task { await saveNewTodoButtonTapped() } + } + } + } + + ForEach(todos) { todo in + Button { + Task { await toggleCompletion(of: todo) } + } label: { + HStack { + Text(todo.description) + Spacer() + Image(systemName: todo.isComplete ? "checkmark.circle.fill" : "circle") + } + } + } + } + .animation(.default, value: todos) + .navigationTitle("Todos") + .toolbar { + ToolbarItem(placement: .primaryAction) { + Button { + withAnimation { + createTodoRequest = .init(description: "", isComplete: false) + } + } label: { + Label("Add", systemImage: "plus") + } + } + } + .task { + do { + error = nil + todos = IdentifiedArrayOf( + uniqueElements: try await supabase.database.from("todos") + .select() + .execute(returning: [Todo].self) + .value + ) + } catch { + self.error = error + } + } + } + + func saveNewTodoButtonTapped() async { + guard let createTodoRequest else { + return + } + + do { + error = nil + + let createdTodo = try await supabase.database.from("todos") + .insert(values: createTodoRequest, returning: .representation) + .single() + .execute(returning: Todo.self) + .value + + withAnimation { + todos.insert(createdTodo, at: 0) + self.createTodoRequest = nil + } + + } catch { + self.error = error + } + } + + func toggleCompletion(of todo: Todo) async { + var updatedTodo = todo + updatedTodo.isComplete.toggle() + todos[id: todo.id] = updatedTodo + + do { + error = nil + + let updateRequest = UpdateTodoRequest(isComplete: updatedTodo.isComplete) + updatedTodo = try await supabase.database.from("todos") + .update(values: updateRequest, returning: .representation) + .eq(column: "id", value: updatedTodo.id) + .single() + .execute(returning: Todo.self) + .value + todos[id: updatedTodo.id] = updatedTodo + } catch { + // rollback old todo. + todos[id: todo.id] = todo + + self.error = error + } + } +} + +struct TodoListView_Previews: PreviewProvider { + static var previews: some View { + NavigationStack { + TodoListView() + } + } +} diff --git a/Examples/supabase/.gitignore b/Examples/supabase/.gitignore new file mode 100644 index 00000000..773c7c3e --- /dev/null +++ b/Examples/supabase/.gitignore @@ -0,0 +1,3 @@ +# Supabase +.branches +.temp diff --git a/Examples/supabase/config.toml b/Examples/supabase/config.toml new file mode 100644 index 00000000..187a7f5d --- /dev/null +++ b/Examples/supabase/config.toml @@ -0,0 +1,71 @@ +# A string used to distinguish different Supabase projects on the same host. Defaults to the working +# directory name when running `supabase init`. +project_id = "Examples" + +[api] +# Port to use for the API URL. +port = 54321 +# Schemas to expose in your API. Tables, views and stored procedures in this schema will get API +# endpoints. public and storage are always included. +schemas = [] +# Extra schemas to add to the search_path of every request. +extra_search_path = ["extensions"] +# The maximum number of rows returns from a view, table, or stored procedure. Limits payload size +# for accidental or malicious requests. +max_rows = 1000 + +[db] +# Port to use for the local database URL. +port = 54322 +# The database major version to use. This has to be the same as your remote database's. Run `SHOW +# server_version;` on the remote database to check. +major_version = 15 + +[studio] +# Port to use for Supabase Studio. +port = 54323 + +# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they +# are monitored, and you can view the emails that would have been sent from the web interface. +[inbucket] +# Port to use for the email testing server web interface. +port = 54324 +smtp_port = 54325 +pop3_port = 54326 + +[storage] +# The maximum file size allowed (e.g. "5MB", "500KB"). +file_size_limit = "50MiB" + +[auth] +# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used +# in emails. +site_url = "http://localhost:3000" +# A list of *exact* URLs that auth providers are permitted to redirect to post authentication. +additional_redirect_urls = ["https://localhost:3000"] +# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 seconds (one +# week). +jwt_expiry = 3600 +# Allow/disallow new user signups to your project. +enable_signup = true + +[auth.email] +# Allow/disallow new user signups via email to your project. +enable_signup = true +# If enabled, a user will be required to confirm any email change on both the old, and new email +# addresses. If disabled, only the new email is required to confirm. +double_confirm_changes = true +# If enabled, users need to confirm their email address before signing in. +enable_confirmations = false + +# Use an external OAuth provider. The full list of providers are: `apple`, `azure`, `bitbucket`, +# `discord`, `facebook`, `github`, `gitlab`, `google`, `twitch`, `twitter`, `slack`, `spotify`. +[auth.external.apple] +enabled = false +client_id = "" +secret = "" +# Overrides the default auth redirectUrl. +redirect_uri = "" +# Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure, +# or any other third-party OIDC providers. +url = "" diff --git a/Examples/supabase/migrations/20221223094509_init.sql b/Examples/supabase/migrations/20221223094509_init.sql new file mode 100644 index 00000000..3be39f7d --- /dev/null +++ b/Examples/supabase/migrations/20221223094509_init.sql @@ -0,0 +1,7 @@ +create table todos ( + id uuid default uuid_generate_v4 () primary key not null, + description text not null, + is_complete boolean not null, + created_at timestamptz default (now() at time zone 'utc'::text) not null +); + diff --git a/Examples/supabase/seed.sql b/Examples/supabase/seed.sql new file mode 100644 index 00000000..e69de29b diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved index 47011e28..02ad11e2 100644 --- a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -64,6 +64,51 @@ "version": null } }, + { + "package": "swift-case-paths", + "repositoryURL": "https://github.com/pointfreeco/swift-case-paths", + "state": { + "branch": null, + "revision": "bb436421f57269fbcfe7360735985321585a86e5", + "version": "0.10.1" + } + }, + { + "package": "swift-collections", + "repositoryURL": "https://github.com/apple/swift-collections", + "state": { + "branch": null, + "revision": "937e904258d22af6e447a0b72c0bc67583ef64a2", + "version": "1.0.4" + } + }, + { + "package": "swift-custom-dump", + "repositoryURL": "https://github.com/pointfreeco/swift-custom-dump", + "state": { + "branch": null, + "revision": "ead7d30cc224c3642c150b546f4f1080d1c411a8", + "version": "0.6.1" + } + }, + { + "package": "swift-identified-collections", + "repositoryURL": "https://github.com/pointfreeco/swift-identified-collections.git", + "state": { + "branch": null, + "revision": "a08887de589e3829d488e0b4b707b2ca804b1060", + "version": "0.5.0" + } + }, + { + "package": "swiftui-navigation", + "repositoryURL": "https://github.com/pointfreeco/swiftui-navigation.git", + "state": { + "branch": null, + "revision": "46acf5ecc1cabdb28d7fe03289f6c8b13a023f52", + "version": "0.4.5" + } + }, { "package": "URLQueryEncoder", "repositoryURL": "https://github.com/kean/URLQueryEncoder", @@ -72,6 +117,15 @@ "revision": "4ce950479707ea109f229d7230ec074a133b15d7", "version": "0.2.1" } + }, + { + "package": "xctest-dynamic-overlay", + "repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay", + "state": { + "branch": null, + "revision": "df16fe6ffe4d6e2e06761aa67716b808b2c9109e", + "version": "0.7.0" + } } ] }, From 8664d90ec5b7d89d06fef00a25845b546f013353 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 07:42:09 -0300 Subject: [PATCH 10/29] Support RLS --- Examples/Examples/AuthView.swift | 15 +++++++++++++-- Examples/Examples/ExamplesApp.swift | 2 ++ Examples/Examples/Models.swift | 11 ++++------- Examples/Examples/RootView.swift | 3 +++ Examples/Examples/TodoListView.swift | 6 ++++-- .../supabase/migrations/20221223094509_init.sql | 9 ++++++++- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Examples/Examples/AuthView.swift b/Examples/Examples/AuthView.swift index 42d431d7..bf1f58b7 100644 --- a/Examples/Examples/AuthView.swift +++ b/Examples/Examples/AuthView.swift @@ -6,15 +6,26 @@ // import SwiftUI +import GoTrue -final class AuthController: ObservableObject {} +final class AuthController: ObservableObject { + @Published var session: Session? + + var currentUserID: UUID { + guard let id = session?.user.id else { + preconditionFailure("Required session.") + } + + return id + } +} struct AuthView: View { enum Mode { case signIn, signUp } - @StateObject var auth = AuthController() + @EnvironmentObject var auth: AuthController @State var email = "" @State var password = "" diff --git a/Examples/Examples/ExamplesApp.swift b/Examples/Examples/ExamplesApp.swift index 699bc98a..cc005e13 100644 --- a/Examples/Examples/ExamplesApp.swift +++ b/Examples/Examples/ExamplesApp.swift @@ -11,6 +11,7 @@ import SwiftUI @main struct ExamplesApp: App { @State var supabaseInitialized = false + @StateObject var auth = AuthController() var body: some Scene { WindowGroup { @@ -22,6 +23,7 @@ struct ExamplesApp: App { var main: some View { if supabaseInitialized { RootView() + .environmentObject(auth) } else { ProgressView() .task { diff --git a/Examples/Examples/Models.swift b/Examples/Examples/Models.swift index 6676ee58..f260099f 100644 --- a/Examples/Examples/Models.swift +++ b/Examples/Examples/Models.swift @@ -1,10 +1,3 @@ -// -// File.swift -// Examples -// -// Created by Guilherme Souza on 23/12/22. -// - import Foundation struct Todo: Identifiable, Hashable, Decodable { @@ -24,19 +17,23 @@ struct Todo: Identifiable, Hashable, Decodable { struct CreateTodoRequest: Encodable { var description: String var isComplete: Bool + var ownerID: UUID enum CodingKeys: String, CodingKey { case description case isComplete = "is_complete" + case ownerID = "owner_id" } } struct UpdateTodoRequest: Encodable { var description: String? var isComplete: Bool? + var ownerID: UUID enum CodingKeys: String, CodingKey { case description case isComplete = "is_complete" + case ownerID = "owner_id" } } diff --git a/Examples/Examples/RootView.swift b/Examples/Examples/RootView.swift index b5a1e30c..3954f561 100644 --- a/Examples/Examples/RootView.swift +++ b/Examples/Examples/RootView.swift @@ -10,6 +10,7 @@ import SwiftUI struct RootView: View { @State var authEvent: AuthChangeEvent? + @EnvironmentObject var auth: AuthController var body: some View { Group { @@ -24,6 +25,8 @@ struct RootView: View { withAnimation { authEvent = event } + + auth.session = try? await supabase.auth.session } } } diff --git a/Examples/Examples/TodoListView.swift b/Examples/Examples/TodoListView.swift index 3b6ec113..533b89b0 100644 --- a/Examples/Examples/TodoListView.swift +++ b/Examples/Examples/TodoListView.swift @@ -10,6 +10,8 @@ import SwiftUI import SwiftUINavigation struct TodoListView: View { + @EnvironmentObject var auth: AuthController + @State var todos: IdentifiedArrayOf = [] @State var error: Error? @@ -48,7 +50,7 @@ struct TodoListView: View { ToolbarItem(placement: .primaryAction) { Button { withAnimation { - createTodoRequest = .init(description: "", isComplete: false) + createTodoRequest = .init(description: "", isComplete: false, ownerID: auth.currentUserID) } } label: { Label("Add", systemImage: "plus") @@ -102,7 +104,7 @@ struct TodoListView: View { do { error = nil - let updateRequest = UpdateTodoRequest(isComplete: updatedTodo.isComplete) + let updateRequest = UpdateTodoRequest(isComplete: updatedTodo.isComplete, ownerID: auth.currentUserID) updatedTodo = try await supabase.database.from("todos") .update(values: updateRequest, returning: .representation) .eq(column: "id", value: updatedTodo.id) diff --git a/Examples/supabase/migrations/20221223094509_init.sql b/Examples/supabase/migrations/20221223094509_init.sql index 3be39f7d..0bb7e8ce 100644 --- a/Examples/supabase/migrations/20221223094509_init.sql +++ b/Examples/supabase/migrations/20221223094509_init.sql @@ -2,6 +2,13 @@ create table todos ( id uuid default uuid_generate_v4 () primary key not null, description text not null, is_complete boolean not null, - created_at timestamptz default (now() at time zone 'utc'::text) not null + created_at timestamptz default (now() at time zone 'utc'::text) not null, + owner_id uuid references auth.users (id) not null ); +alter table todos enable row level security; + +create policy "Allow access to owner only" on todos as permissive + for all to authenticated + using (auth.uid () = owner_id) + with check (auth.uid () = owner_id) From 0d608b454c318765f660cca22b5d9d72074855cd Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 08:55:14 -0300 Subject: [PATCH 11/29] UI improvement --- Examples/Examples/AuthView.swift | 4 +--- Examples/Examples/TodoListView.swift | 13 +++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Examples/Examples/AuthView.swift b/Examples/Examples/AuthView.swift index bf1f58b7..a9d2c111 100644 --- a/Examples/Examples/AuthView.swift +++ b/Examples/Examples/AuthView.swift @@ -51,9 +51,7 @@ struct AuthView: View { } if let error { - Text(String(describing: error)) - .foregroundColor(.red) - .font(.footnote) + ErrorText(error) } } diff --git a/Examples/Examples/TodoListView.swift b/Examples/Examples/TodoListView.swift index 533b89b0..b76f5755 100644 --- a/Examples/Examples/TodoListView.swift +++ b/Examples/Examples/TodoListView.swift @@ -33,14 +33,15 @@ struct TodoListView: View { } ForEach(todos) { todo in - Button { - Task { await toggleCompletion(of: todo) } - } label: { - HStack { - Text(todo.description) - Spacer() + HStack { + Text(todo.description) + Spacer() + Button { + Task { await toggleCompletion(of: todo) } + } label: { Image(systemName: todo.isComplete ? "checkmark.circle.fill" : "circle") } + .buttonStyle(.plain) } } } From f0fb03ba9f7b85404e04a263b85deaaf74b30039 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 09:03:00 -0300 Subject: [PATCH 12/29] Implement delete --- Examples/Examples/TodoListView.swift | 44 ++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Examples/Examples/TodoListView.swift b/Examples/Examples/TodoListView.swift index b76f5755..48f1d3c6 100644 --- a/Examples/Examples/TodoListView.swift +++ b/Examples/Examples/TodoListView.swift @@ -44,17 +44,30 @@ struct TodoListView: View { .buttonStyle(.plain) } } + .onDelete { indexSet in + Task { + await delete(at: indexSet) + } + } } .animation(.default, value: todos) .navigationTitle("Todos") .toolbar { ToolbarItem(placement: .primaryAction) { - Button { - withAnimation { - createTodoRequest = .init(description: "", isComplete: false, ownerID: auth.currentUserID) + if createTodoRequest == nil { + Button { + withAnimation { + createTodoRequest = .init(description: "", isComplete: false, ownerID: auth.currentUserID) + } + } label: { + Label("Add", systemImage: "plus") + } + } else { + Button("Cancel", role: .cancel) { + withAnimation { + createTodoRequest = nil + } } - } label: { - Label("Add", systemImage: "plus") } } } @@ -120,6 +133,27 @@ struct TodoListView: View { self.error = error } } + + func delete(at offset: IndexSet) async { + let oldTodos = todos + + do { + error = nil + let todosToDelete = offset.map { todos[$0] } + + self.todos.remove(atOffsets: offset) + + try await supabase.database.from("todos") + .delete() + .in(column: "id", value: todosToDelete.map(\.id)) + .execute() + } catch { + self.error = error + + // rollback todos on error. + self.todos = oldTodos + } + } } struct TodoListView_Previews: PreviewProvider { From 2f35402617e2c253b273de64d8299212ea80526a Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 09:03:54 -0300 Subject: [PATCH 13/29] swift format --- Examples/Examples/AuthView.swift | 2 +- Examples/Examples/TodoListView.swift | 15 +++++++++++---- Makefile | 6 +----- Package.swift | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Examples/Examples/AuthView.swift b/Examples/Examples/AuthView.swift index a9d2c111..bb040dda 100644 --- a/Examples/Examples/AuthView.swift +++ b/Examples/Examples/AuthView.swift @@ -5,8 +5,8 @@ // Created by Guilherme Souza on 22/12/22. // -import SwiftUI import GoTrue +import SwiftUI final class AuthController: ObservableObject { @Published var session: Session? diff --git a/Examples/Examples/TodoListView.swift b/Examples/Examples/TodoListView.swift index 48f1d3c6..b74aa365 100644 --- a/Examples/Examples/TodoListView.swift +++ b/Examples/Examples/TodoListView.swift @@ -57,7 +57,11 @@ struct TodoListView: View { if createTodoRequest == nil { Button { withAnimation { - createTodoRequest = .init(description: "", isComplete: false, ownerID: auth.currentUserID) + createTodoRequest = .init( + description: "", + isComplete: false, + ownerID: auth.currentUserID + ) } } label: { Label("Add", systemImage: "plus") @@ -118,7 +122,10 @@ struct TodoListView: View { do { error = nil - let updateRequest = UpdateTodoRequest(isComplete: updatedTodo.isComplete, ownerID: auth.currentUserID) + let updateRequest = UpdateTodoRequest( + isComplete: updatedTodo.isComplete, + ownerID: auth.currentUserID + ) updatedTodo = try await supabase.database.from("todos") .update(values: updateRequest, returning: .representation) .eq(column: "id", value: updatedTodo.id) @@ -141,7 +148,7 @@ struct TodoListView: View { error = nil let todosToDelete = offset.map { todos[$0] } - self.todos.remove(atOffsets: offset) + todos.remove(atOffsets: offset) try await supabase.database.from("todos") .delete() @@ -151,7 +158,7 @@ struct TodoListView: View { self.error = error // rollback todos on error. - self.todos = oldTodos + todos = oldTodos } } } diff --git a/Makefile b/Makefile index e83e8ebe..1f75b4ca 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,2 @@ format: - swift format \ - --in-place \ - --ignore-unparsable-files \ - --recursive \ - ./Sources Package.swift + @swiftformat . diff --git a/Package.swift b/Package.swift index 58dce12d..0fedafe9 100644 --- a/Package.swift +++ b/Package.swift @@ -16,7 +16,7 @@ let package = Package( .library( name: "Supabase", targets: ["Supabase"] - ) + ), ], dependencies: [ .package(url: "https://github.com/supabase-community/gotrue-swift", branch: "main"), From ace5b0eb42b6c13701101c1e45959c7453381672 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 09:10:44 -0300 Subject: [PATCH 14/29] Update postgrest-swift --- Examples/Examples/TodoListView.swift | 10 +++++----- Package.resolved | 2 +- .../xcshareddata/swiftpm/Package.resolved | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Examples/Examples/TodoListView.swift b/Examples/Examples/TodoListView.swift index b74aa365..b35fde56 100644 --- a/Examples/Examples/TodoListView.swift +++ b/Examples/Examples/TodoListView.swift @@ -81,8 +81,8 @@ struct TodoListView: View { todos = IdentifiedArrayOf( uniqueElements: try await supabase.database.from("todos") .select() - .execute(returning: [Todo].self) - .value + .execute() + .value as [Todo] ) } catch { self.error = error @@ -98,10 +98,10 @@ struct TodoListView: View { do { error = nil - let createdTodo = try await supabase.database.from("todos") + let createdTodo: Todo = try await supabase.database.from("todos") .insert(values: createTodoRequest, returning: .representation) .single() - .execute(returning: Todo.self) + .execute() .value withAnimation { @@ -130,7 +130,7 @@ struct TodoListView: View { .update(values: updateRequest, returning: .representation) .eq(column: "id", value: updatedTodo.id) .single() - .execute(returning: Todo.self) + .execute() .value todos[id: updatedTodo.id] = updatedTodo } catch { diff --git a/Package.resolved b/Package.resolved index af3b4898..dfa00a70 100644 --- a/Package.resolved +++ b/Package.resolved @@ -42,7 +42,7 @@ "repositoryURL": "https://github.com/supabase-community/postgrest-swift", "state": { "branch": "master", - "revision": "fdf1505bae801be04e3741245f666ce24874532f", + "revision": "d96b5641e0c1574592f83deb73b5484c94f5ce0c", "version": null } }, diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved index 02ad11e2..50d840a9 100644 --- a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -42,7 +42,7 @@ "repositoryURL": "https://github.com/supabase-community/postgrest-swift", "state": { "branch": "master", - "revision": "fdf1505bae801be04e3741245f666ce24874532f", + "revision": "d96b5641e0c1574592f83deb73b5484c94f5ce0c", "version": null } }, From 6428e12b33e86dbddf4e74eb4f3149eefd5f470c Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 09:28:32 -0300 Subject: [PATCH 15/29] Set postgrest-swift to 1.0.0 --- Package.swift | 5 +---- .../xcshareddata/swiftpm/Package.resolved | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Package.swift b/Package.swift index 0fedafe9..03ab9c5a 100644 --- a/Package.swift +++ b/Package.swift @@ -22,10 +22,7 @@ let package = Package( .package(url: "https://github.com/supabase-community/gotrue-swift", branch: "main"), .package(url: "https://github.com/supabase-community/storage-swift.git", branch: "main"), .package(url: "https://github.com/supabase-community/realtime-swift.git", from: "0.0.1"), - .package( - url: "https://github.com/supabase-community/postgrest-swift", - branch: "master" - ), + .package(url: "https://github.com/supabase-community/postgrest-swift", from: "1.0.0"), .package(url: "https://github.com/supabase-community/functions-swift", from: "0.2.0"), ], targets: [ diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved index 50d840a9..948832c9 100644 --- a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -19,6 +19,15 @@ "version": "2.1.5" } }, + { + "package": "GetExtensions", + "repositoryURL": "https://github.com/binaryscraping/GetExtensions", + "state": { + "branch": null, + "revision": "aa20f38721142eb6592b2c8f11179d32d7d70ae3", + "version": "1.0.0" + } + }, { "package": "GoTrue", "repositoryURL": "https://github.com/supabase-community/gotrue-swift", @@ -41,9 +50,9 @@ "package": "PostgREST", "repositoryURL": "https://github.com/supabase-community/postgrest-swift", "state": { - "branch": "master", - "revision": "d96b5641e0c1574592f83deb73b5484c94f5ce0c", - "version": null + "branch": null, + "revision": "a3c2d6a2ede94d2529edf063b056b1a66fd9cdc2", + "version": "1.0.0" } }, { From 0888339cbd470ef63317a84fb3649740f19930eb Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 23 Dec 2022 11:42:41 -0300 Subject: [PATCH 16/29] Improve examples --- Examples/Examples.xcodeproj/project.pbxproj | 8 ++++ Examples/Examples/AddTodoListView.swift | 46 +++++++++++++++++++ Examples/Examples/TodoListRow.swift | 39 ++++++++++++++++ Examples/Examples/TodoListView.swift | 50 ++++++--------------- 4 files changed, 107 insertions(+), 36 deletions(-) create mode 100644 Examples/Examples/AddTodoListView.swift create mode 100644 Examples/Examples/TodoListRow.swift diff --git a/Examples/Examples.xcodeproj/project.pbxproj b/Examples/Examples.xcodeproj/project.pbxproj index a9bcc3fc..e4ecdaef 100644 --- a/Examples/Examples.xcodeproj/project.pbxproj +++ b/Examples/Examples.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 793895CC2954ABFF0044F2B8 /* RootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 793895CB2954ABFF0044F2B8 /* RootView.swift */; }; 793895CE2954AC000044F2B8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 793895CD2954AC000044F2B8 /* Assets.xcassets */; }; 793895D22954AC000044F2B8 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 793895D12954AC000044F2B8 /* Preview Assets.xcassets */; }; + 794EF1222955F26A008C9526 /* AddTodoListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 794EF1212955F26A008C9526 /* AddTodoListView.swift */; }; + 794EF1242955F3DE008C9526 /* TodoListRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 794EF1232955F3DE008C9526 /* TodoListRow.swift */; }; 7956405C2954AC3E0088A06F /* Supabase in Frameworks */ = {isa = PBXBuildFile; productRef = 7956405B2954AC3E0088A06F /* Supabase */; }; 7956405E2954ADE00088A06F /* Secrets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7956405D2954ADE00088A06F /* Secrets.swift */; }; 795640602954AE140088A06F /* AuthView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7956405F2954AE140088A06F /* AuthView.swift */; }; @@ -29,6 +31,8 @@ 793895CD2954AC000044F2B8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 793895CF2954AC000044F2B8 /* Examples.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Examples.entitlements; sourceTree = ""; }; 793895D12954AC000044F2B8 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 794EF1212955F26A008C9526 /* AddTodoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddTodoListView.swift; sourceTree = ""; }; + 794EF1232955F3DE008C9526 /* TodoListRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoListRow.swift; sourceTree = ""; }; 7956405D2954ADE00088A06F /* Secrets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Secrets.swift; sourceTree = ""; }; 7956405F2954AE140088A06F /* AuthView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthView.swift; sourceTree = ""; }; 795640612955AD2B0088A06F /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = ""; }; @@ -84,6 +88,8 @@ 795640652955AE9C0088A06F /* TodoListView.swift */, 795640672955AEB30088A06F /* Models.swift */, 795640692955AFBD0088A06F /* ErrorText.swift */, + 794EF1212955F26A008C9526 /* AddTodoListView.swift */, + 794EF1232955F3DE008C9526 /* TodoListRow.swift */, ); path = Examples; sourceTree = ""; @@ -184,6 +190,8 @@ files = ( 793895CC2954ABFF0044F2B8 /* RootView.swift in Sources */, 7956406A2955AFBD0088A06F /* ErrorText.swift in Sources */, + 794EF1242955F3DE008C9526 /* TodoListRow.swift in Sources */, + 794EF1222955F26A008C9526 /* AddTodoListView.swift in Sources */, 7956405E2954ADE00088A06F /* Secrets.swift in Sources */, 795640682955AEB30088A06F /* Models.swift in Sources */, 795640662955AE9C0088A06F /* TodoListView.swift in Sources */, diff --git a/Examples/Examples/AddTodoListView.swift b/Examples/Examples/AddTodoListView.swift new file mode 100644 index 00000000..9325b461 --- /dev/null +++ b/Examples/Examples/AddTodoListView.swift @@ -0,0 +1,46 @@ +// +// AddTodoListView.swift +// Examples +// +// Created by Guilherme Souza on 23/12/22. +// + +import SwiftUI + +struct AddTodoListView: View { + @Binding var request: CreateTodoRequest + let completion: (Result) -> Void + + var body: some View { + Section { + TextField("Description", text: $request.description) + Button("Save") { + Task { await saveButtonTapped() } + } + } + } + + func saveButtonTapped() async { + do { + let createdTodo: Todo = try await supabase.database.from("todos") + .insert(values: request, returning: .representation) + .single() + .execute() + .value + completion(.success(createdTodo)) + } catch { + completion(.failure(error)) + } + } +} + +struct AddTodoListView_Previews: PreviewProvider { + static var previews: some View { + AddTodoListView(request: .constant(.init( + description: "", + isComplete: false, + ownerID: UUID() + ))) { _ in + } + } +} diff --git a/Examples/Examples/TodoListRow.swift b/Examples/Examples/TodoListRow.swift new file mode 100644 index 00000000..566e90fb --- /dev/null +++ b/Examples/Examples/TodoListRow.swift @@ -0,0 +1,39 @@ +// +// TodoListRow.swift +// Examples +// +// Created by Guilherme Souza on 23/12/22. +// + +import SwiftUI + +struct TodoListRow: View { + let todo: Todo + let completeTapped: () -> Void + + var body: some View { + HStack { + Text(todo.description) + Spacer() + Button { + completeTapped() + } label: { + Image(systemName: todo.isComplete ? "checkmark.circle.fill" : "circle") + } + .buttonStyle(.plain) + } + } +} + +struct TodoListRow_Previews: PreviewProvider { + static var previews: some View { + TodoListRow( + todo: .init( + id: UUID(), + description: "", + isComplete: false, + createdAt: .now + ) + ) {} + } +} diff --git a/Examples/Examples/TodoListView.swift b/Examples/Examples/TodoListView.swift index b35fde56..b4017d09 100644 --- a/Examples/Examples/TodoListView.swift +++ b/Examples/Examples/TodoListView.swift @@ -24,24 +24,26 @@ struct TodoListView: View { } IfLet($createTodoRequest) { $createTodoRequest in - Section { - TextField("Description", text: $createTodoRequest.description) - Button("Save") { - Task { await saveNewTodoButtonTapped() } + AddTodoListView(request: $createTodoRequest) { result in + withAnimation { + self.createTodoRequest = nil + + switch result { + case let .success(todo): + error = nil + _ = todos.insert(todo, at: 0) + case let .failure(error): + self.error = error + } } } } ForEach(todos) { todo in - HStack { - Text(todo.description) - Spacer() - Button { - Task { await toggleCompletion(of: todo) } - } label: { - Image(systemName: todo.isComplete ? "checkmark.circle.fill" : "circle") + TodoListRow(todo: todo) { + Task { + await toggleCompletion(of: todo) } - .buttonStyle(.plain) } } .onDelete { indexSet in @@ -90,30 +92,6 @@ struct TodoListView: View { } } - func saveNewTodoButtonTapped() async { - guard let createTodoRequest else { - return - } - - do { - error = nil - - let createdTodo: Todo = try await supabase.database.from("todos") - .insert(values: createTodoRequest, returning: .representation) - .single() - .execute() - .value - - withAnimation { - todos.insert(createdTodo, at: 0) - self.createTodoRequest = nil - } - - } catch { - self.error = error - } - } - func toggleCompletion(of todo: Todo) async { var updatedTodo = todo updatedTodo.isComplete.toggle() From ce920b4aa9244cd73dc5b026239d5a3c60ce930d Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 3 Jan 2023 08:47:10 -0300 Subject: [PATCH 17/29] Add swift concurrency flags --- .swift-version | 1 - .swiftformat | 1 + Package.resolved | 15 ++++++++++++--- Package.swift | 8 ++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) delete mode 100644 .swift-version diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 2df33d76..00000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -5.6 diff --git a/.swiftformat b/.swiftformat index ae46a8c1..fc594a28 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,3 +1,4 @@ +--swiftversion 5.7 --binarygrouping none --decimalgrouping none --hexgrouping none diff --git a/Package.resolved b/Package.resolved index dfa00a70..81d83675 100644 --- a/Package.resolved +++ b/Package.resolved @@ -19,6 +19,15 @@ "version": "2.1.5" } }, + { + "package": "GetExtensions", + "repositoryURL": "https://github.com/binaryscraping/GetExtensions", + "state": { + "branch": null, + "revision": "aa20f38721142eb6592b2c8f11179d32d7d70ae3", + "version": "1.0.0" + } + }, { "package": "GoTrue", "repositoryURL": "https://github.com/supabase-community/gotrue-swift", @@ -41,9 +50,9 @@ "package": "PostgREST", "repositoryURL": "https://github.com/supabase-community/postgrest-swift", "state": { - "branch": "master", - "revision": "d96b5641e0c1574592f83deb73b5484c94f5ce0c", - "version": null + "branch": null, + "revision": "a3c2d6a2ede94d2529edf063b056b1a66fd9cdc2", + "version": "1.0.0" } }, { diff --git a/Package.swift b/Package.swift index 03ab9c5a..b1cf09c3 100644 --- a/Package.swift +++ b/Package.swift @@ -34,6 +34,14 @@ let package = Package( .product(name: "Realtime", package: "realtime-swift"), .product(name: "PostgREST", package: "postgrest-swift"), .product(name: "Functions", package: "functions-swift"), + ], + swiftSettings: [ + .unsafeFlags( + [ + "-warn-concurrency", + "-enable-actor-data-race-checks", + ] + ) ] ), .testTarget(name: "SupabaseTests", dependencies: ["Supabase"]), From 359d0f8ae02bd253b08df6aaff19d4ff6390e503 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 3 Jan 2023 08:47:43 -0300 Subject: [PATCH 18/29] Set gotrue version to 0.1.0 --- Package.swift | 2 +- .../xcshareddata/swiftpm/Package.resolved | 276 +++++++++--------- 2 files changed, 138 insertions(+), 140 deletions(-) diff --git a/Package.swift b/Package.swift index b1cf09c3..b6e12a5f 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,7 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/supabase-community/gotrue-swift", branch: "main"), + .package(url: "https://github.com/supabase-community/gotrue-swift", from: "0.1.0"), .package(url: "https://github.com/supabase-community/storage-swift.git", branch: "main"), .package(url: "https://github.com/supabase-community/realtime-swift.git", from: "0.0.1"), .package(url: "https://github.com/supabase-community/postgrest-swift", from: "1.0.0"), diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved index 948832c9..325cfb2a 100644 --- a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,142 +1,140 @@ { - "object": { - "pins": [ - { - "package": "functions-swift", - "repositoryURL": "https://github.com/supabase-community/functions-swift", - "state": { - "branch": null, - "revision": "7d5dfce3673bb30bbb7e1fbb5e0afe01bbd92624", - "version": "0.2.0" - } - }, - { - "package": "Get", - "repositoryURL": "https://github.com/kean/Get", - "state": { - "branch": null, - "revision": "7209fdb015686fd90918b2037cb2039206405bd3", - "version": "2.1.5" - } - }, - { - "package": "GetExtensions", - "repositoryURL": "https://github.com/binaryscraping/GetExtensions", - "state": { - "branch": null, - "revision": "aa20f38721142eb6592b2c8f11179d32d7d70ae3", - "version": "1.0.0" - } - }, - { - "package": "GoTrue", - "repositoryURL": "https://github.com/supabase-community/gotrue-swift", - "state": { - "branch": "main", - "revision": "7989dcbc5ee55451c4a4d43d0dce2c333389d3b4", - "version": null - } - }, - { - "package": "KeychainAccess", - "repositoryURL": "https://github.com/kishikawakatsumi/KeychainAccess", - "state": { - "branch": null, - "revision": "84e546727d66f1adc5439debad16270d0fdd04e7", - "version": "4.2.2" - } - }, - { - "package": "PostgREST", - "repositoryURL": "https://github.com/supabase-community/postgrest-swift", - "state": { - "branch": null, - "revision": "a3c2d6a2ede94d2529edf063b056b1a66fd9cdc2", - "version": "1.0.0" - } - }, - { - "package": "Realtime", - "repositoryURL": "https://github.com/supabase-community/realtime-swift.git", - "state": { - "branch": null, - "revision": "0b985c687fe963f6bd818ff77a35c27247b98bb4", - "version": "0.0.2" - } - }, - { - "package": "SupabaseStorage", - "repositoryURL": "https://github.com/supabase-community/storage-swift.git", - "state": { - "branch": "main", - "revision": "04703e499ca258899d7ad45717efe75b8ddc09ab", - "version": null - } - }, - { - "package": "swift-case-paths", - "repositoryURL": "https://github.com/pointfreeco/swift-case-paths", - "state": { - "branch": null, - "revision": "bb436421f57269fbcfe7360735985321585a86e5", - "version": "0.10.1" - } - }, - { - "package": "swift-collections", - "repositoryURL": "https://github.com/apple/swift-collections", - "state": { - "branch": null, - "revision": "937e904258d22af6e447a0b72c0bc67583ef64a2", - "version": "1.0.4" - } - }, - { - "package": "swift-custom-dump", - "repositoryURL": "https://github.com/pointfreeco/swift-custom-dump", - "state": { - "branch": null, - "revision": "ead7d30cc224c3642c150b546f4f1080d1c411a8", - "version": "0.6.1" - } - }, - { - "package": "swift-identified-collections", - "repositoryURL": "https://github.com/pointfreeco/swift-identified-collections.git", - "state": { - "branch": null, - "revision": "a08887de589e3829d488e0b4b707b2ca804b1060", - "version": "0.5.0" - } - }, - { - "package": "swiftui-navigation", - "repositoryURL": "https://github.com/pointfreeco/swiftui-navigation.git", - "state": { - "branch": null, - "revision": "46acf5ecc1cabdb28d7fe03289f6c8b13a023f52", - "version": "0.4.5" - } - }, - { - "package": "URLQueryEncoder", - "repositoryURL": "https://github.com/kean/URLQueryEncoder", - "state": { - "branch": null, - "revision": "4ce950479707ea109f229d7230ec074a133b15d7", - "version": "0.2.1" - } - }, - { - "package": "xctest-dynamic-overlay", - "repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay", - "state": { - "branch": null, - "revision": "df16fe6ffe4d6e2e06761aa67716b808b2c9109e", - "version": "0.7.0" - } + "pins" : [ + { + "identity" : "functions-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/functions-swift", + "state" : { + "revision" : "7d5dfce3673bb30bbb7e1fbb5e0afe01bbd92624", + "version" : "0.2.0" } - ] - }, - "version": 1 + }, + { + "identity" : "get", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kean/Get", + "state" : { + "revision" : "7209fdb015686fd90918b2037cb2039206405bd3", + "version" : "2.1.5" + } + }, + { + "identity" : "getextensions", + "kind" : "remoteSourceControl", + "location" : "https://github.com/binaryscraping/GetExtensions", + "state" : { + "revision" : "aa20f38721142eb6592b2c8f11179d32d7d70ae3", + "version" : "1.0.0" + } + }, + { + "identity" : "gotrue-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/gotrue-swift", + "state" : { + "revision" : "7989dcbc5ee55451c4a4d43d0dce2c333389d3b4", + "version" : "0.1.0" + } + }, + { + "identity" : "keychainaccess", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kishikawakatsumi/KeychainAccess", + "state" : { + "revision" : "84e546727d66f1adc5439debad16270d0fdd04e7", + "version" : "4.2.2" + } + }, + { + "identity" : "postgrest-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/postgrest-swift", + "state" : { + "revision" : "a3c2d6a2ede94d2529edf063b056b1a66fd9cdc2", + "version" : "1.0.0" + } + }, + { + "identity" : "realtime-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/realtime-swift.git", + "state" : { + "revision" : "0b985c687fe963f6bd818ff77a35c27247b98bb4", + "version" : "0.0.2" + } + }, + { + "identity" : "storage-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/storage-swift.git", + "state" : { + "branch" : "main", + "revision" : "04703e499ca258899d7ad45717efe75b8ddc09ab" + } + }, + { + "identity" : "swift-case-paths", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-case-paths", + "state" : { + "revision" : "bb436421f57269fbcfe7360735985321585a86e5", + "version" : "0.10.1" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections", + "state" : { + "revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", + "version" : "1.0.4" + } + }, + { + "identity" : "swift-custom-dump", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-custom-dump", + "state" : { + "revision" : "ead7d30cc224c3642c150b546f4f1080d1c411a8", + "version" : "0.6.1" + } + }, + { + "identity" : "swift-identified-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-identified-collections.git", + "state" : { + "revision" : "a08887de589e3829d488e0b4b707b2ca804b1060", + "version" : "0.5.0" + } + }, + { + "identity" : "swiftui-navigation", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swiftui-navigation.git", + "state" : { + "revision" : "46acf5ecc1cabdb28d7fe03289f6c8b13a023f52", + "version" : "0.4.5" + } + }, + { + "identity" : "urlqueryencoder", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kean/URLQueryEncoder", + "state" : { + "revision" : "4ce950479707ea109f229d7230ec074a133b15d7", + "version" : "0.2.1" + } + }, + { + "identity" : "xctest-dynamic-overlay", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", + "state" : { + "revision" : "df16fe6ffe4d6e2e06761aa67716b808b2c9109e", + "version" : "0.7.0" + } + } + ], + "version" : 2 } From d3bed5b9884ca991468cd8ff69dd69fa80506604 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 3 Jan 2023 08:51:28 -0300 Subject: [PATCH 19/29] Update packages --- Package.resolved | 90 ++----------------- .../xcshareddata/swiftpm/Package.resolved | 12 +-- 2 files changed, 14 insertions(+), 88 deletions(-) diff --git a/Package.resolved b/Package.resolved index 81d83675..70e97180 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,86 +1,12 @@ { - "object": { - "pins": [ - { - "package": "functions-swift", - "repositoryURL": "https://github.com/supabase-community/functions-swift", - "state": { - "branch": null, - "revision": "7d5dfce3673bb30bbb7e1fbb5e0afe01bbd92624", - "version": "0.2.0" - } - }, - { - "package": "Get", - "repositoryURL": "https://github.com/kean/Get", - "state": { - "branch": null, - "revision": "7209fdb015686fd90918b2037cb2039206405bd3", - "version": "2.1.5" - } - }, - { - "package": "GetExtensions", - "repositoryURL": "https://github.com/binaryscraping/GetExtensions", - "state": { - "branch": null, - "revision": "aa20f38721142eb6592b2c8f11179d32d7d70ae3", - "version": "1.0.0" - } - }, - { - "package": "GoTrue", - "repositoryURL": "https://github.com/supabase-community/gotrue-swift", - "state": { - "branch": "main", - "revision": "7989dcbc5ee55451c4a4d43d0dce2c333389d3b4", - "version": null - } - }, - { - "package": "KeychainAccess", - "repositoryURL": "https://github.com/kishikawakatsumi/KeychainAccess", - "state": { - "branch": null, - "revision": "84e546727d66f1adc5439debad16270d0fdd04e7", - "version": "4.2.2" - } - }, - { - "package": "PostgREST", - "repositoryURL": "https://github.com/supabase-community/postgrest-swift", - "state": { - "branch": null, - "revision": "a3c2d6a2ede94d2529edf063b056b1a66fd9cdc2", - "version": "1.0.0" - } - }, - { - "package": "Realtime", - "repositoryURL": "https://github.com/supabase-community/realtime-swift.git", - "state": { - "branch": null, - "revision": "0b985c687fe963f6bd818ff77a35c27247b98bb4", - "version": "0.0.2" - } - }, - { - "package": "SupabaseStorage", - "repositoryURL": "https://github.com/supabase-community/storage-swift.git", - "state": { - "branch": "main", - "revision": "04703e499ca258899d7ad45717efe75b8ddc09ab", - "version": null - } - }, - { - "package": "URLQueryEncoder", - "repositoryURL": "https://github.com/kean/URLQueryEncoder", - "state": { - "branch": null, - "revision": "4ce950479707ea109f229d7230ec074a133b15d7", - "version": "0.2.1" - } + "pins" : [ + { + "identity" : "functions-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/supabase-community/functions-swift", + "state" : { + "revision" : "7d5dfce3673bb30bbb7e1fbb5e0afe01bbd92624", + "version" : "0.2.0" } }, { diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved index 325cfb2a..b0c25acf 100644 --- a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/kean/Get", "state" : { - "revision" : "7209fdb015686fd90918b2037cb2039206405bd3", - "version" : "2.1.5" + "revision" : "12830cc64f31789ae6f4352d2d51d03a25fc3741", + "version" : "2.1.6" } }, { @@ -77,8 +77,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-case-paths", "state" : { - "revision" : "bb436421f57269fbcfe7360735985321585a86e5", - "version" : "0.10.1" + "revision" : "c3a42e8d1a76ff557cf565ed6d8b0aee0e6e75af", + "version" : "0.11.0" } }, { @@ -131,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "df16fe6ffe4d6e2e06761aa67716b808b2c9109e", - "version" : "0.7.0" + "revision" : "a9daebf0bf65981fd159c885d504481a65a75f02", + "version" : "0.8.0" } } ], From 00a94448fab312ea5e5af1a27f21ed758d05036e Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Wed, 18 Jan 2023 11:02:05 -0300 Subject: [PATCH 20/29] Rebase and update dependencies --- Examples/Examples.xcodeproj/project.pbxproj | 2 -- Package.swift | 10 +--------- .../xcshareddata/swiftpm/Package.resolved | 20 +++++++++---------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Examples/Examples.xcodeproj/project.pbxproj b/Examples/Examples.xcodeproj/project.pbxproj index e4ecdaef..ab418d8c 100644 --- a/Examples/Examples.xcodeproj/project.pbxproj +++ b/Examples/Examples.xcodeproj/project.pbxproj @@ -36,7 +36,6 @@ 7956405D2954ADE00088A06F /* Secrets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Secrets.swift; sourceTree = ""; }; 7956405F2954AE140088A06F /* AuthView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthView.swift; sourceTree = ""; }; 795640612955AD2B0088A06F /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = ""; }; - 795640632955ADFB0088A06F /* _Secrets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _Secrets.swift; sourceTree = ""; }; 795640652955AE9C0088A06F /* TodoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoListView.swift; sourceTree = ""; }; 795640672955AEB30088A06F /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = ""; }; 795640692955AFBD0088A06F /* ErrorText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorText.swift; sourceTree = ""; }; @@ -84,7 +83,6 @@ 793895CB2954ABFF0044F2B8 /* RootView.swift */, 7956405D2954ADE00088A06F /* Secrets.swift */, 795640612955AD2B0088A06F /* HomeView.swift */, - 795640632955ADFB0088A06F /* _Secrets.swift */, 795640652955AE9C0088A06F /* TodoListView.swift */, 795640672955AEB30088A06F /* Models.swift */, 795640692955AFBD0088A06F /* ErrorText.swift */, diff --git a/Package.swift b/Package.swift index b6e12a5f..39fdd325 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/supabase-community/gotrue-swift", from: "0.1.0"), - .package(url: "https://github.com/supabase-community/storage-swift.git", branch: "main"), + .package(url: "https://github.com/supabase-community/storage-swift.git", from: "0.1.0"), .package(url: "https://github.com/supabase-community/realtime-swift.git", from: "0.0.1"), .package(url: "https://github.com/supabase-community/postgrest-swift", from: "1.0.0"), .package(url: "https://github.com/supabase-community/functions-swift", from: "0.2.0"), @@ -34,14 +34,6 @@ let package = Package( .product(name: "Realtime", package: "realtime-swift"), .product(name: "PostgREST", package: "postgrest-swift"), .product(name: "Functions", package: "functions-swift"), - ], - swiftSettings: [ - .unsafeFlags( - [ - "-warn-concurrency", - "-enable-actor-data-race-checks", - ] - ) ] ), .testTarget(name: "SupabaseTests", dependencies: ["Supabase"]), diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved index b0c25acf..3b70c211 100644 --- a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/supabase-community/gotrue-swift", "state" : { - "revision" : "7989dcbc5ee55451c4a4d43d0dce2c333389d3b4", - "version" : "0.1.0" + "revision" : "052fff22d1c2ffa4c3a6b3b58432e251f352891b", + "version" : "0.1.1" } }, { @@ -68,8 +68,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/supabase-community/storage-swift.git", "state" : { - "branch" : "main", - "revision" : "04703e499ca258899d7ad45717efe75b8ddc09ab" + "revision" : "04703e499ca258899d7ad45717efe75b8ddc09ab", + "version" : "0.1.0" } }, { @@ -104,8 +104,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-identified-collections.git", "state" : { - "revision" : "a08887de589e3829d488e0b4b707b2ca804b1060", - "version" : "0.5.0" + "revision" : "fd34c544ad27f3ba6b19142b348005bfa85b6005", + "version" : "0.6.0" } }, { @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swiftui-navigation.git", "state" : { - "revision" : "46acf5ecc1cabdb28d7fe03289f6c8b13a023f52", - "version" : "0.4.5" + "revision" : "ddc01cdcddfd30ef7a966049b2e1d251e224ad93", + "version" : "0.5.0" } }, { @@ -131,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "a9daebf0bf65981fd159c885d504481a65a75f02", - "version" : "0.8.0" + "revision" : "16b23a295fa322eb957af98037f86791449de60f", + "version" : "0.8.1" } } ], From f09284e7b1097bebbc664d8e7a9ff9995d6cb16a Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Wed, 18 Jan 2023 11:03:20 -0300 Subject: [PATCH 21/29] Add headers parameter documentation --- Sources/Supabase/SupabaseClient.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Supabase/SupabaseClient.swift b/Sources/Supabase/SupabaseClient.swift index f539b674..6de08419 100644 --- a/Sources/Supabase/SupabaseClient.swift +++ b/Sources/Supabase/SupabaseClient.swift @@ -61,6 +61,7 @@ public class SupabaseClient { /// - supabaseURL: Unique Supabase project url /// - supabaseKey: Supabase anonymous API Key /// - schema: Database schema name, defaults to `public` + /// - headers: Optional headers for initializing the client. public init( supabaseURL: URL, supabaseKey: String, From 916130918d76bfdfd660b976375d1d8c89b11d80 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Wed, 18 Jan 2023 11:04:59 -0300 Subject: [PATCH 22/29] Use `adapt` method --- Sources/Supabase/SupabaseClient.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Sources/Supabase/SupabaseClient.swift b/Sources/Supabase/SupabaseClient.swift index 6de08419..3a85056e 100644 --- a/Sources/Supabase/SupabaseClient.swift +++ b/Sources/Supabase/SupabaseClient.swift @@ -110,12 +110,7 @@ public class SupabaseClient { extension SupabaseClient: APIClientDelegate { public func client(_: APIClient, willSendRequest request: inout URLRequest) async throws { - if let session = try? await auth.session { - request.setValue( - "\(session.tokenType) \(session.accessToken)", - forHTTPHeaderField: "Authorization" - ) - } + request = await adapt(request: request) } } From 3fcc81e5610f73d91f181400ead28330f616adcb Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Wed, 18 Jan 2023 11:13:07 -0300 Subject: [PATCH 23/29] Add CI for building example project --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++++ Makefile | 8 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..ea9a813a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - "*" + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + example: + runs-on: macos-12 + strategy: + matrix: + xcode: ["14.1"] + steps: + - uses: actions/checkout@v3 + - name: Select Xcode ${{ matrix.xcode }} + run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app + - name: Build example + run: make build-example \ No newline at end of file diff --git a/Makefile b/Makefile index 1f75b4ca..bb91c9d5 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,10 @@ +PLATFORM_IOS = iOS Simulator,name=iPhone 14 Pro Max + +build-example: + xcodebuild build \ + -workspace supabase-swift.xcworkspace \ + -scheme Examples \ + -destination platform="$(PLATFORM_IOS)" || exit 1; + format: @swiftformat . From 9bc8fcccf8ec0dbb0ccbf777b630f50b5cd1de53 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Wed, 18 Jan 2023 11:18:10 -0300 Subject: [PATCH 24/29] Fix CI --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea9a813a..39050cfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,5 +22,7 @@ jobs: - uses: actions/checkout@v3 - name: Select Xcode ${{ matrix.xcode }} run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app + - name: Setup Secrets.swift + run: cp Examples/Examples/_Secrets.swift Examples/Examples/Secrets.swift - name: Build example - run: make build-example \ No newline at end of file + run: make build-example From 497c412e0e03492a03ccfb1f60fcc611819f4586 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 13 Feb 2023 07:11:19 -0300 Subject: [PATCH 25/29] Update dependencies --- Package.swift | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Package.swift b/Package.swift index 39fdd325..3a2edca9 100644 --- a/Package.swift +++ b/Package.swift @@ -19,11 +19,11 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/supabase-community/gotrue-swift", from: "0.1.0"), + .package(url: "https://github.com/supabase-community/gotrue-swift", from: "1.0.0"), .package(url: "https://github.com/supabase-community/storage-swift.git", from: "0.1.0"), .package(url: "https://github.com/supabase-community/realtime-swift.git", from: "0.0.1"), .package(url: "https://github.com/supabase-community/postgrest-swift", from: "1.0.0"), - .package(url: "https://github.com/supabase-community/functions-swift", from: "0.2.0"), + .package(url: "https://github.com/supabase-community/functions-swift", from: "1.0.0"), ], targets: [ .target( diff --git a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved index 3b70c211..4c0dc28f 100644 --- a/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/supabase-community/functions-swift", "state" : { - "revision" : "7d5dfce3673bb30bbb7e1fbb5e0afe01bbd92624", - "version" : "0.2.0" + "revision" : "c680cdfc53399376bdece299b1387b4fb3da514e", + "version" : "1.0.0" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/supabase-community/gotrue-swift", "state" : { - "revision" : "052fff22d1c2ffa4c3a6b3b58432e251f352891b", - "version" : "0.1.1" + "revision" : "9626a5833224b92126bd3f2350e3a8e2f4cb7cc5", + "version" : "1.0.0" } }, { @@ -95,8 +95,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-custom-dump", "state" : { - "revision" : "ead7d30cc224c3642c150b546f4f1080d1c411a8", - "version" : "0.6.1" + "revision" : "dd86159e25c749873f144577e5d18309bf57534f", + "version" : "0.8.0" } }, { @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swiftui-navigation.git", "state" : { - "revision" : "ddc01cdcddfd30ef7a966049b2e1d251e224ad93", - "version" : "0.5.0" + "revision" : "270a754308f5440be52fc295242eb7031638bd15", + "version" : "0.6.1" } }, { @@ -131,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "16b23a295fa322eb957af98037f86791449de60f", - "version" : "0.8.1" + "revision" : "ace21305e0dd3a9e749aef79fef14be79a3b4669", + "version" : "0.8.2" } } ], From 081a7535784b0babae46b2912b1c5bb94d34fba9 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 13 Feb 2023 07:47:01 -0300 Subject: [PATCH 26/29] Add example functions --- .gitignore | 1 + .../supabase/functions/hello-world/index.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Examples/supabase/functions/hello-world/index.ts diff --git a/.gitignore b/.gitignore index 8aacde9f..21df42a7 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,4 @@ iOSInjectionProject/ /.swiftpm Secrets.swift +.env diff --git a/Examples/supabase/functions/hello-world/index.ts b/Examples/supabase/functions/hello-world/index.ts new file mode 100644 index 00000000..a9bc1c1e --- /dev/null +++ b/Examples/supabase/functions/hello-world/index.ts @@ -0,0 +1,25 @@ +// Follow this setup guide to integrate the Deno language server with your editor: +// https://deno.land/manual/getting_started/setup_your_environment +// This enables autocomplete, go to definition, etc. + +import { serve } from "https://deno.land/std@0.168.0/http/server.ts" + +console.log("Hello from Functions!") + +serve(async (req) => { + const { name } = await req.json() + const data = { + message: `Hello ${name}!`, + } + + return new Response( + JSON.stringify(data), + { headers: { "Content-Type": "application/json" } }, + ) +}) + +// To invoke: +// curl -i --location --request POST 'http://localhost:54321/functions/v1/' \ +// --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \ +// --header 'Content-Type: application/json' \ +// --data '{"name":"Functions"}' From 014269275e25ce63570977ef3790be0b3916776e Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 13 Feb 2023 07:48:55 -0300 Subject: [PATCH 27/29] swiftformat --- Sources/Supabase/SupabaseClient.swift | 2 +- Tests/SupabaseTests/SupabaseClientTests.swift | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Sources/Supabase/SupabaseClient.swift b/Sources/Supabase/SupabaseClient.swift index 3a85056e..9860f3d7 100644 --- a/Sources/Supabase/SupabaseClient.swift +++ b/Sources/Supabase/SupabaseClient.swift @@ -86,7 +86,7 @@ public class SupabaseClient { let isPlatform = supabaseURL.absoluteString.contains("supabase.co") - || supabaseURL.absoluteString.contains("supabase.in") + || supabaseURL.absoluteString.contains("supabase.in") if isPlatform { let urlParts = supabaseURL.absoluteString.split(separator: ".") functionsURL = URL(string: "\(urlParts[0]).functions.\(urlParts[1]).\(urlParts[2])")! diff --git a/Tests/SupabaseTests/SupabaseClientTests.swift b/Tests/SupabaseTests/SupabaseClientTests.swift index d51bcbf5..37ff44e5 100644 --- a/Tests/SupabaseTests/SupabaseClientTests.swift +++ b/Tests/SupabaseTests/SupabaseClientTests.swift @@ -1,15 +1,24 @@ -import XCTest @testable import Supabase +import XCTest final class SupabaseClientTests: XCTestCase { func testFunctionsURL() { - var client = SupabaseClient(supabaseURL: URL(string: "https://project-ref.supabase.co")!, supabaseKey: "ANON_KEY") + var client = SupabaseClient( + supabaseURL: URL(string: "https://project-ref.supabase.co")!, + supabaseKey: "ANON_KEY" + ) XCTAssertEqual(client.functionsURL.absoluteString, "https://project-ref.functions.supabase.co") - client = SupabaseClient(supabaseURL: URL(string: "https://project-ref.supabase.in")!, supabaseKey: "ANON_KEY") + client = SupabaseClient( + supabaseURL: URL(string: "https://project-ref.supabase.in")!, + supabaseKey: "ANON_KEY" + ) XCTAssertEqual(client.functionsURL.absoluteString, "https://project-ref.functions.supabase.in") - client = SupabaseClient(supabaseURL: URL(string: "https://custom-domain.com")!, supabaseKey: "ANON_KEY") + client = SupabaseClient( + supabaseURL: URL(string: "https://custom-domain.com")!, + supabaseKey: "ANON_KEY" + ) XCTAssertEqual(client.functionsURL.absoluteString, "https://custom-domain.com/functions/v1") } } From 852b9f1663244863d8c8977a0b4c3ba35d6b5a15 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 13 Feb 2023 11:26:06 -0300 Subject: [PATCH 28/29] Add scheme --- .github/workflows/ci.yml | 12 +++ .gitignore | 2 +- .../contents.xcworkspacedata | 7 ++ .../xcshareddata/xcschemes/Supabase.xcscheme | 77 +++++++++++++++++++ Makefile | 6 ++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/Supabase.xcscheme diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39050cfb..bed9dd79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,3 +26,15 @@ jobs: run: cp Examples/Examples/_Secrets.swift Examples/Examples/Secrets.swift - name: Build example run: make build-example + + test-library: + runs-on: macos-12 + steps: + - uses: actions/checkout@v3 + - name: Select Xcode ${{ matrix.xcode }} + run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app + - name: Setup Secrets.swift + run: cp Examples/Examples/_Secrets.swift Examples/Examples/Secrets.swift + - name: Test library + run: make test-library + \ No newline at end of file diff --git a/.gitignore b/.gitignore index 21df42a7..689f7498 100644 --- a/.gitignore +++ b/.gitignore @@ -93,7 +93,7 @@ iOSInjectionProject/ /.build /Packages /*.xcodeproj -/.swiftpm +# /.swiftpm Secrets.swift .env diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/Supabase.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/Supabase.xcscheme new file mode 100644 index 00000000..2b4e3972 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/Supabase.xcscheme @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Makefile b/Makefile index bb91c9d5..e3867858 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,11 @@ PLATFORM_IOS = iOS Simulator,name=iPhone 14 Pro Max +test-library: + xcodebuild test \ + -workspace supabase-swift.xcworkspace \ + -scheme Supabase \ + -destination platform="$(PLATFORM_IOS)" || exit 1; + build-example: xcodebuild build \ -workspace supabase-swift.xcworkspace \ From 731ba22e9f65549f59b453197b5ceecfd3afe0e7 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 13 Feb 2023 11:27:13 -0300 Subject: [PATCH 29/29] Remove xcode selection step from ci --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bed9dd79..b5e6f234 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,8 +31,6 @@ jobs: runs-on: macos-12 steps: - uses: actions/checkout@v3 - - name: Select Xcode ${{ matrix.xcode }} - run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app - name: Setup Secrets.swift run: cp Examples/Examples/_Secrets.swift Examples/Examples/Secrets.swift - name: Test library