Skip to content

Merge back to web fetch #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
build:
Expand All @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-node@v2
with:
node-version: "14"
node-version: "20"

- name: Install dependencies
run: |
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:
- Migrated from `web-promise` to `js-promise`

- 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:

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:
Expand All @@ -27,13 +34,15 @@ 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:

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)

Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/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/).

For a high-level library see [`purescript-fetch`](https://github.com/rowtype-yoga/purescript-fetch)

## Installation

```
spago install web-fetch
spago install js-fetch
```

## 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-js-fetch).
45 changes: 28 additions & 17 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
{
"name": "purescript-web-fetch",
"homepage": "https://github.com/purescript-web/purescript-web-fetch",
"license": "MIT",
"name": "purescript-fetch-core",
"license": [
"MIT"
],
"repository": {
"type": "git",
"url": "https://github.com/purescript-web/purescript-web-fetch.git"
"url": "https://github.com/purescript-contrib/purescript-js-fetch.git"
},
"ignore": [
"**/.*",
"bower_components",
"node_modules",
"output",
"bower.json",
"package.json"
"bower_components",
"output"
],
"dependencies": {
"purescript-effect": "^4.0.0",
"purescript-foreign-object": "^4.0.0",
"purescript-http-methods": "^6.0.0",
"purescript-js-promise": "https://github.com/purescript-contrib/purescript-js-promise.git#^1.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-streams": "https://github.com/purescript-web/purescript-web-streams.git#^4.0.0"
"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#^v1.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"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && purs-tidy check --config-require src/**/*.purs && pulp build -- --censor-lib --strict"
"build": "eslint src && purs-tidy check --config-require src/**/*.purs && pulp build -- --censor-lib --strict",
"test": "spago -x test.dhall test"
},
"devDependencies": {
"eslint": "^8.28.0",
Expand Down
5 changes: 5 additions & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.15.10-20230803/packages.dhall
sha256:7da82e40277c398fd70f16af6450fb74287a88e2a3c8885c065dcdb9df893761

in upstream
26 changes: 26 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ name = "fetch-core"
, dependencies =
[ "arraybuffer-types"
, "arrays"
, "effect"
, "foldable-traversable"
, "foreign"
, "foreign-object"
, "functions"
, "http-methods"
, "js-promise"
, "maybe"
, "newtype"
, "prelude"
, "record"
, "tuples"
, "typelevel-prelude"
, "unfoldable"
, "web-file"
, "web-streams"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
, license = "MIT"
, repository = "https://github.com/purescript-contrib/purescript-js-fetch.git"
}
File renamed without changes.
10 changes: 5 additions & 5 deletions src/Web/Fetch.purs → src/JS/Fetch/Core.purs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module Web.Fetch
module JS.Fetch
( FetchOptions
, fetch
, fetchWithOptions
) where

import Effect (Effect)
import Effect.Uncurried (EffectFn2, runEffectFn2)
import JS.Fetch.AbortController (AbortSignal)
import JS.Fetch.Request (Request)
import JS.Fetch.Response (Response)
import Prim.Row as Row
import Promise (Promise)
import Web.Fetch.AbortController (AbortSignal)
import Web.Fetch.Request (Request)
import Web.Fetch.Response (Response)

type FetchOptions =
( keepalive :: Boolean
Expand All @@ -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
fetchWithOptions = runEffectFn2 _fetch
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Web.Fetch.AbortController where
module JS.Fetch.AbortController where

import Effect (Effect)
import Prelude (Unit)
Expand All @@ -11,4 +11,4 @@ foreign import new :: Effect AbortController

foreign import abort :: AbortController -> Effect Unit

foreign import signal :: AbortController -> AbortSignal
foreign import signal :: AbortController -> AbortSignal
21 changes: 21 additions & 0 deletions src/JS/Fetch/Fetch/Duplex.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module JS.Fetch.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
File renamed without changes.
14 changes: 9 additions & 5 deletions src/Web/Fetch/Headers.purs → src/JS/Fetch/Fetch/Headers.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Web.Fetch.Headers
module JS.Fetch.Headers
( Headers
, fromFoldable
, fromRecord
Expand Down Expand Up @@ -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
Expand All @@ -50,4 +54,4 @@ toUnfoldable :: forall f. Unfoldable f => Headers -> f (Tuple String String)
toUnfoldable = Array.toUnfoldable <<< toArray

empty :: Headers
empty = fromFoldable []
empty = fromFoldable []
10 changes: 10 additions & 0 deletions src/JS/Fetch/Fetch/Integrity.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module JS.Fetch.Integrity where

import Data.Newtype (class Newtype)
import Prelude (class Eq, class Ord)

newtype Integrity = Integrity String

derive instance Newtype Integrity _
derive newtype instance Eq Integrity
derive newtype instance Ord Integrity
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Web.Fetch.Referrer where
module JS.Fetch.Referrer where

data Referrer
= ReferrerNone
Expand All @@ -9,10 +9,10 @@ toString :: Referrer -> String
toString = case _ of
ReferrerNone -> "none"
ReferrerClient -> "client"
ReferrerUrl url -> url
ReferrerUrl url -> url

fromString :: String -> Referrer
fromString = case _ of
"none" -> ReferrerNone
"client" -> ReferrerClient
url -> ReferrerUrl url
url -> ReferrerUrl url
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Web.Fetch.ReferrerPolicy where
module JS.Fetch.ReferrerPolicy where

import Data.Maybe (Maybe(..))

Expand Down
File renamed without changes.
Loading