From b1e53dc7b548a91910591cda5d2ee1aaaa20f573 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:25:10 +0100 Subject: [PATCH 01/20] Rename package and improve request creation - Rename packages to Fetch.Core - Improve request creation and only generate minimal request options - Add basic spago set up --- packages.dhall | 6 + spago.dhall | 27 +++ src/{Web => Fetch/Core}/Fetch.js | 0 src/{Web => Fetch/Core}/Fetch.purs | 10 +- .../Core}/Fetch/AbortController.js | 0 .../Core}/Fetch/AbortController.purs | 4 +- src/{Web => Fetch/Core}/Fetch/Headers.js | 0 src/{Web => Fetch/Core}/Fetch/Headers.purs | 4 +- src/{Web => Fetch/Core}/Fetch/Integrity.purs | 4 +- src/{Web => Fetch/Core}/Fetch/Referrer.purs | 4 +- .../Core}/Fetch/ReferrerPolicy.purs | 2 +- src/{Web => Fetch/Core}/Fetch/Request.js | 0 src/Fetch/Core/Fetch/Request.purs | 153 ++++++++++++++ src/{Web => Fetch/Core}/Fetch/RequestBody.js | 0 .../Core}/Fetch/RequestBody.purs | 4 +- .../Core}/Fetch/RequestCache.purs | 4 +- .../Core}/Fetch/RequestCredentials.purs | 4 +- .../Core}/Fetch/RequestMode.purs | 4 +- .../Core}/Fetch/RequestRedirect.purs | 4 +- src/{Web => Fetch/Core}/Fetch/Response.js | 6 + src/{Web => Fetch/Core}/Fetch/Response.purs | 23 ++- src/Web/Fetch/Request.purs | 191 ------------------ test.dhall | 15 ++ test/Main.purs | 34 ++++ 24 files changed, 285 insertions(+), 218 deletions(-) create mode 100644 packages.dhall create mode 100644 spago.dhall rename src/{Web => Fetch/Core}/Fetch.js (100%) rename src/{Web => Fetch/Core}/Fetch.purs (75%) rename src/{Web => Fetch/Core}/Fetch/AbortController.js (100%) rename src/{Web => Fetch/Core}/Fetch/AbortController.purs (70%) rename src/{Web => Fetch/Core}/Fetch/Headers.js (100%) rename src/{Web => Fetch/Core}/Fetch/Headers.purs (96%) rename src/{Web => Fetch/Core}/Fetch/Integrity.purs (71%) rename src/{Web => Fetch/Core}/Fetch/Referrer.purs (84%) rename src/{Web => Fetch/Core}/Fetch/ReferrerPolicy.purs (96%) rename src/{Web => Fetch/Core}/Fetch/Request.js (100%) create mode 100644 src/Fetch/Core/Fetch/Request.purs rename src/{Web => Fetch/Core}/Fetch/RequestBody.js (100%) rename src/{Web => Fetch/Core}/Fetch/RequestBody.purs (85%) rename src/{Web => Fetch/Core}/Fetch/RequestCache.purs (91%) rename src/{Web => Fetch/Core}/Fetch/RequestCredentials.purs (86%) rename src/{Web => Fetch/Core}/Fetch/RequestMode.purs (89%) rename src/{Web => Fetch/Core}/Fetch/RequestRedirect.purs (86%) rename src/{Web => Fetch/Core}/Fetch/Response.js (89%) rename src/{Web => Fetch/Core}/Fetch/Response.purs (66%) delete mode 100644 src/Web/Fetch/Request.purs create mode 100644 test.dhall create mode 100644 test/Main.purs diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..a5803ee --- /dev/null +++ b/packages.dhall @@ -0,0 +1,6 @@ + +let upstream = + https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220816/packages.dhall + sha256:8b4467b4b5041914f9b765779c8936d6d4c230b1f60eb64f6269c71812fd7e98 + +in upstream diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..0e4e38b --- /dev/null +++ b/spago.dhall @@ -0,0 +1,27 @@ +{ name = "fetch-core" +, dependencies = + [ "arraybuffer-types" + , "arrays" + , "console" + , "effect" + , "foldable-traversable" + , "foreign" + , "foreign-object" + , "functions" + , "http-methods" + , "maybe" + , "newtype" + , "nullable" + , "prelude" + , "record" + , "tuples" + , "typelevel-prelude" + , "unfoldable" + , "unsafe-coerce" + , "web-file" + , "web-promise" + , "web-streams" + ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs" ] +} diff --git a/src/Web/Fetch.js b/src/Fetch/Core/Fetch.js similarity index 100% rename from src/Web/Fetch.js rename to src/Fetch/Core/Fetch.js diff --git a/src/Web/Fetch.purs b/src/Fetch/Core/Fetch.purs similarity index 75% rename from src/Web/Fetch.purs rename to src/Fetch/Core/Fetch.purs index 9ef390a..79066e5 100644 --- a/src/Web/Fetch.purs +++ b/src/Fetch/Core/Fetch.purs @@ -1,4 +1,4 @@ -module Web.Fetch +module Fetch.Core ( FetchOptions , fetch , fetchWithOptions @@ -7,9 +7,9 @@ module Web.Fetch import Effect (Effect) import Effect.Uncurried (EffectFn2, runEffectFn2) import Prim.Row as Row -import Web.Fetch.AbortController (AbortSignal) -import Web.Fetch.Request (Request) -import Web.Fetch.Response (Response) +import Fetch.Core.AbortController (AbortSignal) +import Fetch.Core.Request (Request) +import Fetch.Core.Response (Response) import Web.Promise (Promise) type FetchOptions = @@ -23,4 +23,4 @@ fetch :: Request -> Effect (Promise Response) fetch req = runEffectFn2 _fetch req {} fetchWithOptions :: forall r rx. Row.Union r rx FetchOptions => Request -> { | r } -> Effect (Promise Response) -fetchWithOptions = runEffectFn2 _fetch \ No newline at end of file +fetchWithOptions = runEffectFn2 _fetch diff --git a/src/Web/Fetch/AbortController.js b/src/Fetch/Core/Fetch/AbortController.js similarity index 100% rename from src/Web/Fetch/AbortController.js rename to src/Fetch/Core/Fetch/AbortController.js diff --git a/src/Web/Fetch/AbortController.purs b/src/Fetch/Core/Fetch/AbortController.purs similarity index 70% rename from src/Web/Fetch/AbortController.purs rename to src/Fetch/Core/Fetch/AbortController.purs index bf929b5..cb7de7b 100644 --- a/src/Web/Fetch/AbortController.purs +++ b/src/Fetch/Core/Fetch/AbortController.purs @@ -1,4 +1,4 @@ -module Web.Fetch.AbortController where +module Fetch.Core.AbortController where import Effect (Effect) import Prelude (Unit) @@ -11,4 +11,4 @@ foreign import new :: Effect AbortController foreign import abort :: AbortController -> Effect Unit -foreign import signal :: AbortController -> AbortSignal \ No newline at end of file +foreign import signal :: AbortController -> AbortSignal diff --git a/src/Web/Fetch/Headers.js b/src/Fetch/Core/Fetch/Headers.js similarity index 100% rename from src/Web/Fetch/Headers.js rename to src/Fetch/Core/Fetch/Headers.js diff --git a/src/Web/Fetch/Headers.purs b/src/Fetch/Core/Fetch/Headers.purs similarity index 96% rename from src/Web/Fetch/Headers.purs rename to src/Fetch/Core/Fetch/Headers.purs index 185a4ad..647ee3b 100644 --- a/src/Web/Fetch/Headers.purs +++ b/src/Fetch/Core/Fetch/Headers.purs @@ -1,4 +1,4 @@ -module Web.Fetch.Headers +module Fetch.Core.Headers ( Headers , fromFoldable , fromRecord @@ -50,4 +50,4 @@ toUnfoldable :: forall f. Unfoldable f => Headers -> f (Tuple String String) toUnfoldable = Array.toUnfoldable <<< toArray empty :: Headers -empty = fromFoldable [] \ No newline at end of file +empty = fromFoldable [] diff --git a/src/Web/Fetch/Integrity.purs b/src/Fetch/Core/Fetch/Integrity.purs similarity index 71% rename from src/Web/Fetch/Integrity.purs rename to src/Fetch/Core/Fetch/Integrity.purs index c9a4526..a5b8341 100644 --- a/src/Web/Fetch/Integrity.purs +++ b/src/Fetch/Core/Fetch/Integrity.purs @@ -1,4 +1,4 @@ -module Web.Fetch.Integrity where +module Fetch.Core.Integrity where import Data.Newtype (class Newtype) import Prelude (class Eq, class Ord) @@ -7,4 +7,4 @@ newtype Integrity = Integrity String derive instance newtypeIntegrity :: Newtype Integrity _ derive newtype instance eqIntegrity :: Eq Integrity -derive newtype instance ordIntegrity :: Ord Integrity \ No newline at end of file +derive newtype instance ordIntegrity :: Ord Integrity diff --git a/src/Web/Fetch/Referrer.purs b/src/Fetch/Core/Fetch/Referrer.purs similarity index 84% rename from src/Web/Fetch/Referrer.purs rename to src/Fetch/Core/Fetch/Referrer.purs index edbfcff..764cdfb 100644 --- a/src/Web/Fetch/Referrer.purs +++ b/src/Fetch/Core/Fetch/Referrer.purs @@ -1,4 +1,4 @@ -module Web.Fetch.Referrer where +module Fetch.Core.Referrer where data Referrer = ReferrerNone @@ -15,4 +15,4 @@ fromString :: String -> Referrer fromString = case _ of "none" -> ReferrerNone "client" -> ReferrerClient - url -> ReferrerUrl url \ No newline at end of file + url -> ReferrerUrl url diff --git a/src/Web/Fetch/ReferrerPolicy.purs b/src/Fetch/Core/Fetch/ReferrerPolicy.purs similarity index 96% rename from src/Web/Fetch/ReferrerPolicy.purs rename to src/Fetch/Core/Fetch/ReferrerPolicy.purs index e508b32..2ca9ffe 100644 --- a/src/Web/Fetch/ReferrerPolicy.purs +++ b/src/Fetch/Core/Fetch/ReferrerPolicy.purs @@ -1,4 +1,4 @@ -module Web.Fetch.ReferrerPolicy where +module Fetch.Core.ReferrerPolicy where import Data.Maybe (Maybe(..)) diff --git a/src/Web/Fetch/Request.js b/src/Fetch/Core/Fetch/Request.js similarity index 100% rename from src/Web/Fetch/Request.js rename to src/Fetch/Core/Fetch/Request.js diff --git a/src/Fetch/Core/Fetch/Request.purs b/src/Fetch/Core/Fetch/Request.purs new file mode 100644 index 0000000..c6c5627 --- /dev/null +++ b/src/Fetch/Core/Fetch/Request.purs @@ -0,0 +1,153 @@ +module Fetch.Core.Request + ( Request + , RequestOptions + , UnsafeRequestOptions + , class ToInternal + , class ToInternalConverter + , class ToInternalHelper + , convert + , convertHelper + , convertImpl + , new + , unsafeNew + ) where + +import Prelude + +import Data.HTTP.Method (Method) +import Data.Maybe (Maybe) +import Data.Newtype (un) +import Data.Nullable (Nullable) +import Data.Symbol (class IsSymbol) +import Effect (Effect) +import Effect.Uncurried (EffectFn2, runEffectFn2) +import Fetch.Core.Headers (Headers) +import Fetch.Core.Integrity (Integrity(..)) +import Fetch.Core.Referrer (Referrer) +import Fetch.Core.Referrer as Referrer +import Fetch.Core.ReferrerPolicy (ReferrerPolicy) +import Fetch.Core.ReferrerPolicy as ReferrerPolicy +import Fetch.Core.RequestBody (RequestBody) +import Fetch.Core.RequestCache (RequestCache) +import Fetch.Core.RequestCache as RequestCache +import Fetch.Core.RequestCredentials (RequestCredentials) +import Fetch.Core.RequestCredentials as RequestCredentials +import Fetch.Core.RequestMode (RequestMode) +import Fetch.Core.RequestMode as RequestMode +import Prim.Row (class Lacks, class Union) +import Prim.Row as R +import Prim.RowList as RL +import Record (delete, get, insert) +import Type.Proxy (Proxy(..)) + +foreign import data Request :: Type + +foreign import _unsafeNew :: forall r. EffectFn2 String { | r } Request + +type UnsafeRequestOptions = + ( method :: String + , headers :: Headers + , body :: RequestBody + , credentials :: String + , cache :: String + , mode :: String + , referrer :: Nullable String + , referrerPolicy :: String + , integrity :: String + ) + +type RequestOptions = + ( method :: Method + , headers :: Headers + , body :: RequestBody + , credentials :: RequestCredentials + , cache :: RequestCache + , mode :: RequestMode + , referrer :: Maybe Referrer + , referrerPolicy :: ReferrerPolicy + , integrity :: Integrity + ) + +toUnsafeOptions + :: forall input output thruIn thruOut + . Union input thruIn RequestOptions + => Union output thruOut UnsafeRequestOptions + => ToInternal input output + => { | input } + -> { | output } +toUnsafeOptions = convert + +unsafeNew :: String -> { | UnsafeRequestOptions } -> Effect Request +unsafeNew = runEffectFn2 _unsafeNew + +new + :: forall input output thruIn thruOut + . Union input thruIn RequestOptions + => Union output thruOut UnsafeRequestOptions + => ToInternal input output + => String + -> { | input } + -> Effect Request +new url options = runEffectFn2 _unsafeNew url (toUnsafeOptions options) + +class ToInternal input output | input -> output where + convert :: Record input -> Record output + +instance (Union rIn thru RequestOptions, RL.RowToList rIn rInRL, ToInternalHelper rIn rInRL rOut) => ToInternal (| rIn) (| rOut) where + convert = convertHelper (Proxy :: Proxy rInRL) + +class ToInternalHelper :: forall k. Row Type -> k -> Row Type -> Constraint +class ToInternalHelper input inputRL output | inputRL -> output where + convertHelper :: Proxy inputRL -> Record input -> Record output + +instance ToInternalHelper r RL.Nil () where + convertHelper _ _ = {} +else instance + ( ToInternalConverter tpeIn tpeOut + , R.Cons sym tpeIn tailIn r + , RL.RowToList tailIn tailInRL + , Lacks sym tailIn + , IsSymbol sym + , ToInternalHelper tailIn tailInRL tailOutput + , R.Cons sym tpeOut tailOutput output + , Lacks sym tailOutput + ) => + ToInternalHelper r (RL.Cons sym tpeIn tailInRL) output where + convertHelper _ r = insert (Proxy :: Proxy sym) head tail + where + tail :: Record tailOutput + tail = delete (Proxy :: Proxy sym) r # convertHelper (Proxy :: Proxy tailInRL) + + head :: tpeOut + head = get (Proxy :: Proxy sym) r # convertImpl + +class ToInternalConverter input output | input -> output where + convertImpl :: input -> output + +instance ToInternalConverter Method String where + convertImpl = show + +instance ToInternalConverter Headers Headers where + convertImpl = identity + +instance ToInternalConverter RequestBody RequestBody where + convertImpl = identity + +instance ToInternalConverter RequestCredentials String where + convertImpl = RequestCredentials.toString + +instance ToInternalConverter RequestCache String where + convertImpl = RequestCache.toString + +instance ToInternalConverter RequestMode String where + convertImpl = RequestMode.toString + +instance ToInternalConverter Referrer String where + convertImpl = Referrer.toString + +instance ToInternalConverter ReferrerPolicy String where + convertImpl = ReferrerPolicy.toString + +instance ToInternalConverter Integrity String where + convertImpl = un Integrity + diff --git a/src/Web/Fetch/RequestBody.js b/src/Fetch/Core/Fetch/RequestBody.js similarity index 100% rename from src/Web/Fetch/RequestBody.js rename to src/Fetch/Core/Fetch/RequestBody.js diff --git a/src/Web/Fetch/RequestBody.purs b/src/Fetch/Core/Fetch/RequestBody.purs similarity index 85% rename from src/Web/Fetch/RequestBody.purs rename to src/Fetch/Core/Fetch/RequestBody.purs index 7b937c6..a817de3 100644 --- a/src/Web/Fetch/RequestBody.purs +++ b/src/Fetch/Core/Fetch/RequestBody.purs @@ -1,4 +1,4 @@ -module Web.Fetch.RequestBody where +module Fetch.Core.RequestBody where import Data.ArrayBuffer.Types (ArrayBuffer, ArrayView, Uint8Array) import Web.Streams.ReadableStream (ReadableStream) @@ -13,4 +13,4 @@ foreign import fromString :: String -> RequestBody foreign import fromReadableStream :: ReadableStream Uint8Array -> RequestBody -foreign import empty :: RequestBody \ No newline at end of file +foreign import empty :: RequestBody diff --git a/src/Web/Fetch/RequestCache.purs b/src/Fetch/Core/Fetch/RequestCache.purs similarity index 91% rename from src/Web/Fetch/RequestCache.purs rename to src/Fetch/Core/Fetch/RequestCache.purs index 10d244a..58fdb18 100644 --- a/src/Web/Fetch/RequestCache.purs +++ b/src/Fetch/Core/Fetch/RequestCache.purs @@ -1,4 +1,4 @@ -module Web.Fetch.RequestCache where +module Fetch.Core.RequestCache where import Data.Maybe (Maybe(..)) @@ -27,4 +27,4 @@ fromString = case _ of "no-cache" -> Just NoCache "force-cache" -> Just ForceCache "only-if-cached" -> Just OnlyIfCached - _ -> Nothing \ No newline at end of file + _ -> Nothing diff --git a/src/Web/Fetch/RequestCredentials.purs b/src/Fetch/Core/Fetch/RequestCredentials.purs similarity index 86% rename from src/Web/Fetch/RequestCredentials.purs rename to src/Fetch/Core/Fetch/RequestCredentials.purs index 8727295..b146887 100644 --- a/src/Web/Fetch/RequestCredentials.purs +++ b/src/Fetch/Core/Fetch/RequestCredentials.purs @@ -1,4 +1,4 @@ -module Web.Fetch.RequestCredentials where +module Fetch.Core.RequestCredentials where import Data.Maybe (Maybe(..)) @@ -18,4 +18,4 @@ fromString = case _ of "omit" -> Just Omit "same-origin" -> Just SameOrigin "include" -> Just Include - _ -> Nothing \ No newline at end of file + _ -> Nothing diff --git a/src/Web/Fetch/RequestMode.purs b/src/Fetch/Core/Fetch/RequestMode.purs similarity index 89% rename from src/Web/Fetch/RequestMode.purs rename to src/Fetch/Core/Fetch/RequestMode.purs index c173e1d..cca2ca8 100644 --- a/src/Web/Fetch/RequestMode.purs +++ b/src/Fetch/Core/Fetch/RequestMode.purs @@ -1,4 +1,4 @@ -module Web.Fetch.RequestMode where +module Fetch.Core.RequestMode where import Data.Maybe (Maybe(..)) @@ -21,4 +21,4 @@ fromString = case _ of "no-cors" -> Just NoCors "same-origin" -> Just SameOrigin "navigate" -> Just Navigate - _ -> Nothing \ No newline at end of file + _ -> Nothing diff --git a/src/Web/Fetch/RequestRedirect.purs b/src/Fetch/Core/Fetch/RequestRedirect.purs similarity index 86% rename from src/Web/Fetch/RequestRedirect.purs rename to src/Fetch/Core/Fetch/RequestRedirect.purs index ee215db..391d7f5 100644 --- a/src/Web/Fetch/RequestRedirect.purs +++ b/src/Fetch/Core/Fetch/RequestRedirect.purs @@ -1,4 +1,4 @@ -module Web.Fetch.RequestRedirect where +module Fetch.Core.RequestRedirect where import Data.Maybe (Maybe(..)) @@ -18,4 +18,4 @@ fromString = case _ of "follow" -> Just Follow "error" -> Just Error "manual" -> Just Manual - _ -> Nothing \ No newline at end of file + _ -> Nothing diff --git a/src/Web/Fetch/Response.js b/src/Fetch/Core/Fetch/Response.js similarity index 89% rename from src/Web/Fetch/Response.js rename to src/Fetch/Core/Fetch/Response.js index 7c2db67..382921c 100644 --- a/src/Web/Fetch/Response.js +++ b/src/Fetch/Core/Fetch/Response.js @@ -45,3 +45,9 @@ export function text(resp) { return resp.text(); }; } + +export function json(resp) { + return function() { + return resp.json(); + }; +} diff --git a/src/Web/Fetch/Response.purs b/src/Fetch/Core/Fetch/Response.purs similarity index 66% rename from src/Web/Fetch/Response.purs rename to src/Fetch/Core/Fetch/Response.purs index fc0e9e7..79ebb6e 100644 --- a/src/Web/Fetch/Response.purs +++ b/src/Fetch/Core/Fetch/Response.purs @@ -1,8 +1,23 @@ -module Web.Fetch.Response where +module Fetch.Core.Response + ( Response + , arrayBuffer + , blob + , body + , headers + , json + , ok + , redirected + , status + , statusText + , text + , url + ) + where import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array) import Effect (Effect) -import Web.Fetch.Headers (Headers) +import Fetch.Core.Headers (Headers) +import Foreign (Foreign) import Web.File.Blob (Blob) import Web.Promise (Promise) import Web.Streams.ReadableStream (ReadableStream) @@ -27,4 +42,6 @@ foreign import arrayBuffer :: Response -> Effect (Promise ArrayBuffer) foreign import blob :: Response -> Effect (Promise Blob) -foreign import text :: Response -> Effect (Promise String) \ No newline at end of file +foreign import text :: Response -> Effect (Promise String) + +foreign import json :: Response -> Effect (Promise Foreign) diff --git a/src/Web/Fetch/Request.purs b/src/Web/Fetch/Request.purs deleted file mode 100644 index 35ff325..0000000 --- a/src/Web/Fetch/Request.purs +++ /dev/null @@ -1,191 +0,0 @@ -module Web.Fetch.Request - ( Request - , RequestOptions - , UnsafeRequestOptions - , new - , new' - , unsafeNew - , class BuildRequestOptions - , buildRequestOptions - , defaultOptions - , defaultUnsafeOptions - , class ConvertOptions - , convertOptions - , class ConvertOption - , convertOption - ) where - -import Prelude - -import Data.ArrayBuffer.Types (ArrayBuffer, ArrayView) -import Data.HTTP.Method (Method(..)) -import Data.Maybe (Maybe(..)) -import Data.Newtype (un) -import Data.Nullable (Nullable, toNullable) -import Data.Symbol (class IsSymbol) -import Data.Tuple (Tuple) -import Effect (Effect) -import Effect.Uncurried (EffectFn2, runEffectFn2) -import Foreign.Object (Object) -import Prim.Row as Row -import Prim.RowList (RowList) -import Prim.RowList as RowList -import Record (merge) -import Record.Builder as Record -import Type.Proxy (Proxy(..)) -import Type.Row.Homogeneous (class Homogeneous) -import Web.Fetch.Headers (Headers) -import Web.Fetch.Headers as Headers -import Web.Fetch.Integrity (Integrity(..)) -import Web.Fetch.Referrer (Referrer) -import Web.Fetch.Referrer as Referrer -import Web.Fetch.ReferrerPolicy (ReferrerPolicy) -import Web.Fetch.ReferrerPolicy as ReferrerPolicy -import Web.Fetch.RequestBody (RequestBody) -import Web.Fetch.RequestBody as RequestBody -import Web.Fetch.RequestCache (RequestCache) -import Web.Fetch.RequestCache as RequestCache -import Web.Fetch.RequestCredentials (RequestCredentials) -import Web.Fetch.RequestCredentials as RequestCredentials -import Web.Fetch.RequestMode (RequestMode) -import Web.Fetch.RequestMode as RequestMode - -foreign import data Request :: Type - -foreign import _unsafeNew :: forall r. EffectFn2 String { | r } Request - -type UnsafeRequestOptions = - ( method :: String - , headers :: Headers - , body :: RequestBody - , credentials :: String - , cache :: String - , mode :: String - , referrer :: Nullable String - , referrerPolicy :: String - , integrity :: String - ) - -type RequestOptions = - ( method :: Method - , headers :: Headers - , body :: RequestBody - , credentials :: RequestCredentials - , cache :: RequestCache - , mode :: RequestMode - , referrer :: Maybe Referrer - , referrerPolicy :: ReferrerPolicy - , integrity :: Integrity - ) - -defaultOptions :: { | RequestOptions } -defaultOptions = - { method: GET - , headers: Headers.empty - , body: RequestBody.empty - , credentials: RequestCredentials.SameOrigin - , cache: RequestCache.Default - , mode: RequestMode.Cors - , referrer: Nothing - , referrerPolicy: ReferrerPolicy.NoReferrer - , integrity: Integrity "" - } - -defaultUnsafeOptions :: { | UnsafeRequestOptions } -defaultUnsafeOptions = toUnsafeOptions defaultOptions - -toUnsafeOptions :: { | RequestOptions } -> { | UnsafeRequestOptions } -toUnsafeOptions opts = - { method: show opts.method - , headers: opts.headers - , body: opts.body - , credentials: RequestCredentials.toString opts.credentials - , cache: RequestCache.toString opts.cache - , mode: RequestMode.toString opts.mode - , referrer: toNullable $ Referrer.toString <$> opts.referrer - , referrerPolicy: ReferrerPolicy.toString opts.referrerPolicy - , integrity: un Integrity opts.integrity - } - -unsafeNew :: String -> { | UnsafeRequestOptions } -> Effect Request -unsafeNew = runEffectFn2 _unsafeNew - -new :: String -> { | RequestOptions } -> Effect Request -new url options = runEffectFn2 _unsafeNew url (toUnsafeOptions options) - -new' :: forall r. BuildRequestOptions { | r } => String -> { | r } -> Effect Request -new' url options = runEffectFn2 _unsafeNew url (toUnsafeOptions (buildRequestOptions options)) - -class BuildRequestOptions a where - buildRequestOptions :: a -> { | RequestOptions } - -instance buildRequestOptionsRecord - :: ( RowList.RowToList r rl - , ConvertOptions rl r r' - , Row.Union r' RequestOptions r'' - , Row.Nub r'' RequestOptions - ) - => BuildRequestOptions { | r } where - buildRequestOptions r = merge (Record.build (convertOptions (Proxy :: _ rl)) r) defaultOptions - -class ConvertOptions (rl :: RowList Type) (input :: Row Type) (output :: Row Type) | rl input -> output where - convertOptions :: forall rlproxy. rlproxy rl -> Record.Builder { | input } { | output } - -instance convertOptionsCons :: - ( ConvertOptions rest input' output - , ConvertOption field from to - , Row.Cons field from rx input - , Row.Cons field to rx input' - , IsSymbol field - ) => ConvertOptions (RowList.Cons field from rest) input output where - convertOptions _ = - convertOptions (Proxy :: _ rest) - <<< Record.modify (Proxy :: _ field) (convertOption (Proxy :: _ field)) - -instance convertOptionsNil :: ConvertOptions RowList.Nil r r where - convertOptions _ = identity - -class ConvertOption (field :: Symbol) from to | field -> to where - convertOption :: forall sproxy. sproxy field -> from -> to - -instance convertMethod :: ConvertOption "method" Method Method where - convertOption _ = identity - -instance convertBody :: ConvertOption "body" RequestBody RequestBody where - convertOption _ = identity - -instance convertBodyString :: ConvertOption "body" String RequestBody where - convertOption _ = RequestBody.fromString - -instance convertBodyBuffer :: ConvertOption "body" ArrayBuffer RequestBody where - convertOption _ = RequestBody.fromArrayBuffer - -instance convertBodyView :: ConvertOption "body" (ArrayView t) RequestBody where - convertOption _ = RequestBody.fromArrayView - -instance convertHeaders :: ConvertOption "headers" Headers Headers where - convertOption _ = identity - -instance convertHeadersRecord :: Homogeneous r String => ConvertOption "headers" { | r } Headers where - convertOption _ = Headers.fromRecord - -instance convertHeadersObject :: ConvertOption "headers" (Object String) Headers where - convertOption _ = Headers.fromObject - -instance convertHeadersArray :: ConvertOption "headers" (Array (Tuple String String)) Headers where - convertOption _ = Headers.fromFoldable - -instance convertCache :: ConvertOption "cache" RequestCache RequestCache where - convertOption _ = identity - -instance convertMode :: ConvertOption "mode" RequestMode RequestMode where - convertOption _ = identity - -instance convertReferrer :: ConvertOption "referrer" Referrer (Maybe Referrer) where - convertOption _ = Just - -instance convertReferrerPolicy :: ConvertOption "referrerPolicy" ReferrerPolicy ReferrerPolicy where - convertOption _ = identity - -instance convertIntegrity :: ConvertOption "integrity" Integrity Integrity where - convertOption _ = identity diff --git a/test.dhall b/test.dhall new file mode 100644 index 0000000..06eb399 --- /dev/null +++ b/test.dhall @@ -0,0 +1,15 @@ +let conf = ./spago.dhall + +in conf + // { sources = conf.sources # [ "test/**/*.purs" ] + , dependencies = + conf.dependencies + # [ "aff" + , "aff-promise" + , "effect" + , "spec" + , "spec-discovery" + , "strings" + , "debug" + ] + } diff --git a/test/Main.purs b/test/Main.purs new file mode 100644 index 0000000..5418ad4 --- /dev/null +++ b/test/Main.purs @@ -0,0 +1,34 @@ +module Test.Main where + +import Prelude + +import Control.Promise as Promise +import Data.HTTP.Method (Method(..)) +import Debug (spy) +import Effect (Effect) +import Effect.Aff (launchAff, launchAff_) +import Effect.Class (liftEffect) +import Effect.Class.Console (log) +import Fetch.Core as Fetch +import Fetch.Core.Headers as Headers +import Fetch.Core.Request as Request +import Fetch.Core.RequestBody as RequestBody +import Fetch.Core.Response as Response +import Unsafe.Coerce (unsafeCoerce) + +main :: Effect Unit +main = launchAff_ do + let requestBody = """{"hello":"world"}""" + request <- liftEffect $ Request.new "http://httpbin.org/post" + { method: POST + , body: RequestBody.fromString requestBody + , headers: Headers.fromRecord { "Content-Type": "application/json" } + } + let + _ = spy "request" request + response <- Promise.toAffE $ unsafeCoerce $ Fetch.fetch request + responseBody <- Promise.toAffE $ unsafeCoerce $ Response.text response + let _ = spy "response" response + log $ show $ Response.status response + log responseBody + log "You should add some tests." From c9f757f358aba7c2396e2ecb681b4fbce4e6ed27 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:30:36 +0100 Subject: [PATCH 02/20] Update readme --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 359bcb1..bdd9f05 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ -# purescript-web-fetch +# purescript-fetch-core -[![Latest release](http://img.shields.io/github/release/purescript-web/purescript-web-fetch.svg)](https://github.com/purescript-web/purescript-web-fetch/releases) -[![Build status](https://github.com/purescript-web/purescript-web-fetch/workflows/CI/badge.svg?branch=master)](https://github.com/purescript-web/purescript-web-fetch/actions?query=workflow%3ACI+branch%3Amaster) -[![Pursuit](https://pursuit.purescript.org/packages/purescript-web-fetch/badge)](https://pursuit.purescript.org/packages/purescript-web-fetch) +[![Latest release](http://img.shields.io/github/release/rowtype-yoga/purescript-fetch-core.svg)](https://github.com/rowtype-yoga/purescript-fetch-core/releases) +[![Build status](https://github.com/rowtype-yoga/purescript-fetch-core/workflows/CI/badge.svg?branch=master)](https://github.com/rowtype-yoga/purescript-fetch-core/actions?query=workflow%3ACI+branch%3Amaster) +[![Pursuit](https://pursuit.purescript.org/packages/purescript-fetch-core/badge)](https://pursuit.purescript.org/packages/purescript-fetch-core) Types and low-level implementations for the [WHATWG Fetch Living Standard](https://fetch.spec.whatwg.org/). +For a high-level library see [`purescript-fetch`](https://github.com/rowtype-yoga/purescript-fetch) + ## Installation ``` -spago install web-fetch +spago install fetch-core ``` ## Documentation -Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-web-fetch). +Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-fetch-core). From 5bc41457e860ba1a54d7ca59fc52d508efb45da1 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Fri, 19 Aug 2022 14:11:34 +0100 Subject: [PATCH 03/20] Formatting, cleanup, fix referrer --- src/Fetch/Core/Fetch/Headers.purs | 10 +++++++--- src/Fetch/Core/Fetch/Integrity.purs | 6 +++--- src/Fetch/Core/Fetch/Referrer.purs | 2 +- src/Fetch/Core/Fetch/Request.purs | 7 +++---- src/Fetch/Core/Fetch/Response.purs | 3 +-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Fetch/Core/Fetch/Headers.purs b/src/Fetch/Core/Fetch/Headers.purs index 647ee3b..feae194 100644 --- a/src/Fetch/Core/Fetch/Headers.purs +++ b/src/Fetch/Core/Fetch/Headers.purs @@ -36,9 +36,13 @@ foreign import fromObject :: Object String -> Headers fromFoldable :: forall f. Foldable f => f (Tuple String String) -> Headers fromFoldable f = unsafePerformEffect do init <- unsafeNew - foldM (\headers (Tuple key value) -> do - runEffectFn3 unsafeAppend key value headers - pure headers) init f + foldM + ( \headers (Tuple key value) -> do + runEffectFn3 unsafeAppend key value headers + pure headers + ) + init + f fromRecord :: forall r. Homogeneous r String => { | r } -> Headers fromRecord = unsafeFromRecord diff --git a/src/Fetch/Core/Fetch/Integrity.purs b/src/Fetch/Core/Fetch/Integrity.purs index a5b8341..4af6a4f 100644 --- a/src/Fetch/Core/Fetch/Integrity.purs +++ b/src/Fetch/Core/Fetch/Integrity.purs @@ -5,6 +5,6 @@ import Prelude (class Eq, class Ord) newtype Integrity = Integrity String -derive instance newtypeIntegrity :: Newtype Integrity _ -derive newtype instance eqIntegrity :: Eq Integrity -derive newtype instance ordIntegrity :: Ord Integrity +derive instance Newtype Integrity _ +derive newtype instance Eq Integrity +derive newtype instance Ord Integrity diff --git a/src/Fetch/Core/Fetch/Referrer.purs b/src/Fetch/Core/Fetch/Referrer.purs index 764cdfb..ac97f0c 100644 --- a/src/Fetch/Core/Fetch/Referrer.purs +++ b/src/Fetch/Core/Fetch/Referrer.purs @@ -9,7 +9,7 @@ toString :: Referrer -> String toString = case _ of ReferrerNone -> "none" ReferrerClient -> "client" - ReferrerUrl url -> url + ReferrerUrl url -> url fromString :: String -> Referrer fromString = case _ of diff --git a/src/Fetch/Core/Fetch/Request.purs b/src/Fetch/Core/Fetch/Request.purs index c6c5627..5b539dc 100644 --- a/src/Fetch/Core/Fetch/Request.purs +++ b/src/Fetch/Core/Fetch/Request.purs @@ -2,6 +2,7 @@ module Fetch.Core.Request ( Request , RequestOptions , UnsafeRequestOptions + , _unsafeNew , class ToInternal , class ToInternalConverter , class ToInternalHelper @@ -15,9 +16,7 @@ module Fetch.Core.Request import Prelude import Data.HTTP.Method (Method) -import Data.Maybe (Maybe) import Data.Newtype (un) -import Data.Nullable (Nullable) import Data.Symbol (class IsSymbol) import Effect (Effect) import Effect.Uncurried (EffectFn2, runEffectFn2) @@ -51,7 +50,7 @@ type UnsafeRequestOptions = , credentials :: String , cache :: String , mode :: String - , referrer :: Nullable String + , referrer :: String , referrerPolicy :: String , integrity :: String ) @@ -63,7 +62,7 @@ type RequestOptions = , credentials :: RequestCredentials , cache :: RequestCache , mode :: RequestMode - , referrer :: Maybe Referrer + , referrer :: Referrer , referrerPolicy :: ReferrerPolicy , integrity :: Integrity ) diff --git a/src/Fetch/Core/Fetch/Response.purs b/src/Fetch/Core/Fetch/Response.purs index 79ebb6e..063dac1 100644 --- a/src/Fetch/Core/Fetch/Response.purs +++ b/src/Fetch/Core/Fetch/Response.purs @@ -11,8 +11,7 @@ module Fetch.Core.Response , statusText , text , url - ) - where + ) where import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array) import Effect (Effect) From 0ea8d911234c9094b4877bf9afea69094c3daf28 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Fri, 19 Aug 2022 14:16:01 +0100 Subject: [PATCH 04/20] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e04484..2685bf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,11 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: +- Fork from web-fetch +- Rename package New features: +- Improve request options to only use the provided attributes instead of a full options record using default values Bugfixes: From 8c40575813620a17834345dbf8a701ae31f0096a Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Fri, 19 Aug 2022 14:20:48 +0100 Subject: [PATCH 05/20] Add missing meta info to spago.dhall --- spago.dhall | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spago.dhall b/spago.dhall index 0e4e38b..d6c7fc7 100644 --- a/spago.dhall +++ b/spago.dhall @@ -24,4 +24,6 @@ ] , packages = ./packages.dhall , sources = [ "src/**/*.purs" ] +, license = "MIT" +, repository = "https://github.com/rowtype-yoga/purescript-yoga-fetch.git" } From 684c83dd5c41928b3bb3f1359b41ee2564799f28 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Fri, 19 Aug 2022 14:33:31 +0100 Subject: [PATCH 06/20] Move modules one level up --- src/Fetch/{Core/Fetch.js => Core.js} | 0 src/Fetch/{Core/Fetch.purs => Core.purs} | 0 src/Fetch/Core/{Fetch => }/AbortController.js | 0 src/Fetch/Core/{Fetch => }/AbortController.purs | 0 src/Fetch/Core/{Fetch => }/Headers.js | 0 src/Fetch/Core/{Fetch => }/Headers.purs | 0 src/Fetch/Core/{Fetch => }/Integrity.purs | 0 src/Fetch/Core/{Fetch => }/Referrer.purs | 0 src/Fetch/Core/{Fetch => }/ReferrerPolicy.purs | 0 src/Fetch/Core/{Fetch => }/Request.js | 0 src/Fetch/Core/{Fetch => }/Request.purs | 0 src/Fetch/Core/{Fetch => }/RequestBody.js | 0 src/Fetch/Core/{Fetch => }/RequestBody.purs | 0 src/Fetch/Core/{Fetch => }/RequestCache.purs | 0 src/Fetch/Core/{Fetch => }/RequestCredentials.purs | 0 src/Fetch/Core/{Fetch => }/RequestMode.purs | 0 src/Fetch/Core/{Fetch => }/RequestRedirect.purs | 0 src/Fetch/Core/{Fetch => }/Response.js | 0 src/Fetch/Core/{Fetch => }/Response.purs | 0 19 files changed, 0 insertions(+), 0 deletions(-) rename src/Fetch/{Core/Fetch.js => Core.js} (100%) rename src/Fetch/{Core/Fetch.purs => Core.purs} (100%) rename src/Fetch/Core/{Fetch => }/AbortController.js (100%) rename src/Fetch/Core/{Fetch => }/AbortController.purs (100%) rename src/Fetch/Core/{Fetch => }/Headers.js (100%) rename src/Fetch/Core/{Fetch => }/Headers.purs (100%) rename src/Fetch/Core/{Fetch => }/Integrity.purs (100%) rename src/Fetch/Core/{Fetch => }/Referrer.purs (100%) rename src/Fetch/Core/{Fetch => }/ReferrerPolicy.purs (100%) rename src/Fetch/Core/{Fetch => }/Request.js (100%) rename src/Fetch/Core/{Fetch => }/Request.purs (100%) rename src/Fetch/Core/{Fetch => }/RequestBody.js (100%) rename src/Fetch/Core/{Fetch => }/RequestBody.purs (100%) rename src/Fetch/Core/{Fetch => }/RequestCache.purs (100%) rename src/Fetch/Core/{Fetch => }/RequestCredentials.purs (100%) rename src/Fetch/Core/{Fetch => }/RequestMode.purs (100%) rename src/Fetch/Core/{Fetch => }/RequestRedirect.purs (100%) rename src/Fetch/Core/{Fetch => }/Response.js (100%) rename src/Fetch/Core/{Fetch => }/Response.purs (100%) diff --git a/src/Fetch/Core/Fetch.js b/src/Fetch/Core.js similarity index 100% rename from src/Fetch/Core/Fetch.js rename to src/Fetch/Core.js diff --git a/src/Fetch/Core/Fetch.purs b/src/Fetch/Core.purs similarity index 100% rename from src/Fetch/Core/Fetch.purs rename to src/Fetch/Core.purs diff --git a/src/Fetch/Core/Fetch/AbortController.js b/src/Fetch/Core/AbortController.js similarity index 100% rename from src/Fetch/Core/Fetch/AbortController.js rename to src/Fetch/Core/AbortController.js diff --git a/src/Fetch/Core/Fetch/AbortController.purs b/src/Fetch/Core/AbortController.purs similarity index 100% rename from src/Fetch/Core/Fetch/AbortController.purs rename to src/Fetch/Core/AbortController.purs diff --git a/src/Fetch/Core/Fetch/Headers.js b/src/Fetch/Core/Headers.js similarity index 100% rename from src/Fetch/Core/Fetch/Headers.js rename to src/Fetch/Core/Headers.js diff --git a/src/Fetch/Core/Fetch/Headers.purs b/src/Fetch/Core/Headers.purs similarity index 100% rename from src/Fetch/Core/Fetch/Headers.purs rename to src/Fetch/Core/Headers.purs diff --git a/src/Fetch/Core/Fetch/Integrity.purs b/src/Fetch/Core/Integrity.purs similarity index 100% rename from src/Fetch/Core/Fetch/Integrity.purs rename to src/Fetch/Core/Integrity.purs diff --git a/src/Fetch/Core/Fetch/Referrer.purs b/src/Fetch/Core/Referrer.purs similarity index 100% rename from src/Fetch/Core/Fetch/Referrer.purs rename to src/Fetch/Core/Referrer.purs diff --git a/src/Fetch/Core/Fetch/ReferrerPolicy.purs b/src/Fetch/Core/ReferrerPolicy.purs similarity index 100% rename from src/Fetch/Core/Fetch/ReferrerPolicy.purs rename to src/Fetch/Core/ReferrerPolicy.purs diff --git a/src/Fetch/Core/Fetch/Request.js b/src/Fetch/Core/Request.js similarity index 100% rename from src/Fetch/Core/Fetch/Request.js rename to src/Fetch/Core/Request.js diff --git a/src/Fetch/Core/Fetch/Request.purs b/src/Fetch/Core/Request.purs similarity index 100% rename from src/Fetch/Core/Fetch/Request.purs rename to src/Fetch/Core/Request.purs diff --git a/src/Fetch/Core/Fetch/RequestBody.js b/src/Fetch/Core/RequestBody.js similarity index 100% rename from src/Fetch/Core/Fetch/RequestBody.js rename to src/Fetch/Core/RequestBody.js diff --git a/src/Fetch/Core/Fetch/RequestBody.purs b/src/Fetch/Core/RequestBody.purs similarity index 100% rename from src/Fetch/Core/Fetch/RequestBody.purs rename to src/Fetch/Core/RequestBody.purs diff --git a/src/Fetch/Core/Fetch/RequestCache.purs b/src/Fetch/Core/RequestCache.purs similarity index 100% rename from src/Fetch/Core/Fetch/RequestCache.purs rename to src/Fetch/Core/RequestCache.purs diff --git a/src/Fetch/Core/Fetch/RequestCredentials.purs b/src/Fetch/Core/RequestCredentials.purs similarity index 100% rename from src/Fetch/Core/Fetch/RequestCredentials.purs rename to src/Fetch/Core/RequestCredentials.purs diff --git a/src/Fetch/Core/Fetch/RequestMode.purs b/src/Fetch/Core/RequestMode.purs similarity index 100% rename from src/Fetch/Core/Fetch/RequestMode.purs rename to src/Fetch/Core/RequestMode.purs diff --git a/src/Fetch/Core/Fetch/RequestRedirect.purs b/src/Fetch/Core/RequestRedirect.purs similarity index 100% rename from src/Fetch/Core/Fetch/RequestRedirect.purs rename to src/Fetch/Core/RequestRedirect.purs diff --git a/src/Fetch/Core/Fetch/Response.js b/src/Fetch/Core/Response.js similarity index 100% rename from src/Fetch/Core/Fetch/Response.js rename to src/Fetch/Core/Response.js diff --git a/src/Fetch/Core/Fetch/Response.purs b/src/Fetch/Core/Response.purs similarity index 100% rename from src/Fetch/Core/Fetch/Response.purs rename to src/Fetch/Core/Response.purs From cdf599cf3575f89bbb6fb00122b245a1e707bab0 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:40:27 +0100 Subject: [PATCH 07/20] Update bower.json --- bower.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 1202e02..1d74767 100644 --- a/bower.json +++ b/bower.json @@ -1,10 +1,10 @@ { - "name": "purescript-web-fetch", - "homepage": "https://github.com/purescript-web/purescript-web-fetch", + "name": "purescript-fetch-core", + "homepage": "https://github.com/rowtype-yoga/purescript-fetch-core", "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/purescript-web/purescript-web-fetch.git" + "url": "https://github.com/rowtype-yoga/purescript-fetch-core.git" }, "ignore": [ "**/.*", From 5d7e26b803e093a261e850efe876a5b3b8302249 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:44:24 +0100 Subject: [PATCH 08/20] Update bower.json --- bower.json | 63 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/bower.json b/bower.json index 1d74767..bce6cfa 100644 --- a/bower.json +++ b/bower.json @@ -1,28 +1,39 @@ { - "name": "purescript-fetch-core", - "homepage": "https://github.com/rowtype-yoga/purescript-fetch-core", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/rowtype-yoga/purescript-fetch-core.git" - }, - "ignore": [ - "**/.*", - "bower_components", - "node_modules", - "output", - "bower.json", - "package.json" - ], - "dependencies": { - "purescript-effect": "^4.0.0", - "purescript-foreign-object": "^4.0.0", - "purescript-http-methods": "^6.0.0", - "purescript-prelude": "^6.0.0", - "purescript-record": "^4.0.0", - "purescript-typelevel-prelude": "^7.0.0", - "purescript-web-file": "^4.0.0", - "purescript-web-promise": "https://github.com/purescript-web/purescript-web-promise.git#^3.0.0", - "purescript-web-streams": "https://github.com/purescript-web/purescript-web-streams.git#^3.0.0" - } + "name": "purescript-fetch-core", + "license": [ + "MIT" + ], + "repository": { + "type": "git", + "url": "https://github.com/rowtype-yoga/purescript-yoga-fetch.git" + }, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-arraybuffer-types": "^v3.0.2", + "purescript-arrays": "^v7.0.0", + "purescript-console": "^v6.0.0", + "purescript-effect": "^v4.0.0", + "purescript-foldable-traversable": "^v6.0.0", + "purescript-foreign": "^v7.0.0", + "purescript-foreign-object": "^v4.0.0", + "purescript-functions": "^v6.0.0", + "purescript-http-methods": "^v6.0.0", + "purescript-maybe": "^v6.0.0", + "purescript-newtype": "^v5.0.0", + "purescript-nullable": "^v6.0.0", + "purescript-prelude": "^v6.0.0", + "purescript-record": "^v4.0.0", + "purescript-tuples": "^v7.0.0", + "purescript-typelevel-prelude": "^v7.0.0", + "purescript-unfoldable": "^v6.0.0", + "purescript-unsafe-coerce": "^v6.0.0", + "purescript-web-file": "^v4.0.0", + "purescript-web-promise": "https://github.com/purescript-web/purescript-web-promise.git#v3.0.0", + "purescript-web-streams": "https://github.com/purescript-web/purescript-web-streams.git#v3.0.0" + } } From 9a328733cc2d22039905ac89bd6cf170f817db43 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:44:36 +0100 Subject: [PATCH 09/20] =?UTF-8?q?v0.0.0=20=E2=86=92=20v4.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From ae96b20e0e9487ecee190a56707b32914ae4d900 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:45:51 +0100 Subject: [PATCH 10/20] Update bower.json --- spago.dhall | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spago.dhall b/spago.dhall index d6c7fc7..fbd49b1 100644 --- a/spago.dhall +++ b/spago.dhall @@ -25,5 +25,5 @@ , packages = ./packages.dhall , sources = [ "src/**/*.purs" ] , license = "MIT" -, repository = "https://github.com/rowtype-yoga/purescript-yoga-fetch.git" +, repository = "https://github.com/rowtype-yoga/purescript-fetch-core.git" } From ae0bfe29c21c137e67612d12da53c02dfb295227 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:46:13 +0100 Subject: [PATCH 11/20] Update bower.json --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index bce6cfa..3854365 100644 --- a/bower.json +++ b/bower.json @@ -5,7 +5,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/rowtype-yoga/purescript-yoga-fetch.git" + "url": "https://github.com/rowtype-yoga/purescript-fetch-core.git" }, "ignore": [ "**/.*", From cc81ea04c017dc478faaef3d7de6c7f8ce2d2c6d Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:46:20 +0100 Subject: [PATCH 12/20] =?UTF-8?q?v4.0.1=20=E2=86=92=20v4.0.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 662ddf12541a7d0703f881dc44473fd74844349d Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:58:05 +0100 Subject: [PATCH 13/20] =?UTF-8?q?v4.0.3=20=E2=86=92=20v4.0.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 4d74acdd83f373604557f06be42724cee82ae91c Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Fri, 4 Aug 2023 12:05:35 -0400 Subject: [PATCH 14/20] migrate to js-promise --- CHANGELOG.md | 6 ++++ bower.json | 67 ++++++++++++++++-------------------- packages.dhall | 5 ++- spago.dhall | 5 +-- src/Fetch/Core.purs | 2 +- src/Fetch/Core/Response.purs | 2 +- 6 files changed, 41 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2685bf9..c653a9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,13 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: + - Fork from web-fetch - Rename package +- Replaced web-promise dependency with js-promise New features: + - Improve request options to only use the provided attributes instead of a full options record using default values Bugfixes: @@ -18,6 +21,7 @@ Other improvements: ## [v3.0.0](https://github.com/purescript-web/purescript-web-fetch/releases/tag/v3.0.0) - 2022-04-27 Breaking changes: + - Migrate FFI to ES modules (#8 by @JordanMartinez) New features: @@ -29,6 +33,7 @@ Other improvements: ## [v2.0.0](https://github.com/purescript-web/purescript-web-fetch/releases/tag/v2.0.0) - 2021-02-26 Breaking changes: + - Added support for PureScript 0.14 and dropped support for all previous versions (#2) New features: @@ -36,6 +41,7 @@ New features: Bugfixes: Other improvements: + - Migrated CI to GitHub Actions and updated installation instructions to use Spago (#1) - Added a CHANGELOG.md file and pull request template (#3, #4) diff --git a/bower.json b/bower.json index 3854365..de5f344 100644 --- a/bower.json +++ b/bower.json @@ -1,39 +1,32 @@ { - "name": "purescript-fetch-core", - "license": [ - "MIT" - ], - "repository": { - "type": "git", - "url": "https://github.com/rowtype-yoga/purescript-fetch-core.git" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-arraybuffer-types": "^v3.0.2", - "purescript-arrays": "^v7.0.0", - "purescript-console": "^v6.0.0", - "purescript-effect": "^v4.0.0", - "purescript-foldable-traversable": "^v6.0.0", - "purescript-foreign": "^v7.0.0", - "purescript-foreign-object": "^v4.0.0", - "purescript-functions": "^v6.0.0", - "purescript-http-methods": "^v6.0.0", - "purescript-maybe": "^v6.0.0", - "purescript-newtype": "^v5.0.0", - "purescript-nullable": "^v6.0.0", - "purescript-prelude": "^v6.0.0", - "purescript-record": "^v4.0.0", - "purescript-tuples": "^v7.0.0", - "purescript-typelevel-prelude": "^v7.0.0", - "purescript-unfoldable": "^v6.0.0", - "purescript-unsafe-coerce": "^v6.0.0", - "purescript-web-file": "^v4.0.0", - "purescript-web-promise": "https://github.com/purescript-web/purescript-web-promise.git#v3.0.0", - "purescript-web-streams": "https://github.com/purescript-web/purescript-web-streams.git#v3.0.0" - } + "name": "purescript-fetch-core", + "license": ["MIT"], + "repository": { + "type": "git", + "url": "https://github.com/rowtype-yoga/purescript-fetch-core.git" + }, + "ignore": ["**/.*", "node_modules", "bower_components", "output"], + "dependencies": { + "purescript-arraybuffer-types": "^v3.0.2", + "purescript-arrays": "^v7.0.0", + "purescript-console": "^v6.0.0", + "purescript-effect": "^v4.0.0", + "purescript-foldable-traversable": "^v6.0.0", + "purescript-foreign": "^v7.0.0", + "purescript-foreign-object": "^v4.0.0", + "purescript-functions": "^v6.0.0", + "purescript-http-methods": "^v6.0.0", + "purescript-js-promise": "https://github.com/purescript-contrib/purescript-js-promise.git#^v3.0.0", + "purescript-maybe": "^v6.0.0", + "purescript-newtype": "^v5.0.0", + "purescript-nullable": "^v6.0.0", + "purescript-prelude": "^v6.0.0", + "purescript-record": "^v4.0.0", + "purescript-tuples": "^v7.0.0", + "purescript-typelevel-prelude": "^v7.0.0", + "purescript-unfoldable": "^v6.0.0", + "purescript-unsafe-coerce": "^v6.0.0", + "purescript-web-file": "^v4.0.0", + "purescript-web-streams": "https://github.com/purescript-web/purescript-web-streams.git#^v4.0.0" + } } diff --git a/packages.dhall b/packages.dhall index a5803ee..6fafe74 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,6 +1,5 @@ - let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220816/packages.dhall - sha256:8b4467b4b5041914f9b765779c8936d6d4c230b1f60eb64f6269c71812fd7e98 + https://github.com/purescript/package-sets/releases/download/psc-0.15.10-20230803/packages.dhall + sha256:7da82e40277c398fd70f16af6450fb74287a88e2a3c8885c065dcdb9df893761 in upstream diff --git a/spago.dhall b/spago.dhall index fbd49b1..12e36e9 100644 --- a/spago.dhall +++ b/spago.dhall @@ -2,24 +2,21 @@ , dependencies = [ "arraybuffer-types" , "arrays" - , "console" , "effect" , "foldable-traversable" , "foreign" , "foreign-object" , "functions" , "http-methods" + , "js-promise" , "maybe" , "newtype" - , "nullable" , "prelude" , "record" , "tuples" , "typelevel-prelude" , "unfoldable" - , "unsafe-coerce" , "web-file" - , "web-promise" , "web-streams" ] , packages = ./packages.dhall diff --git a/src/Fetch/Core.purs b/src/Fetch/Core.purs index 79066e5..30af12b 100644 --- a/src/Fetch/Core.purs +++ b/src/Fetch/Core.purs @@ -10,7 +10,7 @@ import Prim.Row as Row import Fetch.Core.AbortController (AbortSignal) import Fetch.Core.Request (Request) import Fetch.Core.Response (Response) -import Web.Promise (Promise) +import Promise (Promise) type FetchOptions = ( keepalive :: Boolean diff --git a/src/Fetch/Core/Response.purs b/src/Fetch/Core/Response.purs index 063dac1..086a58e 100644 --- a/src/Fetch/Core/Response.purs +++ b/src/Fetch/Core/Response.purs @@ -18,7 +18,7 @@ import Effect (Effect) import Fetch.Core.Headers (Headers) import Foreign (Foreign) import Web.File.Blob (Blob) -import Web.Promise (Promise) +import Promise (Promise) import Web.Streams.ReadableStream (ReadableStream) foreign import data Response :: Type From 64960c4f4e0fbff52a78a0e3106db8a0622afe15 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Fri, 4 Aug 2023 12:29:59 -0400 Subject: [PATCH 15/20] Update bower.json --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index de5f344..ee5e1dc 100644 --- a/bower.json +++ b/bower.json @@ -16,7 +16,7 @@ "purescript-foreign-object": "^v4.0.0", "purescript-functions": "^v6.0.0", "purescript-http-methods": "^v6.0.0", - "purescript-js-promise": "https://github.com/purescript-contrib/purescript-js-promise.git#^v3.0.0", + "purescript-js-promise": "https://github.com/purescript-contrib/purescript-js-promise.git#^v1.0.0", "purescript-maybe": "^v6.0.0", "purescript-newtype": "^v5.0.0", "purescript-nullable": "^v6.0.0", From 9a2ef7e7157c80dc0158519d3023cdb4e79b0279 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sun, 6 Aug 2023 17:47:08 -0400 Subject: [PATCH 16/20] Use duplex: 'half' --- src/Fetch/Core/Request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fetch/Core/Request.js b/src/Fetch/Core/Request.js index 0f30528..3d80b37 100644 --- a/src/Fetch/Core/Request.js +++ b/src/Fetch/Core/Request.js @@ -1,6 +1,6 @@ export function _unsafeNew(url, options) { try { - return new Request(url, options); + return new Request(url, { ...options, duplex: 'half' }); } catch (e) { console.error(e); throw e; From 7d0a41454ea42333cf446eaa0ad6ed2fd9707bdb Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sun, 6 Aug 2023 17:48:09 -0400 Subject: [PATCH 17/20] Revert "Use duplex: 'half'" This reverts commit 9a2ef7e7157c80dc0158519d3023cdb4e79b0279. --- src/Fetch/Core/Request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fetch/Core/Request.js b/src/Fetch/Core/Request.js index 3d80b37..0f30528 100644 --- a/src/Fetch/Core/Request.js +++ b/src/Fetch/Core/Request.js @@ -1,6 +1,6 @@ export function _unsafeNew(url, options) { try { - return new Request(url, { ...options, duplex: 'half' }); + return new Request(url, options); } catch (e) { console.error(e); throw e; From a4bb941e6217c3386bb3644fd714fd825258f48a Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Mon, 7 Aug 2023 19:15:56 -0400 Subject: [PATCH 18/20] Update ci.yml --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06ed895..0273808 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [master] + branches: [main] pull_request: - branches: [master] + branches: [main] jobs: build: From 83aad59e6a8ba4ef06d2398103e7fbe98ee98999 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Mon, 7 Aug 2023 19:29:09 -0400 Subject: [PATCH 19/20] Add duplex option (#3) --- .github/workflows/ci.yml | 2 +- package.json | 3 ++- src/Fetch/Core/Duplex.purs | 21 +++++++++++++++++++++ src/Fetch/Core/Request.purs | 6 ++++++ test.dhall | 7 +++---- test/Main.purs | 15 ++++++++------- 6 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/Fetch/Core/Duplex.purs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0273808..95ed32d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-node@v2 with: - node-version: "14" + node-version: "20" - name: Install dependencies run: | diff --git a/package.json b/package.json index 4ea39f9..7e321c0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "private": true, "scripts": { "clean": "rimraf output && rimraf .pulp-cache", - "build": "eslint src && pulp build -- --censor-lib --strict" + "build": "eslint src && pulp build -- --censor-lib --strict", + "test": "spago -x test.dhall test" }, "devDependencies": { "eslint": "^7.15.0", diff --git a/src/Fetch/Core/Duplex.purs b/src/Fetch/Core/Duplex.purs new file mode 100644 index 0000000..12870a3 --- /dev/null +++ b/src/Fetch/Core/Duplex.purs @@ -0,0 +1,21 @@ +module Fetch.Core.Duplex where + +import Prelude + +import Data.Maybe (Maybe(..)) + +data Duplex = Half | Full + +derive instance Eq Duplex +derive instance Ord Duplex + +toString :: Duplex -> String +toString = case _ of + Half -> "half" + Full -> "full" + +fromString :: String -> Maybe Duplex +fromString = case _ of + "full" -> Just Full + "half" -> Just Half + _ -> Nothing diff --git a/src/Fetch/Core/Request.purs b/src/Fetch/Core/Request.purs index 5b539dc..9237b00 100644 --- a/src/Fetch/Core/Request.purs +++ b/src/Fetch/Core/Request.purs @@ -20,6 +20,8 @@ import Data.Newtype (un) import Data.Symbol (class IsSymbol) import Effect (Effect) import Effect.Uncurried (EffectFn2, runEffectFn2) +import Fetch.Core.Duplex (Duplex) +import Fetch.Core.Duplex as Duplex import Fetch.Core.Headers (Headers) import Fetch.Core.Integrity (Integrity(..)) import Fetch.Core.Referrer (Referrer) @@ -53,6 +55,7 @@ type UnsafeRequestOptions = , referrer :: String , referrerPolicy :: String , integrity :: String + , duplex :: String ) type RequestOptions = @@ -65,6 +68,7 @@ type RequestOptions = , referrer :: Referrer , referrerPolicy :: ReferrerPolicy , integrity :: Integrity + , duplex :: Duplex ) toUnsafeOptions @@ -150,3 +154,5 @@ instance ToInternalConverter ReferrerPolicy String where instance ToInternalConverter Integrity String where convertImpl = un Integrity +instance ToInternalConverter Duplex String where + convertImpl = Duplex.toString diff --git a/test.dhall b/test.dhall index 06eb399..b49bd5f 100644 --- a/test.dhall +++ b/test.dhall @@ -6,10 +6,9 @@ in conf conf.dependencies # [ "aff" , "aff-promise" - , "effect" - , "spec" - , "spec-discovery" - , "strings" + , "console" , "debug" + , "effect" + , "unsafe-coerce" ] } diff --git a/test/Main.purs b/test/Main.purs index 5418ad4..d90480c 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -6,10 +6,11 @@ import Control.Promise as Promise import Data.HTTP.Method (Method(..)) import Debug (spy) import Effect (Effect) -import Effect.Aff (launchAff, launchAff_) +import Effect.Aff (launchAff_) import Effect.Class (liftEffect) import Effect.Class.Console (log) import Fetch.Core as Fetch +import Fetch.Core.Duplex (Duplex(..)) import Fetch.Core.Headers as Headers import Fetch.Core.Request as Request import Fetch.Core.RequestBody as RequestBody @@ -20,12 +21,12 @@ main :: Effect Unit main = launchAff_ do let requestBody = """{"hello":"world"}""" request <- liftEffect $ Request.new "http://httpbin.org/post" - { method: POST - , body: RequestBody.fromString requestBody - , headers: Headers.fromRecord { "Content-Type": "application/json" } - } - let - _ = spy "request" request + { method: POST + , body: RequestBody.fromString requestBody + , headers: Headers.fromRecord { "Content-Type": "application/json" } + , duplex: Half + } + let _ = spy "request" request response <- Promise.toAffE $ unsafeCoerce $ Fetch.fetch request responseBody <- Promise.toAffE $ unsafeCoerce $ Response.text response let _ = spy "response" response From 58c7c706de78b8311505f709fa364ef28c564f3c Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Tue, 26 Sep 2023 08:51:30 +0100 Subject: [PATCH 20/20] Rename packages to JS.Fetch --- README.md | 8 ++--- bower.json | 2 +- spago.dhall | 2 +- src/{ => JS}/Fetch/Core.js | 0 src/{ => JS}/Fetch/Core.purs | 8 ++--- .../Fetch/Fetch}/AbortController.js | 0 .../Fetch/Fetch}/AbortController.purs | 2 +- .../Core => JS/Fetch/Fetch}/Duplex.purs | 2 +- src/{Fetch/Core => JS/Fetch/Fetch}/Headers.js | 0 .../Core => JS/Fetch/Fetch}/Headers.purs | 2 +- .../Core => JS/Fetch/Fetch}/Integrity.purs | 2 +- .../Core => JS/Fetch/Fetch}/Referrer.purs | 2 +- .../Fetch/Fetch}/ReferrerPolicy.purs | 2 +- src/{Fetch/Core => JS/Fetch/Fetch}/Request.js | 0 .../Core => JS/Fetch/Fetch}/Request.purs | 32 +++++++++---------- .../Core => JS/Fetch/Fetch}/RequestBody.js | 0 .../Core => JS/Fetch/Fetch}/RequestBody.purs | 2 +- .../Core => JS/Fetch/Fetch}/RequestCache.purs | 2 +- .../Fetch/Fetch}/RequestCredentials.purs | 2 +- .../Core => JS/Fetch/Fetch}/RequestMode.purs | 2 +- .../Fetch/Fetch}/RequestRedirect.purs | 2 +- .../Core => JS/Fetch/Fetch}/Response.js | 0 .../Core => JS/Fetch/Fetch}/Response.purs | 4 +-- test/Main.purs | 15 ++++----- 24 files changed, 45 insertions(+), 48 deletions(-) rename src/{ => JS}/Fetch/Core.js (100%) rename src/{ => JS}/Fetch/Core.purs (80%) rename src/{Fetch/Core => JS/Fetch/Fetch}/AbortController.js (100%) rename src/{Fetch/Core => JS/Fetch/Fetch}/AbortController.purs (87%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Duplex.purs (91%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Headers.js (100%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Headers.purs (98%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Integrity.purs (86%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Referrer.purs (91%) rename src/{Fetch/Core => JS/Fetch/Fetch}/ReferrerPolicy.purs (96%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Request.js (100%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Request.purs (85%) rename src/{Fetch/Core => JS/Fetch/Fetch}/RequestBody.js (100%) rename src/{Fetch/Core => JS/Fetch/Fetch}/RequestBody.purs (92%) rename src/{Fetch/Core => JS/Fetch/Fetch}/RequestCache.purs (94%) rename src/{Fetch/Core => JS/Fetch/Fetch}/RequestCredentials.purs (90%) rename src/{Fetch/Core => JS/Fetch/Fetch}/RequestMode.purs (92%) rename src/{Fetch/Core => JS/Fetch/Fetch}/RequestRedirect.purs (90%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Response.js (100%) rename src/{Fetch/Core => JS/Fetch/Fetch}/Response.purs (93%) diff --git a/README.md b/README.md index bdd9f05..cc2aa33 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # purescript-fetch-core -[![Latest release](http://img.shields.io/github/release/rowtype-yoga/purescript-fetch-core.svg)](https://github.com/rowtype-yoga/purescript-fetch-core/releases) -[![Build status](https://github.com/rowtype-yoga/purescript-fetch-core/workflows/CI/badge.svg?branch=master)](https://github.com/rowtype-yoga/purescript-fetch-core/actions?query=workflow%3ACI+branch%3Amaster) +[![Latest release](http://img.shields.io/github/release/purescript-contrib/purescript-js-fetch.svg)](https://github.com/purescript-contrib/purescript-js-fetch/releases) +[![Build status](https://github.com/purescript-contrib/purescript-js-fetch/workflows/CI/badge.svg?branch=master)](https://github.com/purescript-contrib/purescript-js-fetch/actions?query=workflow%3ACI+branch%3Amaster) [![Pursuit](https://pursuit.purescript.org/packages/purescript-fetch-core/badge)](https://pursuit.purescript.org/packages/purescript-fetch-core) Types and low-level implementations for the [WHATWG Fetch Living Standard](https://fetch.spec.whatwg.org/). @@ -11,9 +11,9 @@ For a high-level library see [`purescript-fetch`](https://github.com/rowtype-yog ## Installation ``` -spago install fetch-core +spago install js-fetch ``` ## Documentation -Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-fetch-core). +Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-js-fetch). diff --git a/bower.json b/bower.json index 0d0f4d8..51a6d76 100644 --- a/bower.json +++ b/bower.json @@ -5,7 +5,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/rowtype-yoga/purescript-fetch-core.git" + "url": "https://github.com/purescript-contrib/purescript-js-fetch.git" }, "ignore": [ "**/.*", diff --git a/spago.dhall b/spago.dhall index 12e36e9..09f3399 100644 --- a/spago.dhall +++ b/spago.dhall @@ -22,5 +22,5 @@ , packages = ./packages.dhall , sources = [ "src/**/*.purs" ] , license = "MIT" -, repository = "https://github.com/rowtype-yoga/purescript-fetch-core.git" +, repository = "https://github.com/purescript-contrib/purescript-js-fetch.git" } diff --git a/src/Fetch/Core.js b/src/JS/Fetch/Core.js similarity index 100% rename from src/Fetch/Core.js rename to src/JS/Fetch/Core.js diff --git a/src/Fetch/Core.purs b/src/JS/Fetch/Core.purs similarity index 80% rename from src/Fetch/Core.purs rename to src/JS/Fetch/Core.purs index bd9ef90..2157646 100644 --- a/src/Fetch/Core.purs +++ b/src/JS/Fetch/Core.purs @@ -1,4 +1,4 @@ -module Fetch.Core +module JS.Fetch ( FetchOptions , fetch , fetchWithOptions @@ -6,9 +6,9 @@ module Fetch.Core import Effect (Effect) import Effect.Uncurried (EffectFn2, runEffectFn2) -import Fetch.Core.AbortController (AbortSignal) -import Fetch.Core.Request (Request) -import Fetch.Core.Response (Response) +import JS.Fetch.AbortController (AbortSignal) +import JS.Fetch.Request (Request) +import JS.Fetch.Response (Response) import Prim.Row as Row import Promise (Promise) diff --git a/src/Fetch/Core/AbortController.js b/src/JS/Fetch/Fetch/AbortController.js similarity index 100% rename from src/Fetch/Core/AbortController.js rename to src/JS/Fetch/Fetch/AbortController.js diff --git a/src/Fetch/Core/AbortController.purs b/src/JS/Fetch/Fetch/AbortController.purs similarity index 87% rename from src/Fetch/Core/AbortController.purs rename to src/JS/Fetch/Fetch/AbortController.purs index cb7de7b..9a16b25 100644 --- a/src/Fetch/Core/AbortController.purs +++ b/src/JS/Fetch/Fetch/AbortController.purs @@ -1,4 +1,4 @@ -module Fetch.Core.AbortController where +module JS.Fetch.AbortController where import Effect (Effect) import Prelude (Unit) diff --git a/src/Fetch/Core/Duplex.purs b/src/JS/Fetch/Fetch/Duplex.purs similarity index 91% rename from src/Fetch/Core/Duplex.purs rename to src/JS/Fetch/Fetch/Duplex.purs index 12870a3..808d14c 100644 --- a/src/Fetch/Core/Duplex.purs +++ b/src/JS/Fetch/Fetch/Duplex.purs @@ -1,4 +1,4 @@ -module Fetch.Core.Duplex where +module JS.Fetch.Duplex where import Prelude diff --git a/src/Fetch/Core/Headers.js b/src/JS/Fetch/Fetch/Headers.js similarity index 100% rename from src/Fetch/Core/Headers.js rename to src/JS/Fetch/Fetch/Headers.js diff --git a/src/Fetch/Core/Headers.purs b/src/JS/Fetch/Fetch/Headers.purs similarity index 98% rename from src/Fetch/Core/Headers.purs rename to src/JS/Fetch/Fetch/Headers.purs index feae194..46c0aa9 100644 --- a/src/Fetch/Core/Headers.purs +++ b/src/JS/Fetch/Fetch/Headers.purs @@ -1,4 +1,4 @@ -module Fetch.Core.Headers +module JS.Fetch.Headers ( Headers , fromFoldable , fromRecord diff --git a/src/Fetch/Core/Integrity.purs b/src/JS/Fetch/Fetch/Integrity.purs similarity index 86% rename from src/Fetch/Core/Integrity.purs rename to src/JS/Fetch/Fetch/Integrity.purs index 4af6a4f..6c4da73 100644 --- a/src/Fetch/Core/Integrity.purs +++ b/src/JS/Fetch/Fetch/Integrity.purs @@ -1,4 +1,4 @@ -module Fetch.Core.Integrity where +module JS.Fetch.Integrity where import Data.Newtype (class Newtype) import Prelude (class Eq, class Ord) diff --git a/src/Fetch/Core/Referrer.purs b/src/JS/Fetch/Fetch/Referrer.purs similarity index 91% rename from src/Fetch/Core/Referrer.purs rename to src/JS/Fetch/Fetch/Referrer.purs index ac97f0c..7f41821 100644 --- a/src/Fetch/Core/Referrer.purs +++ b/src/JS/Fetch/Fetch/Referrer.purs @@ -1,4 +1,4 @@ -module Fetch.Core.Referrer where +module JS.Fetch.Referrer where data Referrer = ReferrerNone diff --git a/src/Fetch/Core/ReferrerPolicy.purs b/src/JS/Fetch/Fetch/ReferrerPolicy.purs similarity index 96% rename from src/Fetch/Core/ReferrerPolicy.purs rename to src/JS/Fetch/Fetch/ReferrerPolicy.purs index 2ca9ffe..3b542de 100644 --- a/src/Fetch/Core/ReferrerPolicy.purs +++ b/src/JS/Fetch/Fetch/ReferrerPolicy.purs @@ -1,4 +1,4 @@ -module Fetch.Core.ReferrerPolicy where +module JS.Fetch.ReferrerPolicy where import Data.Maybe (Maybe(..)) diff --git a/src/Fetch/Core/Request.js b/src/JS/Fetch/Fetch/Request.js similarity index 100% rename from src/Fetch/Core/Request.js rename to src/JS/Fetch/Fetch/Request.js diff --git a/src/Fetch/Core/Request.purs b/src/JS/Fetch/Fetch/Request.purs similarity index 85% rename from src/Fetch/Core/Request.purs rename to src/JS/Fetch/Fetch/Request.purs index 9237b00..5ece006 100644 --- a/src/Fetch/Core/Request.purs +++ b/src/JS/Fetch/Fetch/Request.purs @@ -1,4 +1,4 @@ -module Fetch.Core.Request +module JS.Fetch.Request ( Request , RequestOptions , UnsafeRequestOptions @@ -20,21 +20,21 @@ import Data.Newtype (un) import Data.Symbol (class IsSymbol) import Effect (Effect) import Effect.Uncurried (EffectFn2, runEffectFn2) -import Fetch.Core.Duplex (Duplex) -import Fetch.Core.Duplex as Duplex -import Fetch.Core.Headers (Headers) -import Fetch.Core.Integrity (Integrity(..)) -import Fetch.Core.Referrer (Referrer) -import Fetch.Core.Referrer as Referrer -import Fetch.Core.ReferrerPolicy (ReferrerPolicy) -import Fetch.Core.ReferrerPolicy as ReferrerPolicy -import Fetch.Core.RequestBody (RequestBody) -import Fetch.Core.RequestCache (RequestCache) -import Fetch.Core.RequestCache as RequestCache -import Fetch.Core.RequestCredentials (RequestCredentials) -import Fetch.Core.RequestCredentials as RequestCredentials -import Fetch.Core.RequestMode (RequestMode) -import Fetch.Core.RequestMode as RequestMode +import JS.Fetch.Duplex (Duplex) +import JS.Fetch.Duplex as Duplex +import JS.Fetch.Headers (Headers) +import JS.Fetch.Integrity (Integrity(..)) +import JS.Fetch.Referrer (Referrer) +import JS.Fetch.Referrer as Referrer +import JS.Fetch.ReferrerPolicy (ReferrerPolicy) +import JS.Fetch.ReferrerPolicy as ReferrerPolicy +import JS.Fetch.RequestBody (RequestBody) +import JS.Fetch.RequestCache (RequestCache) +import JS.Fetch.RequestCache as RequestCache +import JS.Fetch.RequestCredentials (RequestCredentials) +import JS.Fetch.RequestCredentials as RequestCredentials +import JS.Fetch.RequestMode (RequestMode) +import JS.Fetch.RequestMode as RequestMode import Prim.Row (class Lacks, class Union) import Prim.Row as R import Prim.RowList as RL diff --git a/src/Fetch/Core/RequestBody.js b/src/JS/Fetch/Fetch/RequestBody.js similarity index 100% rename from src/Fetch/Core/RequestBody.js rename to src/JS/Fetch/Fetch/RequestBody.js diff --git a/src/Fetch/Core/RequestBody.purs b/src/JS/Fetch/Fetch/RequestBody.purs similarity index 92% rename from src/Fetch/Core/RequestBody.purs rename to src/JS/Fetch/Fetch/RequestBody.purs index a817de3..14ece99 100644 --- a/src/Fetch/Core/RequestBody.purs +++ b/src/JS/Fetch/Fetch/RequestBody.purs @@ -1,4 +1,4 @@ -module Fetch.Core.RequestBody where +module JS.Fetch.RequestBody where import Data.ArrayBuffer.Types (ArrayBuffer, ArrayView, Uint8Array) import Web.Streams.ReadableStream (ReadableStream) diff --git a/src/Fetch/Core/RequestCache.purs b/src/JS/Fetch/Fetch/RequestCache.purs similarity index 94% rename from src/Fetch/Core/RequestCache.purs rename to src/JS/Fetch/Fetch/RequestCache.purs index 58fdb18..e1a34b4 100644 --- a/src/Fetch/Core/RequestCache.purs +++ b/src/JS/Fetch/Fetch/RequestCache.purs @@ -1,4 +1,4 @@ -module Fetch.Core.RequestCache where +module JS.Fetch.RequestCache where import Data.Maybe (Maybe(..)) diff --git a/src/Fetch/Core/RequestCredentials.purs b/src/JS/Fetch/Fetch/RequestCredentials.purs similarity index 90% rename from src/Fetch/Core/RequestCredentials.purs rename to src/JS/Fetch/Fetch/RequestCredentials.purs index b146887..9a41da7 100644 --- a/src/Fetch/Core/RequestCredentials.purs +++ b/src/JS/Fetch/Fetch/RequestCredentials.purs @@ -1,4 +1,4 @@ -module Fetch.Core.RequestCredentials where +module JS.Fetch.RequestCredentials where import Data.Maybe (Maybe(..)) diff --git a/src/Fetch/Core/RequestMode.purs b/src/JS/Fetch/Fetch/RequestMode.purs similarity index 92% rename from src/Fetch/Core/RequestMode.purs rename to src/JS/Fetch/Fetch/RequestMode.purs index cca2ca8..fbc4501 100644 --- a/src/Fetch/Core/RequestMode.purs +++ b/src/JS/Fetch/Fetch/RequestMode.purs @@ -1,4 +1,4 @@ -module Fetch.Core.RequestMode where +module JS.Fetch.RequestMode where import Data.Maybe (Maybe(..)) diff --git a/src/Fetch/Core/RequestRedirect.purs b/src/JS/Fetch/Fetch/RequestRedirect.purs similarity index 90% rename from src/Fetch/Core/RequestRedirect.purs rename to src/JS/Fetch/Fetch/RequestRedirect.purs index 391d7f5..561ab8b 100644 --- a/src/Fetch/Core/RequestRedirect.purs +++ b/src/JS/Fetch/Fetch/RequestRedirect.purs @@ -1,4 +1,4 @@ -module Fetch.Core.RequestRedirect where +module JS.Fetch.RequestRedirect where import Data.Maybe (Maybe(..)) diff --git a/src/Fetch/Core/Response.js b/src/JS/Fetch/Fetch/Response.js similarity index 100% rename from src/Fetch/Core/Response.js rename to src/JS/Fetch/Fetch/Response.js diff --git a/src/Fetch/Core/Response.purs b/src/JS/Fetch/Fetch/Response.purs similarity index 93% rename from src/Fetch/Core/Response.purs rename to src/JS/Fetch/Fetch/Response.purs index 5742eb0..2213cfc 100644 --- a/src/Fetch/Core/Response.purs +++ b/src/JS/Fetch/Fetch/Response.purs @@ -1,4 +1,4 @@ -module Fetch.Core.Response +module JS.Fetch.Response ( Response , arrayBuffer , blob @@ -15,8 +15,8 @@ module Fetch.Core.Response import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array) import Effect (Effect) -import Fetch.Core.Headers (Headers) import Foreign (Foreign) +import JS.Fetch.Headers (Headers) import Promise (Promise) import Web.File.Blob (Blob) import Web.Streams.ReadableStream (ReadableStream) diff --git a/test/Main.purs b/test/Main.purs index d90480c..a5e924a 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -9,12 +9,12 @@ import Effect (Effect) import Effect.Aff (launchAff_) import Effect.Class (liftEffect) import Effect.Class.Console (log) -import Fetch.Core as Fetch -import Fetch.Core.Duplex (Duplex(..)) -import Fetch.Core.Headers as Headers -import Fetch.Core.Request as Request -import Fetch.Core.RequestBody as RequestBody -import Fetch.Core.Response as Response +import JS.Fetch as Fetch +import JS.Fetch.Duplex (Duplex(..)) +import JS.Fetch.Headers as Headers +import JS.Fetch.Request as Request +import JS.Fetch.RequestBody as RequestBody +import JS.Fetch.Response as Response import Unsafe.Coerce (unsafeCoerce) main :: Effect Unit @@ -26,10 +26,7 @@ main = launchAff_ do , headers: Headers.fromRecord { "Content-Type": "application/json" } , duplex: Half } - let _ = spy "request" request response <- Promise.toAffE $ unsafeCoerce $ Fetch.fetch request responseBody <- Promise.toAffE $ unsafeCoerce $ Response.text response - let _ = spy "response" response log $ show $ Response.status response log responseBody - log "You should add some tests."