Skip to content

Commit

Permalink
Add Cookies bindings
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
tom-sherman committed Dec 28, 2021
1 parent 9250839 commit 2093a30
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/Remix.res
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,40 @@ module Form = {
@module("remix") external useBeforeUnload: (@uncurry unit => unit) => unit = "useBeforeUnload"

@module("remix") external useLoaderData: unit => 'a = "useLoaderData"

module Cookie = {
type t

@get external name: t => string = "name"
@get external isSigned: t => bool = "isSigned"
@get @return(undefined_to_opt) external expires: t => option<Js.Date.t> = "isSigned"
@send external serialize: (t, {..}) => Promise.t<string> = "serialize"
@module("remix") external isCookie: 'a => bool = "isCookie"

type parseOptions = {decode: string => string}
@send external parse: (t, option<string>) => {..} = "parse"
@send external parseWithOptions: (t, option<string>, parseOptions) => {..} = "parse"
}

module CreateCookieOptions = {
type t

@obj
external make: (
~decode: string => string=?,
~encode: string => string=?,
~domain: string=?,
~expires: Js.Date.t=?,
~httpOnly: bool=?,
~maxAge: int=?,
~path: string=?,
~sameSite: [#lax | #strict | #none]=?,
~secure: bool=?,
~secrets: array<string>=?,
unit,
) => t = ""
}

@module("remix") external createCookie: string => Cookie.t = "createCookie"
@module("remix")
external createCookieWithOptions: (string, CreateCookieOptions.t) => Cookie.t = "createCookie"

0 comments on commit 2093a30

Please sign in to comment.