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 ( MonadAff m
, MonadSession (SessionT m) , MonadSession (SessionT m)
, MonadCursor (CursorT t (SessionT m)) t , MonadCursor (CursorT t (SessionT m)) t
) => MonadPostgres ) =>
(PostgresT m) MonadPostgres
(SessionT m) (PostgresT m)
(CursorT ct (SessionT m)) (SessionT m)
ct (CursorT ct (SessionT m))
ct
where where
session m = do session m = do
pool <- ask pool <- ask
@@ -117,6 +118,7 @@ runPostgres cfg m =
let let
acq :: RE Unit m Pool acq :: RE Unit m Pool
acq = liftEffect $ Pool.make @r @missing @trash cfg acq = liftEffect $ Pool.make @r @missing @trash cfg
rel :: _ -> Pool -> RE Unit m Unit rel :: _ -> Pool -> RE Unit m Unit
rel _ p = RE.liftExcept $ hoist liftAff $ Pool.end p rel _ p = RE.liftExcept $ hoist liftAff $ Pool.end p
in 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 :: forall e m r. MonadEffect m => MonadError e m => Effect Unit -> m (Stream r) -> m (Stream r)
handleStream onError getStream = handleStream onError getStream =
flip catchError flip catchError
(\e -> liftEffect onError *> throwError e) (\e -> liftEffect onError *> throwError e)
do do
stream <- getStream stream <- getStream
liftEffect $ onErrorOrClose stream onError liftEffect $ onErrorOrClose stream onError
pure stream pure stream
onErrorOrClose :: forall r. Stream r -> Effect Unit -> Effect Unit onErrorOrClose :: forall r. Stream r -> Effect Unit -> Effect Unit
onErrorOrClose stream eff = do onErrorOrClose stream eff = do

View File

