Skip to content

Commit

Permalink
Update for Gleam v1
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Mar 21, 2024
1 parent 4e10699 commit 66a6421
Show file tree
Hide file tree
Showing 24 changed files with 518 additions and 590 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.1.0
- uses: erlef/setup-beam@v1.15.0
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: "26.1"
gleam-version: "0.31.0"
gleam-version: "1.0.0"
rebar3-version: "3"
- run: gleam format --check src test
- run: gleam deps download
- run: gleam test
- run: gleam format --check src test
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/gleam-lang/gleam:v0.31.0-erlang-alpine
FROM ghcr.io/gleam-lang/gleam:v1.0.0-erlang-alpine

# Add project code
COPY . /build/
Expand Down
7 changes: 4 additions & 3 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ gleam_json = "~> 0.4"
gleam_erlang = "~> 0.9"
gleam_bbmustache = "~> 2.0"
gleam_otp = "~> 0.3"
gleam_crypto = "~> 0.3"
zeptomail = "~> 0.1"
gleam_crypto = "~> 1.0"
zeptomail = "~> 1.0"
mist = "~> 0.9"
sqlight = "~> 0.5"
nakai = "~> 0.4"
wisp = "~> 0.4"
simplifile = "~> 1.5"

[dev-dependencies]
gleeunit = "~> 0.6"
gleeunit = "~> 1.0"
46 changes: 24 additions & 22 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,48 @@ packages = [
{ name = "bbmustache", version = "1.12.2", build_tools = ["rebar3"], requirements = [], otp_app = "bbmustache", source = "hex", outer_checksum = "688B33A4D5CC2D51F575ADF0B3683FC40A38314A2F150906EDCFC77F5B577B3B" },
{ name = "certifi", version = "2.12.0", build_tools = ["rebar3"], requirements = [], otp_app = "certifi", source = "hex", outer_checksum = "EE68D85DF22E554040CDB4BE100F33873AC6051387BAF6A8F6CE82272340FF1C" },
{ name = "esqlite", version = "0.8.6", build_tools = ["rebar3"], requirements = [], otp_app = "esqlite", source = "hex", outer_checksum = "607E45F4DA42601D8F530979417F57A4CD629AB49085891849302057E68EA188" },
{ name = "exception", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "71F00057D38ADB03BBCCD0E3B07AB2C236BD49DBA7E7611A9DADBD1E26C9F53D" },
{ name = "gleam_bbmustache", version = "2.1.0", build_tools = ["gleam"], requirements = ["bbmustache", "gleam_stdlib"], otp_app = "gleam_bbmustache", source = "hex", outer_checksum = "7C8AB381EA998C87895E7815A6EA2BB9B17BD7B0109671C6EA1339B4CE182649" },
{ name = "gleam_bitwise", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "E2A46EE42E5E9110DAD67E0F71E7358CBE54D5EC22C526DD48CBBA3223025792" },
{ name = "gleam_crypto", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_bitwise", "gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "42429CED0F838B40014E1C017B0495C46C311D08035D2C2D43B749B91A4374F6" },
{ name = "gleam_erlang", version = "0.22.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "367D8B41A7A86809928ED1E7E55BFD0D46D7C4CF473440190F324AFA347109B4" },
{ name = "gleam_hackney", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "hackney", "gleam_http"], otp_app = "gleam_hackney", source = "hex", outer_checksum = "CA69AD9061C4A8775A7BD445DE33ECEFD87379AF8E5B028F3DD0216BECA5DD0B" },
{ name = "gleam_http", version = "3.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "FAE9AE3EB1CA90C2194615D20FFFD1E28B630E84DACA670B28D959B37BCBB02C" },
{ name = "gleam_json", version = "0.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "C6CC5BEECA525117E97D0905013AB3F8836537455645DDDD10FE31A511B195EF" },
{ name = "gleam_otp", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "ED7381E90636E18F5697FD7956EECCA635A3B65538DC2BE2D91A38E61DCE8903" },
{ name = "gleam_stdlib", version = "0.30.2", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "8D8BF3790AA31176B1E1C0B517DD74C86DA8235CF3389EA02043EE4FD82AE3DC" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "glisten", version = "0.8.2", build_tools = ["gleam"], requirements = ["gleam_otp", "gleam_stdlib", "gleam_erlang"], otp_app = "glisten", source = "hex", outer_checksum = "364E9B3D4F78308D2EEE5D73E0FB16C686E08516943EFDA501B17177B382907C" },
{ name = "hackney", version = "1.18.2", build_tools = ["rebar3"], requirements = ["certifi", "mimerl", "metrics", "parse_trans", "idna", "unicode_util_compat", "ssl_verify_fun"], otp_app = "hackney", source = "hex", outer_checksum = "AF94D5C9F97857DB257090A4A10E5426ECB6F4918AA5CC666798566AE14B65FD" },
{ name = "exception", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "F5580D584F16A20B7FCDCABF9E9BE9A2C1F6AC4F9176FA6DD0B63E3B20D450AA" },
{ name = "gleam_bbmustache", version = "2.2.0", build_tools = ["gleam"], requirements = ["bbmustache", "gleam_stdlib"], otp_app = "gleam_bbmustache", source = "hex", outer_checksum = "95863431B77C1701BAB2BF68FDAA8DA838C3C59ECB0183D2687E145B4A355285" },
{ name = "gleam_crypto", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "ADD058DEDE8F0341F1ADE3AAC492A224F15700829D9A3A3F9ADF370F875C51B7" },
{ name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" },
{ name = "gleam_hackney", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_stdlib", "hackney"], otp_app = "gleam_hackney", source = "hex", outer_checksum = "066B1A55D37DBD61CC72A1C4EDE43C6015B1797FAF3818C16FE476534C7B6505" },
{ name = "gleam_http", version = "3.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "8C07DF9DF8CC7F054C650839A51C30A7D3C26482AC241C899C1CEA86B22DBE51" },
{ name = "gleam_json", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB405BD93A8828BCD870463DE29375E7B2D252D9D124C109E5B618AAC00B86FC" },
{ name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" },
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "glisten", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "73BC09C8487C2FFC0963BFAB33ED2F0D636FDFA43B966E65C1251CBAB8458099" },
{ name = "hackney", version = "1.20.1", build_tools = ["rebar3"], requirements = ["certifi", "idna", "metrics", "mimerl", "parse_trans", "ssl_verify_fun", "unicode_util_compat"], otp_app = "hackney", source = "hex", outer_checksum = "FE9094E5F1A2A2C0A7D10918FEE36BFEC0EC2A979994CFF8CFE8058CD9AF38E3" },
{ name = "idna", version = "6.1.1", build_tools = ["rebar3"], requirements = ["unicode_util_compat"], otp_app = "idna", source = "hex", outer_checksum = "92376EB7894412ED19AC475E4A86F7B413C1B9FBB5BD16DCCD57934157944CEA" },
{ name = "logging", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "82C112ED9B6C30C1772A6FE2613B94B13F62EA35F5869A2630D13948D297BD39" },
{ name = "marceau", version = "1.1.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "1AAD727A30BE0F95562C3403BB9B27C823797AD90037714255EEBF617B1CDA81" },
{ name = "metrics", version = "1.0.1", build_tools = ["rebar3"], requirements = [], otp_app = "metrics", source = "hex", outer_checksum = "69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16" },
{ name = "mimerl", version = "1.2.0", build_tools = ["rebar3"], requirements = [], otp_app = "mimerl", source = "hex", outer_checksum = "F278585650AA581986264638EBF698F8BB19DF297F66AD91B18910DFC6E19323" },
{ name = "mist", version = "0.13.2", build_tools = ["gleam"], requirements = ["glisten", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib"], otp_app = "mist", source = "hex", outer_checksum = "51C385C58A78A2013A30F92705814560AD9A2B8EC3ECBA94C620F22D3ACB50BC" },
{ name = "nakai", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "nakai", source = "hex", outer_checksum = "E4BA604229121481776CB4DD42C6E5E7FB1A9BF303D7B1DCDFECFE5FA0B34382" },
{ name = "mist", version = "0.17.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "glisten"], otp_app = "mist", source = "hex", outer_checksum = "DA8ACEE52C1E4892A75181B3166A4876D8CBC69D555E4770250BC84C80F75524" },
{ name = "nakai", version = "0.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "nakai", source = "hex", outer_checksum = "F6FFED9EF4B0E14C7A09B2FB87B42D3A93EFE024FD0299C11F041E92321163A6" },
{ name = "parse_trans", version = "3.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "parse_trans", source = "hex", outer_checksum = "620A406CE75DADA827B82E453C19CF06776BE266F5A67CFF34E1EF2CBB60E49A" },
{ name = "simplifile", version = "0.1.10", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "263B7C7F4B29263555DEA2D30BA918425A27120CDD1E1352744EAB4D56CE01CE" },
{ name = "sqlight", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "esqlite"], otp_app = "sqlight", source = "hex", outer_checksum = "BDBAA35B58E11B6DE20DC869EAA247F447268B8F398E0677F25444C9F7AE54EA" },
{ name = "simplifile", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "EB9AA8E65E5C1E3E0FDCFC81BC363FD433CB122D7D062750FFDF24DE4AC40116" },
{ name = "sqlight", version = "0.9.0", build_tools = ["gleam"], requirements = ["esqlite", "gleam_stdlib"], otp_app = "sqlight", source = "hex", outer_checksum = "2D9C9BA420A5E7DCE7DB2DAAE4CAB0BE6218BEB48FD1531C583550B3D1316E94" },
{ name = "ssl_verify_fun", version = "1.1.7", build_tools = ["mix", "rebar3", "make"], requirements = [], otp_app = "ssl_verify_fun", source = "hex", outer_checksum = "FE4C190E8F37401D30167C8C405EDA19469F34577987C76DDE613E838BBC67F8" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
{ name = "unicode_util_compat", version = "0.7.0", build_tools = ["rebar3"], requirements = [], otp_app = "unicode_util_compat", source = "hex", outer_checksum = "25EEE6D67DF61960CF6A794239566599B09E17E668D3700247BC498638152521" },
{ name = "wisp", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib", "simplifile", "exception", "gleam_crypto", "gleam_http", "mist"], otp_app = "wisp", source = "hex", outer_checksum = "E086699C0AC8BCB3E88631E445E0D416D5672E3B7E090DD442A8E0F65CF245B1" },
{ name = "zeptomail", version = "0.1.1", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_json", "gleam_stdlib"], otp_app = "zeptomail", source = "hex", outer_checksum = "1EAC2A81410A87363F1586F9479472D0DF0428A3090A85CC52C7C6E79373C635" },
{ name = "wisp", version = "0.12.0", build_tools = ["gleam"], requirements = ["exception", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_stdlib", "logging", "marceau", "mist", "simplifile"], otp_app = "wisp", source = "hex", outer_checksum = "C180D7849D011C82E9D4D17DD856FD1325B5FDFA3C03E3E2B6593CF2F5CE156C" },
{ name = "zeptomail", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_json", "gleam_stdlib"], otp_app = "zeptomail", source = "hex", outer_checksum = "D41269BE9F0E4BC52598E54E5AD087B386A44E97F49DA3D9C34CF554A5CB8A71" },
]

[requirements]
gleam_bbmustache = { version = "~> 2.0" }
gleam_crypto = { version = "~> 0.3" }
gleam_crypto = { version = "~> 1.0" }
gleam_erlang = { version = "~> 0.9" }
gleam_hackney = { version = "~> 1.0" }
gleam_http = { version = "~> 3.0" }
gleam_json = { version = "~> 0.4" }
gleam_otp = { version = "~> 0.3" }
gleam_stdlib = { version = "~> 0.19" }
gleeunit = { version = "~> 0.6" }
gleeunit = { version = "~> 1.0" }
mist = { version = "~> 0.9" }
nakai = { version = "~> 0.4" }
simplifile = { version = "~> 1.5"}
sqlight = { version = "~> 0.5" }
wisp = { version = "~> 0.4" }
zeptomail = { version = "~> 0.1" }
zeptomail = { version = "~> 1.0" }
13 changes: 7 additions & 6 deletions src/puck.gleam
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import gleam/erlang
import gleam/erlang/file
import gleam/erlang/process
import gleam/int
import gleam/io
import gleam/list
import gleam/option.{Some}
import gleam/string
import mist
import puck/config.{Config}
import puck/config.{type Config}
import puck/database
import puck/email
import puck/pushover
import puck/routes
import puck/user
import puck/web.{Context}
import puck/web/templates
import puck/web.{type Context, Context}
import puck/web/auth
import puck/web/templates
import simplifile
import wisp

const usage = "USAGE:
puck server
puck email <subject> <body.txt> <addresses.txt>
puck login-url <user_id>
"

pub fn main() {
Expand Down Expand Up @@ -100,8 +101,8 @@ fn email(
addresses: String,
config: Config,
) -> Nil {
let assert Ok(addresses) = file.read(addresses)
let assert Ok(body) = file.read(body)
let assert Ok(addresses) = simplifile.read(addresses)
let assert Ok(body) = simplifile.read(body)
let addresses = string.split(string.trim(addresses), "\n")

list.each(addresses, io.println)
Expand Down
7 changes: 4 additions & 3 deletions src/puck/database.gleam
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sqlight
import puck/error.{Error}
import gleam/dynamic
import gleam/option.{type Option}
import gleam/result
import gleam/option.{Option}
import puck/error.{type Error}
import sqlight

pub type Connection =
sqlight.Connection
Expand Down Expand Up @@ -55,6 +55,7 @@ pub fn maybe_one(
case rows {
[] -> option.None
[row] -> option.Some(row)
_ -> panic as "Expected 0 or 1 rows"
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/puck/email.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import puck/config.{Config}
import gleam/hackney
import gleam/io
import puck/config.{type Config, Config}
import zeptomail

pub type Email {
Expand Down
6 changes: 3 additions & 3 deletions src/puck/fact.gleam
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// Facts about the event! FAQs and what have you!

import gleam/dynamic.{Dynamic} as dy
import gleam/option.{Option}
import gleam/dynamic.{type Dynamic} as dy
import gleam/option.{type Option}
import gleam/result
import puck/database
import puck/error.{Error}
import puck/error.{type Error}
import sqlight

pub type Fact {
Expand Down
23 changes: 10 additions & 13 deletions src/puck/payment.gleam
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sqlight.{ConstraintPrimarykey, SqlightError}
import gleam/bool
import gleam/dynamic.{type Dynamic, element, field, int, string}
import gleam/list
import gleam/string.{lowercase} as stringmod
import gleam/pair
import gleam/result
import gleam/dynamic.{Dynamic, element, field, int, string}
import puck/error.{Error}
import gleam/string.{lowercase}
import puck/database
import gleam/bool
import gleam/pair
import puck/error.{type Error}
import sqlight.{ConstraintPrimarykey, SqlightError}

pub type Payment {
Payment(
Expand Down Expand Up @@ -227,13 +227,10 @@ pub fn per_day(
use rows <- result.then(database.query(sql, conn, [], decoder))
rows
|> list.drop_while(fn(row) { row.1 == 0 })
|> list.map_fold(
0,
fn(total, row) {
let total = total + row.1
#(total, #(row.0, row.1, total))
},
)
|> list.map_fold(0, fn(total, row) {
let total = total + row.1
#(total, #(row.0, row.1, total))
})
|> pair.second
|> list.reverse
|> Ok
Expand Down
24 changes: 13 additions & 11 deletions src/puck/pushover.gleam
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import gleam/json
import gleam/string
import gleam/result
import gleam/hackney
import gleam/http.{Post}
import gleam/http/request
import puck/config.{Config}
import puck/error.{Error}
import gleam/json
import gleam/result
import gleam/string
import puck/config.{type Config}
import puck/error.{type Error}

pub fn notify(
config: Config,
title title: String,
message message: String,
) -> Result(Nil, Error) {
let json =
json.to_string(json.object([
#("token", json.string(config.pushover_key)),
#("user", json.string(config.pushover_user)),
#("title", json.string(string.slice(title, 0, length: 1024))),
#("message", json.string(string.slice(message, 0, length: 250))),
]))
json.to_string(
json.object([
#("token", json.string(config.pushover_key)),
#("user", json.string(config.pushover_user)),
#("title", json.string(string.slice(title, 0, length: 1024))),
#("message", json.string(string.slice(message, 0, length: 250))),
]),
)

let request =
request.new()
Expand Down
Loading

0 comments on commit 66a6421

Please sign in to comment.