Skip to content
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

Update to work with latest stdlib #30

Open
wants to merge 1 commit into
base: main
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: 4 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ version = "0.13.0"
licences = ["Apache-2.0"]
description = "✨ Unique IDs for Gleam"
repository = { type = "github", user = "rvcas", repo = "ids" }
gleam = ">= 0.32.2"
gleam = ">= 1.1.0"

[dependencies]
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
gleam_stdlib = ">= 0.50.0 and < 2.0.0"
gleam_otp = "~> 0.10"
gleam_erlang = "~> 0.25"
gleam_yielder = ">= 1.1.0 and < 2.0.0"
gleam_regexp = ">= 1.0.0 and < 2.0.0"

[dev-dependencies]
gleeunit = "~> 1.0"
14 changes: 9 additions & 5 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" },
{ 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.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" },
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
{ name = "gleam_erlang", version = "0.33.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A1D26B80F01901B59AABEE3475DD4C18D27D58FA5C897D922FCB9B099749C064" },
{ name = "gleam_otp", version = "0.16.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "FA0EB761339749B4E82D63016C6A18C4E6662DA05BAB6F1346F9AF2E679E301A" },
{ name = "gleam_regexp", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "A3655FDD288571E90EE9C4009B719FEF59FA16AFCDF3952A76A125AF23CF1592" },
{ name = "gleam_stdlib", version = "0.51.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "14AFA8D3DDD7045203D422715DBB822D1725992A31DF35A08D97389014B74B68" },
{ name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" },
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
]

[requirements]
gleam_erlang = { version = "~> 0.25" }
gleam_otp = { version = "~> 0.10" }
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
gleam_regexp = { version = ">= 1.0.0 and < 2.0.0" }
gleam_stdlib = { version = ">= 0.50.0 and < 2.0.0" }
gleam_yielder = { version = ">= 1.1.0 and < 2.0.0" }
gleeunit = { version = "~> 1.0" }
4 changes: 2 additions & 2 deletions src/ids/cuid.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn timestamp() -> String {
fn format_count(num: Int) -> String {
num
|> int.to_base36()
|> string.pad_left(to: block_size, with: "0")
|> string.pad_start(to: block_size, with: "0")
}

type CharList
Expand Down Expand Up @@ -171,5 +171,5 @@ fn rand_uniform(n: Int) -> Int
fn random_block() -> String {
rand_uniform(discrete_values - 1)
|> int.to_base36()
|> string.pad_left(to: block_size, with: "0")
|> string.pad_start(to: block_size, with: "0")
}
6 changes: 3 additions & 3 deletions src/ids/typeid.gleam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// Module for generating TypeIDs.

import gleam/bit_array
import gleam/regex
import gleam/regexp
import gleam/result
import gleam/string
import ids/base32
Expand Down Expand Up @@ -32,9 +32,9 @@ pub fn from_uuid(
prefix prefix: String,
uuid uuid: String,
) -> Result(String, String) {
let assert Ok(re) = regex.from_string("^([a-z]([a-z_]{0,61}[a-z])?)?$")
let assert Ok(re) = regexp.from_string("^([a-z]([a-z_]{0,61}[a-z])?)?$")

case regex.check(re, prefix) {
case regexp.check(re, prefix) {
True -> {
let p = case prefix {
"" -> ""
Expand Down
6 changes: 3 additions & 3 deletions test/ids/cuid_test.gleam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gleam/dict
import gleam/iterator.{Done, Next}
import gleam/pair
import gleam/string
import gleam/yielder.{Done, Next}
import gleeunit/should
import ids/cuid

Expand Down Expand Up @@ -55,13 +55,13 @@ const max: Int = 100_000

fn check_collision(func: fn() -> String) -> Bool {
start
|> iterator.unfold(with: fn(acc) {
|> yielder.unfold(with: fn(acc) {
case acc < max {
False -> Done
True -> Next(element: func(), accumulator: acc + 1)
}
})
|> iterator.fold(from: #(dict.new(), True), with: fn(acc, id) {
|> yielder.fold(from: #(dict.new(), True), with: fn(acc, id) {
let #(id_dict, flag) = acc

case flag {
Expand Down