Skip to content

Commit a5b0a48

Browse files
committed
👽 purescript 15
1 parent db56174 commit a5b0a48

File tree

9 files changed

+1383
-77
lines changed

9 files changed

+1383
-77
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "purescript-firebase",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"main": "index.js",
55
"repository": "https://github.com/codingedgar/purescript-firebase.git",
66
"author": "codingedgar <[email protected]>",
@@ -9,6 +9,8 @@
99
"firebase": "9.9.2"
1010
},
1111
"devDependencies": {
12-
"purs-tidy": "0.9.1"
12+
"purescript": "0.15.4",
13+
"purs-tidy": "0.9.1",
14+
"spago": "0.20.9"
1315
}
1416
}

packages.dhall

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ in upstream
9999
-------------------------------
100100
-}
101101
let upstream =
102-
https://github.com/purescript/package-sets/releases/download/psc-0.14.5-20220224/packages.dhall sha256:67cc3d4f0e8fb72bb1413ba94ddd72a3ceb0783eb725e3b22ad7568b3b581163
102+
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221114/packages.dhall
103+
sha256:408417e1565850b0d5eae0d3ad9e11757202a1b44bb86c1ec2d595e4fef58141
103104

104105
in upstream

spago.dhall

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@ to generate this file without the comments in this block.
1414
, dependencies =
1515
[ "aff"
1616
, "aff-promise"
17+
, "argonaut"
1718
, "argonaut-core"
1819
, "effect"
1920
, "either"
2021
, "foreign"
21-
, "foreign-generic"
2222
, "functions"
2323
, "maybe"
2424
, "nullable"
2525
, "point-free"
2626
, "prelude"
27-
, "psci-support"
28-
, "transformers"
29-
, "undefined-or"
3027
, "unsafe-coerce"
3128
]
3229
, packages = ./packages.dhall

src/Firebase/App.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22
const { initializeApp, getApp } = require("firebase/app");
33

