123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145moduleModel=React.Modeltypet=React.elementModel.ttypeof_rsc_error=Rsc_errorofstring|Unexpected_variantofstringexceptionOf_rsc_errorofof_rsc_errorletof_rsc_error_to_string=functionRsc_errormsg->msg|Unexpected_variantmsg->"unexpected variant: "^msgletdescribe_model:t->string=function|Model.Json`Null->"null"|Model.Json(`Bool_)->"bool"|Model.Json(`Int_)->"int"|Model.Json(`Float_)->"float"|Model.Json(`String_)->"string"|Model.Json(`Assoc_)->"json object"|Model.Json(`List_)->"json array"|Model.Element_->"React.element"|Model.Promise_->"Promise"|Model.Function_->"server function"|Model.Assoc_->"object"|Model.List_->"array"|Model.Error_->"error"letof_rsc_msg_errormsg=raise(Of_rsc_error(Rsc_errormsg))letof_rsc_msg_unexpected_variantmsg=raise(Of_rsc_error(Unexpected_variantmsg))letof_rsc_error?depth:_?width:_~rscmsg=of_rsc_msg_error(msg^"; received "^describe_modelrsc)letof_rsc_unexpected_variant?depth:_?width:_~rscmsg=of_rsc_msg_unexpected_variant(msg^"; received "^describe_modelrsc)letof_modelmodel=modelletto_modelmodel=modelletmap_json_listdecodevalues=List.map(funvalue->decode(of_model(Model.Jsonvalue)))valuesmodulePrimitives=structletlist_values_to_rscvalues=of_model(Model.List(List.mapto_modelvalues))letassoc_to_rscvalues=of_model(Model.Assoc(List.map(fun(key,value)->(key,to_modelvalue))values))letstring_to_rscvalue=of_model(Model.Json(`Stringvalue))letbool_to_rscvalue=of_model(Model.Json(`Boolvalue))letfloat_to_rscvalue=of_model(Model.Json(`Floatvalue))letint_to_rscvalue=of_model(Model.Json(`Intvalue))letint64_to_rscvalue=of_model(Model.Json(`String(Int64.to_stringvalue)))letchar_to_rscvalue=string_to_rsc(String.make1value)letunit_to_rsc()=of_model(Model.Json`Null)letoption_to_rscto_rsc=functionNone->unit_to_rsc()|Somevalue->to_rscvalueletresult_to_rscok_to_rscerror_to_rsc=function|Okvalue->list_values_to_rsc[string_to_rsc"Ok";ok_to_rscvalue]|Errorvalue->list_values_to_rsc[string_to_rsc"Error";error_to_rscvalue]letlist_to_rscto_rscvalues=list_values_to_rsc(List.mapto_rscvalues)letarray_to_rscto_rscvalues=values|>Array.to_list|>List.mapto_rsc|>list_values_to_rsclettuple2_to_rsca_to_rscb_to_rsc(a,b)=list_values_to_rsc[a_to_rsca;b_to_rscb]lettuple3_to_rsca_to_rscb_to_rscc_to_rsc(a,b,c)=list_values_to_rsc[a_to_rsca;b_to_rscb;c_to_rscc]lettuple4_to_rsca_to_rscb_to_rscc_to_rscd_to_rsc(a,b,c,d)=list_values_to_rsc[a_to_rsca;b_to_rscb;c_to_rscc;d_to_rscd]letreact_element_to_rscelement=of_model(Model.Elementelement)letpromise_to_rscto_rscpromise=of_model(Model.Promise(promise,funvalue->to_model(to_rscvalue)))letserver_function_to_rscaction=of_model(Model.Functionaction)letstring_of_rscrsc=matchto_modelrscwithModel.Json(`Stringvalue)->value|model->of_rsc_error~rsc:model"expected a string"letbool_of_rscrsc=matchto_modelrscwithModel.Json(`Boolvalue)->value|model->of_rsc_error~rsc:model"expected a bool"letint_of_rscrsc=matchto_modelrscwithModel.Json(`Intvalue)->value|model->of_rsc_error~rsc:model"expected an int"letint64_of_rscrsc=matchto_modelrscwith|Model.Json(`Stringvalue)->(matchInt64.of_string_optvaluewith|Somevalue->value|None->of_rsc_error~rsc:(to_modelrsc)"expected int64 as string")|model->of_rsc_error~rsc:model"expected int64 as string"letfloat_of_rscrsc=matchto_modelrscwith|Model.Json(`Floatvalue)->value|Model.Json(`Intvalue)->float_of_intvalue|model->of_rsc_error~rsc:model"expected a float"letchar_of_rscrsc=letvalue=string_of_rscrscinifString.lengthvalue=1thenString.getvalue0elseof_rsc_error~rsc:(to_modelrsc)"expected a single-character string"letunit_of_rscrsc=matchto_modelrscwithModel.Json`Null->()|model->of_rsc_error~rsc:model"expected null"letoption_of_rscof_rscrsc=matchto_modelrscwithModel.Json`Null->None|_->Some(of_rscrsc)letlist_of_rscof_rscrsc=matchto_modelrscwith|Model.Listvalues->List.mapof_rsc(List.mapof_modelvalues)|Model.Json(`Listvalues)->map_json_listof_rscvalues|model->of_rsc_error~rsc:model"expected an array"letarray_of_rscof_rscrsc=list_of_rscof_rscrsc|>Array.of_listlettuple2_of_rsca_of_rscb_of_rscrsc=matchlist_of_rsc(funvalue->value)rscwith|[a;b]->(a_of_rsca,b_of_rscb)|_->of_rsc_error~rsc:(to_modelrsc)"expected a tuple of length 2"lettuple3_of_rsca_of_rscb_of_rscc_of_rscrsc=matchlist_of_rsc(funvalue->value)rscwith|[a;b;c]->(a_of_rsca,b_of_rscb,c_of_rscc)|_->of_rsc_error~rsc:(to_modelrsc)"expected a tuple of length 3"lettuple4_of_rsca_of_rscb_of_rscc_of_rscd_of_rscrsc=matchlist_of_rsc(funvalue->value)rscwith|[a;b;c;d]->(a_of_rsca,b_of_rscb,c_of_rscc,d_of_rscd)|_->of_rsc_error~rsc:(to_modelrsc)"expected a tuple of length 4"letresult_of_rscok_of_rscerror_of_rscrsc=matchlist_of_rsc(funvalue->value)rscwith|[tag;value]->lettag=string_of_rsctaginiftag="Ok"thenOk(ok_of_rscvalue)elseiftag="Error"thenError(error_of_rscvalue)elseof_rsc_unexpected_variant~rsc:(to_modelrsc){|expected ["Ok"; _] or ["Error"; _]|}|_->of_rsc_error~rsc:(to_modelrsc){|expected ["Ok"; _] or ["Error"; _]|}letreact_element_of_rscrsc=matchto_modelrscwith|Model.Elementelement->element|model->of_rsc_error~rsc:model"expected a React.element"letpromise_of_rscof_rscrsc=matchto_modelrscwith|Model.Promise(promise,to_rsc)->Js.Promise.then_(funvalue->Js.Promise.resolve(of_rsc(of_model(to_rscvalue))))promise|model->of_rsc_error~rsc:model"expected a promise"letserver_function_of_rscrsc=matchto_modelrscwith|Model.Function_->of_rsc_msg_error"decoding Runtime.server_function from native RSC values is only supported on the client"|model->of_rsc_error~rsc:model"expected a server function"end