refactor: bun run fmt

This commit is contained in:
orion kindel
2026-01-28 10:13:53 -06:00
parent e492162253
commit dd518a10eb
11 changed files with 81 additions and 75 deletions

View File

@@ -74,11 +74,12 @@ instance
( MonadAff m
, MonadSession (SessionT m)
, MonadCursor (CursorT t (SessionT m)) t
) => MonadPostgres
(PostgresT m)
(SessionT m)
(CursorT ct (SessionT m))
ct
) =>
MonadPostgres
(PostgresT m)
(SessionT m)
(CursorT ct (SessionT m))
ct
where
session m = do
pool <- ask
@@ -117,6 +118,7 @@ runPostgres cfg m =
let
acq :: RE Unit m Pool
acq = liftEffect $ Pool.make @r @missing @trash cfg
rel :: _ -> Pool -> RE Unit m Unit
rel _ p = RE.liftExcept $ hoist liftAff $ Pool.end p
in

View File

@@ -93,12 +93,12 @@ instance (MonadStartSession s, MonadAff m) => MonadSession (RE s m) where
handleStream :: forall e m r. MonadEffect m => MonadError e m => Effect Unit -> m (Stream r) -> m (Stream r)
handleStream onError getStream =
flip catchError
(\e -> liftEffect onError *> throwError e)
do
stream <- getStream
liftEffect $ onErrorOrClose stream onError
pure stream
flip catchError
(\e -> liftEffect onError *> throwError e)
do
stream <- getStream
liftEffect $ onErrorOrClose stream onError
pure stream
onErrorOrClose :: forall r. Stream r -> Effect Unit -> Effect Unit
onErrorOrClose stream eff = do

View File

