git.iko.soy/rowtype-yoga/purescript-supabase
on main help sign in
Add maybeSingle
623733esigma-andex
src/Supabase/Supabase.js+3−1
@@ -1,6 +1,5 @@
1import { supabaseClient } from "@supabase/auth-helpers-nextjs";
1import { supabaseClient } from "@supabase/auth-helpers-nextjs";
2
2
3−
4// supabaseClient.from("bla")
3// supabaseClient.from("bla")
5// .select("wurst")
4// .select("wurst")
6// .eq("", 1)
5// .eq("", 1)
@@ -34,6 +33,9 @@ export const eqImpl = (builder) => (key, value) => builder.eq(key, value);
34
33
35export const singleImpl = (filterBuilder) => () => filterBuilder.single();
34export const singleImpl = (filterBuilder) => () => filterBuilder.single();
36
35
36+export const maybeSingleImpl = (filterBuilder) => () =>
37+ filterBuilder.maybeSingle();
38+
37export const rangeImpl = (from) => (to) => (filterBuilder) => () =>
39export const rangeImpl = (from) => (to) => (filterBuilder) => () =>
38 filterBuilder.range(from, to);
40 filterBuilder.range(from, to);
39export const upsertImpl = (queryBuilder) => (values) =>
41export const upsertImpl = (queryBuilder) => (values) =>
src/Supabase/Supabase.purs+12−9
@@ -27,10 +27,10 @@ module Supabase.Supabase
27 , signInWithOtp
27 , signInWithOtp
28 , signOut
28 , signOut
29 , single
29 , single
30+ , maybeSingle
30 , update
31 , update
31 , upsert
32 , upsert
32− )
33− where
33+ ) where
34
34
35import Prelude
35import Prelude
36
36
@@ -122,11 +122,14 @@ else instance (YogaJson.ReadForeign output) => Equals FilterBuilder (Aff output)
122
122
123foreign import singleImpl :: FilterBuilder -> Effect (Promise Foreign)
123foreign import singleImpl :: FilterBuilder -> Effect (Promise Foreign)
124
124
125−--type ResultResponse d = { "data" :: Maybe d, status :: Int, error :: Maybe ResultError }
126−
127single :: forall t. YogaJson.ReadForeign t => FilterBuilder -> Aff (Response t)
125single :: forall t. YogaJson.ReadForeign t => FilterBuilder -> Aff (Response t)
128single = singleImpl >>> Promise.toAffE >=> Util.fromJSON
126single = singleImpl >>> Promise.toAffE >=> Util.fromJSON
129
127
128+foreign import maybeSingleImpl :: FilterBuilder -> Effect (Promise Foreign)
129+
130+maybeSingle :: forall t. YogaJson.ReadForeign t => FilterBuilder -> Aff (Response t)
131+maybeSingle = maybeSingleImpl >>> Promise.toAffE >=> Util.fromJSON
132+
130foreign import rangeImpl :: forall i. i -> i -> FilterBuilder -> Effect (Promise Foreign)
133foreign import rangeImpl :: forall i. i -> i -> FilterBuilder -> Effect (Promise Foreign)
131
134
132type CountResponse t = { | DataR t + ErrorR + CountR + StatusR + () }
135type CountResponse t = { | DataR t + ErrorR + CountR + StatusR + () }
@@ -170,14 +173,14 @@ foreign import getSessionImpl :: Client -> Effect (Promise Foreign)
170getSession :: Client -> Aff (Response SessionData)
173getSession :: Client -> Aff (Response SessionData)
171getSession client = getSessionImpl client # Promise.toAffE >>= Util.fromJSON
174getSession client = getSessionImpl client # Promise.toAffE >>= Util.fromJSON
172
175
173−type InternalFunctionResponse d = { "data" :: Nullable d, error :: Nullable { message :: String, context :: YogaJson.Core.Response}}
176+type InternalFunctionResponse d = { "data" :: Nullable d, error :: Nullable { message :: String, context :: YogaJson.Core.Response } }
174−foreign import invokeImpl :: forall body headers t. Client -> Fn3 String body headers (Effect $ Promise $ InternalFunctionResponse t)
175
177
176−type FunctionResponse d = { "data" :: Maybe d, error :: Maybe { message :: String, context :: Fetch.Response}}
178+foreign import invokeImpl :: forall body headers t. Client -> Fn3 String body headers (Effect $ Promise $ InternalFunctionResponse t)
177
179
180+type FunctionResponse d = { "data" :: Maybe d, error :: Maybe { message :: String, context :: Fetch.Response } }
178
181
179invoke ∷ forall t body headers. ReadForeign t ⇒ Client → String → body → headers → Aff (FunctionResponse t)
182invoke ∷ forall t body headers. ReadForeign t ⇒ Client → String → body → headers → Aff (FunctionResponse t)
180invoke client fn body headers = runFn3 (invokeImpl client) fn body headers # Promise.toAffE <#> convert
183invoke client fn body headers = runFn3 (invokeImpl client) fn body headers # Promise.toAffE <#> convert
181 where
184 where
182− convertError { message, context } = { message, context: FetchInternalResponse.convert context}
185+ convertError { message, context } = { message, context: FetchInternalResponse.convert context }
183− convert { "data": d, error } = { "data": Nullable.toMaybe d, error: Nullable.toMaybe error <#> convertError}
186+ convert { "data": d, error } = { "data": Nullable.toMaybe d, error: Nullable.toMaybe error <#> convertError }