From e914bbd9987b168431d0e20a4f1f97b6cdc275c9 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Tue, 15 Nov 2022 20:46:43 -0300 Subject: [PATCH] Migrate to record studio --- Readme.md | 1 - packages.dhall | 4 +-- spago.dhall | 1 + src/HTTPurple/Record/Extra.js | 8 ------ src/HTTPurple/Record/Extra.purs | 49 --------------------------------- src/HTTPurple/Request.purs | 8 +++--- src/HTTPurple/Server.purs | 12 ++++---- 7 files changed, 13 insertions(+), 70 deletions(-) delete mode 100644 src/HTTPurple/Record/Extra.js delete mode 100644 src/HTTPurple/Record/Extra.purs diff --git a/Readme.md b/Readme.md index da52791..715dd2f 100644 --- a/Readme.md +++ b/Readme.md @@ -115,4 +115,3 @@ spago -x test.dhall test ## License This is a fork of [HTTPure](https://github.com/citizennet/purescript-httpure), which is licensed under MIT. See the [original license](./LICENSES/httpure.LICENSE). This work is similarly licensed under [MIT](./License). -It includes part of [`purescript-record-extra`](https://github.com/justinwoo/purescript-record-extra) as an inline dependency, which is licensed under MIT, see [original license](./LICENSES/record-extra.LICENSE). diff --git a/packages.dhall b/packages.dhall index 433d8fd..f082533 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,5 +1,5 @@ let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220822/packages.dhall - sha256:908b4ffbfba37a0a4edf806513a555d0dbcdd0cde7abd621f8d018d2e8ecf828 + https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221115/packages.dhall + sha256:cc53930f0ebfa5b1652f9e37eb7b1c424246ca78db3c7baf0b205e740e0e9e4e in upstream diff --git a/spago.dhall b/spago.dhall index c451861..60eb29e 100644 --- a/spago.dhall +++ b/spago.dhall @@ -29,6 +29,7 @@ , "prelude" , "profunctor" , "record" + , "record-studio" , "refs" , "routing-duplex" , "safe-coerce" diff --git a/src/HTTPurple/Record/Extra.js b/src/HTTPurple/Record/Extra.js deleted file mode 100644 index c7506d8..0000000 --- a/src/HTTPurple/Record/Extra.js +++ /dev/null @@ -1,8 +0,0 @@ - -export const pickFn = function(ks, r) { - var copy = {}; - for(var i = 0; i < ks.length; i++) { - copy[ks[i]] = r[ks[i]]; - } - return copy; - }; diff --git a/src/HTTPurple/Record/Extra.purs b/src/HTTPurple/Record/Extra.purs deleted file mode 100644 index fca3979..0000000 --- a/src/HTTPurple/Record/Extra.purs +++ /dev/null @@ -1,49 +0,0 @@ -module HTTPurple.Record.Extra where - -import Prelude - -import Data.Array (fromFoldable) -import Data.Function.Uncurried (Fn2, runFn2) -import Data.List (List, (:)) -import Data.Symbol (class IsSymbol, reflectSymbol) -import Prim.Row as Row -import Prim.RowList as RL -import Type.Proxy (Proxy(..)) - -class Keys (xs :: RL.RowList Type) where - keysImpl :: Proxy xs -> List String - -instance Keys RL.Nil where - keysImpl _ = mempty - -instance - ( IsSymbol name - , Keys tail - ) => - Keys (RL.Cons name ty tail) where - keysImpl _ = first : rest - where - first = reflectSymbol (Proxy :: _ name) - rest = keysImpl (Proxy :: _ tail) - -keys :: - forall g row rl. - RL.RowToList row rl => - Keys rl => - g row -- this will work for any type with the row as a param! - -> - List String -keys _ = keysImpl (Proxy :: _ rl) - -foreign import pickFn :: forall r1 r2. Fn2 (Array String) (Record r1) (Record r2) - -pick :: - forall a r b l. - Row.Union b r a => - RL.RowToList b l => - Keys l => - Record a -> - Record b -pick = runFn2 pickFn ks - where - ks = fromFoldable $ keys (Proxy :: _ b) diff --git a/src/HTTPurple/Request.purs b/src/HTTPurple/Request.purs index 8ca853f..be31174 100644 --- a/src/HTTPurple/Request.purs +++ b/src/HTTPurple/Request.purs @@ -29,8 +29,6 @@ import HTTPurple.Path (Path) import HTTPurple.Path (read) as Path import HTTPurple.Query (Query) import HTTPurple.Query (read) as Query -import HTTPurple.Record.Extra (pick) -import HTTPurple.Record.Extra as Extra import HTTPurple.Utils (encodeURIComponent) import HTTPurple.Version (Version) import HTTPurple.Version (read) as Version @@ -39,6 +37,8 @@ import Node.HTTP (requestURL) import Prim.Row (class Nub, class Union) import Prim.RowList (class RowToList) import Record (merge) +import Record.Studio (shrink) +import Record.Studio.Keys (class Keys) import Routing.Duplex as RD import Type.Prelude (Proxy) import Unsafe.Coerce (unsafeCoerce) @@ -110,7 +110,7 @@ fromHTTPRequestExt :: Union ctx thru ctx => Nub (RequestR route ctx) (RequestR route ctx) => RowToList ctx ctxRL => - Extra.Keys ctxRL => + Keys ctx => RD.RouteDuplex' route -> Proxy ctx -> HTTP.Request -> @@ -118,7 +118,7 @@ fromHTTPRequestExt :: fromHTTPRequestExt route _ nodeRequest = do let extension :: Record ctx - extension = pick (unsafeCoerce nodeRequest :: Record ctx) + extension = shrink (unsafeCoerce nodeRequest :: Record ctx) addExtension :: Request route -> ExtRequestNT route ctx addExtension = flip merge extension >>> ExtRequestNT diff --git a/src/HTTPurple/Server.purs b/src/HTTPurple/Server.purs index ba89b5f..9313ec6 100644 --- a/src/HTTPurple/Server.purs +++ b/src/HTTPurple/Server.purs @@ -28,7 +28,6 @@ import Effect.Class.Console (log) import Effect.Console (error) import Effect.Exception (Error) import HTTPurple.NodeMiddleware (MiddlewareResult(..), NextInvocation(..), NodeMiddlewareStack(..)) -import HTTPurple.Record.Extra as Extra import HTTPurple.Request (ExtRequest, ExtRequestNT, Request, RequestR, fromHTTPRequestExt, fromHTTPRequestUnit) import HTTPurple.Response (Response, ResponseM, internalServerError, notFound, send) import Justifill (justifill) @@ -44,6 +43,7 @@ import Node.Process (onSignal) import Prim.Row (class Nub, class Union) import Prim.RowList (class RowToList) import Record (merge) +import Record.Studio.Keys (class Keys, class KeysRL) import Routing.Duplex as RD import Safe.Coerce (coerce) import Type.Prelude (Proxy(..)) @@ -121,7 +121,7 @@ handleExtRequest :: forall ctx ctxRL thru route. Union ctx thru ctx => RowToList ctx ctxRL => - Extra.Keys ctxRL => + Keys ctx => Nub (RequestR route ctx) (RequestR route ctx) => { route :: RD.RouteDuplex' route , router :: ExtRequestNT route ctx -> ResponseM @@ -139,7 +139,7 @@ handleRequest :: forall ctx ctxRL thru route. Union ctx thru ctx => RowToList ctx ctxRL => - Extra.Keys ctxRL => + Keys ctx => Nub (RequestR route ctx) (RequestR route ctx) => { route :: RD.RouteDuplex' route , router :: ExtRequestNT route ctx -> ResponseM @@ -154,7 +154,7 @@ handleExtRequestWithMiddleware :: forall input output outputRL thru route. Union output thru output => RowToList output outputRL => - Extra.Keys outputRL => + Keys output => Nub (RequestR route output) (RequestR route output) => { route :: RD.RouteDuplex' route , nodeMiddleware :: NodeMiddlewareStack input output @@ -196,7 +196,7 @@ serveInternal :: JustifiableFields fromRL from () via => Union output thru output => RowToList output outputRL => - Extra.Keys outputRL => + KeysRL outputRL => Nub (RequestR route output) (RequestR route output) => { | from } -> Maybe (NodeMiddlewareStack input output) -> @@ -263,7 +263,7 @@ serveNodeMiddleware :: JustifiableFields fromRL from () via => Union output thru output => RowToList output outputRL => - Extra.Keys outputRL => + KeysRL outputRL => Nub (RequestR route output) (RequestR route output) => { | from } -> ExtRoutingSettings route input output ->