From 7018d8f4b3b8ed2c8da07732483cf08746a9d352 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Fri, 3 Nov 2023 08:56:24 -0300 Subject: [PATCH] refactor: rename functions method parameters --- Sources/Functions/FunctionsClient.swift | 24 +++++++++---------- .../PostgREST/PostgrestFilterBuilder.swift | 13 ++++++---- .../FunctionsTests/FunctionsClientTests.swift | 10 ++++---- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Sources/Functions/FunctionsClient.swift b/Sources/Functions/FunctionsClient.swift index 44c3b78f..2321723d 100644 --- a/Sources/Functions/FunctionsClient.swift +++ b/Sources/Functions/FunctionsClient.swift @@ -51,17 +51,17 @@ public actor FunctionsClient { /// /// - Parameters: /// - functionName: The name of the function to invoke. - /// - invokeOptions: Options for invoking the function. (Default: empty `FunctionInvokeOptions`) + /// - options: Options for invoking the function. (Default: empty `FunctionInvokeOptions`) /// - decode: A closure to decode the response data and HTTPURLResponse into a `Response` /// object. /// - Returns: The decoded `Response` object. public func invoke( - functionName: String, - invokeOptions: FunctionInvokeOptions = .init(), + _ functionName: String, + options: FunctionInvokeOptions = .init(), decode: (Data, HTTPURLResponse) throws -> Response ) async throws -> Response { let (data, response) = try await rawInvoke( - functionName: functionName, invokeOptions: invokeOptions + functionName: functionName, invokeOptions: options ) return try decode(data, response) } @@ -70,15 +70,15 @@ public actor FunctionsClient { /// /// - Parameters: /// - functionName: The name of the function to invoke. - /// - invokeOptions: Options for invoking the function. (Default: empty `FunctionInvokeOptions`) + /// - options: Options for invoking the function. (Default: empty `FunctionInvokeOptions`) /// - decoder: The JSON decoder to use for decoding the response. (Default: `JSONDecoder()`) /// - Returns: The decoded object of type `T`. public func invoke( - functionName: String, - invokeOptions: FunctionInvokeOptions = .init(), + _ functionName: String, + options: FunctionInvokeOptions = .init(), decoder: JSONDecoder = JSONDecoder() ) async throws -> T { - try await invoke(functionName: functionName, invokeOptions: invokeOptions) { data, _ in + try await invoke(functionName, options: options) { data, _ in try decoder.decode(T.self, from: data) } } @@ -87,12 +87,12 @@ public actor FunctionsClient { /// /// - Parameters: /// - functionName: The name of the function to invoke. - /// - invokeOptions: Options for invoking the function. (Default: empty `FunctionInvokeOptions`) + /// - options: Options for invoking the function. (Default: empty `FunctionInvokeOptions`) public func invoke( - functionName: String, - invokeOptions: FunctionInvokeOptions = .init() + _ functionName: String, + options: FunctionInvokeOptions = .init() ) async throws { - try await invoke(functionName: functionName, invokeOptions: invokeOptions) { _, _ in () } + try await invoke(functionName, options: options) { _, _ in () } } private func rawInvoke( diff --git a/Sources/PostgREST/PostgrestFilterBuilder.swift b/Sources/PostgREST/PostgrestFilterBuilder.swift index a8a95f75..32d8ae1f 100644 --- a/Sources/PostgREST/PostgrestFilterBuilder.swift +++ b/Sources/PostgREST/PostgrestFilterBuilder.swift @@ -22,7 +22,7 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder { return self } - public func or(filters: URLQueryRepresentable) -> PostgrestFilterBuilder { + public func or(_ filters: URLQueryRepresentable) -> PostgrestFilterBuilder { mutableState.withValue { $0.request.query.append(URLQueryItem(name: "or", value: "(\(filters.queryValue.queryValue))")) } @@ -139,8 +139,10 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder { return self } - public func rangeAdjacent(_ column: String, range: URLQueryRepresentable) -> PostgrestFilterBuilder - { + public func rangeAdjacent( + _ column: String, + range: URLQueryRepresentable + ) -> PostgrestFilterBuilder { mutableState.withValue { $0.request.query.append(URLQueryItem(name: column, value: "adj.\(range.queryValue)")) } @@ -162,7 +164,8 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder { } public func textSearch( - _ column: String, query: URLQueryRepresentable, config: String? = nil, type: TextSearchType? = nil + _ column: String, query: URLQueryRepresentable, config: String? = nil, + type: TextSearchType? = nil ) -> PostgrestFilterBuilder { mutableState.withValue { $0.request.query.append( @@ -234,7 +237,7 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder { return self } - public func match(query: [String: URLQueryRepresentable]) -> PostgrestFilterBuilder { + public func match(_ query: [String: URLQueryRepresentable]) -> PostgrestFilterBuilder { mutableState.withValue { mutableState in query.forEach { key, value in mutableState.request.query.append(URLQueryItem( diff --git a/Tests/FunctionsTests/FunctionsClientTests.swift b/Tests/FunctionsTests/FunctionsClientTests.swift index 26c18f33..5e40b439 100644 --- a/Tests/FunctionsTests/FunctionsClientTests.swift +++ b/Tests/FunctionsTests/FunctionsClientTests.swift @@ -22,8 +22,8 @@ final class FunctionsClientTests: XCTestCase { let body = ["name": "Supabase"] try await sut.invoke( - functionName: "hello_world", - invokeOptions: .init(headers: ["X-Custom-Key": "value"], body: body) + "hello_world", + options: .init(headers: ["X-Custom-Key": "value"], body: body) ) let request = await _request.value @@ -44,7 +44,7 @@ final class FunctionsClientTests: XCTestCase { } do { - try await sut.invoke(functionName: "hello_world") + try await sut.invoke("hello_world") } catch let urlError as URLError { XCTAssertEqual(urlError.code, .badServerResponse) } catch { @@ -63,7 +63,7 @@ final class FunctionsClientTests: XCTestCase { } do { - try await sut.invoke(functionName: "hello_world") + try await sut.invoke("hello_world") XCTFail("Invoke should fail.") } catch let FunctionsError.httpError(code, data) { XCTAssertEqual(code, 300) @@ -86,7 +86,7 @@ final class FunctionsClientTests: XCTestCase { } do { - try await sut.invoke(functionName: "hello_world") + try await sut.invoke("hello_world") XCTFail("Invoke should fail.") } catch FunctionsError.relayError { } catch {