-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
5,922 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.tmp | ||
extension.tar.br | ||
|
||
# Logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
This project incorporates components from the projects listed below, that may have licenses | ||
differing from this project: | ||
|
||
|
||
1) License Notice for test/cases/elm-spa* (from https://github.com/rtfeldman/elm-spa-example) | ||
--------------------------------------- | ||
|
||
MIT License | ||
|
||
Copyright (c) 2017-2018 Richard Feldman and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { execaCommand } from 'execa' | ||
import path, { dirname } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { cp, readdir, readFile, rm, writeFile } from 'node:fs/promises' | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
const root = path.join(__dirname, '..') | ||
|
||
const REPO = 'https://github.com/rtfeldman/elm-spa-example' | ||
const COMMIT = 'cb32acd73c3d346d0064e7923049867d8ce67193' | ||
|
||
const getTestName = (line) => { | ||
return ( | ||
'elm-spa-' + | ||
line | ||
.toLowerCase() | ||
.trim() | ||
.replaceAll(' ', '-') | ||
.replaceAll('/', '-') | ||
.replace('.elm', '') | ||
) | ||
} | ||
|
||
const getAllTests = async (folder) => { | ||
const dirents = await readdir(folder, { recursive: true }) | ||
const allTests = [] | ||
for (const dirent of dirents) { | ||
if (!dirent.endsWith('.elm')) { | ||
continue | ||
} | ||
const filePath = `${folder}/${dirent}` | ||
const testName = getTestName(dirent) | ||
const fileContent = await readFile(filePath, 'utf8') | ||
allTests.push({ | ||
testName, | ||
testContent: fileContent, | ||
}) | ||
} | ||
return allTests | ||
} | ||
|
||
const writeTestFiles = async (allTests) => { | ||
for (const test of allTests) { | ||
await writeFile(`${root}/test/cases/${test.testName}.elm`, test.testContent) | ||
} | ||
} | ||
|
||
const main = async () => { | ||
process.chdir(root) | ||
await rm(`${root}/.tmp`, { recursive: true, force: true }) | ||
await execaCommand(`git clone ${REPO} .tmp/elm-spa`) | ||
process.chdir(`${root}/.tmp/elm-spa`) | ||
await execaCommand(`git checkout ${COMMIT}`) | ||
process.chdir(root) | ||
await cp(`${root}/.tmp/elm-spa/src`, `${root}/.tmp/elm-spa-src`, { | ||
recursive: true, | ||
}) | ||
const allTests = await getAllTests(`${root}/.tmp/elm-spa-src`) | ||
await writeTestFiles(allTests) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
module Api.Endpoint exposing (Endpoint, article, articles, comment, comments, favorite, feed, follow, login, profiles, request, tags, user, users) | ||
|
||
import Article.Slug as Slug exposing (Slug) | ||
import CommentId exposing (CommentId) | ||
import Http | ||
import Url.Builder exposing (QueryParameter) | ||
import Username exposing (Username) | ||
|
||
|
||
{-| Http.request, except it takes an Endpoint instead of a Url. | ||
-} | ||
request : | ||
{ body : Http.Body | ||
, expect : Http.Expect a | ||
, headers : List Http.Header | ||
, method : String | ||
, timeout : Maybe Float | ||
, url : Endpoint | ||
, withCredentials : Bool | ||
} | ||
-> Http.Request a | ||
request config = | ||
Http.request | ||
{ body = config.body | ||
, expect = config.expect | ||
, headers = config.headers | ||
, method = config.method | ||
, timeout = config.timeout | ||
, url = unwrap config.url | ||
, withCredentials = config.withCredentials | ||
} | ||
|
||
|
||
|
||
-- TYPES | ||
|
||
|
||
{-| Get a URL to the Conduit API. | ||
This is not publicly exposed, because we want to make sure the only way to get one of these URLs is from this module. | ||
-} | ||
type Endpoint | ||
= Endpoint String | ||
|
||
|
||
unwrap : Endpoint -> String | ||
unwrap (Endpoint str) = | ||
str | ||
|
||
|
||
url : List String -> List QueryParameter -> Endpoint | ||
url paths queryParams = | ||
-- NOTE: Url.Builder takes care of percent-encoding special URL characters. | ||
-- See https://package.elm-lang.org/packages/elm/url/latest/Url#percentEncode | ||
Url.Builder.crossOrigin "https://conduit.productionready.io" | ||
("api" :: paths) | ||
queryParams | ||
|> Endpoint | ||
|
||
|
||
|
||
-- ENDPOINTS | ||
|
||
|
||
login : Endpoint | ||
login = | ||
url [ "users", "login" ] [] | ||
|
||
|
||
user : Endpoint | ||
user = | ||
url [ "user" ] [] | ||
|
||
|
||
users : Endpoint | ||
users = | ||
url [ "users" ] [] | ||
|
||
|
||
follow : Username -> Endpoint | ||
follow uname = | ||
url [ "profiles", Username.toString uname, "follow" ] [] | ||
|
||
|
||
|
||
-- ARTICLE ENDPOINTS | ||
|
||
|
||
article : Slug -> Endpoint | ||
article slug = | ||
url [ "articles", Slug.toString slug ] [] | ||
|
||
|
||
comments : Slug -> Endpoint | ||
comments slug = | ||
url [ "articles", Slug.toString slug, "comments" ] [] | ||
|
||
|
||
comment : Slug -> CommentId -> Endpoint | ||
comment slug commentId = | ||
url [ "articles", Slug.toString slug, "comments", CommentId.toString commentId ] [] | ||
|
||
|
||
favorite : Slug -> Endpoint | ||
favorite slug = | ||
url [ "articles", Slug.toString slug, "favorite" ] [] | ||
|
||
|
||
articles : List QueryParameter -> Endpoint | ||
articles params = | ||
url [ "articles" ] params | ||
|
||
|
||
profiles : Username -> Endpoint | ||
profiles uname = | ||
url [ "profiles", Username.toString uname ] [] | ||
|
||
|
||
feed : List QueryParameter -> Endpoint | ||
feed params = | ||
url [ "articles", "feed" ] params | ||
|
||
|
||
tags : Endpoint | ||
tags = | ||
url [ "tags" ] [] |
Oops, something went wrong.