Update for Gleam 0.33

This commit is contained in:
Mikko Ahlroth 2023-12-27 23:44:32 +02:00
parent 4f0071c6c8
commit 74def756c8
8 changed files with 71 additions and 61 deletions

View file

@ -1,3 +1,3 @@
gleam 0.30.2 gleam 0.33.0
erlang 25.2.2 erlang 26.1.2
elixir 1.14.3-otp-25 elixir 1.15.7-otp-26

View file

@ -1,3 +1,8 @@
5.0.0
-----
* Updated for Gleam 0.33.
4.0.0 4.0.0
----- -----

View file

@ -1,7 +1,7 @@
name = "finch_gleam" name = "finch_gleam"
version = "4.0.0" version = "5.0.0"
target = "erlang" target = "erlang"
gleam = ">= 0.30.0" gleam = ">= 0.33.0"
# Fill out these fields if you intend to generate HTML documentation or publish # Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager. # your project to the Hex package manager.
@ -12,11 +12,11 @@ repository = { type = "gitlab", user = "Nicd", repo = "finch_gleam" }
links = [] links = []
[dependencies] [dependencies]
gleam_stdlib = "~> 0.28" gleam_stdlib = "~> 0.34"
gleam_erlang = "~> 0.18" gleam_erlang = "~> 0.23"
gleam_http = "~> 3.1" gleam_http = "~> 3.5"
finch = "~> 0.16" finch = "~> 0.16"
[dev-dependencies] [dev-dependencies]
gleeunit = "~> 0.10" gleeunit = "~> 1.0"
mist = "~> 0.11" mist = "~> 0.15"

View file