@@ -9,7 +9,7 @@ import Data.Time.Duration (class Duration, Days(..), Hours(..), Milliseconds(..)
import Effect (Effect)
zero :: IntervalRecord
zero = {years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 0.0}
zero = { years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 0.0 }
type IntervalRecord =
{ years :: Int
@@ -85,4 +85,4 @@ fromDuration a =
seconds = Int.trunc $ minutesRem / secondFactor
milliseconds = minutesRem - (Int.toNumber seconds * secondFactor)
in
make {years: 0, months: 0, days, hours, minutes, seconds, milliseconds}
make { years: 0, months: 0, days, hours, minutes, seconds, milliseconds }

View File

@@ -8,16 +8,17 @@ export const isInstanceOfBuffer = a => a instanceof Buffer
/** @type {(a: unknown) => boolean} */
export const isInstanceOfInterval = a => {
return typeof a === 'object'
&& a !== null
&& ('years' in a
|| 'months' in a
|| 'days' in a
|| 'hours' in a
|| 'minutes' in a
|| 'seconds' in a
|| 'milliseconds' in a
)
return (
typeof a === 'object' &&
a !== null &&
('years' in a ||
'months' in a ||
'days' in a ||
'hours' in a ||
'minutes' in a ||
'seconds' in a ||
'milliseconds' in a)
)
}
export const modifyPgTypes = () => {

View File

@@ -11,7 +11,7 @@ import Effect.Postgres.Error as E
import Effect.Postgres.Error.Except as E.Except
import Effect.Postgres.Pool (Pool)
import Effect.Postgres.Pool
(Config
( Config
, Pool
, PoolConfigRaw
, acquireE

View File

@@ -33,7 +33,7 @@ toString =
indent n s = fold $ ((fold $ Array.replicate n " ") <> _) <$> String.split (wrap "\n") s
jsError n e =
indent n (Effect.message e)
<> maybe "" (\s -> "\n" <> indent n s) (Effect.stack e)
<> maybe "" (\s -> "\n" <> indent n s) (Effect.stack e)
in
case _ of
Deserializing q es -> "Deserializing " <> show q <> "\n" <> indent 1 (show es)

View File

@@ -45,7 +45,7 @@ spec =
b `shouldEqual` 2
it "multiple sessions concurrently" \cfg -> do
nums <- X.run $ runPostgres cfg $ parTraverse (\n -> query $ "select $1 :: int" /\ n) (Array.range 1 3)
Array.sort nums `shouldEqual` [1, 2, 3]
Array.sort nums `shouldEqual` [ 1, 2, 3 ]
it "transaction commits" \cfg -> do
a <- X.run $ runPostgres cfg do
exec_ "create temporary table test_txn_commits (id int);"
@@ -60,7 +60,7 @@ spec =
exec_ "insert into test_txn_rolls_back values (2);"
throwError $ pure $ E.Other $ error "foo"
query "select * from test_txn_rolls_back"
a `shouldEqual` [1]
a `shouldEqual` [ 1 ]
it "cursor" \cfg ->
X.run $ runPostgres cfg do
exec_ $ "create temporary table test_cursor_data (id int primary key generated always as identity)"

View File

@@ -15,23 +15,23 @@ spec =
describe "Data.Postgres.Interval" do
it "parse & toRecord" do
p <- liftEffect $ Interval.parse "3 days 04:05:06"
Interval.toRecord p `shouldEqual` Interval.zero {days = 3, hours = 4, minutes = 5, seconds = 6}
Interval.toRecord p `shouldEqual` Interval.zero { days = 3, hours = 4, minutes = 5, seconds = 6 }
it "make & toRecord" do
let p = Interval.make $ Interval.zero {days = 3, hours = 4, minutes = 5, seconds = 6}
Interval.toRecord p `shouldEqual` Interval.zero {days = 3, hours = 4, minutes = 5, seconds = 6}
let p = Interval.make $ Interval.zero { days = 3, hours = 4, minutes = 5, seconds = 6 }
Interval.toRecord p `shouldEqual` Interval.zero { days = 3, hours = 4, minutes = 5, seconds = 6 }
describe "fromDuration" do
for_
[ Milliseconds 100.0 /\ Interval.zero {milliseconds = 100.0}
, Milliseconds 1000.0 /\ Interval.zero {seconds = 1}
, Milliseconds 1100.0 /\ Interval.zero {seconds = 1, milliseconds = 100.0}
, Milliseconds 60000.0 /\ Interval.zero {minutes = 1}
, Milliseconds 61100.0 /\ Interval.zero {minutes = 1, seconds = 1, milliseconds = 100.0}
, Milliseconds 3600000.0 /\ Interval.zero {hours = 1}
, Milliseconds 3661100.0 /\ Interval.zero {hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0}
, Milliseconds 86400000.0 /\ Interval.zero {days = 1}
, Milliseconds 90061100.0 /\ Interval.zero {days = 1, hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0}
[ Milliseconds 100.0 /\ Interval.zero { milliseconds = 100.0 }
, Milliseconds 1000.0 /\ Interval.zero { seconds = 1 }
, Milliseconds 1100.0 /\ Interval.zero { seconds = 1, milliseconds = 100.0 }
, Milliseconds 60000.0 /\ Interval.zero { minutes = 1 }
, Milliseconds 61100.0 /\ Interval.zero { minutes = 1, seconds = 1, milliseconds = 100.0 }
, Milliseconds 3600000.0 /\ Interval.zero { hours = 1 }
, Milliseconds 3661100.0 /\ Interval.zero { hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0 }
, Milliseconds 86400000.0 /\ Interval.zero { days = 1 }
, Milliseconds 90061100.0 /\ Interval.zero { days = 1, hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0 }
]
\(i /\ o) -> it ("converts " <> show i) do
Interval.toRecord (Interval.fromDuration i) `shouldEqual` o

View File

@@ -59,7 +59,7 @@ instance Arbitrary GenIntervalSubMonth where
minutes <- chooseInt 0 59
seconds <- chooseInt 0 59
milliseconds <- chooseFloat 0.0 999.9
pure $ wrap $ Interval.make $ Interval.zero {days = days, hours = hours, minutes = minutes, seconds = seconds, milliseconds = milliseconds}
pure $ wrap $ Interval.make $ Interval.zero { days = days, hours = hours, minutes = minutes, seconds = seconds, milliseconds = milliseconds }
newtype GenInterval = GenInterval Interval
@@ -73,7 +73,7 @@ instance Arbitrary GenInterval where
minutes <- chooseInt 0 59
seconds <- chooseInt 0 59
milliseconds <- chooseFloat 0.0 999.9
pure $ wrap $ Interval.make {years, months, days, hours, minutes, seconds, milliseconds}
pure $ wrap $ Interval.make { years, months, days, hours, minutes, seconds, milliseconds }
newtype GenSmallInt = GenSmallInt Int
@@ -225,13 +225,14 @@ spec =
let
durationFromGenInterval :: forall d. Semigroup d => Duration d => Newtype d Number => GenIntervalSubMonth -> d
durationFromGenInterval = fromMaybe (wrap 0.0) <<< Interval.toDuration <<< unwrap
durationEq :: forall d. Duration d => Newtype d Number => d -> d -> Boolean
durationEq a b = Number.abs (unwrap a - unwrap b) <= 0.001
check @Milliseconds @GenIntervalSubMonth { purs: "Milliseconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
check @Seconds @GenIntervalSubMonth { purs: "Seconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
check @Minutes @GenIntervalSubMonth { purs: "Minutes", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
check @Hours @GenIntervalSubMonth { purs: "Hours", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
check @Days @GenIntervalSubMonth { purs: "Days", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq}
check @Milliseconds @GenIntervalSubMonth { purs: "Milliseconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
check @Seconds @GenIntervalSubMonth { purs: "Seconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
check @Minutes @GenIntervalSubMonth { purs: "Minutes", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
check @Hours @GenIntervalSubMonth { purs: "Hours", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
check @Days @GenIntervalSubMonth { purs: "Days", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
check @Int @GenSmallInt { purs: "Int", sql: "int2", fromArb: unwrap, isEq: eq }
check @Int { purs: "Int", sql: "int4", fromArb: identity, isEq: eq }

View File

@@ -63,35 +63,35 @@ spec =
it "bracket catches error in acq" $ const do
either <-
flip RE.toEither unit
$ bracket
(liftAff $ throwError $ Exn.error "foo")
(const $ const $ pure unit)
(const $ pure unit)
$ bracket
(liftAff $ throwError $ Exn.error "foo")
(const $ const $ pure unit)
(const $ pure unit)
isLeft either `shouldEqual` true
it "bracket catches error in rel" $ const do
either <-
flip RE.toEither unit
$ bracket
(pure unit)
(const $ const $ liftAff $ throwError $ Exn.error "foo")
(const $ pure unit)
$ bracket
(pure unit)
(const $ const $ liftAff $ throwError $ Exn.error "foo")
(const $ pure unit)
isLeft either `shouldEqual` true
it "bracket catches error in go" $ const do
either <-
flip RE.toEither unit
$ bracket
(pure unit)
(const $ const $ pure unit)
(const $ liftAff $ throwError $ Exn.error "foo")
$ bracket
(pure unit)
(const $ const $ pure unit)
(const $ liftAff $ throwError $ Exn.error "foo")
isLeft either `shouldEqual` true
it "forked bracket catches error in acq" $ const do
either <- flip RE.toEither unit do
fiber <-
fork
$ bracket
(liftAff $ throwError $ Exn.error "foo")
(const $ const $ pure unit)
(const $ pure unit)
$ bracket
(liftAff $ throwError $ Exn.error "foo")
(const $ const $ pure unit)
(const $ pure unit)
liftAff $ delay $ wrap 1.0
join fiber
isLeft either `shouldEqual` true
@@ -99,10 +99,10 @@ spec =
either <- flip RE.toEither unit do
fiber <-
fork
$ bracket
(pure unit)
(const $ const $ liftAff $ throwError $ Exn.error "foo")
(const $ pure unit)
$ bracket
(pure unit)
(const $ const $ liftAff $ throwError $ Exn.error "foo")
(const $ pure unit)
liftAff $ delay $ wrap 1.0
join fiber
isLeft either `shouldEqual` true
@@ -110,10 +110,10 @@ spec =
either <- flip RE.toEither unit do
fiber <-
fork
$ bracket
(pure unit)
(const $ const $ pure unit)
(const $ liftAff $ throwError $ Exn.error "foo")
$ bracket
(pure unit)
(const $ const $ pure unit)
(const $ liftAff $ throwError $ Exn.error "foo")
liftAff $ delay $ wrap 1.0
join fiber
isLeft either `shouldEqual` true
@@ -121,7 +121,8 @@ spec =
either <-
flip RE.toEither unit
$ parSequence
$ [ liftAff $ throwError $ Exn.error "a"
$
[ liftAff $ throwError $ Exn.error "a"
, pure "a"
]
isLeft either `shouldEqual` true
@@ -129,7 +130,8 @@ spec =
either <-
flip RE.toEither unit
$ parOneOf
$ [ liftAff $ throwError $ Exn.error "a"
$
[ liftAff $ throwError $ Exn.error "a"
, liftAff $ throwError $ Exn.error "b"
]
isLeft either `shouldEqual` true

View File

@@ -49,13 +49,13 @@ spec = describe "Pool" do
c <- X.run $ Pool.connect p
finally (liftEffect $ X.run $ Pool.release p c) $ joinFiber expect
it "acquire" \p -> do
c <- X.run$ Pool.connect p
liftEffect $ X.run$ Pool.release p c
c <- X.run $ Pool.connect p
liftEffect $ X.run $ Pool.release p c
expect <- forkAff do
c'' <- onceAff Pool.acquireE p
refEq c c'' `shouldEqual` true
c' <- X.run $ Pool.connect p
finally (liftEffect $ X.run$ Pool.release p c') $ joinFiber expect
finally (liftEffect $ X.run $ Pool.release p c') $ joinFiber expect
it "release" \p -> do
c <- X.run $ Pool.connect p
expect <- forkAff do