From 1ec695b12751b55af88c195ff40efd045ec3fd2a Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Sun, 5 Nov 2023 08:16:03 -0300 Subject: [PATCH 1/2] feat: add public init to MFA params --- Sources/GoTrue/Types.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/GoTrue/Types.swift b/Sources/GoTrue/Types.swift index ffbd16b6..d413e359 100644 --- a/Sources/GoTrue/Types.swift +++ b/Sources/GoTrue/Types.swift @@ -454,6 +454,10 @@ public struct AuthMFAEnrollResponse: Decodable, Hashable, Sendable { public struct MFAChallengeParams: Encodable, Hashable { /// ID of the factor to be challenged. Returned in ``GoTrueMFA/enroll(params:)``. public let factorId: String + + public init(factorId: String) { + self.factorId = factorId + } } public struct MFAVerifyParams: Encodable, Hashable { @@ -465,6 +469,12 @@ public struct MFAVerifyParams: Encodable, Hashable { /// Verification code provided by the user. public let code: String + + public init(factorId: String, challengeId: String, code: String) { + self.factorId = factorId + self.challengeId = challengeId + self.code = code + } } public struct MFAUnenrollParams: Encodable, Hashable, Sendable { From 108a30a3cf11fbab3a8103a00eac0e74a04cfb4c Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Sun, 5 Nov 2023 08:22:12 -0300 Subject: [PATCH 2/2] feat: support adding filter after rpc call --- .../xcshareddata/xcschemes/PostgREST.xcscheme | 66 +++++++++++++++++++ Sources/PostgREST/PostgrestClient.swift | 8 +-- Sources/PostgREST/PostgrestRpcBuilder.swift | 4 +- .../PostgRESTTests/BuildURLRequestTests.swift | 3 + .../testBuildRequest.call-rpc-with-filter.txt | 6 ++ 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/PostgREST.xcscheme create mode 100644 Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.call-rpc-with-filter.txt diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/PostgREST.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/PostgREST.xcscheme new file mode 100644 index 00000000..764dd662 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/PostgREST.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/PostgREST/PostgrestClient.swift b/Sources/PostgREST/PostgrestClient.swift index f01461d8..8217191f 100644 --- a/Sources/PostgREST/PostgrestClient.swift +++ b/Sources/PostgREST/PostgrestClient.swift @@ -112,13 +112,13 @@ public actor PostgrestClient { /// - params: The parameters to pass to the function call. /// - count: Count algorithm to use to count rows returned by the function. /// Only applicable for set-returning functions. - /// - Returns: A PostgrestTransformBuilder instance. + /// - Returns: A PostgrestFilterBuilder instance. /// - Throws: An error if the function call fails. public func rpc( _ fn: String, params: some Encodable, count: CountOption? = nil - ) throws -> PostgrestTransformBuilder { + ) throws -> PostgrestFilterBuilder { try PostgrestRpcBuilder( configuration: configuration, request: Request(path: "/rpc/\(fn)", method: .post, headers: configuration.headers) @@ -130,12 +130,12 @@ public actor PostgrestClient { /// - fn: The function name to call. /// - count: Count algorithm to use to count rows returned by the function. /// Only applicable for set-returning functions. - /// - Returns: A PostgrestTransformBuilder instance. + /// - Returns: A PostgrestFilterBuilder instance. /// - Throws: An error if the function call fails. public func rpc( _ fn: String, count: CountOption? = nil - ) throws -> PostgrestTransformBuilder { + ) throws -> PostgrestFilterBuilder { try rpc(fn, params: NoParams(), count: count) } } diff --git a/Sources/PostgREST/PostgrestRpcBuilder.swift b/Sources/PostgREST/PostgrestRpcBuilder.swift index 4b5b2dc3..16790fa1 100644 --- a/Sources/PostgREST/PostgrestRpcBuilder.swift +++ b/Sources/PostgREST/PostgrestRpcBuilder.swift @@ -16,7 +16,7 @@ public final class PostgrestRpcBuilder: PostgrestBuilder { params: some Encodable, head: Bool = false, count: CountOption? = nil - ) throws -> PostgrestTransformBuilder { + ) throws -> PostgrestFilterBuilder { // TODO: Support `HEAD` method // https://github.com/supabase/postgrest-js/blob/master/src/lib/PostgrestRpcBuilder.ts#L38 assert(head == false, "HEAD is not currently supported yet.") @@ -38,6 +38,6 @@ public final class PostgrestRpcBuilder: PostgrestBuilder { } } - return PostgrestTransformBuilder(self) + return PostgrestFilterBuilder(self) } } diff --git a/Tests/PostgRESTTests/BuildURLRequestTests.swift b/Tests/PostgRESTTests/BuildURLRequestTests.swift index bb315f4c..006173d6 100644 --- a/Tests/PostgRESTTests/BuildURLRequestTests.swift +++ b/Tests/PostgRESTTests/BuildURLRequestTests.swift @@ -62,6 +62,9 @@ final class BuildURLRequestTests: XCTestCase { TestCase(name: "call rpc without parameter") { client in try await client.rpc("test_fcn") }, + TestCase(name: "call rpc with filter") { client in + try await client.rpc("test_fcn").eq("id", value: 1) + }, TestCase(name: "test all filters and count") { client in var query = await client.from("todos").select() diff --git a/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.call-rpc-with-filter.txt b/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.call-rpc-with-filter.txt new file mode 100644 index 00000000..f1f12813 --- /dev/null +++ b/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.call-rpc-with-filter.txt @@ -0,0 +1,6 @@ +curl \ + --request POST \ + --header "Accept: application/json" \ + --header "Content-Type: application/json" \ + --header "X-Client-Info: postgrest-swift/x.y.z" \ + "https://example.supabase.co/rpc/test_fcn?id=eq.1" \ No newline at end of file