@@ -9,7 +9,7 @@ import Data.Time.Duration (class Duration, Days(..), Hours(..), Milliseconds(..)
import Effect (Effect) import Effect (Effect)
zero :: IntervalRecord 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 = type IntervalRecord =
{ years :: Int { years :: Int
@@ -85,4 +85,4 @@ fromDuration a =
seconds = Int.trunc $ minutesRem / secondFactor seconds = Int.trunc $ minutesRem / secondFactor
milliseconds = minutesRem - (Int.toNumber seconds * secondFactor) milliseconds = minutesRem - (Int.toNumber seconds * secondFactor)
in 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} */ /** @type {(a: unknown) => boolean} */
export const isInstanceOfInterval = a => { export const isInstanceOfInterval = a => {
return typeof a === 'object' return (
&& a !== null typeof a === 'object' &&
&& ('years' in a a !== null &&
|| 'months' in a ('years' in a ||
|| 'days' in a 'months' in a ||
|| 'hours' in a 'days' in a ||
|| 'minutes' in a 'hours' in a ||
|| 'seconds' in a 'minutes' in a ||
|| 'milliseconds' in a 'seconds' in a ||
) 'milliseconds' in a)
)
} }
export const modifyPgTypes = () => { 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.Error.Except as E.Except
import Effect.Postgres.Pool (Pool) import Effect.Postgres.Pool (Pool)
import Effect.Postgres.Pool import Effect.Postgres.Pool
(Config ( Config
, Pool , Pool
, PoolConfigRaw , PoolConfigRaw
, acquireE , acquireE

View File

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

View File

@@ -45,7 +45,7 @@ spec =
b `shouldEqual` 2 b `shouldEqual` 2
it "multiple sessions concurrently" \cfg -> do it "multiple sessions concurrently" \cfg -> do
nums <- X.run $ runPostgres cfg $ parTraverse (\n -> query $ "select $1 :: int" /\ n) (Array.range 1 3) 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 it "transaction commits" \cfg -> do
a <- X.run $ runPostgres cfg do a <- X.run $ runPostgres cfg do
exec_ "create temporary table test_txn_commits (id int);" exec_ "create temporary table test_txn_commits (id int);"
@@ -60,7 +60,7 @@ spec =
exec_ "insert into test_txn_rolls_back values (2);" exec_ "insert into test_txn_rolls_back values (2);"
throwError $ pure $ E.Other $ error "foo" throwError $ pure $ E.Other $ error "foo"
query "select * from test_txn_rolls_back" query "select * from test_txn_rolls_back"
a `shouldEqual` [1] a `shouldEqual` [ 1 ]
it "cursor" \cfg -> it "cursor" \cfg ->
X.run $ runPostgres cfg do X.run $ runPostgres cfg do
exec_ $ "create temporary table test_cursor_data (id int primary key generated always as identity)" 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 describe "Data.Postgres.Interval" do
it "parse & toRecord" do it "parse & toRecord" do
p <- liftEffect $ Interval.parse "3 days 04:05:06" 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 it "make & toRecord" do
let p = Interval.make $ 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} Interval.toRecord p `shouldEqual` Interval.zero { days = 3, hours = 4, minutes = 5, seconds = 6 }
describe "fromDuration" do describe "fromDuration" do
for_ for_
[ Milliseconds 100.0 /\ Interval.zero {milliseconds = 100.0} [ Milliseconds 100.0 /\ Interval.zero { milliseconds = 100.0 }
, Milliseconds 1000.0 /\ Interval.zero {seconds = 1} , Milliseconds 1000.0 /\ Interval.zero { seconds = 1 }
, Milliseconds 1100.0 /\ Interval.zero {seconds = 1, milliseconds = 100.0} , Milliseconds 1100.0 /\ Interval.zero { seconds = 1, milliseconds = 100.0 }
, Milliseconds 60000.0 /\ Interval.zero {minutes = 1} , Milliseconds 60000.0 /\ Interval.zero { minutes = 1 }
, Milliseconds 61100.0 /\ Interval.zero {minutes = 1, seconds = 1, milliseconds = 100.0} , Milliseconds 61100.0 /\ Interval.zero { minutes = 1, seconds = 1, milliseconds = 100.0 }
, Milliseconds 3600000.0 /\ Interval.zero {hours = 1} , Milliseconds 3600000.0 /\ Interval.zero { hours = 1 }
, Milliseconds 3661100.0 /\ Interval.zero {hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0} , Milliseconds 3661100.0 /\ Interval.zero { hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0 }
, Milliseconds 86400000.0 /\ Interval.zero {days = 1} , Milliseconds 86400000.0 /\ Interval.zero { days = 1 }
, Milliseconds 90061100.0 /\ Interval.zero {days = 1, hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0} , Milliseconds 90061100.0 /\ Interval.zero { days = 1, hours = 1, minutes = 1, seconds = 1, milliseconds = 100.0 }
] ]
\(i /\ o) -> it ("converts " <> show i) do \(i /\ o) -> it ("converts " <> show i) do
Interval.toRecord (Interval.fromDuration i) `shouldEqual` o Interval.toRecord (Interval.fromDuration i) `shouldEqual` o

View File

@@ -59,7 +59,7 @@ instance Arbitrary GenIntervalSubMonth where
minutes <- chooseInt 0 59 minutes <- chooseInt 0 59
seconds <- chooseInt 0 59 seconds <- chooseInt 0 59
milliseconds <- chooseFloat 0.0 999.9 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 newtype GenInterval = GenInterval Interval
@@ -73,7 +73,7 @@ instance Arbitrary GenInterval where
minutes <- chooseInt 0 59 minutes <- chooseInt 0 59
seconds <- chooseInt 0 59 seconds <- chooseInt 0 59
milliseconds <- chooseFloat 0.0 999.9 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 newtype GenSmallInt = GenSmallInt Int
@@ -225,13 +225,14 @@ spec =
let let
durationFromGenInterval :: forall d. Semigroup d => Duration d => Newtype d Number => GenIntervalSubMonth -> d durationFromGenInterval :: forall d. Semigroup d => Duration d => Newtype d Number => GenIntervalSubMonth -> d
durationFromGenInterval = fromMaybe (wrap 0.0) <<< Interval.toDuration <<< unwrap durationFromGenInterval = fromMaybe (wrap 0.0) <<< Interval.toDuration <<< unwrap
durationEq :: forall d. Duration d => Newtype d Number => d -> d -> Boolean durationEq :: forall d. Duration d => Newtype d Number => d -> d -> Boolean
durationEq a b = Number.abs (unwrap a - unwrap b) <= 0.001 durationEq a b = Number.abs (unwrap a - unwrap b) <= 0.001
check @Milliseconds @GenIntervalSubMonth { purs: "Milliseconds", 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 @Seconds @GenIntervalSubMonth { purs: "Seconds", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
check @Minutes @GenIntervalSubMonth { purs: "Minutes", 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 @Hours @GenIntervalSubMonth { purs: "Hours", sql: "interval", fromArb: durationFromGenInterval, isEq: durationEq }
check @Days @GenIntervalSubMonth { purs: "Days", 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 @GenSmallInt { purs: "Int", sql: "int2", fromArb: unwrap, isEq: eq }
check @Int { purs: "Int", sql: "int4", fromArb: identity, 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 it "bracket catches error in acq" $ const do
either <- either <-
flip RE.toEither unit flip RE.toEither unit
$ bracket $ bracket
(liftAff $ throwError $ Exn.error "foo") (liftAff $ throwError $ Exn.error "foo")
(const $ const $ pure unit) (const $ const $ pure unit)
(const $ pure unit) (const $ pure unit)
isLeft either `shouldEqual` true isLeft either `shouldEqual` true
it "bracket catches error in rel" $ const do it "bracket catches error in rel" $ const do
either <- either <-
flip RE.toEither unit flip RE.toEither unit
$ bracket $ bracket
(pure unit) (pure unit)
(const $ const $ liftAff $ throwError $ Exn.error "foo") (const $ const $ liftAff $ throwError $ Exn.error "foo")
(const $ pure unit) (const $ pure unit)
isLeft either `shouldEqual` true isLeft either `shouldEqual` true
it "bracket catches error in go" $ const do it "bracket catches error in go" $ const do
either <- either <-
flip RE.toEither unit flip RE.toEither unit
$ bracket $ bracket
(pure unit) (pure unit)
(const $ const $ pure unit) (const $ const $ pure unit)
(const $ liftAff $ throwError $ Exn.error "foo") (const $ liftAff $ throwError $ Exn.error "foo")
isLeft either `shouldEqual` true isLeft either `shouldEqual` true
it "forked bracket catches error in acq" $ const do it "forked bracket catches error in acq" $ const do
either <- flip RE.toEither unit do either <- flip RE.toEither unit do
fiber <- fiber <-
fork fork
$ bracket $ bracket
(liftAff $ throwError $ Exn.error "foo") (liftAff $ throwError $ Exn.error "foo")
(const $ const $ pure unit) (const $ const $ pure unit)
(const $ pure unit) (const $ pure unit)
liftAff $ delay $ wrap 1.0 liftAff $ delay $ wrap 1.0
join fiber join fiber
isLeft either `shouldEqual` true isLeft either `shouldEqual` true
@@ -99,10 +99,10 @@ spec =
either <- flip RE.toEither unit do either <- flip RE.toEither unit do
fiber <- fiber <-
fork fork
$ bracket $ bracket
(pure unit) (pure unit)
(const $ const $ liftAff $ throwError $ Exn.error "foo") (const $ const $ liftAff $ throwError $ Exn.error "foo")
(const $ pure unit) (const $ pure unit)
liftAff $ delay $ wrap 1.0 liftAff $ delay $ wrap 1.0
join fiber join fiber
isLeft either `shouldEqual` true isLeft either `shouldEqual` true
@@ -110,10 +110,10 @@ spec =
either <- flip RE.toEither unit do either <- flip RE.toEither unit do
fiber <- fiber <-
fork fork
$ bracket $ bracket
(pure unit) (pure unit)
(const $ const $ pure unit) (const $ const $ pure unit)
(const $ liftAff $ throwError $ Exn.error "foo") (const $ liftAff $ throwError $ Exn.error "foo")
liftAff $ delay $ wrap 1.0 liftAff $ delay $ wrap 1.0
join fiber join fiber
isLeft either `shouldEqual` true isLeft either `shouldEqual` true
@@ -121,7 +121,8 @@ spec =
either <- either <-
flip RE.toEither unit flip RE.toEither unit
$ parSequence $ parSequence
$ [ liftAff $ throwError $ Exn.error "a" $
[ liftAff $ throwError $ Exn.error "a"
, pure "a" , pure "a"
] ]
isLeft either `shouldEqual` true isLeft either `shouldEqual` true
@@ -129,7 +130,8 @@ spec =
either <- either <-
flip RE.toEither unit flip RE.toEither unit
$ parOneOf $ parOneOf
$ [ liftAff $ throwError $ Exn.error "a" $
[ liftAff $ throwError $ Exn.error "a"
, liftAff $ throwError $ Exn.error "b" , liftAff $ throwError $ Exn.error "b"
] ]
isLeft either `shouldEqual` true isLeft either `shouldEqual` true

View File

@@ -49,13 +49,13 @@ spec = describe "Pool" do
c <- X.run $ Pool.connect p 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 "acquire" \p -> do it "acquire" \p -> do
c <- X.run$ Pool.connect p c <- X.run $ Pool.connect p
liftEffect $ X.run$ Pool.release p c liftEffect $ X.run $ Pool.release p c
expect <- forkAff do expect <- forkAff do
c'' <- onceAff Pool.acquireE p c'' <- onceAff Pool.acquireE p
refEq c c'' `shouldEqual` true refEq c c'' `shouldEqual` true
c' <- X.run $ Pool.connect p 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 it "release" \p -> do
c <- X.run $ Pool.connect p c <- X.run $ Pool.connect p
expect <- forkAff do expect <- forkAff do