text
stringlengths
0
601k
module type Accepted2 = sig val foo : F ( M ) . t -> int end } ] |
module type Reject1 = sig module M := Funct ( M ) end ; ; [ %% expect { | ^^^^^^^^ } ] |
module type Reject2 = sig module M := F ( N ) end ; ; [ %% expect { | ^^^^ } ] |
module type Reject3 = sig type t := u end ; ; [ %% expect { | ^ } ] |
module type RejectRec = sig type t := [ ` Foo of t | ` Nil ] end ; ; [ %% expect { | ^ } ] |
module type AcceptAnd = sig type t := int and u := int * int end ; ; [ %% expect { |
module type AcceptAnd = sig end } ] |
module type RejectAnd = sig type t := int and u := t * int end ; ; [ %% expect { | ^ } ] |
module Web = struct include Web module Http = Web_http module Request = struct include Opium . Request let bearer_token req = match Opium . Request . header " authorization " req with | Some authorization -> ( try Some ( Scanf . sscanf authorization " Bearer % s " ( fun b -> b ) ) with | _ -> None ) | None -> None ; ; ...
module Database = struct include Database module Migration = Database_migration end
module Contract = struct module Cache = Contract_cache module Database = Contract_database module Email = Contract_email module Email_template = Contract_email_template module Http = Contract_http module Migration = Contract_migration module Password_reset = Contract_password_reset module Queue = Contract_queue module ...
module Test = struct module Session = Session end
let log_src = Logs . Src . create ( " sihl . service . " ^ Sihl . Contract . Email . name )
module Logs = ( val Logs . src_log log_src : Logs . LOG )
let dev_inbox : Sihl . Contract . Email . t list ref = ref [ ]
module DevInbox = struct let inbox ( ) = ! dev_inbox let add_to_inbox email = dev_inbox := List . cons email ! dev_inbox let clear_inbox ( ) = dev_inbox := [ ] end
let print email = let open Sihl . Contract . Email in Logs . info ( fun m -> m { | ----------------------- ----------------------- Text : % s ----------------------- Html : % s ----------------------- } | email . sender email . recipient email . subject email . text ( Option . value ~ default " :< None " > email . html...
let should_intercept ( ) = let is_production = Sihl . Configuration . is_production ( ) in let bypass = Option . value ~ default : false ( Sihl . Configuration . read_bool " EMAIL_BYPASS_INTERCEPT " ) in match is_production , bypass with | false , true -> false | false , false -> true | true , _ -> false ; ;
let intercept sender email = let is_development = Sihl . Configuration . is_development ( ) in let console = Option . value ~ default : is_development ( Sihl . Configuration . read_bool " EMAIL_CONSOLE " ) in let ( ) = if console then print email else ( ) in if should_intercept ( ) then Lwt . return ( DevInbox . add_to...
type smtp_config = { sender : string ; username : string ; password : string ; hostname : string ; port : int option ; start_tls : bool ; ca_path : string option ; ca_cert : string option ; console : bool option }
let smtp_config sender username password hostname port start_tls ca_path ca_cert console = { sender ; username ; password ; hostname ; port ; start_tls ; ca_path ; ca_cert ; console } ; ;
let smtp_schema = let open Conformist in make [ string " SMTP_SENDER " ; string " SMTP_USERNAME " ; string " SMTP_PASSWORD " ; string " SMTP_HOST " ; optional ( int ~ default : 587 " SMTP_PORT " ) ; bool " SMTP_START_TLS " ; optional ( string " SMTP_CA_PATH " ) ; optional ( string " SMTP_CA_CERT " ) ; optional ( bool ~...
module type SmtpConfig = sig val fetch : unit -> smtp_config Lwt . t end
module MakeSmtp ( Config : SmtpConfig ) : Sihl . Contract . Email . Sig = struct include DevInbox let send ' ( email : Sihl . Contract . Email . t ) = let recipients = List . concat [ [ Letters . To email . recipient ] ; List . map ( fun address -> Letters . Cc address ) email . cc ; List . map ( fun address -> Letters...
module EnvSmtpConfig = struct let fetch ( ) = Lwt . return @@ Sihl . Configuration . read smtp_schema end
module Smtp = MakeSmtp ( EnvSmtpConfig )
type sendgrid_config = { api_key : string ; console : bool option }
let sendgrid_config api_key console = { api_key ; console }
let sendgrid_schema = let open Conformist in make [ string " SENDGRID_API_KEY " ; optional ( bool ~ default : false " EMAIL_CONSOLE " ) ] sendgrid_config ; ;
module type SendGridConfig = sig val fetch : unit -> sendgrid_config Lwt . t end
module MakeSendGrid ( Config : SendGridConfig ) : Sihl . Contract . Email . Sig = struct include DevInbox let body ~ recipient ~ subject ~ sender ~ content = Printf . sprintf { | { " personalizations " : [ { " to " : [ { " email " : " % s " } ] , " subject " : " % s " } ] , " from " : { " email " : " % s " } , " conten...
module EnvSendGridConfig = struct let fetch ( ) = Lwt . return ( Sihl . Configuration . read sendgrid_schema ) end
module SendGrid = MakeSendGrid ( EnvSendGridConfig )
module Queued ( QueueService : Sihl . Contract . Queue . Sig ) ( Email : Sihl . Contract . Email . Sig ) : Sihl . Contract . Email . Sig = struct include DevInbox module Job = struct let input_to_string email = email |> Sihl . Contract . Email . to_yojson |> Yojson . Safe . to_string ; ; let string_to_input email = let...
let log_src = Logs . Src . create ( " sihl . service . " ^ Sihl . Contract . Queue . name )
module Logs = ( val Logs . src_log log_src : Logs . LOG )
let create_instance input delay now ( job : ' a job ) = let input = job . encode input in let name = job . name in let next_run_at = match delay with | Some delay -> Option . value ( Ptime . add_span now delay ) ~ default : now | None -> now in let max_tries = job . max_tries in { id = Uuidm . v ` V4 |> Uuidm . to_stri...
let update_next_run_at ( retry_delay : Ptime . Span . t ) ( job_instance : instance ) = let next_run_at = match Ptime . add_span job_instance . next_run_at retry_delay with | Some date -> date | None -> failwith " Can not determine next run date of job " in { job_instance with next_run_at } ; ;
let incr_tries job_instance = { job_instance with tries = job_instance . tries + 1 } ; ;
module Make ( Repo : Repo . Sig ) : Sihl . Contract . Queue . Sig = struct type config = { force_async : bool option } let config force_async = { force_async } let schema = let open Conformist in make [ optional ( bool ~ meta " : If set to true , the queue is used even in development . " ~ default : false " QUEUE_FORCE...
module InMemory = Make ( Repo . InMemory )
module MariaDb = Make ( Repo . MariaDb )
module PostgreSql = Make ( Repo . PostgreSql )
let log_src = Logs . Src . create ( " sihl . service . " ^ Sihl . Contract . Storage . name )
module Logs = ( val Logs . src_log log_src : Logs . LOG )
module Make ( Repo : Repo . Sig ) : Sihl . Contract . Storage . Sig = struct let find_opt = Repo . get_file let find ? ctx id = let % lwt file = Repo . get_file ? ctx id in match file with | None -> raise ( Sihl . Contract . Storage . Exception ( " File not found with id " ^ id ) ) | Some file -> Lwt . return file ; ; ...
module MariaDb : Sihl . Contract . Storage . Sig = Make ( Repo . MakeMariaDb ( Sihl . Database . Migration . MariaDb ) )
let log_src = Logs . Src . create ( " sihl . service . " ^ Sihl . Contract . Token . name )
module Logs = ( val Logs . src_log log_src : Logs . LOG )
module Make ( Repo : Repo . Sig ) : Sihl . Contract . Token . Sig = struct type config = { token_length : int option } let config token_length = { token_length } let schema = let open Conformist in make [ optional ( int ~ default : 80 " TOKEN_LENGTH " ) ] config ; ; let is_valid_token token = let open Repo . Model in S...
module MakeJwt ( Repo : Blacklist_repo . Sig ) : Sihl . Contract . Token . Sig = struct let calculate_exp expires_in = Sihl . Time . date_from_now ( Ptime_clock . now ( ) ) expires_in |> Ptime . to_float_s |> Int . of_float |> string_of_int ; ; let create ? ctx : _ ? secret ( ? expires_in = Sihl . Time . OneWeek ) data...
module MariaDb = Make ( Repo . MariaDb ( Sihl . Database . Migration . MariaDb ) )
module PostgreSql = Make ( Repo . PostgreSql ( Sihl . Database . Migration . PostgreSql ) )
module JwtInMemory = MakeJwt ( Blacklist_repo . InMemory )
module JwtMariaDb = MakeJwt ( Blacklist_repo . MariaDb )
module JwtPostgreSql = MakeJwt ( Blacklist_repo . PostgreSql )
let log_src = Logs . Src . create ( " sihl . service . " ^ Sihl . Contract . User . name )
module Logs = ( val Logs . src_log log_src : Logs . LOG )
module Make ( Repo : User_repo . Sig ) : Sihl . Contract . User . Sig = struct let find_opt = Repo . get let find ? ctx user_id = let % lwt m_user = find_opt ? ctx user_id in match m_user with | Some user -> Lwt . return user | None -> Logs . err ( fun m -> m " User not found with id % s " user_id ) ; raise ( Sihl . Co...
module PostgreSql = Make ( User_repo . MakePostgreSql ( Sihl . Database . Migration . PostgreSql ) )
module MariaDb = Make ( User_repo . MakeMariaDb ( Sihl . Database . Migration . MariaDb ) )
module Password_reset = struct let log_src = Password_reset . log_src module MakePostgreSql ( TokenService : Sihl . Contract . Token . Sig ) = Password_reset . Make ( PostgreSql ) ( TokenService ) module MakeMariaDb ( TokenService : Sihl . Contract . Token . Sig ) = Password_reset . Make ( MariaDb ) ( TokenService ) en...
type port = { name : string ; width : int ; get : unit -> Int32 . t array ; set : Int32 . t array -> unit ; }
module C = struct open Ctypes open PosixTypes open Foreign type port_c let port_t : port_c structure typ = structure " port " let name = field port_t " name " string let width = field port_t " width " int let bits = field port_t " bits " ( ptr int32_t ) let ( ) = seal port_t type sim_c let sim_t : sim_c structure typ =...
let compile_shared_lib name = match Unix . system ( " gcc - shared - fPIC " ^ name " . ^ c - o lib " ^ name " . ^ so " ) with | Unix . WEXITED 0 -> ( ) | _ -> failwith ( " failed to compile " ^ name )
let make_from_shared_lib dll = let module B = Bits . Comb . ArraybitsInt32 in let from = Dl . dlopen ~ filename : dll ~ flags [ : Dl . RTLD_NOW ] in let sim = C . init from ( ) in let reset = C . reset from in let cycle = C . cycle from in let in_ports = C . get_ports sim C . in_ports C . num_in_ports in let out_ports ...
let make ( ? name " = tmp " ) circ = let cname = name ^ " . c " in let lname = " lib " ^ name ^ " . so " in let f = open_out cname in let ( ) = Rtl . C . write ( output_string f ) circ in let ( ) = close_out f in let ( ) = compile_shared_lib name in make_from_shared_lib ( " . " / ^ lname )
module I = interface a [ 6 ] b [ 8 ] end
module O = interface c [ 9 ] d [ 8 ] end
let f i = { O . c = I . ( uresize i . a 9 +: uresize i . b 9 ) ; d = I . ( uresize i . a 8 &: uresize i . b 8 ) ; }
let make ( ) = let circ = G . make " adderizer " f in HardCamlCSim . Sim . make circ
let test ( ) = let sim = make ( ) in let i = I . ( map ( fun ( n , _ ) -> S . in_port sim n ) t ) in let o = O . ( map ( fun ( n , _ ) -> S . out_port sim n ) t ) in begin i . a := consti 6 3 ; i . b := consti 8 6 ; S . cycle sim ; Printf . printf " % i % i \ n " ( to_int ( ! o . c ) ) ( to_int ( ! o . d ) ) end
let ( ) = test ( )
type value = { e : e ; gen : unit ref }
type t = { p : p ; mutable freed : bool ; gen : unit ref }
type ds = { ds : ccds ; gen : unit ref ; buf : Bigstringaf . t option }
let threadsEnabled = lazy ( threadsEnabled ( ) ) = " parseMany_stubs " = " docStreamIteratorCompare_stubs " [ @@ noalloc ] [ @@ noalloc ]
let raise_if_already_freed freed msg = if freed then Printf . ksprintf failwith " % s : parser used after being free " msg
let raise_if_different_gen freed msg = if freed then Printf . ksprintf failwith " % s : parser is outdated " msg
let create ( ) = { p = createParser ( ) ; freed = false ; gen = ref ( ) }
let free { p ; freed ; _ } = if freed then ( ) else freeParser p
let free_ds { ds ; _ } = freeDs ds
let padding = Bigstringaf . create paddingLen
let parse_string ? len { p ; freed ; gen } buf = raise_if_already_freed freed " parse_string " ; gen := ( ) ; let maxLen = String . ( length buf - paddingLen ) in let len = match len with | None -> maxLen | Some l when l > maxLen -> invalid_arg " parse_string : len " | Some l -> l in { e = parseString p buf len ; gen }
let parse_bytes ? len t buf = parse_string ? len t ( Bytes . unsafe_to_string buf )
let parse ? len { p ; freed ; gen } buf = raise_if_already_freed freed " parse " ; gen := ( ) ; let maxLen = Bigstringaf . ( length buf - paddingLen ) in let len = match len with | None -> maxLen | Some l when l > maxLen -> invalid_arg " parse : len " | Some l -> l in { e = parse p buf len ; gen }
let parse_many ? len ( ? batchSize = defaultBatchSize ) { p ; freed ; gen } buf = raise_if_already_freed freed " parse_many " ; gen := ( ) ; let maxLen = Bigstringaf . ( length buf - paddingLen ) in let len = match len with | None -> maxLen | Some l when l > maxLen -> invalid_arg " parse_many : len " | Some l -> l in {...
let load { p ; freed ; gen } fn = raise_if_already_freed freed " load_many " ; gen := ( ) ; { e = load p fn ; gen }
let load_many ( ? batchSize = defaultBatchSize ) { p ; freed ; gen } fn = raise_if_already_freed freed " load_many " ; gen := ( ) ; { ds = loadMany p fn batchSize ; gen ; buf = None }
let seq_of_ds t { ds ; gen ; _ } = raise_if_already_freed t . freed " seq_of_ds " ; raise_if_different_gen ( t . gen != gen ) " seq_of_ds " ; let iter_end = docStreamIteratorEnd ds in let iter = docStreamIteratorBegin ds in let rec loop ( ) = match docStreamIteratorCompare iter iter_end with | false -> Seq . Nil | true...
let view ( { e ; gen } : value ) = match elementType e with | ' [ ' -> let a = getArray e in let len = arraySize a in let iter = arrayIterator a in let rec loop acc len = if len < 0 then List . rev acc else let e = arrayIteratorGet iter in arrayIteratorNext iter ; loop ( { e ; gen } :: acc ) ( pred len ) in ` A ( loop ...
let length ( { e ; _ } : value ) = match elementType e with | ' [ ' -> let a = getArray e in arraySize a | ' { ' -> let o = getObject e in objSize o | _ -> 1
let repr _ = assert false
let repr_uid = Json_repr . repr_uid ( )
let kind { e ; _ } = elementType e
let bool_exn { e ; _ } = getBool e
let int64_exn { e ; _ } = getInt64 e
let uint64_exn { e ; _ } = getUInt64 e
let float_exn { e ; _ } = getDouble e
let string_exn { e ; _ } = getString e