123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(**************************************************************************)(* *)(* Copyright 2018-2023 OCamlPro *)(* *)(* All rights reserved. This file is distributed under the terms of the *)(* GNU Lesser General Public License version 2.1, with the special *)(* exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)moduleIntMap=Map.Make(structtypet=intletcompare=compareend)type_case=Case:{code:int;name:string;encoding:'aJson_encoding.encoding;select:'b->'aoption;deselect:'a->'b;}->'bcaseletmake~code~name~encoding~select~deselect=Case{code;name;encoding;select;deselect}letmerge_errs_same_code?definitions_patherrors=letcode_map=List.fold_left(funacc(Case{code;_}asc)->letencs=matchIntMap.find_optcodeaccwith|Somel->l|None->[]inIntMap.addcode(c::encs)acc)IntMap.emptyerrorsinIntMap.map(funl->letencoding=matchlwith|[Case{encoding;select;deselect;_}]->Json_encoding.conv(funx->matchselectxwith|None->assertfalse|Somex->x)deselectencoding|_->leterr_cases=List.map(functionCase{encoding;select;deselect;_}->Json_encoding.caseencodingselectdeselect)linJson_encoding.unionerr_casesinlazy(Json_encoding.schema?definitions_pathencoding))code_map|>IntMap.bindingsletcatch_all_error_case()=Case{code=500;name="AnyError";encoding=(letopenJson_encodinginconv(funx->lets=Marshal.to_stringx[Marshal.No_sharing]|>Digest.string|>Digest.to_hexinFormat.eprintf"No corresponding error case (MD5 %s)@."s;((),s))(fun((),_)->failwith"Cannot parse from undeclared error")(obj2(req"error"(constant"Server Error"))(req"digest"string)));select=(funx->Somex);deselect=(funx->x);}letget~codel=matchList.find_all(functionCase{code=c;_}->c=code)lwith|[]->None|[Case{encoding=enc;select;deselect;_}]->Some(Json_encoding.conv(funx->matchselectxwith|None->assertfalse|Somex->x)deselectenc)|l->letcases=List.map(functionCase{encoding=enc;select;deselect;_}->Json_encoding.caseencselectdeselect)linSome(Json_encoding.unioncases)