@ -3,17 +3,17 @@
packages = [ packages = [
{ name = "castore", version = "1.0.3", build_tools = ["mix"], requirements = [], otp_app = "castore", source = "hex", outer_checksum = "680AB01EF5D15B161ED6A95449FAC5C6B8F60055677A8E79ACF01B27BAA4390B" }, { name = "castore", version = "1.0.3", build_tools = ["mix"], requirements = [], otp_app = "castore", source = "hex", outer_checksum = "680AB01EF5D15B161ED6A95449FAC5C6B8F60055677A8E79ACF01B27BAA4390B" },
{ name = "finch", version = "0.16.0", build_tools = ["mix"], requirements = ["mint", "castore", "telemetry", "nimble_pool", "mime", "nimble_options"], otp_app = "finch", source = "hex", outer_checksum = "F660174C4D519E5FEC629016054D60EDD822CDFE2B7270836739AC2F97735EC5" }, { name = "finch", version = "0.16.0", build_tools = ["mix"], requirements = ["mime", "castore", "telemetry", "nimble_options", "mint", "nimble_pool"], otp_app = "finch", source = "hex", outer_checksum = "F660174C4D519E5FEC629016054D60EDD822CDFE2B7270836739AC2F97735EC5" },
{ name = "gleam_erlang", version = "0.19.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "720D1E0A0CEBBD51C4AA88501D1D4FBFEF4AA7B3332C994691ED944767A52582" }, { name = "gleam_erlang", version = "0.23.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "C21CFB816C114784E669FFF4BBF433535EEA9960FA2F216209B8691E87156B96" },
{ name = "gleam_http", version = "3.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "D034F5CE0639CD142CBA210B7D5D14236C284B0C5772A043D2E22128594573AE" }, { name = "gleam_http", version = "3.5.3", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "C2FC3322203B16F897C1818D9810F5DEFCE347F0751F3B44421E1261277A7373" },
{ name = "gleam_otp", version = "0.5.3", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "6E705B69464237353E0380AC8143BDB29A3F0BF6168755D5F2D6E55A34A8B077" }, { name = "gleam_otp", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "18EF8242A5E54BA92F717C7222F03B3228AEE00D1F286D4C56C3E8C18AA2588E" },
{ name = "gleam_stdlib", version = "0.30.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "03710B3DA047A3683117591707FCA19D32B980229DD8CE8B0603EB5B5144F6C3" }, { name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" }, { name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "glisten", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "52B530FF25370590843998D1B6C4EC6169DB1300D5E4407A5CDA1575374B7AEC" }, { name = "glisten", version = "0.9.2", build_tools = ["gleam"], requirements = ["gleam_otp", "gleam_stdlib", "gleam_erlang"], otp_app = "glisten", source = "hex", outer_checksum = "C960B6CF25D4AABAB01211146E9B57E11827B9C49E4175217E0FB7EF5BCB0FF7" },
{ name = "hpax", version = "0.1.2", build_tools = ["mix"], requirements = [], otp_app = "hpax", source = "hex", outer_checksum = "2C87843D5A23F5F16748EBE77969880E29809580EFDACCD615CD3BED628A8C13" }, { name = "hpax", version = "0.1.2", build_tools = ["mix"], requirements = [], otp_app = "hpax", source = "hex", outer_checksum = "2C87843D5A23F5F16748EBE77969880E29809580EFDACCD615CD3BED628A8C13" },
{ name = "mime", version = "2.0.5", build_tools = ["mix"], requirements = [], otp_app = "mime", source = "hex", outer_checksum = "DA0D64A365C45BC9935CC5C8A7FC5E49A0E0F9932A761C55D6C52B142780A05C" }, { name = "mime", version = "2.0.5", build_tools = ["mix"], requirements = [], otp_app = "mime", source = "hex", outer_checksum = "DA0D64A365C45BC9935CC5C8A7FC5E49A0E0F9932A761C55D6C52B142780A05C" },
{ name = "mint", version = "1.5.1", build_tools = ["mix"], requirements = ["hpax", "castore"], otp_app = "mint", source = "hex", outer_checksum = "4A63E1E76A7C3956ABD2C72F370A0D0AECDDC3976DEA5C27ECCBECFA5E7D5B1E" }, { name = "mint", version = "1.5.1", build_tools = ["mix"], requirements = ["castore", "hpax"], otp_app = "mint", source = "hex", outer_checksum = "4A63E1E76A7C3956ABD2C72F370A0D0AECDDC3976DEA5C27ECCBECFA5E7D5B1E" },
{ name = "mist", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_otp", "gleam_erlang", "gleam_stdlib", "glisten", "gleam_http"], otp_app = "mist", source = "hex", outer_checksum = "6FD3D24B0E79CA90AE07A695C2ADA2049E16A384BEF960B122E841DE88B6CA67" }, { name = "mist", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang", "glisten", "gleam_otp", "gleam_http"], otp_app = "mist", source = "hex", outer_checksum = "49F51DDB64D7B2832F72727CC9721C478D6B524C96EA444C601A19D01E023C03" },
{ name = "nimble_options", version = "1.0.2", build_tools = ["mix"], requirements = [], otp_app = "nimble_options", source = "hex", outer_checksum = "FD12A8DB2021036CE12A309F26F564EC367373265B53E25403F0EE697380F1B8" }, { name = "nimble_options", version = "1.0.2", build_tools = ["mix"], requirements = [], otp_app = "nimble_options", source = "hex", outer_checksum = "FD12A8DB2021036CE12A309F26F564EC367373265B53E25403F0EE697380F1B8" },
{ name = "nimble_pool", version = "1.0.0", build_tools = ["mix"], requirements = [], otp_app = "nimble_pool", source = "hex", outer_checksum = "80BE3B882D2D351882256087078E1B1952A28BF98D0A287BE87E4A24A710B67A" }, { name = "nimble_pool", version = "1.0.0", build_tools = ["mix"], requirements = [], otp_app = "nimble_pool", source = "hex", outer_checksum = "80BE3B882D2D351882256087078E1B1952A28BF98D0A287BE87E4A24A710B67A" },
{ name = "telemetry", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "telemetry", source = "hex", outer_checksum = "DAD9CE9D8EFFC621708F99EAC538EF1CBE05D6A874DD741DE2E689C47FEAFED5" }, { name = "telemetry", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "telemetry", source = "hex", outer_checksum = "DAD9CE9D8EFFC621708F99EAC538EF1CBE05D6A874DD741DE2E689C47FEAFED5" },
@ -21,8 +21,8 @@ packages = [
[requirements] [requirements]
finch = { version = "~> 0.16" } finch = { version = "~> 0.16" }
gleam_erlang = { version = "~> 0.18" } gleam_erlang = { version = "~> 0.23" }
gleam_http = { version = "~> 3.1" } gleam_http = { version = "~> 3.5" }
gleam_stdlib = { version = "~> 0.28" } gleam_stdlib = { version = "~> 0.34" }
gleeunit = { version = "~> 0.10" } gleeunit = { version = "~> 1.0" }
mist = { version = "~> 0.11" } mist = { version = "~> 0.15" }

View file

@ -6,13 +6,13 @@
import gleam/result import gleam/result
import gleam import gleam
import gleam/uri import gleam/uri
import gleam/erlang/atom.{Atom} import gleam/erlang/atom.{type Atom}
import gleam/http import gleam/http
import gleam/http/request as gleam_request import gleam/http/request as gleam_request
import gleam/http/response as gleam_response import gleam/http/response as gleam_response
import finch/headers.{Headers} import finch/headers.{type Headers}
import finch/stream.{StreamFun} import finch/stream.{type StreamFun}
import finch/otp.{InstanceOptions, OnStart} import finch/otp.{type InstanceOptions, type OnStart}
// Finch's HTTP method type // Finch's HTTP method type
type Method { type Method {

View file

@ -1,11 +1,11 @@
//// Types related to OTP usage of Finch. //// Types related to OTP usage of Finch.
import gleam/uri import gleam/uri
import gleam/dynamic.{Dynamic} import gleam/dynamic.{type Dynamic}
import gleam/map.{Map} import gleam/dict.{type Dict}
import gleam/erlang/atom.{Atom} import gleam/erlang/atom.{type Atom}
import gleam/erlang/process.{Pid} import gleam/erlang/process.{type Pid}
import finch/timeout.{Timeout} import finch/timeout.{type Timeout}
pub type UnixSocketPath { pub type UnixSocketPath {
Local(path: String) Local(path: String)
@ -42,7 +42,7 @@ pub type PoolOptions =
pub type InstanceOption { pub type InstanceOption {
Name(Atom) Name(Atom)
Pools(Map(PoolSpecifier, PoolOptions)) Pools(Dict(PoolSpecifier, PoolOptions))
} }
pub type InstanceOptions = pub type InstanceOptions =

View file

@ -1,10 +1,10 @@
import finch/headers.{Headers as ReqHeaders} import finch/headers.{type Headers as ReqHeaders}
/// A block of data sent by Finch from the HTTP request stream. /// A block of data sent by Finch from the HTTP request stream.
pub type StreamBlock { pub type StreamBlock {
Status(status: Int) Status(status: Int)
Headers(headers: ReqHeaders) Headers(headers: ReqHeaders)
Data(data: BitString) Data(data: BitArray)
} }
/// A stream handler function /// A stream handler function

View file

@ -1,11 +1,11 @@
import gleeunit import gleeunit
import gleeunit/should import gleeunit/should
import mist import mist.{type Connection}
import gleam/bit_builder import gleam/bytes_builder
import gleam/http import gleam/http
import gleam/http/request import gleam/http/request
import gleam/http/response import gleam/http/response
import gleam/erlang/atom.{Atom} import gleam/erlang/atom.{type Atom}
import gleam/erlang/process import gleam/erlang/process
import gleam/uri import gleam/uri
import gleam/string import gleam/string
@ -17,28 +17,33 @@ const base_url = "http://localhost:33100"
pub fn main() { pub fn main() {
let assert Ok(_) = let assert Ok(_) =
mist.run_service( fn(req: request.Request(Connection)) {
33_100, case req.method, request.path_segments(req) {
fn(req) { http.Get, ["ok"] ->
case req.method, request.path_segments(req) { response.new(200)
http.Get, ["ok"] -> |> response.set_body(mist.Bytes(bytes_builder.from_string("OK")))
response.new(200)
|> response.set_body(bit_builder.from_string("OK"))
http.Post, ["post"] -> http.Post, ["post"] -> {
response.new(500) let assert Ok(req) = mist.read_body(req, 4_000_000)
|> response.set_body(bit_builder.from_bit_string(req.body)) response.new(500)
|> response.set_body(
http.Delete, ["headers"] -> mist.Bytes(bytes_builder.from_bit_array(req.body)),
response.new(200) )
|> response.set_body(bit_builder.from_string(string.inspect(
req.headers,
)))
|> response.set_header("x-token", "token-x")
} }
},
max_body_limit: 4_000_000, http.Delete, ["headers"] ->
) response.new(200)
|> response.set_body(
mist.Bytes(bytes_builder.from_string(string.inspect(req.headers))),
)
|> response.set_header("x-token", "token-x")
_, _ -> panic
}
}
|> mist.new()
|> mist.port(33_100)
|> mist.start_http()
configure_logger([Level(None)]) configure_logger([Level(None)])
@ -113,7 +118,7 @@ fn headers_url() {
base_url <> "/headers" base_url <> "/headers"
} }
fn with_finch(test: fn() -> a) { fn with_finch(real_test: fn() -> a) {
let subject: process.Subject(process.Pid) = process.new_subject() let subject: process.Subject(process.Pid) = process.new_subject()
process.start( process.start(
@ -132,7 +137,7 @@ fn with_finch(test: fn() -> a) {
process.new_selector() process.new_selector()
|> process.selecting_process_down(monitor, fn(down) { down }) |> process.selecting_process_down(monitor, fn(down) { down })
test() real_test()
process.kill(finch_pid) process.kill(finch_pid)
let assert Ok(_) = process.select(selector, 1000) let assert Ok(_) = process.select(selector, 1000)