senbei 1.0.2 → 1.0.3
raw patch · 7 files changed
+35/−4 lines, 7 files
Files
- .envrc +0/−1
- .gitignore +2/−0
- CHANGELOG.md +7/−0
- README.md +2/−1
- senbei.cabal +1/−1
- src/Senbei.hs +12/−1
- test/tests.hs +11/−0
− .envrc
@@ -1,1 +0,0 @@-use flake
.gitignore view
@@ -11,3 +11,5 @@ dist* dist/ .DS_Store+*.prof+*.svg
CHANGELOG.md view
@@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). As this project is a Haskell Cabal project, it follows the [Package Versioning Policy](https://pvp.haskell.org/). +## [1.0.3] - 2026-12-01++### Added++- Added `maxAge` which allows the safe construction of the `MaxAge` variant of `Expiry` via+a type-level natural number.+ ## [1.0.2] - 2026-11-30 ### Changed
README.md view
@@ -11,4 +11,5 @@ ## Contributing -PRs are expected to update changelog.md and the version number.+PRs are expected to update CHANGELOG.md and the version number where appropriate.+A `flake.nix` is provided featuring a devShell for development.
senbei.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.8 name: senbei-version: 1.0.2+version: 1.0.3 build-type: Simple extra-source-files: README.md category: Web
src/Senbei.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE OverloadedStrings #-} -- |@@ -17,6 +18,7 @@ , DictFor , ExpiryError (..) , Expiry (Expires, Session)+ , maxAge , mkMaxAge , HasCookie (..) , NonEmptyRestrictedText@@ -126,7 +128,16 @@ data Expiry = Expires UTCTime | MaxAge Integer | Session deriving (Eq, Show) --- | Max-Age must be >= 0, so this smart constructor is used to construct it.+-- | Construct the MaxAge variant of Expiry via a type level natural number,+-- which is guaranteed to be non-negative.+--+-- >>> maxAge @1000+-- MaxAge 1000+maxAge :: forall n. KnownNat n => Expiry+maxAge = MaxAge $ natVal $ Proxy @n++-- | Construct the MaxAge variant of Expiry via a runtime-checked Integer value.+-- MaxAge must be >= 0, so this can fail. mkMaxAge :: Integer -> Either ExpiryError Expiry mkMaxAge delta | delta < 0 = Left $ NegativeMaxAge delta
test/tests.hs view
@@ -226,3 +226,14 @@ it "has a smart constructor for Max-Age which fails on a negative value" $ do mkMaxAge 1000 `shouldSatisfy` isRight mkMaxAge (-1000) `shouldBe` Left (NegativeMaxAge (-1000))++ it "has a smart constructor for Max-Age which takes a type level natural number" $ do+ maxAge @1000 `shouldSatisfy` \case+ Expires _ -> False+ Session -> False+ _ -> True+ simpleSetCookie+ (defaultCookieSettings {cookieExpiry = maxAge @1000})+ "expirycookie"+ ("soon" :: Text)+ `shouldBe` Right "expirycookie=soon; Max-Age=1000; HttpOnly; SameSite=Lax; Secure"