123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164openRpc.Typestype_outerfn=|Function:'aIdl.Param.t*'bouterfn->('a->'b)outerfn|NoArgsFunction:'bouterfn->(unit->'b)outerfn|Returning:('aIdl.Param.t*'bIdl.Error.t)->('a,'b)Result.touterfnmoduleMethod=structtype'at={name:string;description:stringlist;ty:'aouterfn;is_notification:bool}letrecfind_inputs:typea.aouterfn->Idl.Param.boxedlist=funm->matchmwith|Function(x,y)->Idl.Param.Boxedx::find_inputsy|NoArgsFunctiony->find_inputsy|Returning_->[]letrecfind_output:typea.aouterfn->Idl.Param.boxed=funm->matchmwith|Returning(x,_y)->Idl.Param.Boxedx|NoArgsFunctiony->find_outputy|Function(_x,y)->find_outputyletrecfind_errors:typea.aouterfn->Rpc.Types.boxed_def=funm->matchmwith|Returning(_x,y)->Rpc.Types.BoxedDefy.Idl.Error.def|NoArgsFunctiony->find_errorsy|Function(_x,y)->find_errorsyendtypeboxed_fn=BoxedFunction:'aMethod.t->boxed_fnmoduleInterface=structincludeIdl.Interfacetypet={details:Idl.Interface.description;methods:boxed_fnlist}letprepend_arg:t->'aIdl.Param.t->t=funinterfaceparam->letprepend:typeb.bouterfn->('a->b)outerfn=funarg->Function(param,arg)in{interfacewithmethods=List.map(fun(BoxedFunctionm)->BoxedFunctionMethod.{name=m.name;description=m.description;ty=prependm.ty;is_notification=m.is_notification})interface.methods}letsetifyl=List.fold_left(funsetx->ifList.memxsetthensetelsex::set)[]l|>List.revletall_types:t->boxed_deflist=funi->letall_inputs=List.map(function|BoxedFunctionf->Method.(find_inputsf.ty))i.methodsinletall_outputs=List.map(function|BoxedFunctionf->Method.(find_outputf.ty))i.methodsinletall=List.concat(all_inputs@[all_outputs])inlettypes=List.map(fun(Idl.Param.Boxedp)->BoxedDefp.Idl.Param.typedef)allinsetifytypesletall_errorsi=i.methods|>List.map(functionBoxedFunctionf->Method.(find_errorsf.ty))|>setifyendmoduleInterfaces=structtypet={name:string;title:string;description:stringlist;type_decls:boxed_deflist;error_decls:boxed_deflist;interfaces:Interface.tlist}letemptynametitledescription={name;title;description;type_decls=[];error_decls=[];interfaces=[]}letadd_interfaceiis=letnot_indefs(BoxedDefdef)=not(List.exists(fun(BoxedDefdef')->def'.name=def.name)defs)inlettypedefs=Interface.all_typesiinletnew_typedefs=List.filter(not_inis.type_decls)typedefsinletnew_errors=List.filter(not_inis.error_decls)(Interface.all_errorsi)in{iswithtype_decls=new_typedefs@is.type_decls;error_decls=new_errors@is.error_decls;interfaces=i::is.interfaces}letcreate~name~title~description~interfaces=leti=emptynametitledescriptioninList.fold_rightadd_interfaceinterfacesiendexceptionInterface_not_describedmoduleGen()=structtype('a,'b)comp=('a,'b)Result.ttype'afn='aouterfntype'ares=unittypeimplementation=unit->Interface.tletmethods=ref[]letimplementi()=letn=i.Interface.nameinifString.capitalize_asciin<>nthenfailwith"Interface names must be capitalized";leti=Interface.{details=i;methods=List.rev!methods}iniletreturningab=Returning(a,b)let(@->)tf=Function(t,f)letnoargsf=NoArgsFunctionfletdeclare_is_notificationnamedescriptionty=letm=BoxedFunctionMethod.{name;description;ty;is_notification}inmethods:=m::!methodsletdeclare:string->stringlist->'afn->'ares=funnamedescriptionty->declare_falsenamedescriptiontyletdeclare_notificationnamedescriptionty=declare_truenamedescriptiontyend