Skip to content

Commit 8463fad

Browse files
authored
feat: add filter to RPC call (#150)
* feat: add public init to MFA params * feat: support adding filter after rpc call
1 parent 75699fc commit 8463fad

File tree

6 files changed

+91
-6
lines changed

6 files changed

+91
-6
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1500"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "PostgREST"
18+
BuildableName = "PostgREST"
19+
BlueprintName = "PostgREST"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
shouldAutocreateTestPlan = "YES">
31+
</TestAction>
32+
<LaunchAction
33+
buildConfiguration = "Debug"
34+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
35+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
36+
launchStyle = "0"
37+
useCustomWorkingDirectory = "NO"
38+
ignoresPersistentStateOnLaunch = "NO"
39+
debugDocumentVersioning = "YES"
40+
debugServiceExtension = "internal"
41+
allowLocationSimulation = "YES">
42+
</LaunchAction>
43+
<ProfileAction
44+
buildConfiguration = "Release"
45+
shouldUseLaunchSchemeArgsEnv = "YES"
46+
savedToolIdentifier = ""
47+
useCustomWorkingDirectory = "NO"
48+
debugDocumentVersioning = "YES">
49+
<MacroExpansion>
50+
<BuildableReference
51+
BuildableIdentifier = "primary"
52+
BlueprintIdentifier = "PostgREST"
53+
BuildableName = "PostgREST"
54+
BlueprintName = "PostgREST"
55+
ReferencedContainer = "container:">
56+
</BuildableReference>
57+
</MacroExpansion>
58+
</ProfileAction>
59+
<AnalyzeAction
60+
buildConfiguration = "Debug">
61+
</AnalyzeAction>
62+
<ArchiveAction
63+
buildConfiguration = "Release"
64+
revealArchiveInOrganizer = "YES">
65+
</ArchiveAction>
66+
</Scheme>

Sources/GoTrue/Types.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ public struct AuthMFAEnrollResponse: Decodable, Hashable, Sendable {
454454
public struct MFAChallengeParams: Encodable, Hashable {
455455
/// ID of the factor to be challenged. Returned in ``GoTrueMFA/enroll(params:)``.
456456
public let factorId: String
457+
458+
public init(factorId: String) {
459+
self.factorId = factorId
460+
}
457461
}
458462

459463
public struct MFAVerifyParams: Encodable, Hashable {
@@ -465,6 +469,12 @@ public struct MFAVerifyParams: Encodable, Hashable {
465469

466470
/// Verification code provided by the user.
467471
public let code: String
472+
473+
public init(factorId: String, challengeId: String, code: String) {
474+
self.factorId = factorId
475+
self.challengeId = challengeId
476+
self.code = code
477+
}
468478
}
469479

470480
public struct MFAUnenrollParams: Encodable, Hashable, Sendable {

Sources/PostgREST/PostgrestClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ public actor PostgrestClient {
112112
/// - params: The parameters to pass to the function call.
113113
/// - count: Count algorithm to use to count rows returned by the function.
114114
/// Only applicable for set-returning functions.
115-
/// - Returns: A PostgrestTransformBuilder instance.
115+
/// - Returns: A PostgrestFilterBuilder instance.
116116
/// - Throws: An error if the function call fails.
117117
public func rpc(
118118
_ fn: String,
119119
params: some Encodable,
120120
count: CountOption? = nil
121-
) throws -> PostgrestTransformBuilder {
121+
) throws -> PostgrestFilterBuilder {
122122
try PostgrestRpcBuilder(
123123
configuration: configuration,
124124
request: Request(path: "/rpc/\(fn)", method: .post, headers: configuration.headers)
@@ -130,12 +130,12 @@ public actor PostgrestClient {
130130
/// - fn: The function name to call.
131131
/// - count: Count algorithm to use to count rows returned by the function.
132132
/// Only applicable for set-returning functions.
133-
/// - Returns: A PostgrestTransformBuilder instance.
133+
/// - Returns: A PostgrestFilterBuilder instance.
134134
/// - Throws: An error if the function call fails.
135135
public func rpc(
136136
_ fn: String,
137137
count: CountOption? = nil
138-
) throws -> PostgrestTransformBuilder {
138+
) throws -> PostgrestFilterBuilder {
139139
try rpc(fn, params: NoParams(), count: count)
140140
}
141141
}

Sources/PostgREST/PostgrestRpcBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public final class PostgrestRpcBuilder: PostgrestBuilder {
1616
params: some Encodable,
1717
head: Bool = false,
1818
count: CountOption? = nil
19-
) throws -> PostgrestTransformBuilder {
19+
) throws -> PostgrestFilterBuilder {
2020
// TODO: Support `HEAD` method
2121
// https://github.com/supabase/postgrest-js/blob/master/src/lib/PostgrestRpcBuilder.ts#L38
2222
assert(head == false, "HEAD is not currently supported yet.")
@@ -38,6 +38,6 @@ public final class PostgrestRpcBuilder: PostgrestBuilder {
3838
}
3939
}
4040

41-
return PostgrestTransformBuilder(self)
41+
return PostgrestFilterBuilder(self)
4242
}
4343
}

Tests/PostgRESTTests/BuildURLRequestTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ final class BuildURLRequestTests: XCTestCase {
6262
TestCase(name: "call rpc without parameter") { client in
6363
try await client.rpc("test_fcn")
6464
},
65+
TestCase(name: "call rpc with filter") { client in
66+
try await client.rpc("test_fcn").eq("id", value: 1)
67+
},
6568
TestCase(name: "test all filters and count") { client in
6669
var query = await client.from("todos").select()
6770

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
curl \
2+
--request POST \
3+
--header "Accept: application/json" \
4+
--header "Content-Type: application/json" \
5+
--header "X-Client-Info: postgrest-swift/x.y.z" \
6+
"https://example.supabase.co/rpc/test_fcn?id=eq.1"

0 commit comments

Comments
 (0)