Skip to content

refactor: rename functions method parameters #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Sources/Functions/FunctionsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>(
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)
}
Expand All @@ -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<T: Decodable>(
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)
}
}
Expand All @@ -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(
Expand Down
13 changes: 8 additions & 5 deletions Sources/PostgREST/PostgrestFilterBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))"))
}
Expand Down Expand Up @@ -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)"))
}
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions Tests/FunctionsTests/FunctionsClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand Down