4-
exports.initializeAppImp = function (config) {
4+
export function initializeAppImp(config) {
55
return function () {
66
return initializeApp(config);
77
}
@@ -12,7 +12,7 @@ exports.initializeAppImp = function (config) {
1212
* @param {String} name
1313
* @returns {() => import("firebase/app").FirebaseApp}
1414
*/
15-
exports.getAppImp = function (name) {
15+
export function getAppImp(name) {
1616
return function () {
1717
return getApp(name);
1818
}
@@ -22,6 +22,6 @@ exports.initializeAppImp = function (config) {
2222
*
2323
* @returns {import("firebase/app").FirebaseApp}
2424
*/
25-
exports.getApp2Imp = function () {
26-
return getApp();
25+
export function getApp2Imp() {
26+
return getApp();
2727
}

src/Firebase/Auth.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ const {
1414
isSignInWithEmailLink,
1515
} = require("firebase/auth");
1616

17-
exports.createUserWithEmailAndPasswordImp = function (email, password, auth) {
17+
export function createUserWithEmailAndPasswordImp(email, password, auth) {
1818
return function () {
1919
return createUserWithEmailAndPassword(auth, email, password);
2020
}
2121
}
2222

23-
exports.signInAnonymouslyImp = function (auth) {
23+
export function signInAnonymouslyImp(auth) {
2424
return function () {
2525
return signInAnonymously(auth);
2626
}
2727
}
2828

29-
exports.signInWithEmailAndPasswordImp = function (email, password, auth) {
29+
export function signInWithEmailAndPasswordImp(email, password, auth) {
3030
return function () {
3131
return signInWithEmailAndPassword(auth, email, password);
3232
}
3333
}
3434

35-
exports.onAuthStateChangedImp = function (callback, auth) {
35+
export function onAuthStateChangedImp(callback, auth) {
3636
return function () {
3737
return onAuthStateChanged(auth, user => {
3838
callback(user)();
3939
});
4040
}
4141
}
4242

43-
exports.signOutImp = function (auth) {
43+
export function signOutImp(auth) {
4444
return function () {
4545
return signOut(auth);
4646
}
@@ -50,7 +50,7 @@ exports.signOutImp = function (auth) {
5050
*
5151
* @param {import("firebase/auth").User} user
5252
*/
53-
exports.getUserIdTokenImp = function (user, force) {
53+
export function getUserIdTokenImp(user, force) {
5454
return function () {
5555
return user.getIdToken(force)
5656
}
@@ -62,7 +62,7 @@ exports.getUserIdTokenImp = function (user, force) {
6262
* @param {import("firebase/app").FirebaseApp} firebase
6363
* @returns {() => import("firebase/auth").Auth}
6464
*/
65-
exports.getAuthImp = function (firebase) {
65+
export function getAuthImp(firebase) {
6666
return function () {
6767
return getAuth(firebase);
6868
}
@@ -75,7 +75,7 @@ exports.getAuthImp = function (firebase) {
7575
* @param {import("firebase/auth").ActionCodeSettings | undefined | null} config
7676
* @returns {() => Promise<void>}
7777
*/
78-
exports.sendEmailVerificationImp = function (user, config) {
78+
export function sendEmailVerificationImp(user, config) {
7979
return function () {
8080
return sendEmailVerification(user, config)
8181
}
@@ -135,7 +135,7 @@ exports.sendEmailVerificationImp = function (user, config) {
135135
* @param { Locale } languageCode
136136
* @returns {() => void}
137137
*/
138-
exports.setLanguageCodeImp = function (auth, languageCode) {
138+
export function setLanguageCodeImp(auth, languageCode) {
139139
return function () {
140140
auth.languageCode = languageCode
141141
}
@@ -146,7 +146,7 @@ exports.setLanguageCodeImp = function (auth, languageCode) {
146146
* @param {import("firebase/auth").Auth} auth
147147
* @returns {() => void}
148148
*/
149-
exports.getLanguageCodeImp = function (auth) {
149+
export function getLanguageCodeImp(auth) {
150150
return function () {
151151
auth.languageCode
152152
}
@@ -157,7 +157,7 @@ exports.getLanguageCodeImp = function (auth) {
157157
* @param {import("firebase/auth").Auth} auth
158158
* @returns {() => Void}
159159
*/
160-
exports.useDeviceLanguageImp = function (auth) {
160+
export function useDeviceLanguageImp(auth) {
161161
return function () {
162162
return useDeviceLanguage(auth)
163163
}
@@ -169,7 +169,7 @@ exports.useDeviceLanguageImp = function (auth) {
169169
* @param {import("firebase/auth").Auth} auth
170170
* @returns {() => () => Void} Unsubscribe
171171
*/
172-
exports.onIdTokenChangedImp = function (callback, auth) {
172+
export function onIdTokenChangedImp(callback, auth) {
173173
return function () {
174174
return onIdTokenChanged(auth, user => {
175175
callback(user)();
@@ -184,7 +184,7 @@ exports.onIdTokenChangedImp = function (callback, auth) {
184184
* @param {import("firebase/auth").Auth} auth
185185
* @returns {() => Promise<Void>}
186186
*/
187-
exports.sendSignInLinkToEmailImp = function (actionCodeSettings, email, auth) {
187+
export function sendSignInLinkToEmailImp(actionCodeSettings, email, auth) {
188188
return function () {
189189
return sendSignInLinkToEmail(auth, email, actionCodeSettings)
190190
}
@@ -196,7 +196,7 @@ exports.sendSignInLinkToEmailImp = function (actionCodeSettings, email, auth) {
196196
* @param {import("firebase/auth").Auth} auth
197197
* @returns {() => Boolean}
198198
*/
199-
exports.isSignInWithEmailLinkImp = function (emailLink, auth) {
199+
export function isSignInWithEmailLinkImp(emailLink, auth) {
200200
return function () {
201201
return isSignInWithEmailLink(auth, emailLink)
202202
}
@@ -209,7 +209,7 @@ exports.isSignInWithEmailLinkImp = function (emailLink, auth) {
209209
* @param {import("firebase/auth").Auth} auth
210210
* @returns {() => Promise<import("firebase/auth").UserCredential>}
211211
*/
212-
exports.signInWithEmailLinkImp = function (emailLink, email, auth) {
212+
export function signInWithEmailLinkImp(emailLink, email, auth) {
213213
return function () {
214214
return signInWithEmailLink(auth, email, emailLink)
215215
}

src/Firebase/Auth.purs

+28-25
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@ module Firebase.Auth
2626

2727
import Prelude
2828

29-
import Control.Monad.Except (runExcept)
3029
import Control.Promise (Promise, toAffE)
31-
import Data.Either (Either)
30+
import Data.Either (Either, note)
3231
import Data.Function.Uncurried (Fn1, Fn2, Fn3, runFn1, runFn2, runFn3)
3332
import Data.Generic.Rep (class Generic)
3433
import Data.Maybe (Maybe)
3534
import Data.Nullable (Nullable, null, toMaybe)
3635
import Effect (Effect)
3736
import Effect.Aff (Aff)
3837
import Firebase.App (FirebaseApp)
39-
import Foreign (MultipleErrors, fail, readString)
40-
import Foreign.Generic (Foreign, decode, encode, class Decode, class Encode, ForeignError(..))
4138
import Unsafe.Coerce (unsafeCoerce)
39+
import Data.Argonaut (class DecodeJson, class EncodeJson, Json, JsonDecodeError(..), encodeJson, decodeJson)
40+
import Data.Maybe (Maybe(..))
4241

4342
foreign import data Auth :: Type
4443

@@ -60,22 +59,26 @@ instance showLanguageCode :: Show LanguageCode where
6059

6160
derive instance genericLanguageCode :: Generic LanguageCode _
6261

63-
instance encodeLanguageCode :: Encode LanguageCode where
64-
encode =
65-
case _ of
66-
Spanish -> "es"
67-
SpanishLatinAmerica -> "es_419"
68-
English -> "en"
69-
>>> encode
70-
71-
instance decodeLanguageCode :: Decode LanguageCode where
72-
decode s =
73-
readString s
74-
>>= case _ of
75-
"es" -> pure Spanish
76-
"es_419" -> pure SpanishLatinAmerica
77-
"en" -> pure English
78-
x -> fail $ ForeignError ("cannot place locale" <> x)
62+
instance encodeJsonLanguageCode :: EncodeJson LanguageCode where
63+
encodeJson =
64+
( case _ of
65+
Spanish -> "es"
66+
SpanishLatinAmerica -> "es_419"
67+
English -> "en"
68+
)
69+
>>> encodeJson
70+
71+
instance decodeJsonLanguageCode :: DecodeJson LanguageCode where
72+
decodeJson json =
73+
do
74+
string <- decodeJson json
75+
( case string of
76+
"es" -> pure Spanish
77+
"es_419" -> pure SpanishLatinAmerica
78+
"en" -> pure English
79+
_ -> Nothing
80+
)
81+
# note (TypeMismatch string)
7982

8083
foreign import getAuthImp :: FirebaseApp -> Effect Auth
8184

@@ -133,15 +136,15 @@ foreign import sendEmailVerificationImp :: Fn2 User (Nullable ActionCodeSettings
133136
sendEmailVerification :: User -> Aff Unit
134137
sendEmailVerification user = runFn2 sendEmailVerificationImp user null # toAffE
135138

136-
foreign import setLanguageCodeImp :: Fn2 Auth Foreign (Effect Unit)
139+
foreign import setLanguageCodeImp :: Fn2 Auth Json (Effect Unit)
137140

138141
setLanguageCode :: LanguageCode -> Auth -> Effect Unit
139-
setLanguageCode lang auth = runFn2 setLanguageCodeImp auth (encode lang)
142+
setLanguageCode lang auth = runFn2 setLanguageCodeImp auth (encodeJson lang)
140143

141-
foreign import getLanguageCodeImp :: Fn1 Auth (Effect Foreign)
144+
foreign import getLanguageCodeImp :: Fn1 Auth (Effect Json)
142145

143-
getLanguageCode :: Auth -> Effect (Either MultipleErrors LanguageCode)
144-
getLanguageCode auth = runFn1 getLanguageCodeImp auth # map (decode >>> runExcept)
146+
getLanguageCode :: Auth -> Effect (Either JsonDecodeError LanguageCode)
147+
getLanguageCode auth = runFn1 getLanguageCodeImp auth # map decodeJson
145148

146149
foreign import useDeviceLanguageImp :: Fn1 Auth (Effect Unit)
147150

0 commit comments

Comments
 (0)