智慧水务管理系统 - 精河县供水工程综合管理平台

protobuf.js 268KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631
  1. /*!
  2. * protobuf.js v8.6.3 (c) 2016, daniel wirtz
  3. * compiled thu, 11 jun 2026 00:02:30 utc
  4. * licensed under the bsd-3-clause license
  5. * see: https://github.com/dcodeio/protobuf.js for details
  6. */
  7. (function(undefined){"use strict";(function prelude(modules, cache, entries) {
  8. // This is the prelude used to bundle protobuf.js for the browser. Wraps up the CommonJS
  9. // sources through a conflict-free require shim and is again wrapped within an iife that
  10. // provides a minification-friendly `undefined` var plus a global "use strict" directive
  11. // so that minification can remove the directives of each module.
  12. function $require(name) {
  13. var $module = cache[name];
  14. if (!$module)
  15. modules[name][0].call($module = cache[name] = { exports: {} }, $require, $module, $module.exports);
  16. return $module.exports;
  17. }
  18. var protobuf = $require(entries[0]);
  19. // Expose globally
  20. protobuf.util.global.protobuf = protobuf;
  21. // Be nice to AMD
  22. if (typeof define === "function" && define.amd)
  23. define(["long"], function(Long) {
  24. if (Long && Long.isLong) {
  25. protobuf.util.Long = Long;
  26. protobuf.configure();
  27. }
  28. return protobuf;
  29. });
  30. // Be nice to CommonJS
  31. if (typeof module === "object" && module && module.exports)
  32. module.exports = protobuf;
  33. })/* end of prelude */({1:[function(require,module,exports){
  34. },{}],2:[function(require,module,exports){
  35. "use strict";
  36. /**
  37. * Runtime message from/to plain object converters.
  38. * @namespace
  39. */
  40. var converter = exports;
  41. var Enum = require(5),
  42. types = require(23),
  43. util = require(24);
  44. /**
  45. * Generates a partial value fromObject conveter.
  46. * @param {Codegen} gen Codegen instance
  47. * @param {Field} field Reflected field
  48. * @param {number} fieldIndex Field index
  49. * @param {string} prop Property reference
  50. * @returns {Codegen} Codegen instance
  51. * @ignore
  52. */
  53. function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
  54. var defaultAlreadyEmitted = false;
  55. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  56. if (field.resolvedType) {
  57. if (field.resolvedType instanceof Enum) { gen
  58. ("switch(d%s){", prop);
  59. for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
  60. // enum unknown values passthrough
  61. if (values[keys[i]] === field.typeDefault && !defaultAlreadyEmitted) { gen
  62. ("default:")
  63. ("if(typeof d%s===\"number\"){m%s=d%s;break}", prop, prop, prop);
  64. if (!field.repeated) gen // fallback to default value only for
  65. // arrays, to avoid leaving holes.
  66. ("break"); // for non-repeated fields, just ignore
  67. defaultAlreadyEmitted = true;
  68. }
  69. gen
  70. ("case%j:", keys[i])
  71. ("case %i:", values[keys[i]])
  72. ("m%s=%j", prop, values[keys[i]])
  73. ("break");
  74. } gen
  75. ("}");
  76. } else gen
  77. ("if(!util.isObject(d%s))", prop)
  78. ("throw TypeError(%j)", field.fullName + ": object expected")
  79. ("m%s=types[%i].fromObject(d%s,q+1)", prop, fieldIndex, prop);
  80. } else {
  81. var isUnsigned = false;
  82. switch (field.type) {
  83. case "double":
  84. case "float": gen
  85. ("m%s=Number(d%s)", prop, prop); // also catches "NaN", "Infinity"
  86. break;
  87. case "uint32":
  88. case "fixed32": gen
  89. ("m%s=d%s>>>0", prop, prop);
  90. break;
  91. case "int32":
  92. case "sint32":
  93. case "sfixed32": gen
  94. ("m%s=d%s|0", prop, prop);
  95. break;
  96. case "uint64":
  97. case "fixed64":
  98. isUnsigned = true;
  99. // eslint-disable-next-line no-fallthrough
  100. case "int64":
  101. case "sint64":
  102. case "sfixed64": gen
  103. ("if(util.Long)")
  104. ("m%s=util.Long.fromValue(d%s,%j)", prop, prop, isUnsigned)
  105. ("else if(typeof d%s===\"string\")", prop)
  106. ("m%s=parseInt(d%s,10)", prop, prop)
  107. ("else if(typeof d%s===\"number\")", prop)
  108. ("m%s=d%s", prop, prop)
  109. ("else if(typeof d%s===\"object\")", prop)
  110. ("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)", prop, prop, prop, isUnsigned ? "true" : "");
  111. break;
  112. case "bytes": gen
  113. ("if(typeof d%s===\"string\")", prop)
  114. ("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop)
  115. ("else if(d%s.length>=0)", prop)
  116. ("m%s=d%s", prop, prop);
  117. break;
  118. case "string": gen
  119. ("m%s=String(d%s)", prop, prop);
  120. break;
  121. case "bool": gen
  122. ("m%s=Boolean(d%s)", prop, prop);
  123. break;
  124. /* default: gen
  125. ("m%s=d%s", prop, prop);
  126. break; */
  127. }
  128. }
  129. return gen;
  130. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  131. }
  132. /**
  133. * Generates a plain object to runtime message converter specific to the specified message type.
  134. * @param {Type} mtype Message type
  135. * @returns {Codegen} Codegen instance
  136. */
  137. converter.fromObject = function fromObject(mtype) {
  138. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  139. var fields = mtype.fieldsArray;
  140. var gen = util.codegen(["d", "q"])
  141. ("if(d instanceof C)")
  142. ("return d")
  143. ("if(!util.isObject(d))")
  144. ("throw TypeError(%j)", mtype.fullName + ": object expected")
  145. ("if(q===undefined)q=0")
  146. ("if(q>util.recursionLimit)")
  147. ("throw Error(\"max depth exceeded\")");
  148. if (!fields.length) return gen
  149. ("return new C");
  150. gen
  151. ("var m=new C");
  152. for (var i = 0; i < fields.length; ++i) {
  153. var field = fields[i].resolve(),
  154. prop = util.safeProp(field.name),
  155. implicitPresence = !field.hasPresence && !field.repeated && !field.map
  156. && (field.resolvedType instanceof Enum || types.basic[field.type] !== undefined);
  157. // Map fields
  158. if (field.map) { gen
  159. ("if(d%s){", prop)
  160. ("if(!util.isObject(d%s))", prop)
  161. ("throw TypeError(%j)", field.fullName + ": object expected")
  162. ("m%s={}", prop)
  163. ("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
  164. gen
  165. ("if(ks[i]===\"__proto__\")")
  166. ("util.makeProp(m%s,ks[i])", prop);
  167. genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[ks[i]]")
  168. ("}")
  169. ("}");
  170. // Repeated fields
  171. } else if (field.repeated) { gen
  172. ("if(d%s){", prop)
  173. ("if(!Array.isArray(d%s))", prop)
  174. ("throw TypeError(%j)", field.fullName + ": array expected")
  175. ("m%s=Array(d%s.length)", prop, prop)
  176. ("for(var i=0;i<d%s.length;++i){", prop);
  177. genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]")
  178. ("}")
  179. ("}");
  180. // Non-repeated fields
  181. } else {
  182. if (!(field.resolvedType instanceof Enum)) gen // no need to test for null/undefined if an enum (uses switch)
  183. ("if(d%s!=null){", prop); // !== undefined && !== null
  184. if (implicitPresence) {
  185. if (field.resolvedType instanceof Enum) gen
  186. ("if(d%s!==%j&&(typeof d%s!==\"string\"||types[%i].values[d%s]!==%j)){", prop, field.typeDefault, prop, i, prop, field.typeDefault);
  187. else if (field.type === "string") gen
  188. ("if(typeof d%s!==\"string\"||d%s.length){", prop, prop);
  189. else if (field.type === "bytes") gen
  190. ("if(d%s.length){", prop);
  191. else if (field.type === "bool") gen
  192. ("if(d%s){", prop);
  193. else if (types.long[field.type] !== undefined) gen
  194. ("if(typeof d%s===\"object\"?d%s.low||d%s.high:Number(d%s)!==0){", prop, prop, prop, prop);
  195. else gen
  196. ("if(Number(d%s)!==0){", prop);
  197. }
  198. genValuePartial_fromObject(gen, field, /* not sorted */ i, prop);
  199. if (implicitPresence) gen
  200. ("}");
  201. if (!(field.resolvedType instanceof Enum)) gen
  202. ("}");
  203. }
  204. } return gen
  205. ("return m");
  206. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  207. };
  208. /**
  209. * Generates a partial value toObject converter.
  210. * @param {Codegen} gen Codegen instance
  211. * @param {Field} field Reflected field
  212. * @param {number} fieldIndex Field index
  213. * @param {string} dstProp Destination property reference
  214. * @param {string} [srcProp] Source property reference
  215. * @returns {Codegen} Codegen instance
  216. * @ignore
  217. */
  218. function genValuePartial_toObject(gen, field, fieldIndex, dstProp, srcProp) {
  219. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  220. if (!srcProp)
  221. srcProp = dstProp;
  222. if (field.resolvedType) {
  223. if (field.resolvedType instanceof Enum) gen
  224. ("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", dstProp, fieldIndex, srcProp, srcProp, fieldIndex, srcProp, srcProp);
  225. else gen
  226. ("d%s=types[%i].toObject(m%s,o,q+1)", dstProp, fieldIndex, srcProp);
  227. } else {
  228. var isUnsigned = false;
  229. switch (field.type) {
  230. case "double":
  231. case "float": gen
  232. ("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s", dstProp, srcProp, srcProp, srcProp);
  233. break;
  234. case "uint64":
  235. case "fixed64":
  236. isUnsigned = true;
  237. // eslint-disable-next-line no-fallthrough
  238. case "int64":
  239. case "sint64":
  240. case "sfixed64": gen
  241. ("if(typeof BigInt!==\"undefined\"&&o.longs===BigInt)")
  242. ("d%s=typeof m%s===\"number\"?BigInt(m%s):util.Long.fromBits(m%s.low>>>0,m%s.high>>>0,%j).toBigInt()", dstProp, srcProp, srcProp, srcProp, srcProp, isUnsigned)
  243. ("else if(typeof m%s===\"number\")", srcProp)
  244. ("d%s=o.longs===String?String(m%s):m%s", dstProp, srcProp, srcProp)
  245. ("else") // Long-like
  246. ("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s", dstProp, srcProp, srcProp, srcProp, isUnsigned ? "true": "", srcProp);
  247. break;
  248. case "bytes": gen
  249. ("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s", dstProp, srcProp, srcProp, srcProp, srcProp);
  250. break;
  251. default: gen
  252. ("d%s=m%s", dstProp, srcProp);
  253. break;
  254. }
  255. }
  256. return gen;
  257. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  258. }
  259. /**
  260. * Generates a runtime message to plain object converter specific to the specified message type.
  261. * @param {Type} mtype Message type
  262. * @returns {Codegen} Codegen instance
  263. */
  264. converter.toObject = function toObject(mtype) {
  265. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  266. var fields = mtype.fieldsArray.slice().sort(util.compareFieldsById);
  267. if (!fields.length)
  268. return util.codegen()("return {}");
  269. var gen = util.codegen(["m", "o", "q"])
  270. ("if(!o)")
  271. ("o={}")
  272. ("if(q===undefined)q=0")
  273. ("if(q>util.recursionLimit)")
  274. ("throw Error(\"max depth exceeded\")")
  275. ("var d={}");
  276. var repeatedFields = [],
  277. mapFields = [],
  278. normalFields = [],
  279. i = 0;
  280. for (; i < fields.length; ++i)
  281. if (!fields[i].partOf)
  282. ( fields[i].resolve().repeated ? repeatedFields
  283. : fields[i].map ? mapFields
  284. : normalFields).push(fields[i]);
  285. if (repeatedFields.length) { gen
  286. ("if(o.arrays||o.defaults){");
  287. for (i = 0; i < repeatedFields.length; ++i) gen
  288. ("d%s=[]", util.safeProp(repeatedFields[i].name));
  289. gen
  290. ("}");
  291. }
  292. if (mapFields.length) { gen
  293. ("if(o.objects||o.defaults){");
  294. for (i = 0; i < mapFields.length; ++i) gen
  295. ("d%s={}", util.safeProp(mapFields[i].name));
  296. gen
  297. ("}");
  298. }
  299. if (normalFields.length) { gen
  300. ("if(o.defaults){");
  301. for (i = 0; i < normalFields.length; ++i) {
  302. var field = normalFields[i],
  303. prop = util.safeProp(field.name);
  304. if (field.resolvedType instanceof Enum) gen
  305. ("d%s=o.enums===String?%j:%j", prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
  306. else if (field.long) gen
  307. ("if(util.Long){")
  308. ("var n=new util.Long(%i,%i,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)
  309. ("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():typeof BigInt!==\"undefined\"&&o.longs===BigInt?n.toBigInt():n", prop)
  310. ("}else")
  311. ("d%s=o.longs===String?%j:typeof BigInt!==\"undefined\"&&o.longs===BigInt?BigInt(%j):%i", prop, field.typeDefault.toString(), field.typeDefault.toString(), field.typeDefault.toNumber());
  312. else if (field.bytes) {
  313. var arrayDefault = Array.prototype.slice.call(field.typeDefault);
  314. gen
  315. ("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
  316. ("else{")
  317. ("d%s=%j", prop, arrayDefault)
  318. ("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
  319. ("}");
  320. } else gen
  321. ("d%s=%j", prop, field.typeDefault); // also messages (=null)
  322. } gen
  323. ("}");
  324. }
  325. var hasKs2 = false;
  326. for (i = 0; i < fields.length; ++i) {
  327. var field = fields[i],
  328. index = mtype._fieldsArray.indexOf(field),
  329. prop = util.safeProp(field.name);
  330. if (field.map) {
  331. if (!hasKs2) { hasKs2 = true; gen
  332. ("var ks2");
  333. } gen
  334. ("if(m%s&&(ks2=Object.keys(m%s)).length){", prop, prop)
  335. ("d%s={}", prop);
  336. var longKey = types.long[field.keyType] !== undefined,
  337. srcProp = prop + "[ks2[j]]";
  338. gen
  339. ("for(var j=0;j<ks2.length;++j){");
  340. if (longKey) gen
  341. ("var k2=util.longFromKey(ks2[j],%j).toString()", field.keyType === "uint64" || field.keyType === "fixed64");
  342. gen
  343. ("if(ks2[j]===\"__proto__\")")
  344. ("util.makeProp(d%s,ks2[j])", prop);
  345. genValuePartial_toObject(gen, field, /* sorted */ index, longKey ? prop + "[k2]" : srcProp, srcProp)
  346. ("}");
  347. } else if (field.repeated) { gen
  348. ("if(m%s&&m%s.length){", prop, prop)
  349. ("d%s=Array(m%s.length)", prop, prop)
  350. ("for(var j=0;j<m%s.length;++j){", prop);
  351. genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")
  352. ("}");
  353. } else { gen
  354. ("if(m%s!=null&&Object.hasOwnProperty.call(m,%j)){", prop, field.name); // !== undefined && !== null
  355. genValuePartial_toObject(gen, field, /* sorted */ index, prop);
  356. if (field.partOf && !field.partOf.isProto3Optional) gen
  357. ("if(o.oneofs)")
  358. ("d%s=%j", util.safeProp(field.partOf.name), field.name);
  359. }
  360. gen
  361. ("}");
  362. }
  363. return gen
  364. ("return d");
  365. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  366. };
  367. },{"23":23,"24":24,"5":5}],3:[function(require,module,exports){
  368. "use strict";
  369. module.exports = decoder;
  370. var Enum = require(5),
  371. types = require(23),
  372. util = require(24);
  373. function missing(field) {
  374. return "missing required '" + field.name + "'";
  375. }
  376. function stringMethod(field) {
  377. return field._features.utf8_validation === "VERIFY" ? "stringVerify" : "string";
  378. }
  379. /**
  380. * Generates a decoder specific to the specified message type.
  381. * @param {Type} mtype Message type
  382. * @returns {Codegen} Codegen instance
  383. */
  384. function decoder(mtype) {
  385. /* eslint-disable no-unexpected-multiline */
  386. var hasMapField = false,
  387. hasImplicitPresenceField = false,
  388. i = 0;
  389. for (; i < mtype.fieldsArray.length; ++i) {
  390. var pfield = mtype._fieldsArray[i];
  391. if (pfield.map)
  392. hasMapField = true;
  393. if (!pfield.repeated && !pfield.map && !pfield.hasPresence)
  394. hasImplicitPresenceField = true;
  395. }
  396. var gen = util.codegen(["r", "l", "z", "q", "g"])
  397. ("if(!(r instanceof Reader))")
  398. ("r=Reader.create(r)")
  399. ("if(q===undefined)q=0")
  400. ("if(q>Reader.recursionLimit)")
  401. ("throw Error(\"max depth exceeded\")")
  402. ("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : hasImplicitPresenceField ? ",v" : ""))
  403. ("while(r.pos<c){")
  404. ("var s=r.pos")
  405. ("var t=r.tag()")
  406. ("if(t===z){")
  407. ("z=undefined")
  408. ("break")
  409. ("}");
  410. if (mtype.fieldsArray.length) gen
  411. ("var u=t&7")
  412. ("switch(t>>>=3){");
  413. for (i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {
  414. var field = mtype._fieldsArray[i].resolve(),
  415. type = field.resolvedType instanceof Enum ? "int32" : field.type,
  416. ref = "m" + util.safeProp(field.name);
  417. // Map fields
  418. if (field.map) {
  419. gen
  420. ("case %i:{", field.id)
  421. ("if(u!==2)")
  422. ("break")
  423. ("if(%s===util.emptyObject)", ref)
  424. ("%s={}", ref)
  425. ("var c2=r.uint32()+r.pos");
  426. if (types.defaults[field.keyType] !== undefined) gen
  427. ("k=%j", types.defaults[field.keyType]);
  428. else gen
  429. ("k=null");
  430. if (types.long[type] !== undefined) gen
  431. ("v=util.Long?util.Long.fromNumber(0,%j):0", type === "uint64" || type === "fixed64");
  432. else if (types.defaults[type] !== undefined) gen
  433. ("v=%j", types.defaults[type]);
  434. else gen
  435. ("v=null");
  436. gen
  437. ("while(r.pos<c2){")
  438. ("var t2=r.tag()")
  439. ("u=t2&7")
  440. ("switch(t2>>>=3){")
  441. ("case 1:")
  442. ("if(u!==%i)", types.mapKey[field.keyType])
  443. ("break")
  444. ("k=r.%s()", field.keyType === "string" ? stringMethod(field) : field.keyType)
  445. ("continue")
  446. ("case 2:")
  447. ("if(u!==%i)", types.basic[type] === undefined ? 2 : types.basic[type])
  448. ("break");
  449. if (types.basic[type] === undefined) gen
  450. ("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
  451. else gen
  452. ("v=r.%s()", type === "string" ? stringMethod(field) : type);
  453. gen
  454. ("continue")
  455. ("}")
  456. ("r.skipType(u,q,t2)")
  457. ("}");
  458. var val = types.basic[type] === undefined ? "v||new types[" + i + "].ctor" : "v";
  459. if (types.long[field.keyType] !== undefined) gen
  460. ("%s[typeof k===\"object\"?util.longToHash(k):k]=%s", ref, val);
  461. else {
  462. if (field.keyType === "string") gen
  463. ("if(k===\"__proto__\")")
  464. ("util.makeProp(%s,k)", ref);
  465. gen
  466. ("%s[k]=%s", ref, val);
  467. }
  468. // Repeated fields
  469. } else if (field.repeated) { gen
  470. ("case %i:", field.id)
  471. ("{");
  472. // Packable (always check for forward and backward compatiblity)
  473. if (types.packed[type] !== undefined) gen
  474. ("if(u===2){")
  475. ("if(!(%s&&%s.length))", ref, ref)
  476. ("%s=[]", ref)
  477. ("var c2=r.uint32()+r.pos")
  478. ("while(r.pos<c2)")
  479. ("%s.push(r.%s())", ref, type)
  480. ("continue")
  481. ("}");
  482. // Non-packed
  483. gen
  484. ("if(u!==%i)", types.basic[type] === undefined ? field.delimited ? 3 : 2 : types.basic[type])
  485. ("break")
  486. ("if(!(%s&&%s.length))", ref, ref)
  487. ("%s=[]", ref);
  488. if (types.basic[type] === undefined) {
  489. if (field.delimited) gen
  490. ("%s.push(types[%i].decode(r,undefined,%i,q+1))", ref, i, field.id * 8 + 4);
  491. else gen
  492. ("%s.push(types[%i].decode(r,r.uint32(),undefined,q+1))", ref, i);
  493. } else gen
  494. ("%s.push(r.%s())", ref, type === "string" ? stringMethod(field) : type);
  495. // Non-repeated
  496. } else if (types.basic[type] === undefined) {
  497. gen
  498. ("case %i:{", field.id)
  499. ("if(u!==%i)", field.delimited ? 3 : 2)
  500. ("break");
  501. if (field.delimited) gen
  502. ("%s=types[%i].decode(r,undefined,%i,q+1,%s)", ref, i, field.id * 8 + 4, ref);
  503. else gen
  504. ("%s=types[%i].decode(r,r.uint32(),undefined,q+1,%s)", ref, i, ref);
  505. }
  506. else if (field.hasPresence) {
  507. gen
  508. ("case %i:{", field.id)
  509. ("if(u!==%i)", types.basic[type])
  510. ("break")
  511. ("%s=r.%s()", ref, type === "string" ? stringMethod(field) : type);
  512. } else {
  513. gen
  514. ("case %i:{", field.id)
  515. ("if(u!==%i)", types.basic[type])
  516. ("break");
  517. if (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
  518. // TODO: Protoc rejects open enums whose first value is not zero.
  519. // We should do the same, but for v8 this would be a regression.
  520. ("if((v=r.%s())!==%j)", type, field.typeDefault);
  521. else if (type === "string") gen
  522. ("if((v=r.%s()).length)", stringMethod(field));
  523. else if (type === "bytes") gen
  524. ("if((v=r.%s()).length)", type);
  525. else if (types.long[type] !== undefined) gen
  526. ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
  527. else if (type === "double" || type === "float") gen
  528. ("if((v=r.%s())!==0)", type);
  529. else gen
  530. ("if(v=r.%s())", type);
  531. gen
  532. ("%s=v", ref)
  533. ("else")
  534. ("delete %s", ref); // rare/odd case: later default clears earlier non-default
  535. }
  536. if (field.partOf) gen
  537. ("m%s=%j", util.safeProp(field.partOf.name), field.name);
  538. gen
  539. ("continue")
  540. ("}");
  541. }
  542. if (i) gen
  543. ("}");
  544. // Unknown fields
  545. gen
  546. ("r.skipType(%s,q,t)", i ? "u" : "t&7")
  547. ("if(!r.discardUnknown){")
  548. ("util.makeProp(m,\"$unknowns\",false);")
  549. ("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
  550. ("}")
  551. ("}")
  552. ("if(z!==undefined)")
  553. ("throw Error(\"missing end group\")");
  554. // Field presence
  555. for (i = 0; i < mtype._fieldsArray.length; ++i) {
  556. var rfield = mtype._fieldsArray[i];
  557. if (rfield.required) gen
  558. ("if(!Object.hasOwnProperty.call(m,%j))", rfield.name)
  559. ("throw util.ProtocolError(%j,{instance:m})", missing(rfield));
  560. }
  561. return gen
  562. ("return m");
  563. /* eslint-enable no-unexpected-multiline */
  564. }
  565. },{"23":23,"24":24,"5":5}],4:[function(require,module,exports){
  566. "use strict";
  567. module.exports = encoder;
  568. var Enum = require(5),
  569. types = require(23),
  570. util = require(24);
  571. /**
  572. * Generates a partial message type encoder.
  573. * @param {Codegen} gen Codegen instance
  574. * @param {Field} field Reflected field
  575. * @param {number} fieldIndex Field index
  576. * @param {string} ref Variable reference
  577. * @returns {Codegen} Codegen instance
  578. * @ignore
  579. */
  580. function genTypePartial(gen, field, fieldIndex, ref) {
  581. return field.delimited
  582. ? gen("types[%i].encode(%s,w.uint32(%i),q+1).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)
  583. : gen("types[%i].encode(%s,w.uint32(%i).fork(),q+1).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
  584. }
  585. /**
  586. * Generates an encoder specific to the specified message type.
  587. * @param {Type} mtype Message type
  588. * @returns {Codegen} Codegen instance
  589. */
  590. function encoder(mtype) {
  591. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  592. var gen = util.codegen(["m", "w", "q"])
  593. ("if(!w)")
  594. ("w=Writer.create()")
  595. ("if(q===undefined)q=0")
  596. ("if(q>util.recursionLimit)")
  597. ("throw Error(\"max depth exceeded\")");
  598. var i, ref;
  599. // "when a message is serialized its known fields should be written sequentially by field number"
  600. var fields = /* initializes */ mtype.fieldsArray.slice().sort(util.compareFieldsById);
  601. for (var i = 0; i < fields.length; ++i) {
  602. var field = fields[i].resolve(),
  603. index = mtype._fieldsArray.indexOf(field),
  604. type = field.resolvedType instanceof Enum ? "int32" : field.type,
  605. wireType = types.basic[type];
  606. ref = "m" + util.safeProp(field.name);
  607. // Map fields
  608. if (field.map) {
  609. gen
  610. ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name) // !== undefined && !== null
  611. ("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref);
  612. if (field.keyType === "bool") gen
  613. ("w.uint32(%i).fork().uint32(%i).bool(util.boolFromKey(ks[i]))", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType]);
  614. else if (types.long[field.keyType] !== undefined) gen
  615. ("w.uint32(%i).fork().uint32(%i).%s(util.longFromKey(ks[i],%j))", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType, field.keyType === "uint64" || field.keyType === "fixed64");
  616. else gen
  617. ("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);
  618. if (wireType === undefined) gen
  619. ("types[%i].encode(%s[ks[i]],w.uint32(18).fork(),q+1).ldelim().ldelim()", index, ref); // can't be groups
  620. else gen
  621. (".uint32(%i).%s(%s[ks[i]]).ldelim()", 16 | wireType, type, ref);
  622. gen
  623. ("}")
  624. ("}");
  625. // Repeated fields
  626. } else if (field.repeated) { gen
  627. ("if(%s!=null&&%s.length){", ref, ref); // !== undefined && !== null
  628. // Packed repeated
  629. if (field.packed && types.packed[type] !== undefined) { gen
  630. ("w.uint32(%i).fork()", (field.id << 3 | 2) >>> 0)
  631. ("for(var i=0;i<%s.length;++i)", ref)
  632. ("w.%s(%s[i])", type, ref)
  633. ("w.ldelim()");
  634. // Non-packed
  635. } else { gen
  636. ("for(var i=0;i<%s.length;++i)", ref);
  637. if (wireType === undefined)
  638. genTypePartial(gen, field, index, ref + "[i]");
  639. else gen
  640. ("w.uint32(%i).%s(%s[i])", (field.id << 3 | wireType) >>> 0, type, ref);
  641. } gen
  642. ("}");
  643. // Non-repeated
  644. } else {
  645. if (!field.required) gen
  646. ("if(%s!=null&&Object.hasOwnProperty.call(m,%j))", ref, field.name); // !== undefined && !== null
  647. if (wireType === undefined)
  648. genTypePartial(gen, field, index, ref);
  649. else gen
  650. ("w.uint32(%i).%s(%s)", (field.id << 3 | wireType) >>> 0, type, ref);
  651. }
  652. }
  653. return gen
  654. ("if(m.$unknowns!=null&&Object.hasOwnProperty.call(m,\"$unknowns\"))")
  655. ("for(var i=0;i<m.$unknowns.length;++i)")
  656. ("w.raw(m.$unknowns[i])")
  657. ("return w");
  658. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  659. }
  660. },{"23":23,"24":24,"5":5}],5:[function(require,module,exports){
  661. "use strict";
  662. module.exports = Enum;
  663. // extends ReflectionObject
  664. var ReflectionObject = require(13);
  665. ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
  666. var Namespace = require(12),
  667. util = require(24);
  668. /**
  669. * Constructs a new enum instance.
  670. * @classdesc Reflected enum.
  671. * @extends ReflectionObject
  672. * @constructor
  673. * @param {string} name Unique name within its namespace
  674. * @param {Object.<string,number>} [values] Enum values as an object, by name
  675. * @param {Object.<string,*>} [options] Declared options
  676. * @param {string} [comment] The comment for this enum
  677. * @param {Object.<string,string|null>} [comments] The value comments for this enum
  678. * @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
  679. */
  680. function Enum(name, values, options, comment, comments, valuesOptions) {
  681. ReflectionObject.call(this, name, options);
  682. if (values && typeof values !== "object")
  683. throw TypeError("values must be an object");
  684. /**
  685. * Enum values by id.
  686. * @type {Object.<number,string>}
  687. */
  688. this.valuesById = {};
  689. /**
  690. * Enum values by name.
  691. * @type {Object.<string,number>}
  692. */
  693. this.values = Object.create(this.valuesById); // toJSON, marker
  694. /**
  695. * Enum comment text.
  696. * @type {string|null}
  697. */
  698. this.comment = comment;
  699. /**
  700. * Value comment texts, if any.
  701. * @type {Object.<string,string|null>}
  702. */
  703. this.comments = comments || {};
  704. /**
  705. * Values options, if any
  706. * @type {Object<string, Object<string, *>>|undefined}
  707. */
  708. this.valuesOptions = valuesOptions;
  709. /**
  710. * Resolved values features, if any
  711. * @type {Object<string, Object<string, *>>|undefined}
  712. */
  713. this._valuesFeatures = {};
  714. /**
  715. * Reserved ranges, if any.
  716. * @type {Array.<number[]|string>}
  717. */
  718. this.reserved = undefined; // toJSON
  719. // Note that values inherit valuesById on their prototype which makes them a TypeScript-
  720. // compatible enum. This is used by pbts to write actual enum definitions that work for
  721. // static and reflection code alike instead of emitting generic object definitions.
  722. if (values)
  723. for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
  724. if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
  725. this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
  726. }
  727. /**
  728. * @override
  729. */
  730. Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
  731. edition = this._edition || edition;
  732. ReflectionObject.prototype._resolveFeatures.call(this, edition);
  733. Object.keys(this.values).forEach(key => {
  734. var parentFeaturesCopy = util.merge({}, this._features);
  735. this._valuesFeatures[key] = util.merge(parentFeaturesCopy, this.valuesOptions && this.valuesOptions[key] && this.valuesOptions[key].features || {});
  736. });
  737. return this;
  738. };
  739. /**
  740. * Enum descriptor.
  741. * @interface IEnum
  742. * @property {string} [edition] Edition
  743. * @property {Object.<string,number>} values Enum values
  744. * @property {Object.<string,*>} [options] Enum options
  745. * @property {Object.<string,Object.<string,*>>} [valuesOptions] Enum value options
  746. * @property {Array.<number[]|string>} [reserved] Reserved ranges
  747. * @property {string|null} [comment] Enum comment
  748. * @property {Object.<string,string|null>} [comments] Value comments
  749. */
  750. /**
  751. * Constructs an enum from an enum descriptor.
  752. * @param {string} name Enum name
  753. * @param {IEnum} json Enum descriptor
  754. * @returns {Enum} Created enum
  755. * @throws {TypeError} If arguments are invalid
  756. */
  757. Enum.fromJSON = function fromJSON(name, json) {
  758. var enm = new Enum(name, json.values, json.options, json.comment, json.comments, json.valuesOptions);
  759. enm.reserved = json.reserved;
  760. if (json.edition)
  761. enm._edition = json.edition;
  762. enm._defaultEdition = "proto3"; // For backwards-compatibility.
  763. return enm;
  764. };
  765. /**
  766. * Converts this enum to an enum descriptor.
  767. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  768. * @returns {IEnum} Enum descriptor
  769. */
  770. Enum.prototype.toJSON = function toJSON(toJSONOptions) {
  771. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  772. return util.toObject([
  773. "edition" , this._editionToJSON(),
  774. "options" , this.options,
  775. "valuesOptions" , this.valuesOptions,
  776. "values" , this.values,
  777. "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
  778. "comment" , keepComments ? this.comment : undefined,
  779. "comments" , keepComments ? this.comments : undefined
  780. ]);
  781. };
  782. /**
  783. * Adds a value to this enum.
  784. * @param {string} name Value name
  785. * @param {number} id Value id
  786. * @param {string} [comment] Comment, if any
  787. * @param {Object.<string, *>|undefined} [options] Options, if any
  788. * @returns {Enum} `this`
  789. * @throws {TypeError} If arguments are invalid
  790. * @throws {Error} If there is already a value with this name or id
  791. */
  792. Enum.prototype.add = function add(name, id, comment, options) {
  793. // utilized by the parser but not by .fromJSON
  794. if (!util.isString(name))
  795. throw TypeError("name must be a string");
  796. if (!util.isInteger(id))
  797. throw TypeError("id must be an integer");
  798. if (name === "__proto__")
  799. return this;
  800. if (this.values[name] !== undefined)
  801. throw Error("duplicate name '" + name + "' in " + this);
  802. if (this.isReservedId(id))
  803. throw Error("id " + id + " is reserved in " + this);
  804. if (this.isReservedName(name))
  805. throw Error("name '" + name + "' is reserved in " + this);
  806. if (this.valuesById[id] !== undefined) {
  807. if (!(this.options && this.options.allow_alias))
  808. throw Error("duplicate id " + id + " in " + this);
  809. this.values[name] = id;
  810. } else
  811. this.valuesById[this.values[name] = id] = name;
  812. if (options) {
  813. if (this.valuesOptions === undefined)
  814. this.valuesOptions = {};
  815. this.valuesOptions[name] = options || null;
  816. }
  817. this.comments[name] = comment || null;
  818. return this;
  819. };
  820. /**
  821. * Removes a value from this enum
  822. * @param {string} name Value name
  823. * @returns {Enum} `this`
  824. * @throws {TypeError} If arguments are invalid
  825. * @throws {Error} If `name` is not a name of this enum
  826. */
  827. Enum.prototype.remove = function remove(name) {
  828. if (!util.isString(name))
  829. throw TypeError("name must be a string");
  830. var val = this.values[name];
  831. if (val == null)
  832. throw Error("name '" + name + "' does not exist in " + this);
  833. delete this.valuesById[val];
  834. delete this.values[name];
  835. delete this.comments[name];
  836. if (this.valuesOptions)
  837. delete this.valuesOptions[name];
  838. return this;
  839. };
  840. /**
  841. * Tests if the specified id is reserved.
  842. * @param {number} id Id to test
  843. * @returns {boolean} `true` if reserved, otherwise `false`
  844. */
  845. Enum.prototype.isReservedId = function isReservedId(id) {
  846. return Namespace.isReservedId(this.reserved, id);
  847. };
  848. /**
  849. * Tests if the specified name is reserved.
  850. * @param {string} name Name to test
  851. * @returns {boolean} `true` if reserved, otherwise `false`
  852. */
  853. Enum.prototype.isReservedName = function isReservedName(name) {
  854. return Namespace.isReservedName(this.reserved, name);
  855. };
  856. },{"12":12,"13":13,"24":24}],6:[function(require,module,exports){
  857. "use strict";
  858. module.exports = Field;
  859. // extends ReflectionObject
  860. var ReflectionObject = require(13);
  861. ((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field";
  862. var Enum = require(5),
  863. types = require(23),
  864. util = require(24);
  865. var Type; // cyclic
  866. var ruleRe = /^(?:required|optional|repeated)$/;
  867. /**
  868. * Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.
  869. * @name Field
  870. * @classdesc Reflected message field.
  871. * @extends FieldBase
  872. * @constructor
  873. * @param {string} name Unique name within its namespace
  874. * @param {number} id Unique id within its namespace
  875. * @param {string} type Value type
  876. * @param {string|Object.<string,*>} [rule="optional"] Field rule
  877. * @param {string|Object.<string,*>} [extend] Extended type if different from parent
  878. * @param {Object.<string,*>} [options] Declared options
  879. */
  880. /**
  881. * Constructs a field from a field descriptor.
  882. * @param {string} name Field name
  883. * @param {IField} json Field descriptor
  884. * @returns {Field} Created field
  885. * @throws {TypeError} If arguments are invalid
  886. */
  887. Field.fromJSON = function fromJSON(name, json) {
  888. var field = new Field(name, json.id, json.type, json.rule, json.extend, json.options, json.comment);
  889. if (json.edition)
  890. field._edition = json.edition;
  891. if (json.protoName)
  892. field.protoName = json.protoName;
  893. if (json.jsonName !== undefined)
  894. field.jsonName = json.jsonName;
  895. else if (json.options && json.options.json_name !== undefined)
  896. field.jsonName = json.options.json_name;
  897. field._defaultEdition = "proto3"; // For backwards-compatibility.
  898. return field;
  899. };
  900. /**
  901. * Not an actual constructor. Use {@link Field} instead.
  902. * @classdesc Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions.
  903. * @exports FieldBase
  904. * @extends ReflectionObject
  905. * @constructor
  906. * @param {string} name Unique name within its namespace
  907. * @param {number} id Unique id within its namespace
  908. * @param {string} type Value type
  909. * @param {string|Object.<string,*>} [rule="optional"] Field rule
  910. * @param {string|Object.<string,*>} [extend] Extended type if different from parent
  911. * @param {Object.<string,*>} [options] Declared options
  912. * @param {string} [comment] Comment associated with this field
  913. */
  914. function Field(name, id, type, rule, extend, options, comment) {
  915. if (util.isObject(rule)) {
  916. comment = extend;
  917. options = rule;
  918. rule = extend = undefined;
  919. } else if (util.isObject(extend)) {
  920. comment = options;
  921. options = extend;
  922. extend = undefined;
  923. }
  924. ReflectionObject.call(this, name, options);
  925. if (!util.isInteger(id) || id < 0)
  926. throw TypeError("id must be a non-negative integer");
  927. if (!util.isString(type))
  928. throw TypeError("type must be a string");
  929. if (rule !== undefined && !ruleRe.test(rule = rule.toString().toLowerCase()))
  930. throw TypeError("rule must be a string rule");
  931. if (extend !== undefined && !util.isString(extend))
  932. throw TypeError("extend must be a string");
  933. /**
  934. * Field rule, if any.
  935. * @type {string|undefined}
  936. */
  937. this.rule = rule && rule !== "optional" ? rule : undefined; // toJSON
  938. /**
  939. * Field type.
  940. * @type {string}
  941. */
  942. this.type = type; // toJSON
  943. /**
  944. * Unique field id.
  945. * @type {number}
  946. */
  947. this.id = id; // toJSON, marker
  948. /**
  949. * Extended type if different from parent.
  950. * @type {string|undefined}
  951. */
  952. this.extend = extend || undefined; // toJSON
  953. /**
  954. * Whether this field is repeated.
  955. * @type {boolean}
  956. */
  957. this.repeated = rule === "repeated";
  958. /**
  959. * Whether this field is a map or not.
  960. * @type {boolean}
  961. */
  962. this.map = false;
  963. /**
  964. * Message this field belongs to.
  965. * @type {Type|null}
  966. */
  967. this.message = null;
  968. /**
  969. * OneOf this field belongs to, if any,
  970. * @type {OneOf|null}
  971. */
  972. this.partOf = null;
  973. /**
  974. * The field type's default value.
  975. * @type {*}
  976. */
  977. this.typeDefault = null;
  978. /**
  979. * The field's default value on prototypes.
  980. * @type {*}
  981. */
  982. this.defaultValue = null;
  983. /**
  984. * Whether this field's value should be treated as a long.
  985. * @type {boolean}
  986. */
  987. this.long = util.Long ? types.long[type] !== undefined : /* istanbul ignore next */ false;
  988. /**
  989. * Whether this field's value is a buffer.
  990. * @type {boolean}
  991. */
  992. this.bytes = type === "bytes";
  993. /**
  994. * Resolved type if not a basic type.
  995. * @type {Type|Enum|null}
  996. */
  997. this.resolvedType = null;
  998. /**
  999. * Sister-field within the extended type if a declaring extension field.
  1000. * @type {Field|null}
  1001. */
  1002. this.extensionField = null;
  1003. /**
  1004. * Sister-field within the declaring namespace if an extended field.
  1005. * @type {Field|null}
  1006. */
  1007. this.declaringField = null;
  1008. /**
  1009. * Comment for this field.
  1010. * @type {string|null}
  1011. */
  1012. this.comment = comment;
  1013. /**
  1014. * Field name as declared in the .proto source, if different from `name`.
  1015. * @type {string|undefined}
  1016. */
  1017. this.protoName = undefined;
  1018. /**
  1019. * JSON name, if different from the derived default.
  1020. * @type {string|undefined}
  1021. */
  1022. this.jsonName = undefined;
  1023. }
  1024. /**
  1025. * Determines whether this field is required.
  1026. * @name Field#required
  1027. * @type {boolean}
  1028. * @readonly
  1029. */
  1030. Object.defineProperty(Field.prototype, "required", {
  1031. get: function() {
  1032. return this._features.field_presence === "LEGACY_REQUIRED";
  1033. }
  1034. });
  1035. /**
  1036. * Determines whether this field is not required.
  1037. * @name Field#optional
  1038. * @type {boolean}
  1039. * @readonly
  1040. */
  1041. Object.defineProperty(Field.prototype, "optional", {
  1042. get: function() {
  1043. return !this.required;
  1044. }
  1045. });
  1046. /**
  1047. * Determines whether this field uses tag-delimited encoding. In proto2 this
  1048. * corresponded to group syntax.
  1049. * @name Field#delimited
  1050. * @type {boolean}
  1051. * @readonly
  1052. */
  1053. Object.defineProperty(Field.prototype, "delimited", {
  1054. get: function() {
  1055. return this.resolvedType instanceof Type &&
  1056. this._features.message_encoding === "DELIMITED";
  1057. }
  1058. });
  1059. /**
  1060. * Determines whether this field is packed. Only relevant when repeated.
  1061. * @name Field#packed
  1062. * @type {boolean}
  1063. * @readonly
  1064. */
  1065. Object.defineProperty(Field.prototype, "packed", {
  1066. get: function() {
  1067. return this._features.repeated_field_encoding === "PACKED";
  1068. }
  1069. });
  1070. /**
  1071. * Determines whether this field tracks presence.
  1072. * @name Field#hasPresence
  1073. * @type {boolean}
  1074. * @readonly
  1075. */
  1076. Object.defineProperty(Field.prototype, "hasPresence", {
  1077. get: function() {
  1078. if (this.repeated || this.map) {
  1079. return false;
  1080. }
  1081. return this.partOf || // oneofs
  1082. this.declaringField || this.extensionField || // extensions
  1083. this._features.field_presence !== "IMPLICIT";
  1084. }
  1085. });
  1086. /**
  1087. * The field name as declared in the .proto source (snake_case). Populated on resolve,
  1088. * falling back to `name`. Mirrors `FieldDescriptorProto.name`.
  1089. * @name Field#protoName
  1090. * @type {string}
  1091. * @readonly
  1092. */
  1093. /**
  1094. * The JSON name of this field (lowerCamelCase per protoc's `ToJsonName`, or an
  1095. * explicit `[json_name]`). Populated on resolve. This is the key used on ProtoJSON output.
  1096. * @name Field#jsonName
  1097. * @type {string}
  1098. * @readonly
  1099. */
  1100. /**
  1101. * @override
  1102. */
  1103. Field.prototype.setOption = function setOption(name, value, ifNotSet) {
  1104. return ReflectionObject.prototype.setOption.call(this, name, value, ifNotSet);
  1105. };
  1106. /**
  1107. * Field descriptor.
  1108. * @interface IField
  1109. * @property {string} [edition] Edition
  1110. * @property {string} [rule="optional"] Field rule
  1111. * @property {string} type Field type
  1112. * @property {number} id Field id
  1113. * @property {Object.<string,*>} [options] Field options
  1114. * @property {string|null} [comment] Field comment
  1115. */
  1116. /**
  1117. * Extension field descriptor.
  1118. * @interface IExtensionField
  1119. * @extends IField
  1120. * @property {string} extend Extended type
  1121. */
  1122. /**
  1123. * Converts this field to a field descriptor.
  1124. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  1125. * @returns {IField} Field descriptor
  1126. */
  1127. Field.prototype.toJSON = function toJSON(toJSONOptions) {
  1128. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  1129. return util.toObject([
  1130. "edition" , this._editionToJSON(),
  1131. "rule" , this.rule !== "optional" && this.rule || undefined,
  1132. "type" , this.type,
  1133. "id" , this.id,
  1134. "extend" , this.extend,
  1135. "protoName" , this.protoName !== this.name ? this.protoName : undefined,
  1136. "jsonName" , this.jsonName !== util.jsonName(this.protoName || this.name) ? this.jsonName : undefined,
  1137. "options" , this.options,
  1138. "comment" , keepComments ? this.comment : undefined
  1139. ]);
  1140. };
  1141. /**
  1142. * Resolves this field's type references.
  1143. * @returns {Field} `this`
  1144. * @throws {Error} If any reference cannot be resolved
  1145. */
  1146. Field.prototype.resolve = function resolve() {
  1147. if (this.resolved)
  1148. return this;
  1149. if ((this.typeDefault = types.defaults[this.type]) === undefined) { // if not a basic type, resolve it
  1150. this.resolvedType = (this.declaringField ? this.declaringField.parent : this.parent).lookupTypeOrEnum(this.type);
  1151. if (this.resolvedType instanceof Type)
  1152. this.typeDefault = null;
  1153. else // instanceof Enum
  1154. this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined
  1155. } else if (this.options && this.options.proto3_optional) {
  1156. // proto3 scalar value marked optional; should default to null
  1157. this.typeDefault = null;
  1158. }
  1159. // use explicitly set default value if present
  1160. if (this.options && this.options["default"] != null) {
  1161. this.typeDefault = this.options["default"];
  1162. if (this.resolvedType instanceof Enum && typeof this.typeDefault === "string")
  1163. this.typeDefault = this.resolvedType.values[this.typeDefault];
  1164. }
  1165. // remove unnecessary options
  1166. if (this.options) {
  1167. if (this.options.packed !== undefined && this.resolvedType && !(this.resolvedType instanceof Enum))
  1168. delete this.options.packed;
  1169. if (!Object.keys(this.options).length)
  1170. this.options = undefined;
  1171. }
  1172. // convert to internal data type if necesssary
  1173. if (this.long) {
  1174. this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type === "uint64" || this.type === "fixed64");
  1175. /* istanbul ignore else */
  1176. if (Object.freeze)
  1177. Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it)
  1178. } else if (this.bytes && typeof this.typeDefault === "string") {
  1179. var buf;
  1180. if (util.base64.test(this.typeDefault))
  1181. util.base64.decode(this.typeDefault, buf = util.newBuffer(util.base64.length(this.typeDefault)), 0);
  1182. else
  1183. util.utf8.write(this.typeDefault, buf = util.newBuffer(util.utf8.length(this.typeDefault)), 0);
  1184. this.typeDefault = buf;
  1185. }
  1186. // take special care of maps and repeated fields
  1187. if (this.map)
  1188. this.defaultValue = util.emptyObject;
  1189. else if (this.repeated)
  1190. this.defaultValue = util.emptyArray;
  1191. else
  1192. this.defaultValue = this.typeDefault;
  1193. // ensure proper value on prototype
  1194. if (this.parent instanceof Type && this.parent._ctor)
  1195. this.parent._ctor.prototype[this.name] = this.defaultValue;
  1196. // derive the proto/JSON names
  1197. if (this.protoName === undefined)
  1198. this.protoName = this.name;
  1199. if (this.jsonName === undefined)
  1200. this.jsonName = util.jsonName(this.protoName);
  1201. return ReflectionObject.prototype.resolve.call(this);
  1202. };
  1203. /**
  1204. * Infers field features from legacy syntax that may have been specified differently.
  1205. * in older editions.
  1206. * @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
  1207. * @returns {object} The feature values to override
  1208. */
  1209. Field.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(edition) {
  1210. if (edition !== "proto2" && edition !== "proto3") {
  1211. return {};
  1212. }
  1213. var features = {};
  1214. if (this.rule === "required") {
  1215. features.field_presence = "LEGACY_REQUIRED";
  1216. }
  1217. if (this.parent && types.defaults[this.type] === undefined) {
  1218. // We can't use resolvedType because types may not have been resolved yet. However,
  1219. // legacy groups are always in the same scope as the field so we don't have to do a
  1220. // full scan of the tree.
  1221. var type = this.parent.get(this.type.split(".").pop());
  1222. if (type && type instanceof Type && type.group) {
  1223. features.message_encoding = "DELIMITED";
  1224. }
  1225. }
  1226. if (this.getOption("packed") === true) {
  1227. features.repeated_field_encoding = "PACKED";
  1228. } else if (this.getOption("packed") === false) {
  1229. features.repeated_field_encoding = "EXPANDED";
  1230. }
  1231. return features;
  1232. };
  1233. /**
  1234. * @override
  1235. */
  1236. Field.prototype._resolveFeatures = function _resolveFeatures(edition) {
  1237. return ReflectionObject.prototype._resolveFeatures.call(this, this._edition || edition);
  1238. };
  1239. /**
  1240. * Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript).
  1241. * @typedef FieldDecorator
  1242. * @type {function}
  1243. * @param {Object} prototype Target prototype
  1244. * @param {string} fieldName Field name
  1245. * @returns {undefined}
  1246. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  1247. */
  1248. /**
  1249. * Field decorator (TypeScript).
  1250. * @name Field.d
  1251. * @function
  1252. * @param {number} fieldId Field id
  1253. * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"string"|"bool"|"bytes"|Object} fieldType Field type
  1254. * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule
  1255. * @param {T} [defaultValue] Default value
  1256. * @returns {FieldDecorator} Decorator function
  1257. * @template T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[]
  1258. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  1259. */
  1260. Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
  1261. // submessage: decorate the submessage and use its name as the type
  1262. if (typeof fieldType === "function")
  1263. fieldType = util.decorateType(fieldType).name;
  1264. // enum reference: create a reflected copy of the enum and keep reuseing it
  1265. else if (fieldType && typeof fieldType === "object")
  1266. fieldType = util.decorateEnum(fieldType).name;
  1267. return function fieldDecorator(prototype, fieldName) {
  1268. util.decorateType(prototype.constructor)
  1269. .add(new Field(fieldName, fieldId, fieldType, fieldRule, { "default": defaultValue }));
  1270. };
  1271. };
  1272. // Sets up cyclic dependencies (called in index-light)
  1273. Field._configure = function configure(Type_) {
  1274. Type = Type_;
  1275. };
  1276. /**
  1277. * Field decorator (TypeScript).
  1278. * @name Field.d
  1279. * @function
  1280. * @param {number} fieldId Field id
  1281. * @param {Constructor<T>|string} fieldType Field type
  1282. * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule
  1283. * @returns {FieldDecorator} Decorator function
  1284. * @template T extends Message<T>
  1285. * @variation 2
  1286. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  1287. */
  1288. // like Field.d but without a default value
  1289. },{"13":13,"23":23,"24":24,"5":5}],7:[function(require,module,exports){
  1290. "use strict";
  1291. exports = module.exports = require(8);
  1292. exports.build = "light";
  1293. /**
  1294. * A node-style callback as used by {@link load} and {@link Root#load}.
  1295. * @typedef LoadCallback
  1296. * @type {function}
  1297. * @param {Error|null} error Error, if any, otherwise `null`
  1298. * @param {Root} [root] Root, if there hasn't been an error
  1299. * @returns {undefined}
  1300. */
  1301. /**
  1302. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
  1303. * @param {string|string[]} filename One or multiple files to load
  1304. * @param {Root} root Root namespace, defaults to create a new one if omitted.
  1305. * @param {LoadCallback} callback Callback function
  1306. * @returns {undefined}
  1307. * @see {@link Root#load}
  1308. */
  1309. function load(filename, root, callback) {
  1310. if (typeof root === "function") {
  1311. callback = root;
  1312. root = new exports.Root();
  1313. } else if (!root)
  1314. root = new exports.Root();
  1315. return root.load(filename, callback);
  1316. }
  1317. /**
  1318. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
  1319. * @name load
  1320. * @function
  1321. * @param {string|string[]} filename One or multiple files to load
  1322. * @param {LoadCallback} callback Callback function
  1323. * @returns {undefined}
  1324. * @see {@link Root#load}
  1325. * @variation 2
  1326. */
  1327. // function load(filename:string, callback:LoadCallback):undefined
  1328. /**
  1329. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
  1330. * @name load
  1331. * @function
  1332. * @param {string|string[]} filename One or multiple files to load
  1333. * @param {Root} [root] Root namespace, defaults to create a new one if omitted.
  1334. * @returns {Promise<Root>} Promise
  1335. * @see {@link Root#load}
  1336. * @variation 3
  1337. */
  1338. // function load(filename:string, [root:Root]):Promise<Root>
  1339. exports.load = load;
  1340. /**
  1341. * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
  1342. * @param {string|string[]} filename One or multiple files to load
  1343. * @param {Root} [root] Root namespace, defaults to create a new one if omitted.
  1344. * @returns {Root} Root namespace
  1345. * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
  1346. * @see {@link Root#loadSync}
  1347. */
  1348. function loadSync(filename, root) {
  1349. if (!root)
  1350. root = new exports.Root();
  1351. return root.loadSync(filename);
  1352. }
  1353. exports.loadSync = loadSync;
  1354. // Serialization
  1355. exports.encoder = require(4);
  1356. exports.decoder = require(3);
  1357. exports.verifier = require(38);
  1358. exports.converter = require(2);
  1359. // Reflection
  1360. exports.ReflectionObject = require(13);
  1361. exports.Namespace = require(12);
  1362. exports.Root = require(17);
  1363. exports.Enum = require(5);
  1364. exports.Type = require(22);
  1365. exports.Field = require(6);
  1366. exports.OneOf = require(14);
  1367. exports.MapField = require(9);
  1368. exports.Service = require(21);
  1369. exports.Method = require(11);
  1370. // Runtime
  1371. exports.Message = require(10);
  1372. exports.wrappers = require(39);
  1373. // Utility
  1374. exports.types = require(23);
  1375. exports.util = require(24);
  1376. // Set up possibly cyclic reflection dependencies
  1377. exports.ReflectionObject._configure(exports.Root);
  1378. exports.Namespace._configure(exports.Type, exports.Service, exports.Enum);
  1379. exports.Root._configure(exports.Type, undefined, {});
  1380. exports.Field._configure(exports.Type);
  1381. },{"10":10,"11":11,"12":12,"13":13,"14":14,"17":17,"2":2,"21":21,"22":22,"23":23,"24":24,"3":3,"38":38,"39":39,"4":4,"5":5,"6":6,"8":8,"9":9}],8:[function(require,module,exports){
  1382. "use strict";
  1383. /**
  1384. * Build type, one of `"full"`, `"light"` or `"minimal"`.
  1385. * @name build
  1386. * @type {string}
  1387. * @const
  1388. */
  1389. exports.build = "minimal";
  1390. // Serialization
  1391. exports.Writer = require(40);
  1392. exports.BufferWriter = require(41);
  1393. exports.Reader = require(15);
  1394. exports.BufferReader = require(16);
  1395. // Utility
  1396. exports.util = require(33);
  1397. exports.rpc = require(19);
  1398. exports.roots = require(18);
  1399. exports.configure = configure;
  1400. /* istanbul ignore next */
  1401. /**
  1402. * Reconfigures the library according to the environment.
  1403. * @returns {undefined}
  1404. */
  1405. function configure() {
  1406. exports.util._configure();
  1407. exports.Writer._configure(exports.BufferWriter);
  1408. exports.Reader._configure(exports.BufferReader);
  1409. }
  1410. // Set up buffer utility according to the environment
  1411. configure();
  1412. },{"15":15,"16":16,"18":18,"19":19,"33":33,"40":40,"41":41}],9:[function(require,module,exports){
  1413. "use strict";
  1414. module.exports = MapField;
  1415. // extends Field
  1416. var Field = require(6);
  1417. ((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";
  1418. var types = require(23),
  1419. util = require(24);
  1420. /**
  1421. * Constructs a new map field instance.
  1422. * @classdesc Reflected map field.
  1423. * @extends FieldBase
  1424. * @constructor
  1425. * @param {string} name Unique name within its namespace
  1426. * @param {number} id Unique id within its namespace
  1427. * @param {string} keyType Key type
  1428. * @param {string} type Value type
  1429. * @param {Object.<string,*>} [options] Declared options
  1430. * @param {string} [comment] Comment associated with this field
  1431. */
  1432. function MapField(name, id, keyType, type, options, comment) {
  1433. Field.call(this, name, id, type, undefined, undefined, options, comment);
  1434. /* istanbul ignore if */
  1435. if (!util.isString(keyType))
  1436. throw TypeError("keyType must be a string");
  1437. /**
  1438. * Key type.
  1439. * @type {string}
  1440. */
  1441. this.keyType = keyType; // toJSON, marker
  1442. /**
  1443. * Resolved key type if not a basic type.
  1444. * @type {ReflectionObject|null}
  1445. */
  1446. this.resolvedKeyType = null;
  1447. // Overrides Field#map
  1448. this.map = true;
  1449. }
  1450. /**
  1451. * Map field descriptor.
  1452. * @interface IMapField
  1453. * @extends {IField}
  1454. * @property {string} keyType Key type
  1455. */
  1456. /**
  1457. * Extension map field descriptor.
  1458. * @interface IExtensionMapField
  1459. * @extends IMapField
  1460. * @property {string} extend Extended type
  1461. */
  1462. /**
  1463. * Constructs a map field from a map field descriptor.
  1464. * @param {string} name Field name
  1465. * @param {IMapField} json Map field descriptor
  1466. * @returns {MapField} Created map field
  1467. * @throws {TypeError} If arguments are invalid
  1468. */
  1469. MapField.fromJSON = function fromJSON(name, json) {
  1470. var field = new MapField(name, json.id, json.keyType, json.type, json.options, json.comment);
  1471. if (json.protoName)
  1472. field.protoName = json.protoName;
  1473. if (json.jsonName !== undefined)
  1474. field.jsonName = json.jsonName;
  1475. else if (json.options && json.options.json_name !== undefined)
  1476. field.jsonName = json.options.json_name;
  1477. return field;
  1478. };
  1479. /**
  1480. * Converts this map field to a map field descriptor.
  1481. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  1482. * @returns {IMapField} Map field descriptor
  1483. */
  1484. MapField.prototype.toJSON = function toJSON(toJSONOptions) {
  1485. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  1486. return util.toObject([
  1487. "keyType" , this.keyType,
  1488. "type" , this.type,
  1489. "id" , this.id,
  1490. "extend" , this.extend,
  1491. "protoName" , this.protoName !== this.name ? this.protoName : undefined,
  1492. "jsonName" , this.jsonName !== util.jsonName(this.protoName || this.name) ? this.jsonName : undefined,
  1493. "options" , this.options,
  1494. "comment" , keepComments ? this.comment : undefined
  1495. ]);
  1496. };
  1497. /**
  1498. * @override
  1499. */
  1500. MapField.prototype.resolve = function resolve() {
  1501. if (this.resolved)
  1502. return this;
  1503. // Besides a value type, map fields have a key type that may be "any scalar type except for floating point types and bytes"
  1504. if (types.mapKey[this.keyType] === undefined)
  1505. throw Error("invalid key type: " + this.keyType);
  1506. return Field.prototype.resolve.call(this);
  1507. };
  1508. /**
  1509. * Map field decorator (TypeScript).
  1510. * @name MapField.d
  1511. * @function
  1512. * @param {number} fieldId Field id
  1513. * @param {"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"} fieldKeyType Field key type
  1514. * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|Object|Constructor<{}>} fieldValueType Field value type
  1515. * @returns {FieldDecorator} Decorator function
  1516. * @template T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }
  1517. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  1518. */
  1519. MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
  1520. // submessage value: decorate the submessage and use its name as the type
  1521. if (typeof fieldValueType === "function")
  1522. fieldValueType = util.decorateType(fieldValueType).name;
  1523. // enum reference value: create a reflected copy of the enum and keep reuseing it
  1524. else if (fieldValueType && typeof fieldValueType === "object")
  1525. fieldValueType = util.decorateEnum(fieldValueType).name;
  1526. return function mapFieldDecorator(prototype, fieldName) {
  1527. util.decorateType(prototype.constructor)
  1528. .add(new MapField(fieldName, fieldId, fieldKeyType, fieldValueType));
  1529. };
  1530. };
  1531. },{"23":23,"24":24,"6":6}],10:[function(require,module,exports){
  1532. "use strict";
  1533. module.exports = Message;
  1534. var util = require(33);
  1535. /**
  1536. * Constructs a new message instance.
  1537. * @classdesc Abstract runtime message.
  1538. * @constructor
  1539. * @param {Properties<T>} [properties] Properties to set
  1540. * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding when enabled
  1541. * @template T extends object = object
  1542. */
  1543. function Message(properties) {
  1544. // not used internally
  1545. if (properties)
  1546. for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
  1547. if (properties[keys[i]] != null && keys[i] !== "__proto__")
  1548. this[keys[i]] = properties[keys[i]];
  1549. }
  1550. /**
  1551. * Reference to the reflected type.
  1552. * @name Message.$type
  1553. * @type {Type}
  1554. * @readonly
  1555. */
  1556. /**
  1557. * Reference to the reflected type.
  1558. * @name Message#$type
  1559. * @type {Type}
  1560. * @readonly
  1561. */
  1562. /**
  1563. * Creates a new message of this type using the specified properties.
  1564. * @param {Object.<string,*>} [properties] Properties to set
  1565. * @returns {T} Message instance
  1566. * @template T extends Message<T>
  1567. * @this Constructor<T>
  1568. */
  1569. Message.create = function create(properties) {
  1570. return this.$type.create(properties);
  1571. };
  1572. /**
  1573. * Encodes a message of this type.
  1574. * @param {T|Object.<string,*>} message Message to encode
  1575. * @param {Writer} [writer] Writer to use
  1576. * @returns {Writer} Writer
  1577. * @template T extends Message<T>
  1578. * @this Constructor<T>
  1579. */
  1580. Message.encode = function encode(message, writer) {
  1581. return this.$type.encode(message, writer);
  1582. };
  1583. /**
  1584. * Encodes a message of this type preceeded by its length as a varint.
  1585. * @param {T|Object.<string,*>} message Message to encode
  1586. * @param {Writer} [writer] Writer to use
  1587. * @returns {Writer} Writer
  1588. * @template T extends Message<T>
  1589. * @this Constructor<T>
  1590. */
  1591. Message.encodeDelimited = function encodeDelimited(message, writer) {
  1592. return this.$type.encodeDelimited(message, writer);
  1593. };
  1594. /**
  1595. * Decodes a message of this type.
  1596. * @name Message.decode
  1597. * @function
  1598. * @param {Reader|Uint8Array} reader Reader or buffer to decode
  1599. * @returns {T} Decoded message
  1600. * @template T extends Message<T>
  1601. * @this Constructor<T>
  1602. */
  1603. Message.decode = function decode(reader) {
  1604. return this.$type.decode(reader);
  1605. };
  1606. /**
  1607. * Decodes a message of this type preceeded by its length as a varint.
  1608. * @name Message.decodeDelimited
  1609. * @function
  1610. * @param {Reader|Uint8Array} reader Reader or buffer to decode
  1611. * @returns {T} Decoded message
  1612. * @template T extends Message<T>
  1613. * @this Constructor<T>
  1614. */
  1615. Message.decodeDelimited = function decodeDelimited(reader) {
  1616. return this.$type.decodeDelimited(reader);
  1617. };
  1618. /**
  1619. * Verifies a message of this type.
  1620. * @name Message.verify
  1621. * @function
  1622. * @param {Object.<string,*>} message Plain object to verify
  1623. * @returns {string|null} `null` if valid, otherwise the reason why it is not
  1624. */
  1625. Message.verify = function verify(message) {
  1626. return this.$type.verify(message);
  1627. };
  1628. /**
  1629. * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
  1630. * @param {Object.<string,*>} object Plain object
  1631. * @returns {T} Message instance
  1632. * @template T extends Message<T>
  1633. * @this Constructor<T>
  1634. */
  1635. Message.fromObject = function fromObject(object) {
  1636. return this.$type.fromObject(object);
  1637. };
  1638. /**
  1639. * Creates a plain object from a message of this type. Also converts values to other types if specified.
  1640. * @param {T} message Message instance
  1641. * @param {IConversionOptions} [options] Conversion options
  1642. * @returns {Object.<string,*>} Plain object
  1643. * @template T extends Message<T>
  1644. * @this Constructor<T>
  1645. */
  1646. Message.toObject = function toObject(message, options) {
  1647. return this.$type.toObject(message, options);
  1648. };
  1649. /**
  1650. * Converts this message to JSON.
  1651. * @returns {Object.<string,*>} JSON object
  1652. */
  1653. Message.prototype.toJSON = function toJSON() {
  1654. return this.$type.toObject(this, util.toJSONOptions);
  1655. };
  1656. },{"33":33}],11:[function(require,module,exports){
  1657. "use strict";
  1658. module.exports = Method;
  1659. // extends ReflectionObject
  1660. var ReflectionObject = require(13);
  1661. ((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";
  1662. var util = require(24);
  1663. /**
  1664. * Constructs a new service method instance.
  1665. * @classdesc Reflected service method.
  1666. * @extends ReflectionObject
  1667. * @constructor
  1668. * @param {string} name Method name
  1669. * @param {string|undefined} type Method type, usually `"rpc"`
  1670. * @param {string} requestType Request message type
  1671. * @param {string} responseType Response message type
  1672. * @param {boolean|Object.<string,*>} [requestStream] Whether the request is streamed
  1673. * @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
  1674. * @param {Object.<string,*>} [options] Declared options
  1675. * @param {string} [comment] The comment for this method
  1676. * @param {Array.<Object.<string,*>>} [parsedOptions] Declared options, properly parsed into objects
  1677. */
  1678. function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment, parsedOptions) {
  1679. /* istanbul ignore next */
  1680. if (util.isObject(requestStream)) {
  1681. options = requestStream;
  1682. requestStream = responseStream = undefined;
  1683. } else if (util.isObject(responseStream)) {
  1684. options = responseStream;
  1685. responseStream = undefined;
  1686. }
  1687. /* istanbul ignore if */
  1688. if (!(type === undefined || util.isString(type)))
  1689. throw TypeError("type must be a string");
  1690. /* istanbul ignore if */
  1691. if (!util.isString(requestType))
  1692. throw TypeError("requestType must be a string");
  1693. /* istanbul ignore if */
  1694. if (!util.isString(responseType))
  1695. throw TypeError("responseType must be a string");
  1696. ReflectionObject.call(this, name, options);
  1697. /**
  1698. * Method type.
  1699. * @type {string}
  1700. */
  1701. this.type = type || "rpc"; // toJSON
  1702. /**
  1703. * Request type.
  1704. * @type {string}
  1705. */
  1706. this.requestType = requestType; // toJSON, marker
  1707. /**
  1708. * Whether requests are streamed or not.
  1709. * @type {true|undefined}
  1710. */
  1711. this.requestStream = requestStream ? true : undefined; // toJSON
  1712. /**
  1713. * Response type.
  1714. * @type {string}
  1715. */
  1716. this.responseType = responseType; // toJSON
  1717. /**
  1718. * Whether responses are streamed or not.
  1719. * @type {true|undefined}
  1720. */
  1721. this.responseStream = responseStream ? true : undefined; // toJSON
  1722. /**
  1723. * gRPC-style method path.
  1724. * @type {string}
  1725. */
  1726. this.path = "/" + this.name;
  1727. /**
  1728. * Resolved request type.
  1729. * @type {Type|null}
  1730. */
  1731. this.resolvedRequestType = null;
  1732. /**
  1733. * Resolved response type.
  1734. * @type {Type|null}
  1735. */
  1736. this.resolvedResponseType = null;
  1737. /**
  1738. * Comment for this method
  1739. * @type {string|null}
  1740. */
  1741. this.comment = comment;
  1742. /**
  1743. * Options properly parsed into objects
  1744. * @type {Array.<Object.<string,*>>|undefined}
  1745. */
  1746. this.parsedOptions = parsedOptions;
  1747. }
  1748. /**
  1749. * Method descriptor.
  1750. * @interface IMethod
  1751. * @property {string} [type="rpc"] Method type
  1752. * @property {string} requestType Request type
  1753. * @property {string} responseType Response type
  1754. * @property {boolean} [requestStream=false] Whether requests are streamed
  1755. * @property {boolean} [responseStream=false] Whether responses are streamed
  1756. * @property {Object.<string,*>} [options] Method options
  1757. * @property {string|null} [comment] Method comment
  1758. * @property {Array.<Object.<string,*>>} [parsedOptions] Method options properly parsed into objects
  1759. */
  1760. /**
  1761. * Constructs a method from a method descriptor.
  1762. * @param {string} name Method name
  1763. * @param {IMethod} json Method descriptor
  1764. * @returns {Method} Created method
  1765. * @throws {TypeError} If arguments are invalid
  1766. */
  1767. Method.fromJSON = function fromJSON(name, json) {
  1768. return new Method(name, json.type, json.requestType, json.responseType, json.requestStream, json.responseStream, json.options, json.comment, json.parsedOptions);
  1769. };
  1770. /**
  1771. * Converts this method to a method descriptor.
  1772. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  1773. * @returns {IMethod} Method descriptor
  1774. */
  1775. Method.prototype.toJSON = function toJSON(toJSONOptions) {
  1776. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  1777. return util.toObject([
  1778. "type" , this.type !== "rpc" && /* istanbul ignore next */ this.type || undefined,
  1779. "requestType" , this.requestType,
  1780. "requestStream" , this.requestStream,
  1781. "responseType" , this.responseType,
  1782. "responseStream" , this.responseStream,
  1783. "options" , this.options,
  1784. "comment" , keepComments ? this.comment : undefined,
  1785. "parsedOptions" , this.parsedOptions,
  1786. ]);
  1787. };
  1788. /**
  1789. * @override
  1790. */
  1791. Method.prototype.resolve = function resolve() {
  1792. /* istanbul ignore if */
  1793. if (this.resolved)
  1794. return this;
  1795. if (this.parent) {
  1796. var serviceName = this.parent.fullName;
  1797. if (serviceName.charAt(0) === ".")
  1798. serviceName = serviceName.substring(1);
  1799. this.path = "/" + serviceName + "/" + this.name;
  1800. } else
  1801. this.path = "/" + this.name;
  1802. this.resolvedRequestType = this.parent.lookupType(this.requestType);
  1803. this.resolvedResponseType = this.parent.lookupType(this.responseType);
  1804. return ReflectionObject.prototype.resolve.call(this);
  1805. };
  1806. },{"13":13,"24":24}],12:[function(require,module,exports){
  1807. "use strict";
  1808. module.exports = Namespace;
  1809. // extends ReflectionObject
  1810. var ReflectionObject = require(13);
  1811. ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
  1812. var Field = require(6),
  1813. util = require(24),
  1814. OneOf = require(14);
  1815. var Type, // cyclic
  1816. Service,
  1817. Enum;
  1818. /**
  1819. * Constructs a new namespace instance.
  1820. * @name Namespace
  1821. * @classdesc Reflected namespace.
  1822. * @extends NamespaceBase
  1823. * @constructor
  1824. * @param {string} name Namespace name
  1825. * @param {Object.<string,*>} [options] Declared options
  1826. */
  1827. /**
  1828. * Constructs a namespace from JSON.
  1829. * @memberof Namespace
  1830. * @function
  1831. * @param {string} name Namespace name
  1832. * @param {Object.<string,*>} json JSON object
  1833. * @param {number} [depth] Current nesting depth, defaults to `0`
  1834. * @returns {Namespace} Created namespace
  1835. * @throws {TypeError} If arguments are invalid
  1836. */
  1837. Namespace.fromJSON = function fromJSON(name, json, depth) {
  1838. if (depth === undefined)
  1839. depth = 0;
  1840. if (depth > util.recursionLimit)
  1841. throw Error("max depth exceeded");
  1842. return new Namespace(name, json.options).addJSON(json.nested, depth);
  1843. };
  1844. /**
  1845. * Converts an array of reflection objects to JSON.
  1846. * @memberof Namespace
  1847. * @param {ReflectionObject[]} array Object array
  1848. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  1849. * @returns {Object.<string,*>|undefined} JSON object or `undefined` when array is empty
  1850. */
  1851. function arrayToJSON(array, toJSONOptions) {
  1852. if (!(array && array.length))
  1853. return undefined;
  1854. var obj = {};
  1855. for (var i = 0; i < array.length; ++i)
  1856. obj[array[i].name] = array[i].toJSON(toJSONOptions);
  1857. return obj;
  1858. }
  1859. Namespace.arrayToJSON = arrayToJSON;
  1860. /**
  1861. * Tests if the specified id is reserved.
  1862. * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names
  1863. * @param {number} id Id to test
  1864. * @returns {boolean} `true` if reserved, otherwise `false`
  1865. */
  1866. Namespace.isReservedId = function isReservedId(reserved, id) {
  1867. if (reserved)
  1868. for (var i = 0; i < reserved.length; ++i)
  1869. if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] >= id)
  1870. return true;
  1871. return false;
  1872. };
  1873. /**
  1874. * Tests if the specified name is reserved.
  1875. * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names
  1876. * @param {string} name Name to test
  1877. * @returns {boolean} `true` if reserved, otherwise `false`
  1878. */
  1879. Namespace.isReservedName = function isReservedName(reserved, name) {
  1880. if (reserved)
  1881. for (var i = 0; i < reserved.length; ++i)
  1882. if (reserved[i] === name)
  1883. return true;
  1884. return false;
  1885. };
  1886. /**
  1887. * Not an actual constructor. Use {@link Namespace} instead.
  1888. * @classdesc Base class of all reflection objects containing nested objects. This is not an actual class but here for the sake of having consistent type definitions.
  1889. * @exports NamespaceBase
  1890. * @extends ReflectionObject
  1891. * @abstract
  1892. * @constructor
  1893. * @param {string} name Namespace name
  1894. * @param {Object.<string,*>} [options] Declared options
  1895. * @see {@link Namespace}
  1896. */
  1897. function Namespace(name, options) {
  1898. ReflectionObject.call(this, name, options);
  1899. /**
  1900. * Nested objects by name.
  1901. * @type {Object.<string,ReflectionObject>|undefined}
  1902. */
  1903. this.nested = undefined; // toJSON
  1904. /**
  1905. * Cached nested objects as an array.
  1906. * @type {ReflectionObject[]|null}
  1907. * @private
  1908. */
  1909. this._nestedArray = null;
  1910. /**
  1911. * Cache lookup calls for any objects contains anywhere under this namespace.
  1912. * This drastically speeds up resolve for large cross-linked protos where the same
  1913. * types are looked up repeatedly.
  1914. * @type {Object.<string,ReflectionObject|null>}
  1915. * @private
  1916. */
  1917. this._lookupCache = Object.create(null);
  1918. /**
  1919. * Whether or not objects contained in this namespace need feature resolution.
  1920. * @type {boolean}
  1921. * @protected
  1922. */
  1923. this._needsRecursiveFeatureResolution = true;
  1924. /**
  1925. * Whether or not objects contained in this namespace need a resolve.
  1926. * @type {boolean}
  1927. * @protected
  1928. */
  1929. this._needsRecursiveResolve = true;
  1930. }
  1931. function clearCache(namespace) {
  1932. namespace._nestedArray = null;
  1933. namespace._lookupCache = Object.create(null);
  1934. // Also clear parent caches, since they include nested lookups.
  1935. var parent = namespace;
  1936. while(parent = parent.parent) {
  1937. parent._lookupCache = Object.create(null);
  1938. }
  1939. return namespace;
  1940. }
  1941. /**
  1942. * Nested objects of this namespace as an array for iteration.
  1943. * @name NamespaceBase#nestedArray
  1944. * @type {ReflectionObject[]}
  1945. * @readonly
  1946. */
  1947. Object.defineProperty(Namespace.prototype, "nestedArray", {
  1948. get: function() {
  1949. return this._nestedArray || (this._nestedArray = util.toArray(this.nested));
  1950. }
  1951. });
  1952. /**
  1953. * Namespace descriptor.
  1954. * @interface INamespace
  1955. * @property {Object.<string,*>} [options] Namespace options
  1956. * @property {Object.<string,AnyNestedObject>} [nested] Nested object descriptors
  1957. */
  1958. /**
  1959. * Any extension field descriptor.
  1960. * @typedef AnyExtensionField
  1961. * @type {IExtensionField|IExtensionMapField}
  1962. */
  1963. /**
  1964. * Any nested object descriptor.
  1965. * @typedef AnyNestedObject
  1966. * @type {IEnum|IType|IService|AnyExtensionField|INamespace|IOneOf}
  1967. */
  1968. /**
  1969. * Converts this namespace to a namespace descriptor.
  1970. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  1971. * @returns {INamespace} Namespace descriptor
  1972. */
  1973. Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
  1974. return util.toObject([
  1975. "options" , this.options,
  1976. "nested" , arrayToJSON(this.nestedArray, toJSONOptions)
  1977. ]);
  1978. };
  1979. /**
  1980. * Adds nested objects to this namespace from nested object descriptors.
  1981. * @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
  1982. * @param {number} [depth] Current nesting depth, defaults to `0`
  1983. * @returns {Namespace} `this`
  1984. */
  1985. Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
  1986. if (depth === undefined)
  1987. depth = 0;
  1988. if (depth > util.recursionLimit)
  1989. throw Error("max depth exceeded");
  1990. var ns = this;
  1991. /* istanbul ignore else */
  1992. if (nestedJson) {
  1993. for (var names = Object.keys(nestedJson), i = 0, nested; i < names.length; ++i) {
  1994. nested = nestedJson[names[i]];
  1995. ns.add( // most to least likely
  1996. ( nested.fields !== undefined
  1997. ? Type.fromJSON
  1998. : nested.values !== undefined
  1999. ? Enum.fromJSON
  2000. : nested.methods !== undefined
  2001. ? Service.fromJSON
  2002. : nested.id !== undefined
  2003. ? Field.fromJSON
  2004. : Namespace.fromJSON )(names[i], nested, depth + 1)
  2005. );
  2006. }
  2007. }
  2008. return this;
  2009. };
  2010. /**
  2011. * Gets the nested object of the specified name.
  2012. * @param {string} name Nested object name
  2013. * @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist
  2014. */
  2015. Namespace.prototype.get = function get(name) {
  2016. return this.nested && Object.prototype.hasOwnProperty.call(this.nested, name)
  2017. ? this.nested[name]
  2018. : null;
  2019. };
  2020. /**
  2021. * Gets the values of the nested {@link Enum|enum} of the specified name.
  2022. * This methods differs from {@link Namespace#get|get} in that it returns an enum's values directly and throws instead of returning `null`.
  2023. * @param {string} name Nested enum name
  2024. * @returns {Object.<string,number>} Enum values
  2025. * @throws {Error} If there is no such enum
  2026. */
  2027. Namespace.prototype.getEnum = function getEnum(name) {
  2028. if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name) && this.nested[name] instanceof Enum)
  2029. return this.nested[name].values;
  2030. throw Error("no such enum: " + name);
  2031. };
  2032. /**
  2033. * Adds a nested object to this namespace.
  2034. * @param {ReflectionObject} object Nested object to add
  2035. * @returns {Namespace} `this`
  2036. * @throws {TypeError} If arguments are invalid
  2037. * @throws {Error} If there is already a nested object with this name
  2038. */
  2039. Namespace.prototype.add = function add(object) {
  2040. if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
  2041. throw TypeError("object must be a valid nested object");
  2042. if (object.name === "__proto__")
  2043. return this;
  2044. if (!this.nested)
  2045. this.nested = {};
  2046. else {
  2047. var prev = this.get(object.name);
  2048. if (prev) {
  2049. if (prev instanceof Namespace && object instanceof Namespace && !(prev instanceof Type || prev instanceof Service)) {
  2050. // replace plain namespace but keep existing nested elements and options
  2051. var nested = prev.nestedArray;
  2052. for (var i = 0; i < nested.length; ++i)
  2053. object.add(nested[i]);
  2054. this.remove(prev);
  2055. if (!this.nested)
  2056. this.nested = {};
  2057. object.setOptions(prev.options, true);
  2058. } else
  2059. throw Error("duplicate name '" + object.name + "' in " + this);
  2060. }
  2061. }
  2062. this.nested[object.name] = object;
  2063. if (!(this instanceof Type || this instanceof Service || this instanceof Enum || this instanceof Field)) {
  2064. // This is a package or a root namespace.
  2065. if (!object._edition) {
  2066. // Make sure that some edition is set if it hasn't already been specified.
  2067. object._edition = object._defaultEdition;
  2068. }
  2069. }
  2070. this._needsRecursiveFeatureResolution = true;
  2071. this._needsRecursiveResolve = true;
  2072. // Also clear parent caches, since they need to recurse down.
  2073. var parent = this;
  2074. while(parent = parent.parent) {
  2075. parent._needsRecursiveFeatureResolution = true;
  2076. parent._needsRecursiveResolve = true;
  2077. }
  2078. object.onAdd(this);
  2079. return clearCache(this);
  2080. };
  2081. /**
  2082. * Removes a nested object from this namespace.
  2083. * @param {ReflectionObject} object Nested object to remove
  2084. * @returns {Namespace} `this`
  2085. * @throws {TypeError} If arguments are invalid
  2086. * @throws {Error} If `object` is not a member of this namespace
  2087. */
  2088. Namespace.prototype.remove = function remove(object) {
  2089. if (!(object instanceof ReflectionObject))
  2090. throw TypeError("object must be a ReflectionObject");
  2091. if (object.parent !== this)
  2092. throw Error(object + " is not a member of " + this);
  2093. if (!util.remove(this.nested, object, object.name))
  2094. throw Error(object + " is not a member of " + this);
  2095. if (!Object.keys(this.nested).length)
  2096. this.nested = undefined;
  2097. object.onRemove(this);
  2098. return clearCache(this);
  2099. };
  2100. /**
  2101. * Defines additial namespaces within this one if not yet existing.
  2102. * @param {string|string[]} path Path to create
  2103. * @param {*} [json] Nested types to create from JSON
  2104. * @returns {Namespace} Pointer to the last namespace created or `this` if path is empty
  2105. */
  2106. Namespace.prototype.define = function define(path, json) {
  2107. if (util.isString(path))
  2108. path = path.split(".");
  2109. else if (!Array.isArray(path))
  2110. throw TypeError("illegal path");
  2111. if (path && path.length && path[0] === "")
  2112. throw Error("path must be relative");
  2113. if (path.length > util.recursionLimit)
  2114. throw Error("max depth exceeded");
  2115. var ptr = this;
  2116. while (path.length > 0) {
  2117. var part = path.shift();
  2118. if (ptr.nested && ptr.nested[part]) {
  2119. ptr = ptr.nested[part];
  2120. if (!(ptr instanceof Namespace))
  2121. throw Error("path conflicts with non-namespace objects");
  2122. } else
  2123. ptr.add(ptr = new Namespace(part));
  2124. }
  2125. if (json)
  2126. ptr.addJSON(json);
  2127. return ptr;
  2128. };
  2129. /**
  2130. * Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
  2131. * @returns {Namespace} `this`
  2132. */
  2133. Namespace.prototype.resolveAll = function resolveAll() {
  2134. if (!this._needsRecursiveResolve) return this;
  2135. if (this._needsRecursiveFeatureResolution)
  2136. this._resolveFeaturesRecursive(this._edition);
  2137. var nested = this.nestedArray, i = 0;
  2138. this.resolve();
  2139. while (i < nested.length)
  2140. if (nested[i] instanceof Namespace)
  2141. nested[i++].resolveAll();
  2142. else
  2143. nested[i++].resolve();
  2144. this._needsRecursiveResolve = false;
  2145. return this;
  2146. };
  2147. /**
  2148. * @override
  2149. */
  2150. Namespace.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
  2151. if (!this._needsRecursiveFeatureResolution) return this;
  2152. this._needsRecursiveFeatureResolution = false;
  2153. edition = this._edition || edition;
  2154. ReflectionObject.prototype._resolveFeaturesRecursive.call(this, edition);
  2155. this.nestedArray.forEach(nested => {
  2156. nested._resolveFeaturesRecursive(edition);
  2157. });
  2158. return this;
  2159. };
  2160. /**
  2161. * Recursively looks up the reflection object matching the specified path in the scope of this namespace.
  2162. * @param {string|string[]} path Path to look up
  2163. * @param {*|Array.<*>} filterTypes Filter types, any combination of the constructors of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.
  2164. * @param {boolean} [parentAlreadyChecked=false] If known, whether the parent has already been checked
  2165. * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
  2166. */
  2167. Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChecked) {
  2168. /* istanbul ignore next */
  2169. if (typeof filterTypes === "boolean") {
  2170. parentAlreadyChecked = filterTypes;
  2171. filterTypes = undefined;
  2172. } else if (filterTypes && !Array.isArray(filterTypes))
  2173. filterTypes = [ filterTypes ];
  2174. if (util.isString(path) && path.length) {
  2175. if (path === ".")
  2176. return this.root;
  2177. path = path.split(".");
  2178. } else if (!path.length)
  2179. return this;
  2180. var flatPath = path.join(".");
  2181. // Start at root if path is absolute
  2182. if (path[0] === "")
  2183. return this.root.lookup(path.slice(1), filterTypes);
  2184. // Lookup at this namespace and below
  2185. var found = this._lookupImpl(path, flatPath);
  2186. if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
  2187. return found;
  2188. }
  2189. // Fall back to respective absolute path once relative scope has been checked (non-standard)
  2190. found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
  2191. if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
  2192. return found;
  2193. }
  2194. if (parentAlreadyChecked)
  2195. return null;
  2196. // If there hasn't been a match, walk up the tree and look more broadly
  2197. var current = this;
  2198. while (current.parent) {
  2199. found = current.parent._lookupImpl(path, flatPath);
  2200. if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
  2201. return found;
  2202. }
  2203. current = current.parent;
  2204. }
  2205. return null;
  2206. };
  2207. /**
  2208. * Internal helper for lookup that handles searching just at this namespace and below along with caching.
  2209. * @param {string[]} path Path to look up
  2210. * @param {string} flatPath Flattened version of the path to use as a cache key
  2211. * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
  2212. * @private
  2213. */
  2214. Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
  2215. if(Object.prototype.hasOwnProperty.call(this._lookupCache, flatPath)) {
  2216. return this._lookupCache[flatPath];
  2217. }
  2218. // Test if the first part matches any nested object, and if so, traverse if path contains more
  2219. var found = this.get(path[0]);
  2220. var exact = null;
  2221. if (found) {
  2222. if (path.length === 1) {
  2223. exact = found;
  2224. } else if (found instanceof Namespace) {
  2225. path = path.slice(1);
  2226. exact = found._lookupImpl(path, path.join("."));
  2227. }
  2228. // Otherwise try each nested namespace
  2229. } else {
  2230. for (var i = 0; i < this.nestedArray.length; ++i)
  2231. if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath))) {
  2232. exact = found;
  2233. break;
  2234. }
  2235. }
  2236. // Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.
  2237. this._lookupCache[flatPath] = exact;
  2238. return exact;
  2239. };
  2240. /**
  2241. * Looks up the reflection object at the specified path, relative to this namespace.
  2242. * @name NamespaceBase#lookup
  2243. * @function
  2244. * @param {string|string[]} path Path to look up
  2245. * @param {boolean} [parentAlreadyChecked=false] Whether the parent has already been checked
  2246. * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
  2247. * @variation 2
  2248. */
  2249. // lookup(path: string, [parentAlreadyChecked: boolean])
  2250. /**
  2251. * Looks up the {@link Type|type} at the specified path, relative to this namespace.
  2252. * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
  2253. * @param {string|string[]} path Path to look up
  2254. * @returns {Type} Looked up type
  2255. * @throws {Error} If `path` does not point to a type
  2256. */
  2257. Namespace.prototype.lookupType = function lookupType(path) {
  2258. var found = this.lookup(path, [ Type ]);
  2259. if (!found)
  2260. throw Error("no such type: " + path);
  2261. return found;
  2262. };
  2263. /**
  2264. * Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
  2265. * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
  2266. * @param {string|string[]} path Path to look up
  2267. * @returns {Enum} Looked up enum
  2268. * @throws {Error} If `path` does not point to an enum
  2269. */
  2270. Namespace.prototype.lookupEnum = function lookupEnum(path) {
  2271. var found = this.lookup(path, [ Enum ]);
  2272. if (!found)
  2273. throw Error("no such Enum '" + path + "' in " + this);
  2274. return found;
  2275. };
  2276. /**
  2277. * Looks up the {@link Type|type} or {@link Enum|enum} at the specified path, relative to this namespace.
  2278. * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
  2279. * @param {string|string[]} path Path to look up
  2280. * @returns {Type} Looked up type or enum
  2281. * @throws {Error} If `path` does not point to a type or enum
  2282. */
  2283. Namespace.prototype.lookupTypeOrEnum = function lookupTypeOrEnum(path) {
  2284. var found = this.lookup(path, [ Type, Enum ]);
  2285. if (!found)
  2286. throw Error("no such Type or Enum '" + path + "' in " + this);
  2287. return found;
  2288. };
  2289. /**
  2290. * Looks up the {@link Service|service} at the specified path, relative to this namespace.
  2291. * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
  2292. * @param {string|string[]} path Path to look up
  2293. * @returns {Service} Looked up service
  2294. * @throws {Error} If `path` does not point to a service
  2295. */
  2296. Namespace.prototype.lookupService = function lookupService(path) {
  2297. var found = this.lookup(path, [ Service ]);
  2298. if (!found)
  2299. throw Error("no such Service '" + path + "' in " + this);
  2300. return found;
  2301. };
  2302. // Sets up cyclic dependencies (called in index-light)
  2303. Namespace._configure = function(Type_, Service_, Enum_) {
  2304. Type = Type_;
  2305. Service = Service_;
  2306. Enum = Enum_;
  2307. };
  2308. },{"13":13,"14":14,"24":24,"6":6}],13:[function(require,module,exports){
  2309. "use strict";
  2310. module.exports = ReflectionObject;
  2311. ReflectionObject.className = "ReflectionObject";
  2312. const OneOf = require(14);
  2313. var util = require(24);
  2314. var Root; // cyclic
  2315. /* eslint-disable no-warning-comments */
  2316. // TODO: Replace with embedded proto.
  2317. var editions2024Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE2024", default_symbol_visibility: "EXPORT_TOP_LEVEL" };
  2318. var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
  2319. var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
  2320. var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
  2321. /**
  2322. * Constructs a new reflection object instance.
  2323. * @classdesc Base class of all reflection objects.
  2324. * @constructor
  2325. * @param {string} name Object name
  2326. * @param {Object.<string,*>} [options] Declared options
  2327. * @abstract
  2328. */
  2329. function ReflectionObject(name, options) {
  2330. if (!util.isString(name))
  2331. throw TypeError("name must be a string");
  2332. if (options && !util.isObject(options))
  2333. throw TypeError("options must be an object");
  2334. /**
  2335. * Options.
  2336. * @type {Object.<string,*>|undefined}
  2337. */
  2338. this.options = options; // toJSON
  2339. /**
  2340. * Parsed Options.
  2341. * @type {Array.<Object.<string,*>>|undefined}
  2342. */
  2343. this.parsedOptions = null;
  2344. /**
  2345. * Unique name within its namespace.
  2346. * @type {string}
  2347. */
  2348. this.name = name;
  2349. /**
  2350. * The edition specified for this object. Only relevant for top-level objects.
  2351. * @type {string}
  2352. * @private
  2353. */
  2354. this._edition = null;
  2355. /**
  2356. * The default edition to use for this object if none is specified. For legacy reasons,
  2357. * this is proto2 except in the JSON parsing case where it was proto3.
  2358. * @type {string}
  2359. * @private
  2360. */
  2361. this._defaultEdition = "proto2";
  2362. /**
  2363. * Resolved Features.
  2364. * @type {object}
  2365. * @private
  2366. */
  2367. this._features = {};
  2368. /**
  2369. * Whether or not features have been resolved.
  2370. * @type {boolean}
  2371. * @private
  2372. */
  2373. this._featuresResolved = false;
  2374. /**
  2375. * Parent namespace.
  2376. * @type {Namespace|null}
  2377. */
  2378. this.parent = null;
  2379. /**
  2380. * Whether already resolved or not.
  2381. * @type {boolean}
  2382. */
  2383. this.resolved = false;
  2384. /**
  2385. * Comment text, if any.
  2386. * @type {string|null}
  2387. */
  2388. this.comment = null;
  2389. /**
  2390. * Defining file name.
  2391. * @type {string|null}
  2392. */
  2393. this.filename = null;
  2394. }
  2395. Object.defineProperties(ReflectionObject.prototype, {
  2396. /**
  2397. * Reference to the root namespace.
  2398. * @name ReflectionObject#root
  2399. * @type {Root}
  2400. * @readonly
  2401. */
  2402. root: {
  2403. get: function() {
  2404. var ptr = this;
  2405. while (ptr.parent !== null)
  2406. ptr = ptr.parent;
  2407. return ptr;
  2408. }
  2409. },
  2410. /**
  2411. * Full name including leading dot.
  2412. * @name ReflectionObject#fullName
  2413. * @type {string}
  2414. * @readonly
  2415. */
  2416. fullName: {
  2417. get: function() {
  2418. var path = [ this.name ],
  2419. ptr = this.parent;
  2420. while (ptr) {
  2421. path.unshift(ptr.name);
  2422. ptr = ptr.parent;
  2423. }
  2424. return path.join(".");
  2425. }
  2426. }
  2427. });
  2428. /**
  2429. * Converts this reflection object to its descriptor representation.
  2430. * @returns {Object.<string,*>} Descriptor
  2431. */
  2432. ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
  2433. throw Error(); // not implemented, shouldn't happen
  2434. };
  2435. /**
  2436. * Called when this object is added to a parent.
  2437. * @param {ReflectionObject} parent Parent added to
  2438. * @returns {undefined}
  2439. */
  2440. ReflectionObject.prototype.onAdd = function onAdd(parent) {
  2441. if (this.parent && this.parent !== parent)
  2442. this.parent.remove(this);
  2443. this.parent = parent;
  2444. this.resolved = false;
  2445. var root = parent.root;
  2446. if (root instanceof Root)
  2447. root._handleAdd(this);
  2448. };
  2449. /**
  2450. * Called when this object is removed from a parent.
  2451. * @param {ReflectionObject} parent Parent removed from
  2452. * @returns {undefined}
  2453. */
  2454. ReflectionObject.prototype.onRemove = function onRemove(parent) {
  2455. var root = parent.root;
  2456. if (root instanceof Root)
  2457. root._handleRemove(this);
  2458. this.parent = null;
  2459. this.resolved = false;
  2460. };
  2461. /**
  2462. * Resolves this objects type references.
  2463. * @returns {ReflectionObject} `this`
  2464. */
  2465. ReflectionObject.prototype.resolve = function resolve() {
  2466. if (this.resolved)
  2467. return this;
  2468. if (this.root instanceof Root)
  2469. this.resolved = true; // only if part of a root
  2470. return this;
  2471. };
  2472. /**
  2473. * Resolves this objects editions features.
  2474. * @param {string} edition The edition we're currently resolving for.
  2475. * @returns {ReflectionObject} `this`
  2476. */
  2477. ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
  2478. return this._resolveFeatures(this._edition || edition);
  2479. };
  2480. /**
  2481. * Resolves child features from parent features
  2482. * @param {string} edition The edition we're currently resolving for.
  2483. * @returns {undefined}
  2484. */
  2485. ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
  2486. if (this._featuresResolved) {
  2487. return;
  2488. }
  2489. var defaults = {};
  2490. /* istanbul ignore if */
  2491. if (!edition) {
  2492. throw new Error("Unknown edition for " + this.fullName);
  2493. }
  2494. var protoFeatures = util.merge({}, this.options && this.options.features,
  2495. this._inferLegacyProtoFeatures(edition));
  2496. if (this._edition) {
  2497. // For a namespace marked with a specific edition, reset defaults.
  2498. /* istanbul ignore else */
  2499. if (edition === "proto2") {
  2500. defaults = Object.assign({}, proto2Defaults);
  2501. } else if (edition === "proto3") {
  2502. defaults = Object.assign({}, proto3Defaults);
  2503. } else if (edition === "2023") {
  2504. defaults = Object.assign({}, editions2023Defaults);
  2505. } else if (edition === "2024") {
  2506. defaults = Object.assign({}, editions2024Defaults);
  2507. } else {
  2508. throw new Error("Unknown edition: " + edition);
  2509. }
  2510. this._features = util.merge(defaults, protoFeatures);
  2511. } else {
  2512. // fields in Oneofs aren't actually children of them, so we have to
  2513. // special-case it
  2514. /* istanbul ignore else */
  2515. if (this.partOf instanceof OneOf) {
  2516. var lexicalParentFeaturesCopy = util.merge({}, this.partOf._features);
  2517. this._features = util.merge(lexicalParentFeaturesCopy, protoFeatures);
  2518. } else if (this.declaringField) {
  2519. // Skip feature resolution of sister fields.
  2520. } else if (this.parent) {
  2521. var parentFeaturesCopy = util.merge({}, this.parent._features);
  2522. this._features = util.merge(parentFeaturesCopy, protoFeatures);
  2523. } else {
  2524. throw new Error("Unable to find a parent for " + this.fullName);
  2525. }
  2526. }
  2527. if (this.extensionField) {
  2528. // Sister fields should have the same features as their extensions.
  2529. this.extensionField._features = this._features;
  2530. }
  2531. this._featuresResolved = true;
  2532. };
  2533. /**
  2534. * Infers features from legacy syntax that may have been specified differently.
  2535. * in older editions.
  2536. * @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
  2537. * @returns {object} The feature values to override
  2538. */
  2539. ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(/*edition*/) {
  2540. return {};
  2541. };
  2542. /**
  2543. * Gets an option value.
  2544. * @param {string} name Option name
  2545. * @returns {*} Option value or `undefined` if not set
  2546. */
  2547. ReflectionObject.prototype.getOption = function getOption(name) {
  2548. if (this.options)
  2549. return this.options[name];
  2550. return undefined;
  2551. };
  2552. /**
  2553. * Sets an option.
  2554. * @param {string} name Option name
  2555. * @param {*} value Option value
  2556. * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
  2557. * @returns {ReflectionObject} `this`
  2558. */
  2559. ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
  2560. if (name === "__proto__")
  2561. return this;
  2562. if (!this.options)
  2563. this.options = {};
  2564. if (/^features\./.test(name)) {
  2565. util.setProperty(this.options, name, value, ifNotSet);
  2566. } else if (!ifNotSet || this.options[name] === undefined) {
  2567. if (this.getOption(name) !== value) this.resolved = false;
  2568. this.options[name] = value;
  2569. }
  2570. return this;
  2571. };
  2572. /**
  2573. * Sets a parsed option.
  2574. * @param {string} name parsed Option name
  2575. * @param {*} value Option value
  2576. * @param {string} propName dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value
  2577. * @returns {ReflectionObject} `this`
  2578. */
  2579. ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
  2580. if (name === "__proto__")
  2581. return this;
  2582. if (!this.parsedOptions) {
  2583. this.parsedOptions = [];
  2584. }
  2585. var parsedOptions = this.parsedOptions;
  2586. if (propName) {
  2587. // If setting a sub property of an option then try to merge it
  2588. // with an existing option
  2589. var opt = parsedOptions.find(function (opt) {
  2590. return Object.prototype.hasOwnProperty.call(opt, name);
  2591. });
  2592. if (opt) {
  2593. // If we found an existing option - just merge the property value
  2594. // (If it's a feature, will just write over)
  2595. var newValue = opt[name];
  2596. util.setProperty(newValue, propName, value);
  2597. } else {
  2598. // otherwise, create a new option, set its property and add it to the list
  2599. opt = {};
  2600. opt[name] = util.setProperty({}, propName, value);
  2601. parsedOptions.push(opt);
  2602. }
  2603. } else {
  2604. // Always create a new option when setting the value of the option itself
  2605. var newOpt = {};
  2606. newOpt[name] = value;
  2607. parsedOptions.push(newOpt);
  2608. }
  2609. return this;
  2610. };
  2611. /**
  2612. * Sets multiple options.
  2613. * @param {Object.<string,*>} options Options to set
  2614. * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
  2615. * @returns {ReflectionObject} `this`
  2616. */
  2617. ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
  2618. if (options)
  2619. for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)
  2620. this.setOption(keys[i], options[keys[i]], ifNotSet);
  2621. return this;
  2622. };
  2623. /**
  2624. * Converts this instance to its string representation.
  2625. * @returns {string} Class name[, space, full name]
  2626. */
  2627. ReflectionObject.prototype.toString = function toString() {
  2628. var className = this.constructor.className,
  2629. fullName = this.fullName;
  2630. if (fullName.length)
  2631. return className + " " + fullName;
  2632. return className;
  2633. };
  2634. /**
  2635. * Converts the edition this object is pinned to for JSON format.
  2636. * @returns {string|undefined} The edition string for JSON representation
  2637. */
  2638. ReflectionObject.prototype._editionToJSON = function _editionToJSON() {
  2639. if (!this._edition || this._edition === "proto3") {
  2640. // Avoid emitting proto3 since we need to default to it for backwards
  2641. // compatibility anyway.
  2642. return undefined;
  2643. }
  2644. return this._edition;
  2645. };
  2646. // Sets up cyclic dependencies (called in index-light)
  2647. ReflectionObject._configure = function(Root_) {
  2648. Root = Root_;
  2649. };
  2650. },{"14":14,"24":24}],14:[function(require,module,exports){
  2651. "use strict";
  2652. module.exports = OneOf;
  2653. // extends ReflectionObject
  2654. var ReflectionObject = require(13);
  2655. ((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
  2656. var Field = require(6),
  2657. util = require(24);
  2658. /**
  2659. * Constructs a new oneof instance.
  2660. * @classdesc Reflected oneof.
  2661. * @extends ReflectionObject
  2662. * @constructor
  2663. * @param {string} name Oneof name
  2664. * @param {string[]|Object.<string,*>} [fieldNames] Field names
  2665. * @param {Object.<string,*>} [options] Declared options
  2666. * @param {string} [comment] Comment associated with this field
  2667. */
  2668. function OneOf(name, fieldNames, options, comment) {
  2669. if (!Array.isArray(fieldNames)) {
  2670. options = fieldNames;
  2671. fieldNames = undefined;
  2672. }
  2673. ReflectionObject.call(this, name, options);
  2674. /* istanbul ignore if */
  2675. if (!(fieldNames === undefined || Array.isArray(fieldNames)))
  2676. throw TypeError("fieldNames must be an Array");
  2677. /**
  2678. * Field names that belong to this oneof.
  2679. * @type {string[]}
  2680. */
  2681. this.oneof = fieldNames || []; // toJSON, marker
  2682. /**
  2683. * Fields that belong to this oneof as an array for iteration.
  2684. * @type {Field[]}
  2685. * @readonly
  2686. */
  2687. this.fieldsArray = []; // declared readonly for conformance, possibly not yet added to parent
  2688. /**
  2689. * Comment for this field.
  2690. * @type {string|null}
  2691. */
  2692. this.comment = comment;
  2693. }
  2694. /**
  2695. * Oneof descriptor.
  2696. * @interface IOneOf
  2697. * @property {Array.<string>} oneof Oneof field names
  2698. * @property {Object.<string,*>} [options] Oneof options
  2699. * @property {string|null} [comment] Oneof comment
  2700. */
  2701. /**
  2702. * Constructs a oneof from a oneof descriptor.
  2703. * @param {string} name Oneof name
  2704. * @param {IOneOf} json Oneof descriptor
  2705. * @returns {OneOf} Created oneof
  2706. * @throws {TypeError} If arguments are invalid
  2707. */
  2708. OneOf.fromJSON = function fromJSON(name, json) {
  2709. return new OneOf(name, json.oneof, json.options, json.comment);
  2710. };
  2711. /**
  2712. * Converts this oneof to a oneof descriptor.
  2713. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  2714. * @returns {IOneOf} Oneof descriptor
  2715. */
  2716. OneOf.prototype.toJSON = function toJSON(toJSONOptions) {
  2717. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  2718. return util.toObject([
  2719. "options" , this.options,
  2720. "oneof" , this.oneof,
  2721. "comment" , keepComments ? this.comment : undefined
  2722. ]);
  2723. };
  2724. /**
  2725. * Adds the fields of the specified oneof to the parent if not already done so.
  2726. * @param {OneOf} oneof The oneof
  2727. * @returns {undefined}
  2728. * @inner
  2729. * @ignore
  2730. */
  2731. function addFieldsToParent(oneof) {
  2732. if (oneof.parent)
  2733. for (var i = 0; i < oneof.fieldsArray.length; ++i)
  2734. if (!oneof.fieldsArray[i].parent)
  2735. oneof.parent.add(oneof.fieldsArray[i]);
  2736. }
  2737. /**
  2738. * Adds a field to this oneof and removes it from its current parent, if any.
  2739. * @param {Field} field Field to add
  2740. * @returns {OneOf} `this`
  2741. */
  2742. OneOf.prototype.add = function add(field) {
  2743. /* istanbul ignore if */
  2744. if (!(field instanceof Field))
  2745. throw TypeError("field must be a Field");
  2746. if (field.parent && field.parent !== this.parent)
  2747. field.parent.remove(field);
  2748. this.oneof.push(field.name);
  2749. this.fieldsArray.push(field);
  2750. field.partOf = this; // field.parent remains null
  2751. addFieldsToParent(this);
  2752. return this;
  2753. };
  2754. /**
  2755. * Removes a field from this oneof and puts it back to the oneof's parent.
  2756. * @param {Field} field Field to remove
  2757. * @returns {OneOf} `this`
  2758. */
  2759. OneOf.prototype.remove = function remove(field) {
  2760. /* istanbul ignore if */
  2761. if (!(field instanceof Field))
  2762. throw TypeError("field must be a Field");
  2763. var index = this.fieldsArray.indexOf(field);
  2764. /* istanbul ignore if */
  2765. if (index < 0)
  2766. throw Error(field + " is not a member of " + this);
  2767. this.fieldsArray.splice(index, 1);
  2768. index = this.oneof.indexOf(field.name);
  2769. /* istanbul ignore else */
  2770. if (index > -1) // theoretical
  2771. this.oneof.splice(index, 1);
  2772. field.partOf = null;
  2773. return this;
  2774. };
  2775. /**
  2776. * @override
  2777. */
  2778. OneOf.prototype.onAdd = function onAdd(parent) {
  2779. ReflectionObject.prototype.onAdd.call(this, parent);
  2780. var self = this;
  2781. // Collect present fields
  2782. for (var i = 0; i < this.oneof.length; ++i) {
  2783. var field = parent.get(this.oneof[i]);
  2784. if (field && !field.partOf) {
  2785. field.partOf = self;
  2786. self.fieldsArray.push(field);
  2787. }
  2788. }
  2789. // Add not yet present fields
  2790. addFieldsToParent(this);
  2791. };
  2792. /**
  2793. * @override
  2794. */
  2795. OneOf.prototype.onRemove = function onRemove(parent) {
  2796. for (var i = 0, field; i < this.fieldsArray.length; ++i)
  2797. if ((field = this.fieldsArray[i]).parent)
  2798. field.parent.remove(field);
  2799. ReflectionObject.prototype.onRemove.call(this, parent);
  2800. };
  2801. /**
  2802. * Determines whether this field corresponds to a synthetic oneof created for
  2803. * a proto3 optional field. No behavioral logic should depend on this, but it
  2804. * can be relevant for reflection.
  2805. * @name OneOf#isProto3Optional
  2806. * @type {boolean}
  2807. * @readonly
  2808. */
  2809. Object.defineProperty(OneOf.prototype, "isProto3Optional", {
  2810. get: function() {
  2811. if (this.fieldsArray == null || this.fieldsArray.length !== 1) {
  2812. return false;
  2813. }
  2814. var field = this.fieldsArray[0];
  2815. return field.options != null && field.options["proto3_optional"] === true;
  2816. }
  2817. });
  2818. /**
  2819. * Decorator function as returned by {@link OneOf.d} (TypeScript).
  2820. * @typedef OneOfDecorator
  2821. * @type {function}
  2822. * @param {Object} prototype Target prototype
  2823. * @param {string} oneofName OneOf name
  2824. * @returns {undefined}
  2825. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  2826. */
  2827. /**
  2828. * OneOf decorator (TypeScript).
  2829. * @function
  2830. * @param {...string} fieldNames Field names
  2831. * @returns {OneOfDecorator} Decorator function
  2832. * @template T extends string
  2833. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  2834. */
  2835. OneOf.d = function decorateOneOf() {
  2836. var fieldNames = new Array(arguments.length),
  2837. index = 0;
  2838. while (index < arguments.length)
  2839. fieldNames[index] = arguments[index++];
  2840. return function oneOfDecorator(prototype, oneofName) {
  2841. util.decorateType(prototype.constructor)
  2842. .add(new OneOf(oneofName, fieldNames));
  2843. Object.defineProperty(prototype, oneofName, {
  2844. get: util.oneOfGetter(fieldNames),
  2845. set: util.oneOfSetter(fieldNames)
  2846. });
  2847. };
  2848. };
  2849. },{"13":13,"24":24,"6":6}],15:[function(require,module,exports){
  2850. "use strict";
  2851. module.exports = Reader;
  2852. var util = require(33);
  2853. var BufferReader; // cyclic
  2854. var LongBits = util.LongBits,
  2855. utf8 = util.utf8;
  2856. /* istanbul ignore next */
  2857. function indexOutOfRange(reader, writeLength) {
  2858. return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
  2859. }
  2860. /**
  2861. * Constructs a new reader instance using the specified buffer.
  2862. * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
  2863. * @constructor
  2864. * @param {Uint8Array} buffer Buffer to read from
  2865. */
  2866. function Reader(buffer) {
  2867. /**
  2868. * Read buffer.
  2869. * @type {Uint8Array}
  2870. */
  2871. this.buf = buffer;
  2872. /**
  2873. * Read buffer position.
  2874. * @type {number}
  2875. */
  2876. this.pos = 0;
  2877. /**
  2878. * Read buffer length.
  2879. * @type {number}
  2880. */
  2881. this.len = buffer.length;
  2882. /**
  2883. * Whether to discard unknown fields while decoding.
  2884. * @type {boolean}
  2885. */
  2886. this.discardUnknown = Reader.discardUnknown;
  2887. }
  2888. var create_array = typeof Uint8Array !== "undefined"
  2889. ? function create_typed_array(buffer) {
  2890. if (buffer instanceof Uint8Array || Array.isArray(buffer))
  2891. return new Reader(buffer);
  2892. throw Error("illegal buffer");
  2893. }
  2894. /* istanbul ignore next */
  2895. : function create_array(buffer) {
  2896. if (Array.isArray(buffer))
  2897. return new Reader(buffer);
  2898. throw Error("illegal buffer");
  2899. };
  2900. var create = function create() {
  2901. return util.Buffer
  2902. ? function create_buffer_setup(buffer) {
  2903. return (Reader.create = function create_buffer(buffer) {
  2904. return util.Buffer.isBuffer(buffer)
  2905. ? new BufferReader(buffer)
  2906. /* istanbul ignore next */
  2907. : create_array(buffer);
  2908. })(buffer);
  2909. }
  2910. /* istanbul ignore next */
  2911. : create_array;
  2912. };
  2913. /**
  2914. * Creates a new reader using the specified buffer.
  2915. * @function
  2916. * @param {Uint8Array|Buffer} buffer Buffer to read from
  2917. * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
  2918. * @throws {Error} If `buffer` is not a valid buffer
  2919. */
  2920. Reader.create = create();
  2921. Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
  2922. /**
  2923. * Returns raw bytes from the backing buffer without advancing the reader.
  2924. * @param {number} start Start offset
  2925. * @param {number} end End offset
  2926. * @returns {Uint8Array} Raw bytes
  2927. */
  2928. Reader.prototype.raw = function read_raw(start, end) {
  2929. if (Array.isArray(this.buf)) // plain array
  2930. return this.buf.slice(start, end);
  2931. if (start === end) // fix for IE 10/Win8 and others' subarray returning array of size 1
  2932. return new this.buf.constructor(0);
  2933. return this._slice.call(this.buf, start, end);
  2934. };
  2935. /**
  2936. * Reads a varint as an unsigned 32 bit value.
  2937. * @function
  2938. * @returns {number} Value read
  2939. */
  2940. Reader.prototype.uint32 = function read_uint32() {
  2941. var buf = this.buf,
  2942. pos = this.pos,
  2943. value = (buf[pos] & 127) >>> 0;
  2944. if (buf[pos++] < 128) {
  2945. this.pos = pos;
  2946. return value;
  2947. }
  2948. value = (value | (buf[pos] & 127) << 7) >>> 0;
  2949. if (buf[pos++] < 128) {
  2950. this.pos = pos;
  2951. return value;
  2952. }
  2953. value = (value | (buf[pos] & 127) << 14) >>> 0;
  2954. if (buf[pos++] < 128) {
  2955. this.pos = pos;
  2956. return value;
  2957. }
  2958. value = (value | (buf[pos] & 127) << 21) >>> 0;
  2959. if (buf[pos++] < 128) {
  2960. this.pos = pos;
  2961. return value;
  2962. }
  2963. value = (value | (buf[pos] & 15) << 28) >>> 0;
  2964. if (buf[pos++] < 128) {
  2965. this.pos = pos;
  2966. return value;
  2967. }
  2968. for (var i = 0; i < 5; ++i) {
  2969. /* istanbul ignore if */
  2970. if (pos >= this.len) {
  2971. this.pos = pos;
  2972. throw indexOutOfRange(this);
  2973. }
  2974. if (buf[pos++] < 128) {
  2975. this.pos = pos;
  2976. return value;
  2977. }
  2978. }
  2979. /* istanbul ignore next */
  2980. this.pos = pos;
  2981. throw Error("invalid varint encoding");
  2982. };
  2983. /**
  2984. * Reads a field tag.
  2985. * @function
  2986. * @returns {number} Tag read
  2987. */
  2988. Reader.prototype.tag = function read_tag() {
  2989. var buf = this.buf,
  2990. pos = this.pos,
  2991. value = (buf[pos] & 127) >>> 0;
  2992. if (buf[pos++] < 128) {
  2993. this.pos = pos;
  2994. return value;
  2995. }
  2996. value = (value | (buf[pos] & 127) << 7) >>> 0;
  2997. if (buf[pos++] < 128) {
  2998. this.pos = pos;
  2999. return value;
  3000. }
  3001. value = (value | (buf[pos] & 127) << 14) >>> 0;
  3002. if (buf[pos++] < 128) {
  3003. this.pos = pos;
  3004. return value;
  3005. }
  3006. value = (value | (buf[pos] & 127) << 21) >>> 0;
  3007. if (buf[pos++] < 128) {
  3008. this.pos = pos;
  3009. return value;
  3010. }
  3011. value = (value | (buf[pos] & 15) << 28) >>> 0;
  3012. if (buf[pos] < 128 && (buf[pos] & 112) === 0) {
  3013. this.pos = pos + 1;
  3014. return value;
  3015. }
  3016. this.pos = pos + 1;
  3017. throw Error("invalid tag encoding");
  3018. };
  3019. /**
  3020. * Reads a varint as a signed 32 bit value.
  3021. * @returns {number} Value read
  3022. */
  3023. Reader.prototype.int32 = function read_int32() {
  3024. return this.uint32() | 0;
  3025. };
  3026. /**
  3027. * Reads a zig-zag encoded varint as a signed 32 bit value.
  3028. * @returns {number} Value read
  3029. */
  3030. Reader.prototype.sint32 = function read_sint32() {
  3031. var value = this.uint32();
  3032. return value >>> 1 ^ -(value & 1) | 0;
  3033. };
  3034. /* eslint-disable no-invalid-this */
  3035. function readLongVarint() {
  3036. // tends to deopt with local vars for octet etc.
  3037. var bits = new LongBits(0, 0);
  3038. var i = 0;
  3039. if (this.len - this.pos > 4) { // fast route (lo)
  3040. for (; i < 4; ++i) {
  3041. // 1st..4th
  3042. bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
  3043. if (this.buf[this.pos++] < 128)
  3044. return bits;
  3045. }
  3046. // 5th
  3047. bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
  3048. bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
  3049. if (this.buf[this.pos++] < 128)
  3050. return bits;
  3051. i = 0;
  3052. } else {
  3053. for (; i < 4; ++i) {
  3054. /* istanbul ignore if */
  3055. if (this.pos >= this.len)
  3056. throw indexOutOfRange(this);
  3057. // 1st..4th
  3058. bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
  3059. if (this.buf[this.pos++] < 128)
  3060. return bits;
  3061. }
  3062. throw indexOutOfRange(this);
  3063. }
  3064. if (this.len - this.pos > 4) { // fast route (hi)
  3065. for (; i < 5; ++i) {
  3066. // 6th..10th
  3067. bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
  3068. if (this.buf[this.pos++] < 128)
  3069. return bits;
  3070. }
  3071. } else {
  3072. for (; i < 5; ++i) {
  3073. /* istanbul ignore if */
  3074. if (this.pos >= this.len)
  3075. throw indexOutOfRange(this);
  3076. // 6th..10th
  3077. bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
  3078. if (this.buf[this.pos++] < 128)
  3079. return bits;
  3080. }
  3081. }
  3082. /* istanbul ignore next */
  3083. throw Error("invalid varint encoding");
  3084. }
  3085. /* eslint-enable no-invalid-this */
  3086. /**
  3087. * Reads a varint as a signed 64 bit value.
  3088. * @name Reader#int64
  3089. * @function
  3090. * @returns {Long} Value read
  3091. */
  3092. /**
  3093. * Reads a varint as an unsigned 64 bit value.
  3094. * @name Reader#uint64
  3095. * @function
  3096. * @returns {Long} Value read
  3097. */
  3098. /**
  3099. * Reads a zig-zag encoded varint as a signed 64 bit value.
  3100. * @name Reader#sint64
  3101. * @function
  3102. * @returns {Long} Value read
  3103. */
  3104. /**
  3105. * Reads a varint as a boolean.
  3106. * @returns {boolean} Value read
  3107. */
  3108. Reader.prototype.bool = function read_bool() {
  3109. var value = false,
  3110. b;
  3111. for (var i = 0; i < 10; ++i) {
  3112. /* istanbul ignore if */
  3113. if (this.pos >= this.len)
  3114. throw indexOutOfRange(this);
  3115. b = this.buf[this.pos++];
  3116. if (b & 127)
  3117. value = true;
  3118. if (b < 128)
  3119. return value;
  3120. }
  3121. /* istanbul ignore next */
  3122. throw Error("invalid varint encoding");
  3123. };
  3124. function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
  3125. return (buf[end - 4]
  3126. | buf[end - 3] << 8
  3127. | buf[end - 2] << 16
  3128. | buf[end - 1] << 24) >>> 0;
  3129. }
  3130. /**
  3131. * Reads fixed 32 bits as an unsigned 32 bit integer.
  3132. * @returns {number} Value read
  3133. */
  3134. Reader.prototype.fixed32 = function read_fixed32() {
  3135. /* istanbul ignore if */
  3136. if (this.pos + 4 > this.len)
  3137. throw indexOutOfRange(this, 4);
  3138. return readFixed32_end(this.buf, this.pos += 4);
  3139. };
  3140. /**
  3141. * Reads fixed 32 bits as a signed 32 bit integer.
  3142. * @returns {number} Value read
  3143. */
  3144. Reader.prototype.sfixed32 = function read_sfixed32() {
  3145. /* istanbul ignore if */
  3146. if (this.pos + 4 > this.len)
  3147. throw indexOutOfRange(this, 4);
  3148. return readFixed32_end(this.buf, this.pos += 4) | 0;
  3149. };
  3150. /* eslint-disable no-invalid-this */
  3151. function readFixed64(/* this: Reader */) {
  3152. /* istanbul ignore if */
  3153. if (this.pos + 8 > this.len)
  3154. throw indexOutOfRange(this, 8);
  3155. return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
  3156. }
  3157. /* eslint-enable no-invalid-this */
  3158. /**
  3159. * Reads fixed 64 bits.
  3160. * @name Reader#fixed64
  3161. * @function
  3162. * @returns {Long} Value read
  3163. */
  3164. /**
  3165. * Reads zig-zag encoded fixed 64 bits.
  3166. * @name Reader#sfixed64
  3167. * @function
  3168. * @returns {Long} Value read
  3169. */
  3170. /**
  3171. * Reads a float (32 bit) as a number.
  3172. * @function
  3173. * @returns {number} Value read
  3174. */
  3175. Reader.prototype.float = function read_float() {
  3176. /* istanbul ignore if */
  3177. if (this.pos + 4 > this.len)
  3178. throw indexOutOfRange(this, 4);
  3179. var value = util.float.readFloatLE(this.buf, this.pos);
  3180. this.pos += 4;
  3181. return value;
  3182. };
  3183. /**
  3184. * Reads a double (64 bit float) as a number.
  3185. * @function
  3186. * @returns {number} Value read
  3187. */
  3188. Reader.prototype.double = function read_double() {
  3189. /* istanbul ignore if */
  3190. if (this.pos + 8 > this.len)
  3191. throw indexOutOfRange(this, 4);
  3192. var value = util.float.readDoubleLE(this.buf, this.pos);
  3193. this.pos += 8;
  3194. return value;
  3195. };
  3196. /**
  3197. * Reads a sequence of bytes preceeded by its length as a varint.
  3198. * @returns {Uint8Array} Value read
  3199. */
  3200. Reader.prototype.bytes = function read_bytes() {
  3201. var length = this.uint32(),
  3202. start = this.pos,
  3203. end = this.pos + length;
  3204. /* istanbul ignore if */
  3205. if (end > this.len)
  3206. throw indexOutOfRange(this, length);
  3207. this.pos = end;
  3208. return this.raw(start, end);
  3209. };
  3210. /**
  3211. * Reads a string preceeded by its byte length as a varint.
  3212. * @returns {string} Value read
  3213. */
  3214. Reader.prototype.string = function read_string() {
  3215. var length = this.uint32(),
  3216. start = this.pos,
  3217. end = this.pos + length;
  3218. /* istanbul ignore if */
  3219. if (end > this.len)
  3220. throw indexOutOfRange(this, length);
  3221. this.pos = end;
  3222. return utf8.read(this.buf, start, end);
  3223. };
  3224. /**
  3225. * Reads a string preceeded by its byte length as a varint, rejecting invalid UTF8.
  3226. * @returns {string} Value read
  3227. */
  3228. Reader.prototype.stringVerify = function read_string_verify() {
  3229. var length = this.uint32(),
  3230. start = this.pos,
  3231. end = this.pos + length;
  3232. /* istanbul ignore if */
  3233. if (end > this.len)
  3234. throw indexOutOfRange(this, length);
  3235. this.pos = end;
  3236. return utf8.readStrict(this.buf, start, end);
  3237. };
  3238. /**
  3239. * Skips the specified number of bytes if specified, otherwise skips a varint.
  3240. * @param {number} [length] Length if known, otherwise a varint is assumed
  3241. * @returns {Reader} `this`
  3242. */
  3243. Reader.prototype.skip = function skip(length) {
  3244. if (typeof length === "number") {
  3245. /* istanbul ignore if */
  3246. if (this.pos + length > this.len)
  3247. throw indexOutOfRange(this, length);
  3248. this.pos += length;
  3249. } else {
  3250. do {
  3251. /* istanbul ignore if */
  3252. if (this.pos >= this.len)
  3253. throw indexOutOfRange(this);
  3254. } while (this.buf[this.pos++] & 128);
  3255. }
  3256. return this;
  3257. };
  3258. /**
  3259. * Recursion limit.
  3260. * @type {number}
  3261. */
  3262. Reader.recursionLimit = util.recursionLimit;
  3263. /**
  3264. * Whether readers discard unknown fields while decoding.
  3265. * @type {boolean}
  3266. */
  3267. Reader.discardUnknown = true;
  3268. /**
  3269. * Skips the next element of the specified wire type.
  3270. * @param {number} wireType Wire type received
  3271. * @param {number} [depth] Depth of recursion to control nested calls; 0 if omitted
  3272. * @param {number} [fieldNumber] Field number for validating group end tags
  3273. * @returns {Reader} `this`
  3274. */
  3275. Reader.prototype.skipType = function(wireType, depth, fieldNumber) {
  3276. if (depth === undefined) depth = 0;
  3277. if (depth > Reader.recursionLimit)
  3278. throw Error("max depth exceeded");
  3279. if (fieldNumber === 0)
  3280. throw Error("illegal tag: field number 0");
  3281. switch (wireType) {
  3282. case 0:
  3283. this.skip();
  3284. break;
  3285. case 1:
  3286. this.skip(8);
  3287. break;
  3288. case 2:
  3289. this.skip(this.uint32());
  3290. break;
  3291. case 3:
  3292. while (true) {
  3293. var tag = this.tag();
  3294. var nestedField = tag >>> 3;
  3295. wireType = tag & 7;
  3296. if (!nestedField)
  3297. throw Error("illegal tag: field number 0");
  3298. if (wireType === 4) {
  3299. if (fieldNumber !== undefined && nestedField !== fieldNumber)
  3300. throw Error("invalid end group tag");
  3301. break;
  3302. }
  3303. this.skipType(wireType, depth + 1, nestedField);
  3304. }
  3305. break;
  3306. case 5:
  3307. this.skip(4);
  3308. break;
  3309. /* istanbul ignore next */
  3310. default:
  3311. throw Error("invalid wire type " + wireType + " at offset " + this.pos);
  3312. }
  3313. return this;
  3314. };
  3315. Reader._configure = function(BufferReader_) {
  3316. BufferReader = BufferReader_;
  3317. Reader.create = create();
  3318. BufferReader._configure();
  3319. var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
  3320. util.merge(Reader.prototype, {
  3321. int64: function read_int64() {
  3322. return readLongVarint.call(this)[fn](false);
  3323. },
  3324. uint64: function read_uint64() {
  3325. return readLongVarint.call(this)[fn](true);
  3326. },
  3327. sint64: function read_sint64() {
  3328. return readLongVarint.call(this).zzDecode()[fn](false);
  3329. },
  3330. fixed64: function read_fixed64() {
  3331. return readFixed64.call(this)[fn](true);
  3332. },
  3333. sfixed64: function read_sfixed64() {
  3334. return readFixed64.call(this)[fn](false);
  3335. }
  3336. });
  3337. };
  3338. },{"33":33}],16:[function(require,module,exports){
  3339. "use strict";
  3340. module.exports = BufferReader;
  3341. // extends Reader
  3342. var Reader = require(15);
  3343. (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
  3344. var util = require(33);
  3345. /**
  3346. * Constructs a new buffer reader instance.
  3347. * @classdesc Wire format reader using node buffers.
  3348. * @extends Reader
  3349. * @constructor
  3350. * @param {Buffer} buffer Buffer to read from
  3351. */
  3352. function BufferReader(buffer) {
  3353. Reader.call(this, buffer);
  3354. /**
  3355. * Read buffer.
  3356. * @name BufferReader#buf
  3357. * @type {Buffer}
  3358. */
  3359. }
  3360. BufferReader._configure = function () {
  3361. /* istanbul ignore else */
  3362. if (util.Buffer)
  3363. BufferReader.prototype._slice = util.Buffer.prototype.slice;
  3364. };
  3365. /**
  3366. * Returns raw bytes from the backing buffer without advancing the reader.
  3367. * @name BufferReader#raw
  3368. * @function
  3369. * @param {number} start Start offset
  3370. * @param {number} end End offset
  3371. * @returns {Buffer} Raw bytes
  3372. */
  3373. BufferReader.prototype.raw = function read_raw_buffer(start, end) {
  3374. if (start === end)
  3375. return util.Buffer.alloc(0);
  3376. return this._slice.call(this.buf, start, end);
  3377. };
  3378. /**
  3379. * @override
  3380. */
  3381. BufferReader.prototype.string = function read_string_buffer() {
  3382. var len = this.uint32(), // modifies pos
  3383. start = this.pos,
  3384. end = this.pos + len;
  3385. /* istanbul ignore if */
  3386. if (end > this.len)
  3387. throw RangeError("index out of range: " + this.pos + " + " + len + " > " + this.len);
  3388. this.pos = end;
  3389. return this.buf.utf8Slice
  3390. ? this.buf.utf8Slice(start, end)
  3391. : this.buf.toString("utf-8", start, end);
  3392. };
  3393. /**
  3394. * Reads a sequence of bytes preceeded by its length as a varint.
  3395. * @name BufferReader#bytes
  3396. * @function
  3397. * @returns {Buffer} Value read
  3398. */
  3399. BufferReader._configure();
  3400. },{"15":15,"33":33}],17:[function(require,module,exports){
  3401. "use strict";
  3402. module.exports = Root;
  3403. // extends Namespace
  3404. var Namespace = require(12);
  3405. ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
  3406. var Field = require(6),
  3407. Enum = require(5),
  3408. OneOf = require(14),
  3409. util = require(24);
  3410. var Type, // cyclic
  3411. parse, // might be excluded
  3412. common; // "
  3413. /**
  3414. * Constructs a new root namespace instance.
  3415. * @classdesc Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together.
  3416. * @extends NamespaceBase
  3417. * @constructor
  3418. * @param {Object.<string,*>} [options] Top level options
  3419. */
  3420. function Root(options) {
  3421. Namespace.call(this, "", options);
  3422. /**
  3423. * Deferred extension fields.
  3424. * @type {Field[]}
  3425. */
  3426. this.deferred = [];
  3427. /**
  3428. * Resolved file names of loaded files.
  3429. * @type {string[]}
  3430. */
  3431. this.files = [];
  3432. /**
  3433. * Edition, defaults to proto2 if unspecified.
  3434. * @type {string}
  3435. * @private
  3436. */
  3437. this._edition = "proto2";
  3438. /**
  3439. * Global lookup cache of fully qualified names.
  3440. * @type {Object.<string,ReflectionObject>}
  3441. * @private
  3442. */
  3443. this._fullyQualifiedObjects = {};
  3444. }
  3445. /**
  3446. * Loads a namespace descriptor into a root namespace.
  3447. * @param {INamespace} json Namespace descriptor
  3448. * @param {Root} [root] Root namespace, defaults to create a new one if omitted
  3449. * @param {number} [depth] Current nesting depth, defaults to `0`
  3450. * @returns {Root} Root namespace
  3451. */
  3452. Root.fromJSON = function fromJSON(json, root, depth) {
  3453. if (depth === undefined)
  3454. depth = 0;
  3455. if (depth > util.recursionLimit)
  3456. throw Error("max depth exceeded");
  3457. if (!root)
  3458. root = new Root();
  3459. if (json.options)
  3460. root.setOptions(json.options);
  3461. return root.addJSON(json.nested, depth).resolveAll();
  3462. };
  3463. /**
  3464. * Resolves the path of an imported file, relative to the importing origin.
  3465. * This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.
  3466. * @function
  3467. * @param {string} origin The file name of the importing file
  3468. * @param {string} target The file name being imported
  3469. * @returns {string|null} Resolved path to `target` or `null` to skip the file
  3470. */
  3471. Root.prototype.resolvePath = util.path.resolve;
  3472. /**
  3473. * Fetch content from file path or url
  3474. * This method exists so you can override it with your own logic.
  3475. * @function
  3476. * @param {string} path File path or url
  3477. * @param {FetchCallback} callback Callback function
  3478. * @returns {undefined}
  3479. */
  3480. Root.prototype.fetch = util.fetch;
  3481. // A symbol-like function to safely signal synchronous loading
  3482. /* istanbul ignore next */
  3483. function SYNC() {} // eslint-disable-line no-empty-function
  3484. /**
  3485. * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
  3486. * @param {string|string[]} filename Names of one or multiple files to load
  3487. * @param {IParseOptions} options Parse options
  3488. * @param {LoadCallback} callback Callback function
  3489. * @returns {undefined}
  3490. */
  3491. Root.prototype.load = function load(filename, options, callback) {
  3492. if (typeof options === "function") {
  3493. callback = options;
  3494. options = undefined;
  3495. }
  3496. var self = this;
  3497. if (!callback) {
  3498. return util.asPromise(load, self, filename, options);
  3499. }
  3500. var sync = callback === SYNC; // undocumented
  3501. // Finishes loading by calling the callback (exactly once)
  3502. function finish(err, root) {
  3503. /* istanbul ignore if */
  3504. if (!callback) {
  3505. return;
  3506. }
  3507. if (sync) {
  3508. throw err;
  3509. }
  3510. if (root) {
  3511. root.resolveAll();
  3512. }
  3513. var cb = callback;
  3514. callback = null;
  3515. cb(err, root);
  3516. }
  3517. // Bundled definition existence checking
  3518. function getBundledFileName(filename) {
  3519. var idx = filename.lastIndexOf("google/protobuf/");
  3520. if (idx > -1) {
  3521. var altname = filename.substring(idx);
  3522. if (Object.prototype.hasOwnProperty.call(common, altname)) return altname;
  3523. }
  3524. if (Object.prototype.hasOwnProperty.call(common, filename)) return filename;
  3525. return null;
  3526. }
  3527. // Processes a single file
  3528. function process(filename, source, depth) {
  3529. if (depth === undefined)
  3530. depth = 0;
  3531. try {
  3532. if (depth > util.recursionLimit)
  3533. throw Error("max depth exceeded");
  3534. if (util.isString(source) && source.charAt(0) === "{")
  3535. source = JSON.parse(source);
  3536. if (!util.isString(source))
  3537. self.setOptions(source.options).addJSON(source.nested);
  3538. else {
  3539. parse.filename = filename;
  3540. var parsed = parse(source, self, options),
  3541. resolved,
  3542. i = 0;
  3543. if (parsed.imports)
  3544. for (; i < parsed.imports.length; ++i)
  3545. if (resolved = getBundledFileName(parsed.imports[i]) || self.resolvePath(filename, parsed.imports[i]))
  3546. fetch(resolved, false, depth + 1);
  3547. if (parsed.weakImports)
  3548. for (i = 0; i < parsed.weakImports.length; ++i)
  3549. if (resolved = getBundledFileName(parsed.weakImports[i]) || self.resolvePath(filename, parsed.weakImports[i]))
  3550. fetch(resolved, true, depth + 1);
  3551. }
  3552. } catch (err) {
  3553. finish(err);
  3554. }
  3555. if (!sync && !queued) {
  3556. finish(null, self); // only once anyway
  3557. }
  3558. }
  3559. // Fetches a single file
  3560. function fetch(filename, weak, depth) {
  3561. if (depth === undefined)
  3562. depth = 0;
  3563. filename = getBundledFileName(filename) || filename;
  3564. // Skip if already loaded / attempted
  3565. if (self.files.indexOf(filename) > -1) {
  3566. return;
  3567. }
  3568. self.files.push(filename);
  3569. // Shortcut bundled definitions
  3570. if (Object.prototype.hasOwnProperty.call(common, filename)) {
  3571. if (sync) {
  3572. process(filename, common[filename], depth);
  3573. } else {
  3574. ++queued;
  3575. setTimeout(function() {
  3576. --queued;
  3577. process(filename, common[filename], depth);
  3578. });
  3579. }
  3580. return;
  3581. }
  3582. // Otherwise fetch from disk or network
  3583. if (sync) {
  3584. var source;
  3585. try {
  3586. source = util.fs.readFileSync(filename).toString("utf8");
  3587. } catch (err) {
  3588. if (!weak)
  3589. finish(err);
  3590. return;
  3591. }
  3592. process(filename, source, depth);
  3593. } else {
  3594. ++queued;
  3595. self.fetch(filename, function(err, source) {
  3596. --queued;
  3597. /* istanbul ignore if */
  3598. if (!callback) {
  3599. return; // terminated meanwhile
  3600. }
  3601. if (err) {
  3602. /* istanbul ignore else */
  3603. if (!weak)
  3604. finish(err);
  3605. else if (!queued) // can't be covered reliably
  3606. finish(null, self);
  3607. return;
  3608. }
  3609. process(filename, source, depth);
  3610. });
  3611. }
  3612. }
  3613. var queued = 0;
  3614. // Assembling the root namespace doesn't require working type
  3615. // references anymore, so we can load everything in parallel
  3616. if (util.isString(filename)) {
  3617. filename = [ filename ];
  3618. }
  3619. for (var i = 0, resolved; i < filename.length; ++i)
  3620. if (resolved = self.resolvePath("", filename[i]))
  3621. fetch(resolved);
  3622. if (sync) {
  3623. self.resolveAll();
  3624. return self;
  3625. }
  3626. if (!queued) {
  3627. finish(null, self);
  3628. }
  3629. return self;
  3630. };
  3631. // function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined
  3632. /**
  3633. * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
  3634. * @function Root#load
  3635. * @param {string|string[]} filename Names of one or multiple files to load
  3636. * @param {LoadCallback} callback Callback function
  3637. * @returns {undefined}
  3638. * @variation 2
  3639. */
  3640. // function load(filename:string, callback:LoadCallback):undefined
  3641. /**
  3642. * Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
  3643. * @function Root#load
  3644. * @param {string|string[]} filename Names of one or multiple files to load
  3645. * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
  3646. * @returns {Promise<Root>} Promise
  3647. * @variation 3
  3648. */
  3649. // function load(filename:string, [options:IParseOptions]):Promise<Root>
  3650. /**
  3651. * Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
  3652. * @function Root#loadSync
  3653. * @param {string|string[]} filename Names of one or multiple files to load
  3654. * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
  3655. * @returns {Root} Root namespace
  3656. * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
  3657. */
  3658. Root.prototype.loadSync = function loadSync(filename, options) {
  3659. if (!util.isNode)
  3660. throw Error("not supported");
  3661. return this.load(filename, options, SYNC);
  3662. };
  3663. /**
  3664. * @override
  3665. */
  3666. Root.prototype.resolveAll = function resolveAll() {
  3667. if (!this._needsRecursiveResolve) return this;
  3668. if (this.deferred.length)
  3669. throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
  3670. return "'extend " + field.extend + "' in " + field.parent.fullName;
  3671. }).join(", "));
  3672. return Namespace.prototype.resolveAll.call(this);
  3673. };
  3674. // only uppercased (and thus conflict-free) children are exposed, see below
  3675. var exposeRe = /^[A-Z]/;
  3676. /**
  3677. * Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.
  3678. * @param {Root} root Root instance
  3679. * @param {Field} field Declaring extension field witin the declaring type
  3680. * @returns {boolean} `true` if successfully added to the extended type, `false` otherwise
  3681. * @inner
  3682. * @ignore
  3683. */
  3684. function tryHandleExtension(root, field) {
  3685. var extendedType = field.parent.lookup(field.extend);
  3686. if (extendedType) {
  3687. var sisterField = new Field(field.fullName, field.id, field.type, field.rule, undefined, field.options);
  3688. //do not allow to extend same field twice to prevent the error
  3689. if (extendedType.get(sisterField.name)) {
  3690. return true;
  3691. }
  3692. sisterField.declaringField = field;
  3693. field.extensionField = sisterField;
  3694. extendedType.add(sisterField);
  3695. return true;
  3696. }
  3697. return false;
  3698. }
  3699. /**
  3700. * Called when any object is added to this root or its sub-namespaces.
  3701. * @param {ReflectionObject} object Object added
  3702. * @returns {undefined}
  3703. * @private
  3704. */
  3705. Root.prototype._handleAdd = function _handleAdd(object) {
  3706. if (object instanceof Field) {
  3707. if (/* an extension field (implies not part of a oneof) */ object.extend !== undefined && /* not already handled */ !object.extensionField)
  3708. if (!tryHandleExtension(this, object))
  3709. this.deferred.push(object);
  3710. } else if (object instanceof Enum) {
  3711. if (exposeRe.test(object.name))
  3712. object.parent[object.name] = object.values; // expose enum values as property of its parent
  3713. } else if (!(object instanceof OneOf)) /* everything else is a namespace */ {
  3714. if (object instanceof Type) // Try to handle any deferred extensions
  3715. for (var i = 0; i < this.deferred.length;)
  3716. if (tryHandleExtension(this, this.deferred[i]))
  3717. this.deferred.splice(i, 1);
  3718. else
  3719. ++i;
  3720. for (var j = 0; j < /* initializes */ object.nestedArray.length; ++j) // recurse into the namespace
  3721. this._handleAdd(object._nestedArray[j]);
  3722. if (exposeRe.test(object.name))
  3723. object.parent[object.name] = object; // expose namespace as property of its parent
  3724. }
  3725. if (object instanceof Type || object instanceof Enum || object instanceof Field) {
  3726. // Only store types and enums for quick lookup during resolve.
  3727. this._fullyQualifiedObjects[object.fullName] = object;
  3728. }
  3729. // The above also adds uppercased (and thus conflict-free) nested types, services and enums as
  3730. // properties of namespaces just like static code does. This allows using a .d.ts generated for
  3731. // a static module with reflection-based solutions where the condition is met.
  3732. };
  3733. /**
  3734. * Called when any object is removed from this root or its sub-namespaces.
  3735. * @param {ReflectionObject} object Object removed
  3736. * @returns {undefined}
  3737. * @private
  3738. */
  3739. Root.prototype._handleRemove = function _handleRemove(object) {
  3740. if (object instanceof Field) {
  3741. if (/* an extension field */ object.extend !== undefined) {
  3742. if (/* already handled */ object.extensionField) { // remove its sister field
  3743. object.extensionField.parent.remove(object.extensionField);
  3744. object.extensionField = null;
  3745. } else { // cancel the extension
  3746. var index = this.deferred.indexOf(object);
  3747. /* istanbul ignore else */
  3748. if (index > -1)
  3749. this.deferred.splice(index, 1);
  3750. }
  3751. }
  3752. } else if (object instanceof Enum) {
  3753. if (exposeRe.test(object.name))
  3754. delete object.parent[object.name]; // unexpose enum values
  3755. } else if (object instanceof Namespace) {
  3756. for (var i = 0; i < /* initializes */ object.nestedArray.length; ++i) // recurse into the namespace
  3757. this._handleRemove(object._nestedArray[i]);
  3758. if (exposeRe.test(object.name))
  3759. delete object.parent[object.name]; // unexpose namespaces
  3760. }
  3761. delete this._fullyQualifiedObjects[object.fullName];
  3762. };
  3763. // Sets up cyclic dependencies (called in index-light)
  3764. Root._configure = function(Type_, parse_, common_) {
  3765. Type = Type_;
  3766. parse = parse_;
  3767. common = common_;
  3768. };
  3769. },{"12":12,"14":14,"24":24,"5":5,"6":6}],18:[function(require,module,exports){
  3770. "use strict";
  3771. module.exports = Object.create(null);
  3772. /**
  3773. * Named roots.
  3774. * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
  3775. * Can also be used manually to make roots available across modules.
  3776. * @name roots
  3777. * @type {Object.<string,Root>}
  3778. * @example
  3779. * // pbjs -r myroot -o compiled.js ...
  3780. *
  3781. * // in another module:
  3782. * require("./compiled.js");
  3783. *
  3784. * // in any subsequent module:
  3785. * var root = protobuf.roots["myroot"];
  3786. */
  3787. },{}],19:[function(require,module,exports){
  3788. "use strict";
  3789. /**
  3790. * Streaming RPC helpers.
  3791. * @namespace
  3792. */
  3793. var rpc = exports;
  3794. /**
  3795. * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
  3796. * @typedef RPCImpl
  3797. * @type {function}
  3798. * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
  3799. * @param {Uint8Array} requestData Request data
  3800. * @param {RPCImplCallback} callback Callback function
  3801. * @returns {undefined}
  3802. * @example
  3803. * function rpcImpl(method, requestData, callback) {
  3804. * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
  3805. * throw Error("no such method");
  3806. * asynchronouslyObtainAResponse(requestData, function(err, responseData) {
  3807. * callback(err, responseData);
  3808. * });
  3809. * }
  3810. */
  3811. /**
  3812. * Node-style callback as used by {@link RPCImpl}.
  3813. * @typedef RPCImplCallback
  3814. * @type {function}
  3815. * @param {Error|null} error Error, if any, otherwise `null`
  3816. * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
  3817. * @returns {undefined}
  3818. */
  3819. rpc.Service = require(20);
  3820. },{"20":20}],20:[function(require,module,exports){
  3821. "use strict";
  3822. module.exports = Service;
  3823. var util = require(33);
  3824. // Extends EventEmitter
  3825. (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
  3826. /**
  3827. * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
  3828. *
  3829. * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
  3830. * @typedef rpc.ServiceMethodCallback
  3831. * @template TRes extends Message<TRes>
  3832. * @type {function}
  3833. * @param {Error|null} error Error, if any
  3834. * @param {TRes} [response] Response message
  3835. * @returns {undefined}
  3836. */
  3837. /**
  3838. * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
  3839. * @typedef rpc.ServiceMethod
  3840. * @template TReq extends Message<TReq>
  3841. * @template TRes extends Message<TRes>
  3842. * @type {{
  3843. * (request: TReq|Properties<TReq>, callback: rpc.ServiceMethodCallback<TRes>): void;
  3844. * (request: TReq|Properties<TReq>): Promise<TRes>;
  3845. * readonly name: string;
  3846. * readonly path: string;
  3847. * readonly requestType: string;
  3848. * readonly responseType: string;
  3849. * readonly requestStream: true|undefined;
  3850. * readonly responseStream: true|undefined;
  3851. * }}
  3852. */
  3853. /**
  3854. * Constructs a new RPC service instance.
  3855. * @classdesc An RPC service as returned by {@link Service#create}.
  3856. * @exports rpc.Service
  3857. * @extends util.EventEmitter
  3858. * @constructor
  3859. * @param {RPCImpl} rpcImpl RPC implementation
  3860. * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
  3861. * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
  3862. */
  3863. function Service(rpcImpl, requestDelimited, responseDelimited) {
  3864. if (typeof rpcImpl !== "function")
  3865. throw TypeError("rpcImpl must be a function");
  3866. util.EventEmitter.call(this);
  3867. /**
  3868. * RPC implementation. Becomes `null` once the service is ended.
  3869. * @type {RPCImpl|null}
  3870. */
  3871. this.rpcImpl = rpcImpl;
  3872. /**
  3873. * Whether requests are length-delimited.
  3874. * @type {boolean}
  3875. */
  3876. this.requestDelimited = Boolean(requestDelimited);
  3877. /**
  3878. * Whether responses are length-delimited.
  3879. * @type {boolean}
  3880. */
  3881. this.responseDelimited = Boolean(responseDelimited);
  3882. }
  3883. /**
  3884. * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
  3885. * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method
  3886. * @param {Constructor<TReq>} requestCtor Request constructor
  3887. * @param {Constructor<TRes>} responseCtor Response constructor
  3888. * @param {TReq|Properties<TReq>} request Request message or plain object
  3889. * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback
  3890. * @returns {undefined}
  3891. * @template TReq extends Message<TReq>
  3892. * @template TRes extends Message<TRes>
  3893. */
  3894. Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {
  3895. if (!request)
  3896. throw TypeError("request must be specified");
  3897. var self = this;
  3898. if (!callback)
  3899. return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
  3900. if (!self.rpcImpl) {
  3901. setTimeout(function() { callback(Error("already ended")); }, 0);
  3902. return undefined;
  3903. }
  3904. try {
  3905. return self.rpcImpl(
  3906. method,
  3907. requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),
  3908. function rpcCallback(err, response) {
  3909. if (err) {
  3910. self.emit("error", err, method);
  3911. return callback(err);
  3912. }
  3913. if (response === null) {
  3914. self.end(/* endedByRPC */ true);
  3915. return undefined;
  3916. }
  3917. if (!(response instanceof responseCtor)) {
  3918. try {
  3919. response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);
  3920. } catch (err) {
  3921. self.emit("error", err, method);
  3922. return callback(err);
  3923. }
  3924. }
  3925. self.emit("data", response, method);
  3926. return callback(null, response);
  3927. }
  3928. );
  3929. } catch (err) {
  3930. self.emit("error", err, method);
  3931. setTimeout(function() { callback(err); }, 0);
  3932. return undefined;
  3933. }
  3934. };
  3935. /**
  3936. * Ends this service and emits the `end` event.
  3937. * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.
  3938. * @returns {rpc.Service} `this`
  3939. */
  3940. Service.prototype.end = function end(endedByRPC) {
  3941. if (this.rpcImpl) {
  3942. if (!endedByRPC) // signal end to rpcImpl
  3943. this.rpcImpl(null, null, null);
  3944. this.rpcImpl = null;
  3945. this.emit("end").off();
  3946. }
  3947. return this;
  3948. };
  3949. },{"33":33}],21:[function(require,module,exports){
  3950. "use strict";
  3951. module.exports = Service;
  3952. // extends Namespace
  3953. var Namespace = require(12);
  3954. ((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
  3955. var Method = require(11),
  3956. util = require(24),
  3957. rpc = require(19);
  3958. /**
  3959. * Constructs a new service instance.
  3960. * @classdesc Reflected service.
  3961. * @extends NamespaceBase
  3962. * @constructor
  3963. * @param {string} name Service name
  3964. * @param {Object.<string,*>} [options] Service options
  3965. * @throws {TypeError} If arguments are invalid
  3966. */
  3967. function Service(name, options) {
  3968. Namespace.call(this, name, options);
  3969. /**
  3970. * Service methods.
  3971. * @type {Object.<string,Method>}
  3972. */
  3973. this.methods = {}; // toJSON, marker
  3974. /**
  3975. * Cached methods as an array.
  3976. * @type {Method[]|null}
  3977. * @private
  3978. */
  3979. this._methodsArray = null;
  3980. }
  3981. /**
  3982. * Service descriptor.
  3983. * @interface IService
  3984. * @extends INamespace
  3985. * @property {string} [edition] Edition
  3986. * @property {Object.<string,IMethod>} methods Method descriptors
  3987. * @property {string|null} [comment] Service comment
  3988. */
  3989. /**
  3990. * Constructs a service from a service descriptor.
  3991. * @param {string} name Service name
  3992. * @param {IService} json Service descriptor
  3993. * @param {number} [depth] Current nesting depth, defaults to `0`
  3994. * @returns {Service} Created service
  3995. * @throws {TypeError} If arguments are invalid
  3996. */
  3997. Service.fromJSON = function fromJSON(name, json, depth) {
  3998. if (depth === undefined)
  3999. depth = 0;
  4000. if (depth > util.recursionLimit)
  4001. throw Error("max depth exceeded");
  4002. var service = new Service(name, json.options);
  4003. /* istanbul ignore else */
  4004. if (json.methods)
  4005. for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
  4006. service.add(Method.fromJSON(names[i], json.methods[names[i]]));
  4007. if (json.nested)
  4008. service.addJSON(json.nested, depth);
  4009. if (json.edition)
  4010. service._edition = json.edition;
  4011. service.comment = json.comment;
  4012. service._defaultEdition = "proto3"; // For backwards-compatibility.
  4013. return service;
  4014. };
  4015. /**
  4016. * Converts this service to a service descriptor.
  4017. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  4018. * @returns {IService} Service descriptor
  4019. */
  4020. Service.prototype.toJSON = function toJSON(toJSONOptions) {
  4021. var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
  4022. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  4023. return util.toObject([
  4024. "edition" , this._editionToJSON(),
  4025. "options" , inherited && inherited.options || undefined,
  4026. "methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
  4027. "nested" , inherited && inherited.nested || undefined,
  4028. "comment" , keepComments ? this.comment : undefined
  4029. ]);
  4030. };
  4031. /**
  4032. * Methods of this service as an array for iteration.
  4033. * @name Service#methodsArray
  4034. * @type {Method[]}
  4035. * @readonly
  4036. */
  4037. Object.defineProperty(Service.prototype, "methodsArray", {
  4038. get: function() {
  4039. return this._methodsArray || (this._methodsArray = util.toArray(this.methods));
  4040. }
  4041. });
  4042. function clearCache(service) {
  4043. service._methodsArray = null;
  4044. return service;
  4045. }
  4046. /**
  4047. * @override
  4048. */
  4049. Service.prototype.get = function get(name) {
  4050. return Object.prototype.hasOwnProperty.call(this.methods, name)
  4051. ? this.methods[name]
  4052. : Namespace.prototype.get.call(this, name);
  4053. };
  4054. /**
  4055. * @override
  4056. */
  4057. Service.prototype.resolveAll = function resolveAll() {
  4058. if (!this._needsRecursiveResolve) return this;
  4059. Namespace.prototype.resolve.call(this);
  4060. var methods = this.methodsArray;
  4061. for (var i = 0; i < methods.length; ++i)
  4062. methods[i].resolve();
  4063. return this;
  4064. };
  4065. /**
  4066. * @override
  4067. */
  4068. Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
  4069. if (!this._needsRecursiveFeatureResolution) return this;
  4070. edition = this._edition || edition;
  4071. Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
  4072. this.methodsArray.forEach(method => {
  4073. method._resolveFeaturesRecursive(edition);
  4074. });
  4075. return this;
  4076. };
  4077. /**
  4078. * @override
  4079. */
  4080. Service.prototype.add = function add(object) {
  4081. /* istanbul ignore if */
  4082. if (this.get(object.name))
  4083. throw Error("duplicate name '" + object.name + "' in " + this);
  4084. if (object instanceof Method) {
  4085. if (object.name === "__proto__")
  4086. return this;
  4087. this.methods[object.name] = object;
  4088. object.parent = this;
  4089. return clearCache(this);
  4090. }
  4091. return Namespace.prototype.add.call(this, object);
  4092. };
  4093. /**
  4094. * @override
  4095. */
  4096. Service.prototype.remove = function remove(object) {
  4097. if (object instanceof Method) {
  4098. /* istanbul ignore if */
  4099. if (this.methods[object.name] !== object)
  4100. throw Error(object + " is not a member of " + this);
  4101. delete this.methods[object.name];
  4102. object.parent = null;
  4103. return clearCache(this);
  4104. }
  4105. return Namespace.prototype.remove.call(this, object);
  4106. };
  4107. /**
  4108. * Creates a runtime service using the specified rpc implementation.
  4109. * @param {RPCImpl} rpcImpl RPC implementation
  4110. * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
  4111. * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
  4112. * @returns {rpc.Service} RPC service. Useful where requests and/or responses are streamed.
  4113. */
  4114. Service.prototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
  4115. var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
  4116. for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
  4117. var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
  4118. rpcService[methodName] = (function(method, requestType, responseType) {
  4119. return function rpcMethod(request, callback) {
  4120. return rpc.Service.prototype.rpcCall.call(this, method, requestType, responseType, request, callback);
  4121. };
  4122. })(method, method.resolvedRequestType.ctor, method.resolvedResponseType.ctor);
  4123. }
  4124. return rpcService;
  4125. };
  4126. },{"11":11,"12":12,"19":19,"24":24}],22:[function(require,module,exports){
  4127. "use strict";
  4128. module.exports = Type;
  4129. // extends Namespace
  4130. var Namespace = require(12);
  4131. ((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
  4132. var Enum = require(5),
  4133. OneOf = require(14),
  4134. Field = require(6),
  4135. MapField = require(9),
  4136. Service = require(21),
  4137. Message = require(10),
  4138. Reader = require(15),
  4139. Writer = require(40),
  4140. util = require(24),
  4141. encoder = require(4),
  4142. decoder = require(3),
  4143. verifier = require(38),
  4144. converter = require(2),
  4145. wrappers = require(39);
  4146. /**
  4147. * Constructs a new reflected message type instance.
  4148. * @classdesc Reflected message type.
  4149. * @extends NamespaceBase
  4150. * @constructor
  4151. * @param {string} name Message name
  4152. * @param {Object.<string,*>} [options] Declared options
  4153. */
  4154. function Type(name, options) {
  4155. name = name.replace(/\W/g, "");
  4156. Namespace.call(this, name, options);
  4157. /**
  4158. * Message fields.
  4159. * @type {Object.<string,Field>}
  4160. */
  4161. this.fields = {}; // toJSON, marker
  4162. /**
  4163. * Oneofs declared within this namespace, if any.
  4164. * @type {Object.<string,OneOf>}
  4165. */
  4166. this.oneofs = undefined; // toJSON
  4167. /**
  4168. * Extension ranges, if any.
  4169. * @type {number[][]}
  4170. */
  4171. this.extensions = undefined; // toJSON
  4172. /**
  4173. * Reserved ranges, if any.
  4174. * @type {Array.<number[]|string>}
  4175. */
  4176. this.reserved = undefined; // toJSON
  4177. /*?
  4178. * Whether this type is a legacy group.
  4179. * @type {boolean|undefined}
  4180. */
  4181. this.group = undefined; // toJSON
  4182. /**
  4183. * Cached fields by id.
  4184. * @type {Object.<number,Field>|null}
  4185. * @private
  4186. */
  4187. this._fieldsById = null;
  4188. /**
  4189. * Cached fields as an array.
  4190. * @type {Field[]|null}
  4191. * @private
  4192. */
  4193. this._fieldsArray = null;
  4194. /**
  4195. * Cached oneofs as an array.
  4196. * @type {OneOf[]|null}
  4197. * @private
  4198. */
  4199. this._oneofsArray = null;
  4200. /**
  4201. * Cached constructor.
  4202. * @type {Constructor<{}>}
  4203. * @private
  4204. */
  4205. this._ctor = null;
  4206. /**
  4207. * Cached fields by JSON name.
  4208. * @type {Object.<string,Field>|null}
  4209. * @private
  4210. */
  4211. this._fieldsByJsonName = null; // used by ext/protojson
  4212. }
  4213. Object.defineProperties(Type.prototype, {
  4214. /**
  4215. * Message fields by id.
  4216. * @name Type#fieldsById
  4217. * @type {Object.<number,Field>}
  4218. * @readonly
  4219. */
  4220. fieldsById: {
  4221. get: function() {
  4222. /* istanbul ignore if */
  4223. if (this._fieldsById)
  4224. return this._fieldsById;
  4225. this._fieldsById = {};
  4226. for (var names = Object.keys(this.fields), i = 0; i < names.length; ++i) {
  4227. var field = this.fields[names[i]],
  4228. id = field.id;
  4229. /* istanbul ignore if */
  4230. if (this._fieldsById[id])
  4231. throw Error("duplicate id " + id + " in " + this);
  4232. this._fieldsById[id] = field;
  4233. }
  4234. return this._fieldsById;
  4235. }
  4236. },
  4237. /**
  4238. * Fields of this message as an array for iteration.
  4239. * @name Type#fieldsArray
  4240. * @type {Field[]}
  4241. * @readonly
  4242. */
  4243. fieldsArray: {
  4244. get: function() {
  4245. return this._fieldsArray || (this._fieldsArray = util.toArray(this.fields));
  4246. }
  4247. },
  4248. /**
  4249. * Oneofs of this message as an array for iteration.
  4250. * @name Type#oneofsArray
  4251. * @type {OneOf[]}
  4252. * @readonly
  4253. */
  4254. oneofsArray: {
  4255. get: function() {
  4256. return this._oneofsArray || (this._oneofsArray = util.toArray(this.oneofs));
  4257. }
  4258. },
  4259. /**
  4260. * The registered constructor, if any registered, otherwise a generic constructor.
  4261. * Assigning a function replaces the internal constructor. If the function does not extend {@link Message} yet, its prototype will be setup accordingly and static methods will be populated. If it already extends {@link Message}, it will just replace the internal constructor.
  4262. * When assigning manually, add the type to its parent namespace/root first if fields reference other reflected types, because constructor setup resolves field defaults.
  4263. * @name Type#ctor
  4264. * @type {Constructor<{}>}
  4265. */
  4266. ctor: {
  4267. get: function() {
  4268. return this._ctor || (this.ctor = Type.generateConstructor(this)());
  4269. },
  4270. set: function(ctor) {
  4271. // Ensure proper prototype
  4272. var prototype = ctor.prototype;
  4273. if (!(prototype instanceof Message)) {
  4274. (ctor.prototype = new Message()).constructor = ctor;
  4275. util.merge(ctor.prototype, prototype);
  4276. }
  4277. // Classes and messages reference their reflected type
  4278. ctor.$type = ctor.prototype.$type = this;
  4279. // Mix in static methods
  4280. util.merge(ctor, Message, true);
  4281. this._ctor = ctor;
  4282. delete this.decode;
  4283. delete this.fromObject;
  4284. // Messages have non-enumerable default values on their prototype
  4285. var i = 0;
  4286. for (var field; i < /* initializes */ this.fieldsArray.length; ++i) {
  4287. field = this._fieldsArray[i].resolve(); // ensures a proper value
  4288. ctor.prototype[field.name] = field.defaultValue;
  4289. }
  4290. // Messages have non-enumerable getters and setters for each virtual oneof field
  4291. var ctorProperties = {};
  4292. for (i = 0; i < /* initializes */ this.oneofsArray.length; ++i)
  4293. ctorProperties[this._oneofsArray[i].resolve().name] = {
  4294. get: util.oneOfGetter(this._oneofsArray[i].oneof),
  4295. set: util.oneOfSetter(this._oneofsArray[i].oneof)
  4296. };
  4297. if (i)
  4298. Object.defineProperties(ctor.prototype, ctorProperties);
  4299. }
  4300. }
  4301. });
  4302. /**
  4303. * Generates a constructor function for the specified type.
  4304. * @param {Type} mtype Message type
  4305. * @returns {Codegen} Codegen instance
  4306. */
  4307. Type.generateConstructor = function generateConstructor(mtype) {
  4308. /* eslint-disable no-unexpected-multiline */
  4309. var gen = util.codegen(["p"]);
  4310. // explicitly initialize mutable object/array fields so that these aren't just inherited from the prototype
  4311. for (var i = 0, field; i < mtype.fieldsArray.length; ++i)
  4312. if ((field = mtype._fieldsArray[i]).map) gen
  4313. ("this%s={}", util.safeProp(field.name));
  4314. else if (field.repeated) gen
  4315. ("this%s=[]", util.safeProp(field.name));
  4316. return gen
  4317. ("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null&&ks[i]!==\"__proto__\")") // omit undefined or null
  4318. ("this[ks[i]]=p[ks[i]]");
  4319. /* eslint-enable no-unexpected-multiline */
  4320. };
  4321. function clearCache(type) {
  4322. type._fieldsById = type._fieldsArray = type._oneofsArray = type._fieldsByJsonName = null;
  4323. delete type.encode;
  4324. delete type.decode;
  4325. delete type.verify;
  4326. return type;
  4327. }
  4328. /**
  4329. * Message type descriptor.
  4330. * @interface IType
  4331. * @extends INamespace
  4332. * @property {string} [edition] Edition
  4333. * @property {Object.<string,IOneOf>} [oneofs] Oneof descriptors
  4334. * @property {Object.<string,IField>} fields Field descriptors
  4335. * @property {number[][]} [extensions] Extension ranges
  4336. * @property {Array.<number[]|string>} [reserved] Reserved ranges
  4337. * @property {boolean} [group=false] Whether a legacy group or not
  4338. * @property {string|null} [comment] Message type comment
  4339. */
  4340. /**
  4341. * Creates a message type from a message type descriptor.
  4342. * @param {string} name Message name
  4343. * @param {IType} json Message type descriptor
  4344. * @param {number} [depth] Current nesting depth, defaults to `0`
  4345. * @returns {Type} Created message type
  4346. */
  4347. Type.fromJSON = function fromJSON(name, json, depth) {
  4348. if (depth === undefined)
  4349. depth = 0;
  4350. if (depth > util.nestingLimit)
  4351. throw Error("max depth exceeded");
  4352. var type = new Type(name, json.options);
  4353. type.extensions = json.extensions;
  4354. type.reserved = json.reserved;
  4355. var names = Object.keys(json.fields),
  4356. i = 0;
  4357. for (; i < names.length; ++i)
  4358. type.add(
  4359. ( typeof json.fields[names[i]].keyType !== "undefined"
  4360. ? MapField.fromJSON
  4361. : Field.fromJSON )(names[i], json.fields[names[i]])
  4362. );
  4363. if (json.oneofs)
  4364. for (names = Object.keys(json.oneofs), i = 0; i < names.length; ++i)
  4365. type.add(OneOf.fromJSON(names[i], json.oneofs[names[i]]));
  4366. if (json.nested)
  4367. for (names = Object.keys(json.nested), i = 0; i < names.length; ++i) {
  4368. var nested = json.nested[names[i]];
  4369. type.add( // most to least likely
  4370. ( nested.id !== undefined
  4371. ? Field.fromJSON
  4372. : nested.fields !== undefined
  4373. ? Type.fromJSON
  4374. : nested.values !== undefined
  4375. ? Enum.fromJSON
  4376. : nested.methods !== undefined
  4377. ? Service.fromJSON
  4378. : Namespace.fromJSON )(names[i], nested, depth + 1)
  4379. );
  4380. }
  4381. if (json.extensions && json.extensions.length)
  4382. type.extensions = json.extensions;
  4383. if (json.reserved && json.reserved.length)
  4384. type.reserved = json.reserved;
  4385. if (json.group)
  4386. type.group = true;
  4387. if (json.comment)
  4388. type.comment = json.comment;
  4389. if (json.edition)
  4390. type._edition = json.edition;
  4391. type._defaultEdition = "proto3"; // For backwards-compatibility.
  4392. return type;
  4393. };
  4394. /**
  4395. * Converts this message type to a message type descriptor.
  4396. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  4397. * @returns {IType} Message type descriptor
  4398. */
  4399. Type.prototype.toJSON = function toJSON(toJSONOptions) {
  4400. var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
  4401. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  4402. return util.toObject([
  4403. "edition" , this._editionToJSON(),
  4404. "options" , inherited && inherited.options || undefined,
  4405. "oneofs" , Namespace.arrayToJSON(this.oneofsArray, toJSONOptions),
  4406. "fields" , Namespace.arrayToJSON(this.fieldsArray.filter(function(obj) { return !obj.declaringField; }), toJSONOptions) || {},
  4407. "extensions" , this.extensions && this.extensions.length ? this.extensions : undefined,
  4408. "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
  4409. "group" , this.group || undefined,
  4410. "nested" , inherited && inherited.nested || undefined,
  4411. "comment" , keepComments ? this.comment : undefined
  4412. ]);
  4413. };
  4414. /**
  4415. * @override
  4416. */
  4417. Type.prototype.resolveAll = function resolveAll() {
  4418. if (!this._needsRecursiveResolve) return this;
  4419. Namespace.prototype.resolveAll.call(this);
  4420. var oneofs = this.oneofsArray; i = 0;
  4421. while (i < oneofs.length)
  4422. oneofs[i++].resolve();
  4423. var fields = this.fieldsArray, i = 0;
  4424. while (i < fields.length)
  4425. fields[i++].resolve();
  4426. return this;
  4427. };
  4428. /**
  4429. * @override
  4430. */
  4431. Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
  4432. if (!this._needsRecursiveFeatureResolution) return this;
  4433. edition = this._edition || edition;
  4434. Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
  4435. this.oneofsArray.forEach(oneof => {
  4436. oneof._resolveFeatures(edition);
  4437. });
  4438. this.fieldsArray.forEach(field => {
  4439. field._resolveFeatures(edition);
  4440. });
  4441. return this;
  4442. };
  4443. /**
  4444. * @override
  4445. */
  4446. Type.prototype.get = function get(name) {
  4447. if (Object.prototype.hasOwnProperty.call(this.fields, name))
  4448. return this.fields[name];
  4449. if (this.oneofs && Object.prototype.hasOwnProperty.call(this.oneofs, name))
  4450. return this.oneofs[name];
  4451. if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name))
  4452. return this.nested[name];
  4453. return null;
  4454. };
  4455. /**
  4456. * Adds a nested object to this type.
  4457. * @param {ReflectionObject} object Nested object to add
  4458. * @returns {Type} `this`
  4459. * @throws {TypeError} If arguments are invalid
  4460. * @throws {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id
  4461. */
  4462. Type.prototype.add = function add(object) {
  4463. if (this.get(object.name))
  4464. throw Error("duplicate name '" + object.name + "' in " + this);
  4465. if (object instanceof Field && object.extend === undefined) {
  4466. // NOTE: Extension fields aren't actual fields on the declaring type, but nested objects.
  4467. // The root object takes care of adding distinct sister-fields to the respective extended
  4468. // type instead.
  4469. // avoids calling the getter if not absolutely necessary because it's called quite frequently
  4470. if (this._fieldsById ? /* istanbul ignore next */ this._fieldsById[object.id] : this.fieldsById[object.id])
  4471. throw Error("duplicate id " + object.id + " in " + this);
  4472. if (this.isReservedId(object.id))
  4473. throw Error("id " + object.id + " is reserved in " + this);
  4474. if (this.isReservedName(object.name) || object.name.charAt(0) === "$")
  4475. throw Error("name '" + object.name + "' is reserved in " + this);
  4476. if (object.name === "__proto__")
  4477. return this;
  4478. if (object.parent)
  4479. object.parent.remove(object);
  4480. this.fields[object.name] = object;
  4481. object.message = this;
  4482. object.onAdd(this);
  4483. return clearCache(this);
  4484. }
  4485. if (object instanceof OneOf) {
  4486. if (object.name.charAt(0) === "$")
  4487. throw Error("name '" + object.name + "' is reserved in " + this);
  4488. if (object.name === "__proto__")
  4489. return this;
  4490. if (!this.oneofs)
  4491. this.oneofs = {};
  4492. this.oneofs[object.name] = object;
  4493. object.onAdd(this);
  4494. return clearCache(this);
  4495. }
  4496. return Namespace.prototype.add.call(this, object);
  4497. };
  4498. /**
  4499. * Removes a nested object from this type.
  4500. * @param {ReflectionObject} object Nested object to remove
  4501. * @returns {Type} `this`
  4502. * @throws {TypeError} If arguments are invalid
  4503. * @throws {Error} If `object` is not a member of this type
  4504. */
  4505. Type.prototype.remove = function remove(object) {
  4506. if (object instanceof Field && object.extend === undefined) {
  4507. // See Type#add for the reason why extension fields are excluded here.
  4508. /* istanbul ignore if */
  4509. if (!util.remove(this.fields, object, object.name))
  4510. throw Error(object + " is not a member of " + this);
  4511. object.parent = null;
  4512. object.onRemove(this);
  4513. return clearCache(this);
  4514. }
  4515. if (object instanceof OneOf) {
  4516. /* istanbul ignore if */
  4517. if (!util.remove(this.oneofs, object, object.name))
  4518. throw Error(object + " is not a member of " + this);
  4519. object.parent = null;
  4520. object.onRemove(this);
  4521. return clearCache(this);
  4522. }
  4523. return Namespace.prototype.remove.call(this, object);
  4524. };
  4525. /**
  4526. * Tests if the specified id is reserved.
  4527. * @param {number} id Id to test
  4528. * @returns {boolean} `true` if reserved, otherwise `false`
  4529. */
  4530. Type.prototype.isReservedId = function isReservedId(id) {
  4531. return Namespace.isReservedId(this.reserved, id);
  4532. };
  4533. /**
  4534. * Tests if the specified name is reserved.
  4535. * @param {string} name Name to test
  4536. * @returns {boolean} `true` if reserved, otherwise `false`
  4537. */
  4538. Type.prototype.isReservedName = function isReservedName(name) {
  4539. return Namespace.isReservedName(this.reserved, name);
  4540. };
  4541. /**
  4542. * Creates a new message of this type using the specified properties.
  4543. * @param {Object.<string,*>} [properties] Properties to set
  4544. * @returns {ReflectedMessage} Message instance
  4545. */
  4546. Type.prototype.create = function create(properties) {
  4547. return new this.ctor(properties);
  4548. };
  4549. /**
  4550. * Sets up {@link Type#encode|encode}, {@link Type#decode|decode} and {@link Type#verify|verify}.
  4551. * @returns {Type} `this`
  4552. */
  4553. Type.prototype.setup = function setup() {
  4554. // Sets up everything at once so that the prototype chain does not have to be re-evaluated
  4555. // multiple times (V8, soft-deopt prototype-check).
  4556. var fullName = this.fullName,
  4557. types = [];
  4558. for (var i = 0; i < /* initializes */ this.fieldsArray.length; ++i)
  4559. types.push(this._fieldsArray[i].resolve().resolvedType);
  4560. // Replace setup methods with type-specific generated functions
  4561. this.encode = encoder(this)({
  4562. Writer : Writer,
  4563. types : types,
  4564. util : util
  4565. });
  4566. this.decode = decoder(this)({
  4567. Reader : Reader,
  4568. types : types,
  4569. util : util,
  4570. C : this.ctor
  4571. });
  4572. this.verify = verifier(this)({
  4573. types : types,
  4574. util : util
  4575. });
  4576. this.fromObject = converter.fromObject(this)({
  4577. types : types,
  4578. util : util,
  4579. C : this.ctor
  4580. });
  4581. this.toObject = converter.toObject(this)({
  4582. types : types,
  4583. util : util
  4584. });
  4585. // Inject custom wrappers for common types
  4586. var wrapper = wrappers[fullName];
  4587. if (wrapper) {
  4588. var wrapperThis = Object.create(this);
  4589. // Reuse this type's runtime constructor in wrapper fromObject/toObject
  4590. wrapperThis._ctor = this.ctor;
  4591. wrapperThis.fromObject = this.fromObject;
  4592. this.fromObject = wrapper.fromObject.bind(wrapperThis);
  4593. wrapperThis.toObject = this.toObject;
  4594. this.toObject = wrapper.toObject.bind(wrapperThis);
  4595. }
  4596. return this;
  4597. };
  4598. /**
  4599. * Encodes a message of this type. Does not implicitly {@link Type#verify|verify} messages.
  4600. * @param {Message<{}>|Object.<string,*>} message Message instance or plain object
  4601. * @param {Writer} [writer] Writer to encode to
  4602. * @returns {Writer} writer
  4603. */
  4604. Type.prototype.encode = function encode_setup(message, writer) { // eslint-disable-line no-unused-vars
  4605. return this.setup().encode.apply(this, arguments); // overrides this method
  4606. };
  4607. /**
  4608. * Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly {@link Type#verify|verify} messages.
  4609. * @param {Message<{}>|Object.<string,*>} message Message instance or plain object
  4610. * @param {Writer} [writer] Writer to encode to
  4611. * @returns {Writer} writer
  4612. */
  4613. Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
  4614. return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
  4615. };
  4616. /**
  4617. * Decodes a message of this type.
  4618. * @param {Reader|Uint8Array} reader Reader or buffer to decode from
  4619. * @param {number} [length] Length of the message, if known beforehand
  4620. * @returns {ReflectedMessage} Decoded message
  4621. * @throws {Error} If the payload is not a reader or valid buffer
  4622. * @throws {util.ProtocolError<{}>} If required fields are missing
  4623. */
  4624. Type.prototype.decode = function decode_setup(reader, length) { // eslint-disable-line no-unused-vars
  4625. return this.setup().decode.apply(this, arguments); // overrides this method
  4626. };
  4627. /**
  4628. * Decodes a message of this type preceeded by its byte length as a varint.
  4629. * @param {Reader|Uint8Array} reader Reader or buffer to decode from
  4630. * @returns {ReflectedMessage} Decoded message
  4631. * @throws {Error} If the payload is not a reader or valid buffer
  4632. * @throws {util.ProtocolError} If required fields are missing
  4633. */
  4634. Type.prototype.decodeDelimited = function decodeDelimited(reader) {
  4635. if (!(reader instanceof Reader))
  4636. reader = Reader.create(reader);
  4637. return this.decode(reader, reader.uint32());
  4638. };
  4639. /**
  4640. * Verifies that field values are valid and that required fields are present.
  4641. * @param {Object.<string,*>} message Plain object to verify
  4642. * @returns {null|string} `null` if valid, otherwise the reason why it is not
  4643. */
  4644. Type.prototype.verify = function verify_setup(message) { // eslint-disable-line no-unused-vars
  4645. return this.setup().verify.apply(this, arguments); // overrides this method
  4646. };
  4647. /**
  4648. * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
  4649. * @param {Object.<string,*>} object Plain object to convert
  4650. * @returns {ReflectedMessage} Message instance
  4651. */
  4652. Type.prototype.fromObject = function fromObject(object) { // eslint-disable-line no-unused-vars
  4653. return this.setup().fromObject.apply(this, arguments);
  4654. };
  4655. /**
  4656. * Conversion options as used by {@link Type#toObject} and {@link Message.toObject}.
  4657. * @interface IConversionOptions
  4658. * @property {Function} [longs] Long conversion type.
  4659. * Valid values are `BigInt`, `String` and `Number` (the global types).
  4660. * Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.
  4661. * @property {Function} [enums] Enum value conversion type.
  4662. * Only valid value is `String` (the global type).
  4663. * Defaults to copy the present value, which is the numeric id.
  4664. * @property {Function} [bytes] Bytes value conversion type.
  4665. * Valid values are `Array` and (a base64 encoded) `String` (the global types).
  4666. * Defaults to copy the present value, which usually is a Buffer under node and an Uint8Array in the browser.
  4667. * @property {boolean} [defaults=false] Also sets default values on the resulting object
  4668. * @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
  4669. * @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`
  4670. * @property {boolean} [oneofs=false] Includes virtual oneof properties set to the present field's name, if any
  4671. * @property {boolean} [json=false] Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings
  4672. */
  4673. /**
  4674. * Creates a plain object from a message of this type. Also converts values to other types if specified.
  4675. * @param {Message<{}>} message Message instance
  4676. * @param {IConversionOptions} [options] Conversion options
  4677. * @returns {Object.<string,*>} Plain object
  4678. */
  4679. Type.prototype.toObject = function toObject(message, options) { // eslint-disable-line no-unused-vars
  4680. return this.setup().toObject.apply(this, arguments);
  4681. };
  4682. /**
  4683. * Gets the type url for this type.
  4684. * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
  4685. * @returns {string} The type url
  4686. */
  4687. Type.prototype.getTypeUrl = function getTypeUrl(prefix) {
  4688. if (prefix === undefined)
  4689. prefix = "type.googleapis.com";
  4690. var fullName = this.fullName;
  4691. return prefix + "/" + (fullName.charAt(0) === "." ? fullName.substring(1) : fullName);
  4692. };
  4693. /**
  4694. * Decorator function as returned by {@link Type.d} (TypeScript).
  4695. * @typedef TypeDecorator
  4696. * @type {function}
  4697. * @param {Constructor<T>} target Target constructor
  4698. * @returns {undefined}
  4699. * @template T extends Message<T>
  4700. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  4701. */
  4702. /**
  4703. * Type decorator (TypeScript).
  4704. * @param {string} [typeName] Type name, defaults to the constructor's name
  4705. * @returns {TypeDecorator<T>} Decorator function
  4706. * @template T extends Message<T>
  4707. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  4708. */
  4709. Type.d = function decorateType(typeName) {
  4710. return function typeDecorator(target) {
  4711. util.decorateType(target, typeName);
  4712. };
  4713. };
  4714. },{"10":10,"12":12,"14":14,"15":15,"2":2,"21":21,"24":24,"3":3,"38":38,"39":39,"4":4,"40":40,"5":5,"6":6,"9":9}],23:[function(require,module,exports){
  4715. "use strict";
  4716. /**
  4717. * Common type constants.
  4718. * @namespace
  4719. */
  4720. var types = exports;
  4721. var util = require(24);
  4722. var s = [
  4723. "double", // 0
  4724. "float", // 1
  4725. "int32", // 2
  4726. "uint32", // 3
  4727. "sint32", // 4
  4728. "fixed32", // 5
  4729. "sfixed32", // 6
  4730. "int64", // 7
  4731. "uint64", // 8
  4732. "sint64", // 9
  4733. "fixed64", // 10
  4734. "sfixed64", // 11
  4735. "bool", // 12
  4736. "string", // 13
  4737. "bytes" // 14
  4738. ];
  4739. function bake(values, offset) {
  4740. var i = 0, o = Object.create(null);
  4741. offset |= 0;
  4742. while (i < values.length) o[s[i + offset]] = values[i++];
  4743. return o;
  4744. }
  4745. /**
  4746. * Basic type wire types.
  4747. * @type {Object.<string,number>}
  4748. * @const
  4749. * @property {number} double=1 Fixed64 wire type
  4750. * @property {number} float=5 Fixed32 wire type
  4751. * @property {number} int32=0 Varint wire type
  4752. * @property {number} uint32=0 Varint wire type
  4753. * @property {number} sint32=0 Varint wire type
  4754. * @property {number} fixed32=5 Fixed32 wire type
  4755. * @property {number} sfixed32=5 Fixed32 wire type
  4756. * @property {number} int64=0 Varint wire type
  4757. * @property {number} uint64=0 Varint wire type
  4758. * @property {number} sint64=0 Varint wire type
  4759. * @property {number} fixed64=1 Fixed64 wire type
  4760. * @property {number} sfixed64=1 Fixed64 wire type
  4761. * @property {number} bool=0 Varint wire type
  4762. * @property {number} string=2 Ldelim wire type
  4763. * @property {number} bytes=2 Ldelim wire type
  4764. */
  4765. types.basic = bake([
  4766. /* double */ 1,
  4767. /* float */ 5,
  4768. /* int32 */ 0,
  4769. /* uint32 */ 0,
  4770. /* sint32 */ 0,
  4771. /* fixed32 */ 5,
  4772. /* sfixed32 */ 5,
  4773. /* int64 */ 0,
  4774. /* uint64 */ 0,
  4775. /* sint64 */ 0,
  4776. /* fixed64 */ 1,
  4777. /* sfixed64 */ 1,
  4778. /* bool */ 0,
  4779. /* string */ 2,
  4780. /* bytes */ 2
  4781. ]);
  4782. /**
  4783. * Basic type defaults.
  4784. * @type {Object.<string,*>}
  4785. * @const
  4786. * @property {number} double=0 Double default
  4787. * @property {number} float=0 Float default
  4788. * @property {number} int32=0 Int32 default
  4789. * @property {number} uint32=0 Uint32 default
  4790. * @property {number} sint32=0 Sint32 default
  4791. * @property {number} fixed32=0 Fixed32 default
  4792. * @property {number} sfixed32=0 Sfixed32 default
  4793. * @property {number} int64=0 Int64 default
  4794. * @property {number} uint64=0 Uint64 default
  4795. * @property {number} sint64=0 Sint32 default
  4796. * @property {number} fixed64=0 Fixed64 default
  4797. * @property {number} sfixed64=0 Sfixed64 default
  4798. * @property {boolean} bool=false Bool default
  4799. * @property {string} string="" String default
  4800. * @property {Array.<number>} bytes=Array(0) Bytes default
  4801. * @property {null} message=null Message default
  4802. */
  4803. types.defaults = bake([
  4804. /* double */ 0,
  4805. /* float */ 0,
  4806. /* int32 */ 0,
  4807. /* uint32 */ 0,
  4808. /* sint32 */ 0,
  4809. /* fixed32 */ 0,
  4810. /* sfixed32 */ 0,
  4811. /* int64 */ 0,
  4812. /* uint64 */ 0,
  4813. /* sint64 */ 0,
  4814. /* fixed64 */ 0,
  4815. /* sfixed64 */ 0,
  4816. /* bool */ false,
  4817. /* string */ "",
  4818. /* bytes */ util.emptyArray,
  4819. /* message */ null
  4820. ]);
  4821. /**
  4822. * Basic long type wire types.
  4823. * @type {Object.<string,number>}
  4824. * @const
  4825. * @property {number} int64=0 Varint wire type
  4826. * @property {number} uint64=0 Varint wire type
  4827. * @property {number} sint64=0 Varint wire type
  4828. * @property {number} fixed64=1 Fixed64 wire type
  4829. * @property {number} sfixed64=1 Fixed64 wire type
  4830. */
  4831. types.long = bake([
  4832. /* int64 */ 0,
  4833. /* uint64 */ 0,
  4834. /* sint64 */ 0,
  4835. /* fixed64 */ 1,
  4836. /* sfixed64 */ 1
  4837. ], 7);
  4838. /**
  4839. * Allowed types for map keys with their associated wire type.
  4840. * @type {Object.<string,number>}
  4841. * @const
  4842. * @property {number} int32=0 Varint wire type
  4843. * @property {number} uint32=0 Varint wire type
  4844. * @property {number} sint32=0 Varint wire type
  4845. * @property {number} fixed32=5 Fixed32 wire type
  4846. * @property {number} sfixed32=5 Fixed32 wire type
  4847. * @property {number} int64=0 Varint wire type
  4848. * @property {number} uint64=0 Varint wire type
  4849. * @property {number} sint64=0 Varint wire type
  4850. * @property {number} fixed64=1 Fixed64 wire type
  4851. * @property {number} sfixed64=1 Fixed64 wire type
  4852. * @property {number} bool=0 Varint wire type
  4853. * @property {number} string=2 Ldelim wire type
  4854. */
  4855. types.mapKey = bake([
  4856. /* int32 */ 0,
  4857. /* uint32 */ 0,
  4858. /* sint32 */ 0,
  4859. /* fixed32 */ 5,
  4860. /* sfixed32 */ 5,
  4861. /* int64 */ 0,
  4862. /* uint64 */ 0,
  4863. /* sint64 */ 0,
  4864. /* fixed64 */ 1,
  4865. /* sfixed64 */ 1,
  4866. /* bool */ 0,
  4867. /* string */ 2
  4868. ], 2);
  4869. /**
  4870. * Allowed types for packed repeated fields with their associated wire type.
  4871. * @type {Object.<string,number>}
  4872. * @const
  4873. * @property {number} double=1 Fixed64 wire type
  4874. * @property {number} float=5 Fixed32 wire type
  4875. * @property {number} int32=0 Varint wire type
  4876. * @property {number} uint32=0 Varint wire type
  4877. * @property {number} sint32=0 Varint wire type
  4878. * @property {number} fixed32=5 Fixed32 wire type
  4879. * @property {number} sfixed32=5 Fixed32 wire type
  4880. * @property {number} int64=0 Varint wire type
  4881. * @property {number} uint64=0 Varint wire type
  4882. * @property {number} sint64=0 Varint wire type
  4883. * @property {number} fixed64=1 Fixed64 wire type
  4884. * @property {number} sfixed64=1 Fixed64 wire type
  4885. * @property {number} bool=0 Varint wire type
  4886. */
  4887. types.packed = bake([
  4888. /* double */ 1,
  4889. /* float */ 5,
  4890. /* int32 */ 0,
  4891. /* uint32 */ 0,
  4892. /* sint32 */ 0,
  4893. /* fixed32 */ 5,
  4894. /* sfixed32 */ 5,
  4895. /* int64 */ 0,
  4896. /* uint64 */ 0,
  4897. /* sint64 */ 0,
  4898. /* fixed64 */ 1,
  4899. /* sfixed64 */ 1,
  4900. /* bool */ 0
  4901. ]);
  4902. },{"24":24}],24:[function(require,module,exports){
  4903. "use strict";
  4904. /**
  4905. * Various utility functions.
  4906. * @namespace
  4907. */
  4908. var util = module.exports = require(33);
  4909. var roots = require(18);
  4910. var Type, // cyclic
  4911. Enum;
  4912. util.codegen = require(27);
  4913. util.fetch = require(29);
  4914. util.path = require(34);
  4915. util.patterns = require(35);
  4916. var reservedRe = util.patterns.reservedRe;
  4917. /**
  4918. * Node's fs module if available.
  4919. * @type {Object.<string,*>}
  4920. */
  4921. util.fs = require(31);
  4922. /**
  4923. * Converts an object's values to an array.
  4924. * @param {Object.<string,*>} object Object to convert
  4925. * @returns {Array.<*>} Converted array
  4926. */
  4927. util.toArray = function toArray(object) {
  4928. if (object) {
  4929. var keys = Object.keys(object),
  4930. array = new Array(keys.length),
  4931. index = 0;
  4932. while (index < keys.length)
  4933. array[index] = object[keys[index++]];
  4934. return array;
  4935. }
  4936. return [];
  4937. };
  4938. /**
  4939. * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
  4940. * @param {Array.<*>} array Array to convert
  4941. * @returns {Object.<string,*>} Converted object
  4942. */
  4943. util.toObject = function toObject(array) {
  4944. var object = {},
  4945. index = 0;
  4946. while (index < array.length) {
  4947. var key = array[index++],
  4948. val = array[index++];
  4949. if (val !== undefined)
  4950. object[key] = val;
  4951. }
  4952. return object;
  4953. };
  4954. /**
  4955. * Removes the first matching value from an object.
  4956. * @param {Object.<string,*>|undefined} object Object to remove from
  4957. * @param {*} value Value to remove
  4958. * @param {string} [key] Optional key for fast path removal
  4959. * @returns {boolean} `true` if removed, otherwise `false`
  4960. */
  4961. util.remove = function remove(object, value, key) {
  4962. if (!object)
  4963. return false;
  4964. if (key !== undefined && Object.prototype.hasOwnProperty.call(object, key) && object[key] === value) {
  4965. delete object[key];
  4966. return true;
  4967. }
  4968. for (var names = Object.keys(object), i = 0; i < names.length; ++i)
  4969. if (object[names[i]] === value) {
  4970. delete object[names[i]];
  4971. return true;
  4972. }
  4973. return false;
  4974. };
  4975. /**
  4976. * Tests whether the specified name is a reserved word in JS.
  4977. * @param {string} name Name to test
  4978. * @returns {boolean} `true` if reserved, otherwise `false`
  4979. */
  4980. util.isReserved = function isReserved(name) {
  4981. return reservedRe.test(name);
  4982. };
  4983. /**
  4984. * Returns a safe property accessor for the specified property name.
  4985. * @param {string} prop Property name
  4986. * @returns {string} Safe accessor
  4987. */
  4988. util.safeProp = function safeProp(prop) {
  4989. if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
  4990. return "[" + JSON.stringify(prop) + "]";
  4991. return "." + prop;
  4992. };
  4993. /**
  4994. * Converts the first character of a string to upper case.
  4995. * @param {string} str String to convert
  4996. * @returns {string} Converted string
  4997. */
  4998. util.ucFirst = function ucFirst(str) {
  4999. return str.charAt(0).toUpperCase() + str.substring(1);
  5000. };
  5001. var camelCaseRe = /_([a-z])/g;
  5002. /**
  5003. * Converts a string to camel case.
  5004. * @param {string} str String to convert
  5005. * @returns {string} Converted string
  5006. * @deprecated Use {@link util.jsonName} for protobuf field JSON names.
  5007. */
  5008. util.camelCase = function camelCase(str) {
  5009. return str.substring(0, 1)
  5010. + str.substring(1)
  5011. .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
  5012. };
  5013. /**
  5014. * Converts a proto field name to its protoc-compatible JSON name.
  5015. * @param {string} str Proto field name
  5016. * @returns {string} JSON name
  5017. */
  5018. util.jsonName = function jsonName(str) {
  5019. var result = "",
  5020. upperNext = false,
  5021. i = 0;
  5022. for (; i < str.length; ++i) {
  5023. var ch = str.charAt(i);
  5024. if (ch === "_")
  5025. upperNext = true;
  5026. else if (upperNext) {
  5027. result += ch.toUpperCase();
  5028. upperNext = false;
  5029. } else
  5030. result += ch;
  5031. }
  5032. return result;
  5033. };
  5034. /**
  5035. * Compares reflected fields by id.
  5036. * @param {Field} a First field
  5037. * @param {Field} b Second field
  5038. * @returns {number} Comparison value
  5039. */
  5040. util.compareFieldsById = function compareFieldsById(a, b) {
  5041. return a.id - b.id;
  5042. };
  5043. /**
  5044. * Decorator helper for types (TypeScript).
  5045. * @param {Constructor<T>} ctor Constructor function
  5046. * @param {string} [typeName] Type name, defaults to the constructor's name
  5047. * @returns {Type} Reflected type
  5048. * @template T extends Message<T>
  5049. * @property {Root} root Decorators root
  5050. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  5051. */
  5052. util.decorateType = function decorateType(ctor, typeName) {
  5053. /* istanbul ignore if */
  5054. if (ctor.$type) {
  5055. if (typeName && ctor.$type.name !== typeName) {
  5056. util.decorateRoot.remove(ctor.$type);
  5057. ctor.$type.name = typeName;
  5058. util.decorateRoot.add(ctor.$type);
  5059. }
  5060. return ctor.$type;
  5061. }
  5062. /* istanbul ignore next */
  5063. if (!Type)
  5064. Type = require(22);
  5065. var type = new Type(typeName || ctor.name);
  5066. util.decorateRoot.add(type);
  5067. type.ctor = ctor; // sets up .encode, .decode etc.
  5068. Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
  5069. Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
  5070. return type;
  5071. };
  5072. var decorateEnumIndex = 0;
  5073. /**
  5074. * Decorator helper for enums (TypeScript).
  5075. * @param {Object} object Enum object
  5076. * @returns {Enum} Reflected enum
  5077. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  5078. */
  5079. util.decorateEnum = function decorateEnum(object) {
  5080. /* istanbul ignore if */
  5081. if (object.$type)
  5082. return object.$type;
  5083. /* istanbul ignore next */
  5084. if (!Enum)
  5085. Enum = require(5);
  5086. var enm = new Enum("Enum" + decorateEnumIndex++, object);
  5087. util.decorateRoot.add(enm);
  5088. Object.defineProperty(object, "$type", { value: enm, enumerable: false });
  5089. return enm;
  5090. };
  5091. /**
  5092. * Sets the value of a property by property path. If a value already exists, it is turned to an array
  5093. * @param {Object.<string,*>} dst Destination object
  5094. * @param {string} path dot '.' delimited path of the property to set
  5095. * @param {Object} value the value to set
  5096. * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
  5097. * @returns {Object.<string,*>} Destination object
  5098. */
  5099. util.setProperty = function setProperty(dst, path, value, ifNotSet) {
  5100. function setProp(dst, path, value) {
  5101. var part = path.shift();
  5102. if (util.isUnsafeProperty(part))
  5103. return dst;
  5104. if (path.length > 0) {
  5105. dst[part] = setProp(dst[part] || {}, path, value);
  5106. } else {
  5107. var prevValue = dst[part];
  5108. if (prevValue && ifNotSet)
  5109. return dst;
  5110. if (prevValue)
  5111. value = [].concat(prevValue).concat(value);
  5112. dst[part] = value;
  5113. }
  5114. return dst;
  5115. }
  5116. if (typeof dst !== "object")
  5117. throw TypeError("dst must be an object");
  5118. if (!path)
  5119. throw TypeError("path must be specified");
  5120. path = path.split(".");
  5121. if (path.length > util.recursionLimit)
  5122. throw Error("max depth exceeded");
  5123. return setProp(dst, path, value);
  5124. };
  5125. /**
  5126. * Decorator root (TypeScript).
  5127. * @name util.decorateRoot
  5128. * @type {Root}
  5129. * @readonly
  5130. * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
  5131. */
  5132. Object.defineProperty(util, "decorateRoot", {
  5133. get: function() {
  5134. return roots["decorated"] || (roots["decorated"] = new (require(17))());
  5135. }
  5136. });
  5137. },{"17":17,"18":18,"22":22,"27":27,"29":29,"31":31,"33":33,"34":34,"35":35,"5":5}],25:[function(require,module,exports){
  5138. "use strict";
  5139. module.exports = asPromise;
  5140. /**
  5141. * Callback as used by {@link util.asPromise}.
  5142. * @typedef asPromiseCallback
  5143. * @type {function}
  5144. * @param {Error|null} error Error, if any
  5145. * @param {...*} params Additional arguments
  5146. * @returns {undefined}
  5147. */
  5148. /**
  5149. * Returns a promise from a node-style callback function.
  5150. * @memberof util
  5151. * @param {asPromiseCallback} fn Function to call
  5152. * @param {*} ctx Function context
  5153. * @param {...*} params Function arguments
  5154. * @returns {Promise<*>} Promisified function
  5155. */
  5156. function asPromise(fn, ctx/*, varargs */) {
  5157. var params = new Array(arguments.length - 1),
  5158. offset = 0,
  5159. index = 2,
  5160. pending = true;
  5161. while (index < arguments.length)
  5162. params[offset++] = arguments[index++];
  5163. return new Promise(function executor(resolve, reject) {
  5164. params[offset] = function callback(err/*, varargs */) {
  5165. if (pending) {
  5166. pending = false;
  5167. if (err)
  5168. reject(err);
  5169. else {
  5170. var params = new Array(arguments.length - 1),
  5171. offset = 0;
  5172. while (offset < params.length)
  5173. params[offset++] = arguments[offset];
  5174. resolve.apply(null, params);
  5175. }
  5176. }
  5177. };
  5178. try {
  5179. fn.apply(ctx || null, params);
  5180. } catch (err) {
  5181. if (pending) {
  5182. pending = false;
  5183. reject(err);
  5184. }
  5185. }
  5186. });
  5187. }
  5188. },{}],26:[function(require,module,exports){
  5189. "use strict";
  5190. /**
  5191. * A minimal base64 implementation for number arrays.
  5192. * @memberof util
  5193. * @namespace
  5194. */
  5195. var base64 = exports;
  5196. /**
  5197. * Calculates the byte length of a base64 encoded string.
  5198. * @param {string} string Base64 encoded string
  5199. * @returns {number} Byte length
  5200. */
  5201. base64.length = function length(string) {
  5202. var p = string.length;
  5203. if (!p)
  5204. return 0;
  5205. while (p > 0 && string.charAt(p - 1) === "=")
  5206. --p;
  5207. return Math.floor(p * 3 / 4);
  5208. };
  5209. // Base64 encoding table
  5210. var b64 = new Array(64);
  5211. // Base64 decoding table
  5212. var s64 = new Array(123);
  5213. // 65..90, 97..122, 48..57, 43, 47
  5214. for (var i = 0; i < 64;)
  5215. s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
  5216. s64[45] = 62; // - -> +
  5217. s64[95] = 63; // _ -> /
  5218. /**
  5219. * Encodes a buffer to a base64 encoded string.
  5220. * @param {Uint8Array} buffer Source buffer
  5221. * @param {number} start Source start
  5222. * @param {number} end Source end
  5223. * @returns {string} Base64 encoded string
  5224. */
  5225. base64.encode = function encode(buffer, start, end) {
  5226. var parts = null,
  5227. chunk = [];
  5228. var i = 0, // output index
  5229. j = 0, // goto index
  5230. t; // temporary
  5231. while (start < end) {
  5232. var b = buffer[start++];
  5233. switch (j) {
  5234. case 0:
  5235. chunk[i++] = b64[b >> 2];
  5236. t = (b & 3) << 4;
  5237. j = 1;
  5238. break;
  5239. case 1:
  5240. chunk[i++] = b64[t | b >> 4];
  5241. t = (b & 15) << 2;
  5242. j = 2;
  5243. break;
  5244. case 2:
  5245. chunk[i++] = b64[t | b >> 6];
  5246. chunk[i++] = b64[b & 63];
  5247. j = 0;
  5248. break;
  5249. }
  5250. if (i > 8191) {
  5251. (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
  5252. i = 0;
  5253. }
  5254. }
  5255. if (j) {
  5256. chunk[i++] = b64[t];
  5257. chunk[i++] = 61;
  5258. if (j === 1)
  5259. chunk[i++] = 61;
  5260. }
  5261. if (parts) {
  5262. if (i)
  5263. parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
  5264. return parts.join("");
  5265. }
  5266. return String.fromCharCode.apply(String, chunk.slice(0, i));
  5267. };
  5268. var invalidEncoding = "invalid encoding";
  5269. /**
  5270. * Decodes a base64 encoded string to a buffer.
  5271. * @param {string} string Source string
  5272. * @param {Uint8Array} buffer Destination buffer
  5273. * @param {number} offset Destination offset
  5274. * @returns {number} Number of bytes written
  5275. * @throws {Error} If encoding is invalid
  5276. */
  5277. base64.decode = function decode(string, buffer, offset) {
  5278. var start = offset;
  5279. var j = 0, // goto index
  5280. t; // temporary
  5281. for (var i = 0; i < string.length;) {
  5282. var c = string.charCodeAt(i++);
  5283. if (c === 61 && j > 1)
  5284. break;
  5285. if ((c = s64[c]) === undefined)
  5286. throw Error(invalidEncoding);
  5287. switch (j) {
  5288. case 0:
  5289. t = c;
  5290. j = 1;
  5291. break;
  5292. case 1:
  5293. buffer[offset++] = t << 2 | (c & 48) >> 4;
  5294. t = c;
  5295. j = 2;
  5296. break;
  5297. case 2:
  5298. buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
  5299. t = c;
  5300. j = 3;
  5301. break;
  5302. case 3:
  5303. buffer[offset++] = (t & 3) << 6 | c;
  5304. j = 0;
  5305. break;
  5306. }
  5307. }
  5308. if (j === 1)
  5309. throw Error(invalidEncoding);
  5310. return offset - start;
  5311. };
  5312. var base64Re = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,
  5313. base64UrlRe = /[-_]/,
  5314. base64UrlNoPaddingRe = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}(?:==)?|[A-Za-z0-9_-]{3}=?)?$/;
  5315. /**
  5316. * Tests if the specified string appears to be base64 encoded.
  5317. * @param {string} string String to test
  5318. * @returns {boolean} `true` if probably base64 encoded, otherwise false
  5319. */
  5320. base64.test = function test(string) {
  5321. return base64Re.test(string)
  5322. || base64UrlRe.test(string) && base64UrlNoPaddingRe.test(string);
  5323. };
  5324. },{}],27:[function(require,module,exports){
  5325. "use strict";
  5326. module.exports = codegen;
  5327. var patterns = require(35);
  5328. var reservedRe = patterns.reservedRe;
  5329. /**
  5330. * Begins generating a function.
  5331. * @memberof util
  5332. * @param {string[]} functionParams Function parameter names
  5333. * @param {string} [functionName] Function name if not anonymous
  5334. * @returns {Codegen} Appender that appends code to the function's body
  5335. */
  5336. function codegen(functionParams, functionName) {
  5337. /* istanbul ignore if */
  5338. if (typeof functionParams === "string") {
  5339. functionName = functionParams;
  5340. functionParams = undefined;
  5341. }
  5342. var body = [];
  5343. /**
  5344. * Appends code to the function's body or finishes generation.
  5345. * @typedef Codegen
  5346. * @type {function}
  5347. * @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
  5348. * @param {...*} [formatParams] Format parameters
  5349. * @returns {Codegen|Function} Itself or the generated function if finished
  5350. * @throws {Error} If format parameter counts do not match
  5351. */
  5352. function Codegen(formatStringOrScope) {
  5353. // note that explicit array handling below makes this ~50% faster
  5354. // finish the function
  5355. if (typeof formatStringOrScope !== "string") {
  5356. var source = toString();
  5357. if (codegen.verbose)
  5358. console.log("codegen: " + source); // eslint-disable-line no-console
  5359. source = "return " + source;
  5360. if (formatStringOrScope) {
  5361. var scopeKeys = Object.keys(formatStringOrScope),
  5362. scopeParams = new Array(scopeKeys.length + 1),
  5363. scopeValues = new Array(scopeKeys.length),
  5364. scopeOffset = 0;
  5365. while (scopeOffset < scopeKeys.length) {
  5366. scopeParams[scopeOffset] = scopeKeys[scopeOffset];
  5367. scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
  5368. }
  5369. scopeParams[scopeOffset] = source;
  5370. return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
  5371. }
  5372. return Function(source)(); // eslint-disable-line no-new-func
  5373. }
  5374. // otherwise append to body
  5375. var formatParams = new Array(arguments.length - 1),
  5376. formatOffset = 0;
  5377. while (formatOffset < formatParams.length)
  5378. formatParams[formatOffset] = arguments[++formatOffset];
  5379. formatOffset = 0;
  5380. formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
  5381. var value = formatParams[formatOffset++];
  5382. switch ($1) {
  5383. case "d": case "f": return String(Number(value));
  5384. case "i": return String(Math.floor(value));
  5385. case "j": return JSON.stringify(value);
  5386. case "s": return String(value);
  5387. }
  5388. return "%";
  5389. });
  5390. if (formatOffset !== formatParams.length)
  5391. throw Error("parameter count mismatch");
  5392. body.push(formatStringOrScope);
  5393. return Codegen;
  5394. }
  5395. function toString(functionNameOverride) {
  5396. return "function " + safeFunctionName(functionNameOverride || functionName) + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
  5397. }
  5398. Codegen.toString = toString;
  5399. return Codegen;
  5400. }
  5401. /**
  5402. * Begins generating a function.
  5403. * @memberof util
  5404. * @function codegen
  5405. * @param {string} [functionName] Function name if not anonymous
  5406. * @returns {Codegen} Appender that appends code to the function's body
  5407. * @variation 2
  5408. */
  5409. /**
  5410. * When set to `true`, codegen will log generated code to console. Useful for debugging.
  5411. * @name util.codegen.verbose
  5412. * @type {boolean}
  5413. */
  5414. codegen.verbose = false;
  5415. function safeFunctionName(name) {
  5416. if (!name)
  5417. return "";
  5418. name = String(name).replace(/[^\w$]/g, "");
  5419. if (!name)
  5420. return "";
  5421. if (/^\d/.test(name))
  5422. name = "_" + name;
  5423. return reservedRe.test(name) ? name + "_" : name;
  5424. }
  5425. },{"35":35}],28:[function(require,module,exports){
  5426. "use strict";
  5427. module.exports = EventEmitter;
  5428. /**
  5429. * Constructs a new event emitter instance.
  5430. * @classdesc A minimal event emitter.
  5431. * @memberof util
  5432. * @constructor
  5433. */
  5434. function EventEmitter() {
  5435. /**
  5436. * Registered listeners.
  5437. * @type {Object.<string,*>}
  5438. * @private
  5439. */
  5440. this._listeners = Object.create(null);
  5441. }
  5442. /**
  5443. * Event listener as used by {@link util.EventEmitter}.
  5444. * @typedef EventEmitterListener
  5445. * @type {function}
  5446. * @param {...*} args Arguments
  5447. * @returns {undefined}
  5448. */
  5449. /**
  5450. * Registers an event listener.
  5451. * @param {string} evt Event name
  5452. * @param {EventEmitterListener} fn Listener
  5453. * @param {*} [ctx] Listener context
  5454. * @returns {this} `this`
  5455. */
  5456. EventEmitter.prototype.on = function on(evt, fn, ctx) {
  5457. (this._listeners[evt] || (this._listeners[evt] = [])).push({
  5458. fn : fn,
  5459. ctx : ctx || this
  5460. });
  5461. return this;
  5462. };
  5463. /**
  5464. * Removes an event listener or any matching listeners if arguments are omitted.
  5465. * @param {string} [evt] Event name. Removes all listeners if omitted.
  5466. * @param {EventEmitterListener} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
  5467. * @returns {this} `this`
  5468. */
  5469. EventEmitter.prototype.off = function off(evt, fn) {
  5470. if (evt === undefined)
  5471. this._listeners = Object.create(null);
  5472. else {
  5473. if (fn === undefined)
  5474. this._listeners[evt] = [];
  5475. else {
  5476. var listeners = this._listeners[evt];
  5477. if (!listeners)
  5478. return this;
  5479. for (var i = 0; i < listeners.length;)
  5480. if (listeners[i].fn === fn)
  5481. listeners.splice(i, 1);
  5482. else
  5483. ++i;
  5484. }
  5485. }
  5486. return this;
  5487. };
  5488. /**
  5489. * Emits an event by calling its listeners with the specified arguments.
  5490. * @param {string} evt Event name
  5491. * @param {...*} args Arguments
  5492. * @returns {this} `this`
  5493. */
  5494. EventEmitter.prototype.emit = function emit(evt) {
  5495. var listeners = this._listeners[evt];
  5496. if (listeners) {
  5497. var args = [],
  5498. i = 1;
  5499. for (; i < arguments.length;)
  5500. args.push(arguments[i++]);
  5501. for (i = 0; i < listeners.length;)
  5502. listeners[i].fn.apply(listeners[i++].ctx, args);
  5503. }
  5504. return this;
  5505. };
  5506. },{}],29:[function(require,module,exports){
  5507. "use strict";
  5508. module.exports = fetch;
  5509. var asPromise = require(25),
  5510. fs = require(31);
  5511. /**
  5512. * Node-style callback as used by {@link util.fetch}.
  5513. * @typedef FetchCallback
  5514. * @type {function}
  5515. * @param {?Error} error Error, if any, otherwise `null`
  5516. * @param {string} [contents] File contents, if there hasn't been an error
  5517. * @returns {undefined}
  5518. */
  5519. /**
  5520. * Options as used by {@link util.fetch}.
  5521. * @interface IFetchOptions
  5522. * @property {boolean} [binary=false] Whether expecting a binary response
  5523. * @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
  5524. */
  5525. /**
  5526. * Fetches the contents of a file.
  5527. * @memberof util
  5528. * @param {string} filename File path or url
  5529. * @param {IFetchOptions} options Fetch options
  5530. * @param {FetchCallback} callback Callback function
  5531. * @returns {undefined}
  5532. */
  5533. function fetch(filename, options, callback) {
  5534. if (typeof options === "function") {
  5535. callback = options;
  5536. options = {};
  5537. } else if (!options)
  5538. options = {};
  5539. if (!callback)
  5540. return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
  5541. // if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
  5542. if (!options.xhr && fs && fs.readFile)
  5543. return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
  5544. return err && typeof XMLHttpRequest !== "undefined"
  5545. ? fetch.xhr(filename, options, callback)
  5546. : err
  5547. ? callback(err)
  5548. : callback(null, options.binary ? contents : contents.toString("utf8"));
  5549. });
  5550. // use the XHR version otherwise.
  5551. return fetch.xhr(filename, options, callback);
  5552. }
  5553. /**
  5554. * Fetches the contents of a file.
  5555. * @name util.fetch
  5556. * @function
  5557. * @param {string} path File path or url
  5558. * @param {FetchCallback} callback Callback function
  5559. * @returns {undefined}
  5560. * @variation 2
  5561. */
  5562. /**
  5563. * Fetches the contents of a file.
  5564. * @name util.fetch
  5565. * @function
  5566. * @param {string} path File path or url
  5567. * @param {IFetchOptions} [options] Fetch options
  5568. * @returns {Promise<string|Uint8Array>} Promise
  5569. * @variation 3
  5570. */
  5571. /**/
  5572. fetch.xhr = function fetch_xhr(filename, options, callback) {
  5573. var xhr = new XMLHttpRequest();
  5574. xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
  5575. if (xhr.readyState !== 4)
  5576. return undefined;
  5577. // local cors security errors return status 0 / empty string, too. afaik this cannot be
  5578. // reliably distinguished from an actually empty file for security reasons. feel free
  5579. // to send a pull request if you are aware of a solution.
  5580. if (xhr.status !== 0 && xhr.status !== 200)
  5581. return callback(Error("status " + xhr.status));
  5582. // if binary data is expected, make sure that some sort of array is returned, even if
  5583. // ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
  5584. if (options.binary) {
  5585. var buffer = xhr.response;
  5586. if (!buffer) {
  5587. buffer = [];
  5588. for (var i = 0; i < xhr.responseText.length; ++i)
  5589. buffer.push(xhr.responseText.charCodeAt(i) & 255);
  5590. }
  5591. return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
  5592. }
  5593. return callback(null, xhr.responseText);
  5594. };
  5595. if (options.binary) {
  5596. // ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
  5597. if ("overrideMimeType" in xhr)
  5598. xhr.overrideMimeType("text/plain; charset=x-user-defined");
  5599. xhr.responseType = "arraybuffer";
  5600. }
  5601. xhr.open("GET", filename);
  5602. xhr.send();
  5603. };
  5604. },{"25":25,"31":31}],30:[function(require,module,exports){
  5605. "use strict";
  5606. module.exports = factory(factory);
  5607. /**
  5608. * Reads / writes floats / doubles from / to buffers.
  5609. * @name util.float
  5610. * @namespace
  5611. */
  5612. /**
  5613. * Writes a 32 bit float to a buffer using little endian byte order.
  5614. * @name util.float.writeFloatLE
  5615. * @function
  5616. * @param {number} val Value to write
  5617. * @param {Uint8Array} buf Target buffer
  5618. * @param {number} pos Target buffer offset
  5619. * @returns {undefined}
  5620. */
  5621. /**
  5622. * Writes a 32 bit float to a buffer using big endian byte order.
  5623. * @name util.float.writeFloatBE
  5624. * @function
  5625. * @param {number} val Value to write
  5626. * @param {Uint8Array} buf Target buffer
  5627. * @param {number} pos Target buffer offset
  5628. * @returns {undefined}
  5629. */
  5630. /**
  5631. * Reads a 32 bit float from a buffer using little endian byte order.
  5632. * @name util.float.readFloatLE
  5633. * @function
  5634. * @param {Uint8Array} buf Source buffer
  5635. * @param {number} pos Source buffer offset
  5636. * @returns {number} Value read
  5637. */
  5638. /**
  5639. * Reads a 32 bit float from a buffer using big endian byte order.
  5640. * @name util.float.readFloatBE
  5641. * @function
  5642. * @param {Uint8Array} buf Source buffer
  5643. * @param {number} pos Source buffer offset
  5644. * @returns {number} Value read
  5645. */
  5646. /**
  5647. * Writes a 64 bit double to a buffer using little endian byte order.
  5648. * @name util.float.writeDoubleLE
  5649. * @function
  5650. * @param {number} val Value to write
  5651. * @param {Uint8Array} buf Target buffer
  5652. * @param {number} pos Target buffer offset
  5653. * @returns {undefined}
  5654. */
  5655. /**
  5656. * Writes a 64 bit double to a buffer using big endian byte order.
  5657. * @name util.float.writeDoubleBE
  5658. * @function
  5659. * @param {number} val Value to write
  5660. * @param {Uint8Array} buf Target buffer
  5661. * @param {number} pos Target buffer offset
  5662. * @returns {undefined}
  5663. */
  5664. /**
  5665. * Reads a 64 bit double from a buffer using little endian byte order.
  5666. * @name util.float.readDoubleLE
  5667. * @function
  5668. * @param {Uint8Array} buf Source buffer
  5669. * @param {number} pos Source buffer offset
  5670. * @returns {number} Value read
  5671. */
  5672. /**
  5673. * Reads a 64 bit double from a buffer using big endian byte order.
  5674. * @name util.float.readDoubleBE
  5675. * @function
  5676. * @param {Uint8Array} buf Source buffer
  5677. * @param {number} pos Source buffer offset
  5678. * @returns {number} Value read
  5679. */
  5680. // Factory function for the purpose of node-based testing in modified global environments
  5681. function factory(exports) {
  5682. // float: typed array
  5683. if (typeof Float32Array !== "undefined") (function() {
  5684. var f32 = new Float32Array([ -0 ]),
  5685. f8b = new Uint8Array(f32.buffer),
  5686. le = f8b[3] === 128;
  5687. function writeFloat_f32_cpy(val, buf, pos) {
  5688. f32[0] = val;
  5689. buf[pos ] = f8b[0];
  5690. buf[pos + 1] = f8b[1];
  5691. buf[pos + 2] = f8b[2];
  5692. buf[pos + 3] = f8b[3];
  5693. }
  5694. function writeFloat_f32_rev(val, buf, pos) {
  5695. f32[0] = val;
  5696. buf[pos ] = f8b[3];
  5697. buf[pos + 1] = f8b[2];
  5698. buf[pos + 2] = f8b[1];
  5699. buf[pos + 3] = f8b[0];
  5700. }
  5701. /* istanbul ignore next */
  5702. exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
  5703. /* istanbul ignore next */
  5704. exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
  5705. function readFloat_f32_cpy(buf, pos) {
  5706. f8b[0] = buf[pos ];
  5707. f8b[1] = buf[pos + 1];
  5708. f8b[2] = buf[pos + 2];
  5709. f8b[3] = buf[pos + 3];
  5710. return f32[0];
  5711. }
  5712. function readFloat_f32_rev(buf, pos) {
  5713. f8b[3] = buf[pos ];
  5714. f8b[2] = buf[pos + 1];
  5715. f8b[1] = buf[pos + 2];
  5716. f8b[0] = buf[pos + 3];
  5717. return f32[0];
  5718. }
  5719. /* istanbul ignore next */
  5720. exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
  5721. /* istanbul ignore next */
  5722. exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
  5723. // float: ieee754
  5724. })(); else (function() {
  5725. function writeFloat_ieee754(writeUint, val, buf, pos) {
  5726. var sign = val < 0 ? 1 : 0;
  5727. if (sign)
  5728. val = -val;
  5729. if (val === 0)
  5730. writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
  5731. else if (isNaN(val))
  5732. writeUint(2143289344, buf, pos);
  5733. else if (val > 3.4028234663852886e+38) // +-Infinity
  5734. writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
  5735. else if (val < 1.1754943508222875e-38) // denormal
  5736. writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
  5737. else {
  5738. var exponent = Math.floor(Math.log(val) / Math.LN2),
  5739. mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
  5740. writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
  5741. }
  5742. }
  5743. exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
  5744. exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
  5745. function readFloat_ieee754(readUint, buf, pos) {
  5746. var uint = readUint(buf, pos),
  5747. sign = (uint >> 31) * 2 + 1,
  5748. exponent = uint >>> 23 & 255,
  5749. mantissa = uint & 8388607;
  5750. return exponent === 255
  5751. ? mantissa
  5752. ? NaN
  5753. : sign * Infinity
  5754. : exponent === 0 // denormal
  5755. ? sign * 1.401298464324817e-45 * mantissa
  5756. : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
  5757. }
  5758. exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
  5759. exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
  5760. })();
  5761. // double: typed array
  5762. if (typeof Float64Array !== "undefined") (function() {
  5763. var f64 = new Float64Array([-0]),
  5764. f8b = new Uint8Array(f64.buffer),
  5765. le = f8b[7] === 128;
  5766. function writeDouble_f64_cpy(val, buf, pos) {
  5767. f64[0] = val;
  5768. buf[pos ] = f8b[0];
  5769. buf[pos + 1] = f8b[1];
  5770. buf[pos + 2] = f8b[2];
  5771. buf[pos + 3] = f8b[3];
  5772. buf[pos + 4] = f8b[4];
  5773. buf[pos + 5] = f8b[5];
  5774. buf[pos + 6] = f8b[6];
  5775. buf[pos + 7] = f8b[7];
  5776. }
  5777. function writeDouble_f64_rev(val, buf, pos) {
  5778. f64[0] = val;
  5779. buf[pos ] = f8b[7];
  5780. buf[pos + 1] = f8b[6];
  5781. buf[pos + 2] = f8b[5];
  5782. buf[pos + 3] = f8b[4];
  5783. buf[pos + 4] = f8b[3];
  5784. buf[pos + 5] = f8b[2];
  5785. buf[pos + 6] = f8b[1];
  5786. buf[pos + 7] = f8b[0];
  5787. }
  5788. /* istanbul ignore next */
  5789. exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
  5790. /* istanbul ignore next */
  5791. exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
  5792. function readDouble_f64_cpy(buf, pos) {
  5793. f8b[0] = buf[pos ];
  5794. f8b[1] = buf[pos + 1];
  5795. f8b[2] = buf[pos + 2];
  5796. f8b[3] = buf[pos + 3];
  5797. f8b[4] = buf[pos + 4];
  5798. f8b[5] = buf[pos + 5];
  5799. f8b[6] = buf[pos + 6];
  5800. f8b[7] = buf[pos + 7];
  5801. return f64[0];
  5802. }
  5803. function readDouble_f64_rev(buf, pos) {
  5804. f8b[7] = buf[pos ];
  5805. f8b[6] = buf[pos + 1];
  5806. f8b[5] = buf[pos + 2];
  5807. f8b[4] = buf[pos + 3];
  5808. f8b[3] = buf[pos + 4];
  5809. f8b[2] = buf[pos + 5];
  5810. f8b[1] = buf[pos + 6];
  5811. f8b[0] = buf[pos + 7];
  5812. return f64[0];
  5813. }
  5814. /* istanbul ignore next */
  5815. exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
  5816. /* istanbul ignore next */
  5817. exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
  5818. // double: ieee754
  5819. })(); else (function() {
  5820. function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
  5821. var sign = val < 0 ? 1 : 0;
  5822. if (sign)
  5823. val = -val;
  5824. if (val === 0) {
  5825. writeUint(0, buf, pos + off0);
  5826. writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
  5827. } else if (isNaN(val)) {
  5828. writeUint(0, buf, pos + off0);
  5829. writeUint(2146959360, buf, pos + off1);
  5830. } else if (val > 1.7976931348623157e+308) { // +-Infinity
  5831. writeUint(0, buf, pos + off0);
  5832. writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
  5833. } else {
  5834. var mantissa;
  5835. if (val < 2.2250738585072014e-308) { // denormal
  5836. mantissa = val / 5e-324;
  5837. writeUint(mantissa >>> 0, buf, pos + off0);
  5838. writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
  5839. } else {
  5840. var exponent = Math.floor(Math.log(val) / Math.LN2);
  5841. if (exponent === 1024)
  5842. exponent = 1023;
  5843. mantissa = val * Math.pow(2, -exponent);
  5844. writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
  5845. writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
  5846. }
  5847. }
  5848. }
  5849. exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
  5850. exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
  5851. function readDouble_ieee754(readUint, off0, off1, buf, pos) {
  5852. var lo = readUint(buf, pos + off0),
  5853. hi = readUint(buf, pos + off1);
  5854. var sign = (hi >> 31) * 2 + 1,
  5855. exponent = hi >>> 20 & 2047,
  5856. mantissa = 4294967296 * (hi & 1048575) + lo;
  5857. return exponent === 2047
  5858. ? mantissa
  5859. ? NaN
  5860. : sign * Infinity
  5861. : exponent === 0 // denormal
  5862. ? sign * 5e-324 * mantissa
  5863. : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
  5864. }
  5865. exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
  5866. exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
  5867. })();
  5868. return exports;
  5869. }
  5870. // uint helpers
  5871. function writeUintLE(val, buf, pos) {
  5872. buf[pos ] = val & 255;
  5873. buf[pos + 1] = val >>> 8 & 255;
  5874. buf[pos + 2] = val >>> 16 & 255;
  5875. buf[pos + 3] = val >>> 24;
  5876. }
  5877. function writeUintBE(val, buf, pos) {
  5878. buf[pos ] = val >>> 24;
  5879. buf[pos + 1] = val >>> 16 & 255;
  5880. buf[pos + 2] = val >>> 8 & 255;
  5881. buf[pos + 3] = val & 255;
  5882. }
  5883. function readUintLE(buf, pos) {
  5884. return (buf[pos ]
  5885. | buf[pos + 1] << 8
  5886. | buf[pos + 2] << 16
  5887. | buf[pos + 3] << 24) >>> 0;
  5888. }
  5889. function readUintBE(buf, pos) {
  5890. return (buf[pos ] << 24
  5891. | buf[pos + 1] << 16
  5892. | buf[pos + 2] << 8
  5893. | buf[pos + 3]) >>> 0;
  5894. }
  5895. },{}],31:[function(require,module,exports){
  5896. "use strict";
  5897. var fs = null;
  5898. try {
  5899. fs = require(1);
  5900. if (!fs || !fs.readFile || !fs.readFileSync)
  5901. fs = null;
  5902. } catch (e) {
  5903. // `fs` is unavailable in browsers and browser-like bundles.
  5904. }
  5905. module.exports = fs;
  5906. },{"1":1}],32:[function(require,module,exports){
  5907. "use strict";
  5908. module.exports = LongBits;
  5909. var util = require(33);
  5910. /**
  5911. * Constructs new long bits.
  5912. * @classdesc Helper class for working with the low and high bits of a 64 bit value.
  5913. * @memberof util
  5914. * @constructor
  5915. * @param {number} lo Low 32 bits, unsigned
  5916. * @param {number} hi High 32 bits, unsigned
  5917. */
  5918. function LongBits(lo, hi) {
  5919. // note that the casts below are theoretically unnecessary as of today, but older statically
  5920. // generated converter code might still call the ctor with signed 32bits. kept for compat.
  5921. /**
  5922. * Low bits.
  5923. * @type {number}
  5924. */
  5925. this.lo = lo >>> 0;
  5926. /**
  5927. * High bits.
  5928. * @type {number}
  5929. */
  5930. this.hi = hi >>> 0;
  5931. }
  5932. /**
  5933. * Zero bits.
  5934. * @memberof util.LongBits
  5935. * @type {util.LongBits}
  5936. */
  5937. var zero = LongBits.zero = new LongBits(0, 0);
  5938. zero.toNumber = function() { return 0; };
  5939. zero.zzEncode = zero.zzDecode = function() { return this; };
  5940. zero.length = function() { return 1; };
  5941. /**
  5942. * Zero hash.
  5943. * @memberof util.LongBits
  5944. * @type {string}
  5945. */
  5946. var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
  5947. /**
  5948. * Constructs new long bits from the specified number.
  5949. * @param {number} value Value
  5950. * @returns {util.LongBits} Instance
  5951. */
  5952. LongBits.fromNumber = function fromNumber(value) {
  5953. if (value === 0)
  5954. return zero;
  5955. var sign = value < 0;
  5956. if (sign)
  5957. value = -value;
  5958. var lo = value >>> 0,
  5959. hi = (value - lo) / 4294967296 >>> 0;
  5960. if (sign) {
  5961. hi = ~hi >>> 0;
  5962. lo = ~lo >>> 0;
  5963. if (++lo > 4294967295) {
  5964. lo = 0;
  5965. if (++hi > 4294967295)
  5966. hi = 0;
  5967. }
  5968. }
  5969. return new LongBits(lo, hi);
  5970. };
  5971. /**
  5972. * Constructs new long bits from a number, long or string.
  5973. * @param {Long|number|string} value Value
  5974. * @returns {util.LongBits} Instance
  5975. */
  5976. LongBits.from = function from(value) {
  5977. if (typeof value === "number")
  5978. return LongBits.fromNumber(value);
  5979. if (util.isString(value)) {
  5980. /* istanbul ignore else */
  5981. if (util.Long)
  5982. value = util.Long.fromString(value);
  5983. else
  5984. return LongBits.fromNumber(parseInt(value, 10));
  5985. }
  5986. return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
  5987. };
  5988. /**
  5989. * Converts this long bits to a possibly unsafe JavaScript number.
  5990. * @param {boolean} [unsigned=false] Whether unsigned or not
  5991. * @returns {number} Possibly unsafe number
  5992. */
  5993. LongBits.prototype.toNumber = function toNumber(unsigned) {
  5994. if (!unsigned && this.hi >>> 31) {
  5995. var lo = ~this.lo + 1 >>> 0,
  5996. hi = ~this.hi >>> 0;
  5997. if (!lo)
  5998. hi = hi + 1 >>> 0;
  5999. return -(lo + hi * 4294967296);
  6000. }
  6001. return this.lo + this.hi * 4294967296;
  6002. };
  6003. /**
  6004. * Converts this long bits to a long.
  6005. * @param {boolean} [unsigned=false] Whether unsigned or not
  6006. * @returns {Long} Long
  6007. */
  6008. LongBits.prototype.toLong = function toLong(unsigned) {
  6009. return util.Long
  6010. ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
  6011. /* istanbul ignore next */
  6012. : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
  6013. };
  6014. var charCodeAt = String.prototype.charCodeAt;
  6015. /**
  6016. * Constructs new long bits from the specified 8 characters long hash.
  6017. * @param {string} hash Hash
  6018. * @returns {util.LongBits} Bits
  6019. */
  6020. LongBits.fromHash = function fromHash(hash) {
  6021. if (hash === zeroHash)
  6022. return zero;
  6023. return new LongBits(
  6024. ( charCodeAt.call(hash, 0)
  6025. | charCodeAt.call(hash, 1) << 8
  6026. | charCodeAt.call(hash, 2) << 16
  6027. | charCodeAt.call(hash, 3) << 24) >>> 0
  6028. ,
  6029. ( charCodeAt.call(hash, 4)
  6030. | charCodeAt.call(hash, 5) << 8
  6031. | charCodeAt.call(hash, 6) << 16
  6032. | charCodeAt.call(hash, 7) << 24) >>> 0
  6033. );
  6034. };
  6035. /**
  6036. * Converts this long bits to a 8 characters long hash.
  6037. * @returns {string} Hash
  6038. */
  6039. LongBits.prototype.toHash = function toHash() {
  6040. return String.fromCharCode(
  6041. this.lo & 255,
  6042. this.lo >>> 8 & 255,
  6043. this.lo >>> 16 & 255,
  6044. this.lo >>> 24 ,
  6045. this.hi & 255,
  6046. this.hi >>> 8 & 255,
  6047. this.hi >>> 16 & 255,
  6048. this.hi >>> 24
  6049. );
  6050. };
  6051. /**
  6052. * Zig-zag encodes this long bits.
  6053. * @returns {util.LongBits} `this`
  6054. */
  6055. LongBits.prototype.zzEncode = function zzEncode() {
  6056. var mask = this.hi >> 31;
  6057. this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
  6058. this.lo = ( this.lo << 1 ^ mask) >>> 0;
  6059. return this;
  6060. };
  6061. /**
  6062. * Zig-zag decodes this long bits.
  6063. * @returns {util.LongBits} `this`
  6064. */
  6065. LongBits.prototype.zzDecode = function zzDecode() {
  6066. var mask = -(this.lo & 1);
  6067. this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
  6068. this.hi = ( this.hi >>> 1 ^ mask) >>> 0;
  6069. return this;
  6070. };
  6071. /**
  6072. * Calculates the length of this longbits when encoded as a varint.
  6073. * @returns {number} Length
  6074. */
  6075. LongBits.prototype.length = function length() {
  6076. var part0 = this.lo,
  6077. part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
  6078. part2 = this.hi >>> 24;
  6079. return part2 === 0
  6080. ? part1 === 0
  6081. ? part0 < 16384
  6082. ? part0 < 128 ? 1 : 2
  6083. : part0 < 2097152 ? 3 : 4
  6084. : part1 < 16384
  6085. ? part1 < 128 ? 5 : 6
  6086. : part1 < 2097152 ? 7 : 8
  6087. : part2 < 128 ? 9 : 10;
  6088. };
  6089. },{"33":33}],33:[function(require,module,exports){
  6090. "use strict";
  6091. var util = exports;
  6092. // used to return a Promise where callback is omitted
  6093. util.asPromise = require(25);
  6094. // converts to / from base64 encoded strings
  6095. util.base64 = require(26);
  6096. // base class of rpc.Service
  6097. util.EventEmitter = require(28);
  6098. // float handling accross browsers
  6099. util.float = require(30);
  6100. // converts to / from utf8 encoded strings
  6101. util.utf8 = require(37);
  6102. // provides a node-like buffer pool in the browser
  6103. util.pool = require(36);
  6104. // utility to work with the low and high bits of a 64 bit value
  6105. util.LongBits = require(32);
  6106. /**
  6107. * Tests if the specified key can affect object prototypes.
  6108. * @memberof util
  6109. * @param {string} key Key to test
  6110. * @returns {boolean} `true` if the key is unsafe
  6111. */
  6112. function isUnsafeProperty(key) {
  6113. return key === "__proto__" || key === "prototype" || key === "constructor";
  6114. }
  6115. util.isUnsafeProperty = isUnsafeProperty;
  6116. /**
  6117. * Whether running within node or not.
  6118. * @memberof util
  6119. * @type {boolean}
  6120. */
  6121. util.isNode = Boolean(typeof global !== "undefined"
  6122. && global
  6123. && global.process
  6124. && global.process.versions
  6125. && global.process.versions.node);
  6126. /**
  6127. * Global object reference.
  6128. * @memberof util
  6129. * @type {Object}
  6130. */
  6131. util.global = util.isNode && global
  6132. || typeof window !== "undefined" && window
  6133. || typeof self !== "undefined" && self
  6134. || this; // eslint-disable-line no-invalid-this
  6135. /**
  6136. * An immuable empty array.
  6137. * @memberof util
  6138. * @type {Array.<*>}
  6139. * @const
  6140. */
  6141. util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
  6142. /**
  6143. * An immutable empty object.
  6144. * @type {Object}
  6145. * @const
  6146. */
  6147. util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
  6148. /**
  6149. * Tests if the specified value is an integer.
  6150. * @function
  6151. * @param {*} value Value to test
  6152. * @returns {boolean} `true` if the value is an integer
  6153. */
  6154. util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
  6155. return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
  6156. };
  6157. /**
  6158. * Tests if the specified value is a string.
  6159. * @param {*} value Value to test
  6160. * @returns {boolean} `true` if the value is a string
  6161. */
  6162. util.isString = function isString(value) {
  6163. return typeof value === "string" || value instanceof String;
  6164. };
  6165. /**
  6166. * Tests if the specified value is a non-null object.
  6167. * @param {*} value Value to test
  6168. * @returns {boolean} `true` if the value is a non-null object
  6169. */
  6170. util.isObject = function isObject(value) {
  6171. return value && typeof value === "object";
  6172. };
  6173. /**
  6174. * Checks if a property on a message is considered to be present.
  6175. * This is an alias of {@link util.isSet}.
  6176. * @function
  6177. * @param {Object} obj Plain object or message instance
  6178. * @param {string} prop Property name
  6179. * @returns {boolean} `true` if considered to be present, otherwise `false`
  6180. */
  6181. util.isset =
  6182. /**
  6183. * Checks if a property on a message is considered to be present.
  6184. * @param {Object} obj Plain object or message instance
  6185. * @param {string} prop Property name
  6186. * @returns {boolean} `true` if considered to be present, otherwise `false`
  6187. */
  6188. util.isSet = function isSet(obj, prop) {
  6189. var value = obj[prop];
  6190. if (value != null && Object.hasOwnProperty.call(obj, prop)) // eslint-disable-line eqeqeq
  6191. return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
  6192. return false;
  6193. };
  6194. /**
  6195. * Any compatible Buffer instance.
  6196. * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
  6197. * @interface Buffer
  6198. * @extends Uint8Array
  6199. */
  6200. /**
  6201. * Node's Buffer class if available.
  6202. * @type {Constructor<Buffer>}
  6203. */
  6204. util.Buffer = (function() {
  6205. try {
  6206. var Buffer = util.global.Buffer;
  6207. // refuse to use non-node buffers if not explicitly assigned (perf reasons):
  6208. return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
  6209. } catch (e) {
  6210. /* istanbul ignore next */
  6211. return null;
  6212. }
  6213. })();
  6214. // Internal alias of or polyfull for Buffer.from.
  6215. util._Buffer_from = null;
  6216. // Internal alias of or polyfill for Buffer.allocUnsafe.
  6217. util._Buffer_allocUnsafe = null;
  6218. /**
  6219. * Creates a new buffer of whatever type supported by the environment.
  6220. * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
  6221. * @returns {Uint8Array|Buffer} Buffer
  6222. */
  6223. util.newBuffer = function newBuffer(sizeOrArray) {
  6224. /* istanbul ignore next */
  6225. return typeof sizeOrArray === "number"
  6226. ? util.Buffer
  6227. ? util._Buffer_allocUnsafe(sizeOrArray)
  6228. : new util.Array(sizeOrArray)
  6229. : util.Buffer
  6230. ? util._Buffer_from(sizeOrArray)
  6231. : typeof Uint8Array === "undefined"
  6232. ? sizeOrArray
  6233. : new Uint8Array(sizeOrArray);
  6234. };
  6235. /**
  6236. * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
  6237. * @type {Constructor<Uint8Array>}
  6238. */
  6239. util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
  6240. /**
  6241. * Any compatible Long instance.
  6242. * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
  6243. * @interface Long
  6244. * @property {number} low Low bits
  6245. * @property {number} high High bits
  6246. * @property {boolean} unsigned Whether unsigned or not
  6247. */
  6248. /**
  6249. * Long.js's Long class if available.
  6250. * @type {Constructor<Long>}
  6251. */
  6252. util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
  6253. || /* istanbul ignore next */ util.global.Long
  6254. || (function() {
  6255. try {
  6256. var Long = require("long");
  6257. return Long && Long.isLong ? Long : null;
  6258. } catch (e) {
  6259. /* istanbul ignore next */
  6260. return null;
  6261. }
  6262. })();
  6263. /**
  6264. * Regular expression used to verify 2 bit (`bool`) map keys.
  6265. * @type {RegExp}
  6266. * @const
  6267. */
  6268. util.key2Re = /^(?:true|false|0|1)$/;
  6269. /**
  6270. * Regular expression used to verify 32 bit (`int32` etc.) map keys.
  6271. * @type {RegExp}
  6272. * @const
  6273. */
  6274. util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
  6275. /**
  6276. * Regular expression used to verify 64 bit (`int64` etc.) map keys.
  6277. * @type {RegExp}
  6278. * @const
  6279. */
  6280. util.key64Re = /^(?:[\x00-\xff]{8}|-?(?:0|[1-9][0-9]*))$/; // eslint-disable-line no-control-regex
  6281. /**
  6282. * Converts a number or long to an 8 characters long hash string.
  6283. * @param {Long|number} value Value to convert
  6284. * @returns {string} Hash
  6285. */
  6286. util.longToHash = function longToHash(value) {
  6287. return value
  6288. ? util.LongBits.from(value).toHash()
  6289. : util.LongBits.zeroHash;
  6290. };
  6291. /**
  6292. * Converts an 8 characters long hash string to a long or number.
  6293. * @param {string} hash Hash
  6294. * @param {boolean} [unsigned=false] Whether unsigned or not
  6295. * @returns {Long|number} Original value
  6296. */
  6297. util.longFromHash = function longFromHash(hash, unsigned) {
  6298. var bits = util.LongBits.fromHash(hash);
  6299. if (util.Long)
  6300. return util.Long.fromBits(bits.lo, bits.hi, unsigned);
  6301. return bits.toNumber(Boolean(unsigned));
  6302. };
  6303. /**
  6304. * Converts a 64 bit key to a long or number if it is an 8 characters long hash string.
  6305. * @param {string} key Map key
  6306. * @param {boolean} [unsigned=false] Whether unsigned or not
  6307. * @returns {Long|number|string} Original value
  6308. */
  6309. util.longFromKey = function longFromKey(key, unsigned) {
  6310. return util.key64Re.test(key) && !util.key32Re.test(key)
  6311. ? util.longFromHash(key, unsigned)
  6312. : key;
  6313. };
  6314. /**
  6315. * Converts a boolean key to a boolean value.
  6316. * @param {string} key Map key
  6317. * @returns {boolean} Boolean value
  6318. */
  6319. util.boolFromKey = function boolFromKey(key) {
  6320. return key === "true" || key === "1";
  6321. };
  6322. /**
  6323. * Merges the properties of the source object into the destination object.
  6324. * @memberof util
  6325. * @param {Object.<string,*>} dst Destination object
  6326. * @param {...(Object.<string,*>|boolean)} src Source objects, optionally followed by an `ifNotSet` flag
  6327. * @returns {Object.<string,*>} Destination object
  6328. */
  6329. function merge(dst) { // used by converters
  6330. var ifNotSet = typeof arguments[arguments.length - 1] === "boolean",
  6331. limit = ifNotSet ? arguments.length - 1 : arguments.length;
  6332. ifNotSet = ifNotSet && arguments[arguments.length - 1];
  6333. for (var a = 1; a < limit; ++a) {
  6334. var src = arguments[a];
  6335. if (!src)
  6336. continue;
  6337. for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
  6338. if (!isUnsafeProperty(keys[i]) && (dst[keys[i]] === undefined || !ifNotSet))
  6339. dst[keys[i]] = src[keys[i]];
  6340. }
  6341. return dst;
  6342. }
  6343. util.merge = merge;
  6344. /**
  6345. * Schema declaration nesting limit.
  6346. * @memberof util
  6347. * @type {number}
  6348. */
  6349. util.nestingLimit = 32; // protoc: MaxMessageDeclarationNestingDepth
  6350. /**
  6351. * Recursion limit.
  6352. * @memberof util
  6353. * @type {number}
  6354. */
  6355. util.recursionLimit = 100; // protoc: CodedInputStream::default_recursion_limit_
  6356. /**
  6357. * Makes a property safe for assignment as an own property.
  6358. * @memberof util
  6359. * @param {Object.<string,*>} obj Object
  6360. * @param {string} key Property key
  6361. * @param {boolean} [enumerable=true] Whether the property should be enumerable
  6362. * @returns {undefined}
  6363. */
  6364. util.makeProp = function makeProp(obj, key, enumerable) {
  6365. if (Object.prototype.hasOwnProperty.call(obj, key))
  6366. return;
  6367. Object.defineProperty(obj, key, {
  6368. enumerable: enumerable === undefined ? true : enumerable,
  6369. configurable: true,
  6370. writable: true
  6371. });
  6372. };
  6373. /**
  6374. * Converts the first character of a string to lower case.
  6375. * @param {string} str String to convert
  6376. * @returns {string} Converted string
  6377. */
  6378. util.lcFirst = function lcFirst(str) {
  6379. return str.charAt(0).toLowerCase() + str.substring(1);
  6380. };
  6381. /**
  6382. * Creates a custom error constructor.
  6383. * @memberof util
  6384. * @param {string} name Error name
  6385. * @returns {Constructor<Error>} Custom error constructor
  6386. */
  6387. function newError(name) {
  6388. function CustomError(message, properties) {
  6389. if (!(this instanceof CustomError))
  6390. return new CustomError(message, properties);
  6391. // Error.call(this, message);
  6392. // ^ just returns a new error instance because the ctor can be called as a function
  6393. Object.defineProperty(this, "message", { get: function() { return message; } });
  6394. /* istanbul ignore next */
  6395. if (Error.captureStackTrace) // node
  6396. Error.captureStackTrace(this, CustomError);
  6397. else
  6398. Object.defineProperty(this, "stack", { value: new Error().stack || "" });
  6399. if (properties)
  6400. merge(this, properties);
  6401. }
  6402. CustomError.prototype = Object.create(Error.prototype, {
  6403. constructor: {
  6404. value: CustomError,
  6405. writable: true,
  6406. enumerable: false,
  6407. configurable: true,
  6408. },
  6409. name: {
  6410. get: function get() { return name; },
  6411. set: undefined,
  6412. enumerable: false,
  6413. // configurable: false would accurately preserve the behavior of
  6414. // the original, but I'm guessing that was not intentional.
  6415. // For an actual error subclass, this property would
  6416. // be configurable.
  6417. configurable: true,
  6418. },
  6419. toString: {
  6420. value: function value() { return this.name + ": " + this.message; },
  6421. writable: true,
  6422. enumerable: false,
  6423. configurable: true,
  6424. },
  6425. });
  6426. return CustomError;
  6427. }
  6428. util.newError = newError;
  6429. /**
  6430. * Constructs a new protocol error.
  6431. * @classdesc Error subclass indicating a protocol specifc error.
  6432. * @memberof util
  6433. * @extends Error
  6434. * @template T extends Message<T>
  6435. * @constructor
  6436. * @param {string} message Error message
  6437. * @param {Object.<string,*>} [properties] Additional properties
  6438. * @example
  6439. * try {
  6440. * MyMessage.decode(someBuffer); // throws if required fields are missing
  6441. * } catch (e) {
  6442. * if (e instanceof ProtocolError && e.instance)
  6443. * console.log("decoded so far: " + JSON.stringify(e.instance));
  6444. * }
  6445. */
  6446. util.ProtocolError = newError("ProtocolError");
  6447. /**
  6448. * So far decoded message instance.
  6449. * @name util.ProtocolError#instance
  6450. * @type {Message<T>}
  6451. */
  6452. /**
  6453. * A OneOf getter as returned by {@link util.oneOfGetter}.
  6454. * @typedef OneOfGetter
  6455. * @type {function}
  6456. * @returns {string|undefined} Set field name, if any
  6457. */
  6458. /**
  6459. * Builds a getter for a oneof's present field name.
  6460. * @param {string[]} fieldNames Field names
  6461. * @returns {OneOfGetter} Unbound getter
  6462. */
  6463. util.oneOfGetter = function getOneOf(fieldNames) {
  6464. var fieldMap = {};
  6465. for (var i = 0; i < fieldNames.length; ++i)
  6466. fieldMap[fieldNames[i]] = 1;
  6467. /**
  6468. * @returns {string|undefined} Set field name, if any
  6469. * @this Object
  6470. * @ignore
  6471. */
  6472. return function() { // eslint-disable-line consistent-return
  6473. for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
  6474. if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
  6475. return keys[i];
  6476. };
  6477. };
  6478. /**
  6479. * A OneOf setter as returned by {@link util.oneOfSetter}.
  6480. * @typedef OneOfSetter
  6481. * @type {function}
  6482. * @param {string|undefined} value Field name
  6483. * @returns {undefined}
  6484. */
  6485. /**
  6486. * Builds a setter for a oneof's present field name.
  6487. * @param {string[]} fieldNames Field names
  6488. * @returns {OneOfSetter} Unbound setter
  6489. */
  6490. util.oneOfSetter = function setOneOf(fieldNames) {
  6491. /**
  6492. * @param {string} name Field name
  6493. * @returns {undefined}
  6494. * @this Object
  6495. * @ignore
  6496. */
  6497. return function(name) {
  6498. for (var i = 0; i < fieldNames.length; ++i)
  6499. if (fieldNames[i] !== name)
  6500. delete this[fieldNames[i]];
  6501. };
  6502. };
  6503. /**
  6504. * Default conversion options used for {@link Message#toJSON} implementations.
  6505. *
  6506. * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
  6507. *
  6508. * - Longs become strings
  6509. * - Enums become string keys
  6510. * - Bytes become base64 encoded strings
  6511. * - (Sub-)Messages become plain objects
  6512. * - Maps become plain objects with all string keys
  6513. * - Repeated fields become arrays
  6514. * - NaN and Infinity for float and double fields become strings
  6515. *
  6516. * @type {IConversionOptions}
  6517. * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
  6518. */
  6519. util.toJSONOptions = {
  6520. longs: String,
  6521. enums: String,
  6522. bytes: String,
  6523. json: true
  6524. };
  6525. // Sets up buffer utility according to the environment (called in index-minimal)
  6526. util._configure = function() {
  6527. var Buffer = util.Buffer;
  6528. /* istanbul ignore if */
  6529. if (!Buffer) {
  6530. util._Buffer_from = util._Buffer_allocUnsafe = null;
  6531. return;
  6532. }
  6533. // because node 4.x buffers are incompatible & immutable
  6534. // see: https://github.com/dcodeIO/protobuf.js/pull/665
  6535. util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
  6536. /* istanbul ignore next */
  6537. function Buffer_from(value, encoding) {
  6538. return new Buffer(value, encoding);
  6539. };
  6540. util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
  6541. /* istanbul ignore next */
  6542. function Buffer_allocUnsafe(size) {
  6543. return new Buffer(size);
  6544. };
  6545. };
  6546. },{"25":25,"26":26,"28":28,"30":30,"32":32,"36":36,"37":37,"long":"long"}],34:[function(require,module,exports){
  6547. "use strict";
  6548. /**
  6549. * A minimal path module to resolve Unix, Windows and URL paths alike.
  6550. * @memberof util
  6551. * @namespace
  6552. */
  6553. var path = exports;
  6554. var urlRe = /^[a-zA-Z][a-zA-Z0-9+.-]+:\/\//;
  6555. function normalizeUrl(path) {
  6556. if (typeof URL === "undefined" || !urlRe.test(path))
  6557. return null;
  6558. try {
  6559. return new URL(path).href;
  6560. } catch (e) {
  6561. return null;
  6562. }
  6563. }
  6564. function resolveUrl(originPath, includePath) {
  6565. if (typeof URL === "undefined" || !urlRe.test(originPath) || urlRe.test(includePath))
  6566. return null;
  6567. try {
  6568. return new URL(includePath, originPath).href;
  6569. } catch (e) {
  6570. return null;
  6571. }
  6572. }
  6573. var isAbsolute =
  6574. /**
  6575. * Tests if the specified path is absolute.
  6576. * @param {string} path Path to test
  6577. * @returns {boolean} `true` if path is absolute
  6578. */
  6579. path.isAbsolute = function isAbsolute(path) {
  6580. return /^(?:\/|\w+:|\\\\\w+)/.test(path);
  6581. };
  6582. var normalize =
  6583. /**
  6584. * Normalizes the specified path.
  6585. * @param {string} path Path to normalize
  6586. * @returns {string} Normalized path
  6587. */
  6588. path.normalize = function normalize(path) {
  6589. var normalizedUrl = normalizeUrl(path);
  6590. if (normalizedUrl)
  6591. return normalizedUrl;
  6592. var firstTwoCharacters = path.substring(0,2);
  6593. var uncPrefix = "";
  6594. if (firstTwoCharacters === "\\\\") {
  6595. uncPrefix = firstTwoCharacters;
  6596. path = path.substring(2);
  6597. }
  6598. path = path.replace(/\\/g, "/")
  6599. .replace(/\/{2,}/g, "/");
  6600. var parts = path.split("/"),
  6601. absolute = isAbsolute(path),
  6602. prefix = "";
  6603. if (absolute)
  6604. prefix = parts.shift() + "/";
  6605. for (var i = 0; i < parts.length;) {
  6606. if (parts[i] === "..") {
  6607. if (i > 0 && parts[i - 1] !== "..")
  6608. parts.splice(--i, 2);
  6609. else if (absolute)
  6610. parts.splice(i, 1);
  6611. else
  6612. ++i;
  6613. } else if (parts[i] === ".")
  6614. parts.splice(i, 1);
  6615. else
  6616. ++i;
  6617. }
  6618. return uncPrefix + prefix + parts.join("/");
  6619. };
  6620. /**
  6621. * Resolves the specified include path against the specified origin path.
  6622. * @param {string} originPath Path to the origin file
  6623. * @param {string} includePath Include path relative to origin path
  6624. * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
  6625. * @returns {string} Path to the include file
  6626. */
  6627. path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
  6628. var resolvedUrl = resolveUrl(originPath, includePath);
  6629. if (resolvedUrl)
  6630. return resolvedUrl;
  6631. if (!alreadyNormalized)
  6632. includePath = normalize(includePath); // path or absolute url
  6633. if (isAbsolute(includePath))
  6634. return includePath;
  6635. if (!alreadyNormalized)
  6636. originPath = normalize(originPath);
  6637. return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
  6638. };
  6639. },{}],35:[function(require,module,exports){
  6640. "use strict";
  6641. var patterns = exports;
  6642. patterns.numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
  6643. patterns.typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/;
  6644. patterns.reservedRe = /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/;
  6645. },{}],36:[function(require,module,exports){
  6646. "use strict";
  6647. module.exports = pool;
  6648. /**
  6649. * An allocator as used by {@link util.pool}.
  6650. * @typedef PoolAllocator
  6651. * @type {function}
  6652. * @param {number} size Buffer size
  6653. * @returns {Uint8Array} Buffer
  6654. */
  6655. /**
  6656. * A slicer as used by {@link util.pool}.
  6657. * @typedef PoolSlicer
  6658. * @type {function}
  6659. * @param {number} start Start offset
  6660. * @param {number} end End offset
  6661. * @returns {Uint8Array} Buffer slice
  6662. * @this Uint8Array
  6663. */
  6664. /**
  6665. * A general purpose buffer pool.
  6666. * @memberof util
  6667. * @function
  6668. * @param {PoolAllocator} alloc Allocator
  6669. * @param {PoolSlicer} slice Slicer
  6670. * @param {number} [size=8192] Slab size
  6671. * @returns {PoolAllocator} Pooled allocator
  6672. */
  6673. function pool(alloc, slice, size) {
  6674. var SIZE = size || 8192;
  6675. var MAX = SIZE >>> 1;
  6676. var slab = null;
  6677. var offset = SIZE;
  6678. return function pool_alloc(size) {
  6679. if (size < 1 || size > MAX)
  6680. return alloc(size);
  6681. if (offset + size > SIZE) {
  6682. slab = alloc(SIZE);
  6683. offset = 0;
  6684. }
  6685. var buf = slice.call(slab, offset, offset += size);
  6686. if (offset & 7) // align to 32 bit
  6687. offset = (offset | 7) + 1;
  6688. return buf;
  6689. };
  6690. }
  6691. },{}],37:[function(require,module,exports){
  6692. "use strict";
  6693. /**
  6694. * A minimal UTF8 implementation for number arrays.
  6695. * @memberof util
  6696. * @namespace
  6697. */
  6698. var utf8 = exports,
  6699. replacementChar = "\ufffd",
  6700. strictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
  6701. /**
  6702. * Calculates the UTF8 byte length of a string.
  6703. * @param {string} string String
  6704. * @returns {number} Byte length
  6705. */
  6706. utf8.length = function utf8_length(string) {
  6707. var len = 0,
  6708. c = 0;
  6709. for (var i = 0; i < string.length; ++i) {
  6710. c = string.charCodeAt(i);
  6711. if (c < 128)
  6712. len += 1;
  6713. else if (c < 2048)
  6714. len += 2;
  6715. else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
  6716. ++i;
  6717. len += 4;
  6718. } else
  6719. len += 3;
  6720. }
  6721. return len;
  6722. };
  6723. function utf8_read_js(buffer, start, end, str) {
  6724. for (var i = start; i < end;) {
  6725. var t = buffer[i++];
  6726. if (t <= 0x7F) {
  6727. str += String.fromCharCode(t);
  6728. } else if (t >= 0xC0 && t < 0xE0) {
  6729. var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
  6730. str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
  6731. } else if (t >= 0xE0 && t < 0xF0) {
  6732. var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
  6733. str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
  6734. } else if (t >= 0xF0) {
  6735. var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
  6736. if (t2 < 0x10000 || t2 > 0x10FFFF)
  6737. str += replacementChar;
  6738. else {
  6739. t2 -= 0x10000;
  6740. str += String.fromCharCode(0xD800 + (t2 >> 10));
  6741. str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
  6742. }
  6743. }
  6744. }
  6745. return str;
  6746. }
  6747. /**
  6748. * Reads UTF8 bytes as a string.
  6749. * @param {Uint8Array} buffer Source buffer
  6750. * @param {number} start Source start
  6751. * @param {number} end Source end
  6752. * @returns {string} String read
  6753. */
  6754. utf8.read = function utf8_read_ascii(buffer, start, end) {
  6755. if (end - start < 1)
  6756. return "";
  6757. var str = "",
  6758. i = start,
  6759. c1, c2, c3, c4, c5, c6, c7, c8;
  6760. for (; i + 7 < end; i += 8) {
  6761. c1 = buffer[i];
  6762. c2 = buffer[i + 1];
  6763. c3 = buffer[i + 2];
  6764. c4 = buffer[i + 3];
  6765. c5 = buffer[i + 4];
  6766. c6 = buffer[i + 5];
  6767. c7 = buffer[i + 6];
  6768. c8 = buffer[i + 7];
  6769. if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
  6770. return utf8_read_js(buffer, i, end, str);
  6771. str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
  6772. }
  6773. for (; i < end; ++i) {
  6774. c1 = buffer[i];
  6775. if (c1 & 0x80)
  6776. return utf8_read_js(buffer, i, end, str);
  6777. str += String.fromCharCode(c1);
  6778. }
  6779. return str;
  6780. };
  6781. function utf8_read_strict(buffer, start, end) {
  6782. var source = start === 0 && end === buffer.length
  6783. ? buffer
  6784. : buffer.subarray
  6785. ? buffer.subarray(start, end)
  6786. : buffer.slice(start, end);
  6787. if (Array.isArray(source))
  6788. source = Uint8Array.from(source);
  6789. return strictDecoder.decode(source);
  6790. }
  6791. /**
  6792. * Reads UTF8 bytes as a string, rejecting invalid UTF8.
  6793. * @param {Uint8Array} buffer Source buffer
  6794. * @param {number} start Source start
  6795. * @param {number} end Source end
  6796. * @returns {string} String read
  6797. */
  6798. utf8.readStrict = function utf8_read_strict_ascii(buffer, start, end) {
  6799. if (end - start < 1)
  6800. return "";
  6801. var str = "",
  6802. i = start,
  6803. c1, c2, c3, c4, c5, c6, c7, c8;
  6804. for (; i + 7 < end; i += 8) {
  6805. c1 = buffer[i];
  6806. c2 = buffer[i + 1];
  6807. c3 = buffer[i + 2];
  6808. c4 = buffer[i + 3];
  6809. c5 = buffer[i + 4];
  6810. c6 = buffer[i + 5];
  6811. c7 = buffer[i + 6];
  6812. c8 = buffer[i + 7];
  6813. if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
  6814. return str + utf8_read_strict(buffer, i, end);
  6815. str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
  6816. }
  6817. for (; i < end; ++i) {
  6818. c1 = buffer[i];
  6819. if (c1 & 0x80)
  6820. return str + utf8_read_strict(buffer, i, end);
  6821. str += String.fromCharCode(c1);
  6822. }
  6823. return str;
  6824. };
  6825. /**
  6826. * Writes a string as UTF8 bytes.
  6827. * @param {string} string Source string
  6828. * @param {Uint8Array} buffer Destination buffer
  6829. * @param {number} offset Destination offset
  6830. * @returns {number} Bytes written
  6831. */
  6832. utf8.write = function utf8_write(string, buffer, offset) {
  6833. var start = offset,
  6834. c1, // character 1
  6835. c2; // character 2
  6836. for (var i = 0; i < string.length; ++i) {
  6837. c1 = string.charCodeAt(i);
  6838. if (c1 < 128) {
  6839. buffer[offset++] = c1;
  6840. } else if (c1 < 2048) {
  6841. buffer[offset++] = c1 >> 6 | 192;
  6842. buffer[offset++] = c1 & 63 | 128;
  6843. } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
  6844. c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
  6845. ++i;
  6846. buffer[offset++] = c1 >> 18 | 240;
  6847. buffer[offset++] = c1 >> 12 & 63 | 128;
  6848. buffer[offset++] = c1 >> 6 & 63 | 128;
  6849. buffer[offset++] = c1 & 63 | 128;
  6850. } else {
  6851. buffer[offset++] = c1 >> 12 | 224;
  6852. buffer[offset++] = c1 >> 6 & 63 | 128;
  6853. buffer[offset++] = c1 & 63 | 128;
  6854. }
  6855. }
  6856. return offset - start;
  6857. };
  6858. },{}],38:[function(require,module,exports){
  6859. "use strict";
  6860. module.exports = verifier;
  6861. var Enum = require(5),
  6862. util = require(24);
  6863. function invalid(field, expected) {
  6864. return field.name + ": " + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected";
  6865. }
  6866. /**
  6867. * Generates a partial value verifier.
  6868. * @param {Codegen} gen Codegen instance
  6869. * @param {Field} field Reflected field
  6870. * @param {number} fieldIndex Field index
  6871. * @param {string} ref Variable reference
  6872. * @returns {Codegen} Codegen instance
  6873. * @ignore
  6874. */
  6875. function genVerifyValue(gen, field, fieldIndex, ref) {
  6876. /* eslint-disable no-unexpected-multiline */
  6877. if (field.resolvedType) {
  6878. if (field.resolvedType instanceof Enum) { gen
  6879. ("switch(%s){", ref)
  6880. ("default:")
  6881. ("return%j", invalid(field, "enum value"));
  6882. for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen
  6883. ("case %i:", field.resolvedType.values[keys[j]]);
  6884. gen
  6885. ("break")
  6886. ("}");
  6887. } else {
  6888. gen
  6889. ("{")
  6890. ("var e=types[%i].verify(%s,q+1);", fieldIndex, ref)
  6891. ("if(e)")
  6892. ("return%j+e", field.name + ".")
  6893. ("}");
  6894. }
  6895. } else {
  6896. switch (field.type) {
  6897. case "int32":
  6898. case "uint32":
  6899. case "sint32":
  6900. case "fixed32":
  6901. case "sfixed32": gen
  6902. ("if(!util.isInteger(%s))", ref)
  6903. ("return%j", invalid(field, "integer"));
  6904. break;
  6905. case "int64":
  6906. case "uint64":
  6907. case "sint64":
  6908. case "fixed64":
  6909. case "sfixed64": gen
  6910. ("if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))", ref, ref, ref, ref)
  6911. ("return%j", invalid(field, "integer|Long"));
  6912. break;
  6913. case "float":
  6914. case "double": gen
  6915. ("if(typeof %s!==\"number\")", ref)
  6916. ("return%j", invalid(field, "number"));
  6917. break;
  6918. case "bool": gen
  6919. ("if(typeof %s!==\"boolean\")", ref)
  6920. ("return%j", invalid(field, "boolean"));
  6921. break;
  6922. case "string": gen
  6923. ("if(!util.isString(%s))", ref)
  6924. ("return%j", invalid(field, "string"));
  6925. break;
  6926. case "bytes": gen
  6927. ("if(!(%s&&typeof %s.length===\"number\"||util.isString(%s)))", ref, ref, ref)
  6928. ("return%j", invalid(field, "buffer"));
  6929. break;
  6930. }
  6931. }
  6932. return gen;
  6933. /* eslint-enable no-unexpected-multiline */
  6934. }
  6935. /**
  6936. * Generates a partial key verifier.
  6937. * @param {Codegen} gen Codegen instance
  6938. * @param {Field} field Reflected field
  6939. * @param {string} ref Variable reference
  6940. * @returns {Codegen} Codegen instance
  6941. * @ignore
  6942. */
  6943. function genVerifyKey(gen, field, ref) {
  6944. /* eslint-disable no-unexpected-multiline */
  6945. switch (field.keyType) {
  6946. case "int32":
  6947. case "uint32":
  6948. case "sint32":
  6949. case "fixed32":
  6950. case "sfixed32": gen
  6951. ("if(!util.key32Re.test(%s))", ref)
  6952. ("return%j", invalid(field, "integer key"));
  6953. break;
  6954. case "int64":
  6955. case "uint64":
  6956. case "sint64":
  6957. case "fixed64":
  6958. case "sfixed64": gen
  6959. ("if(!util.key64Re.test(%s))", ref) // see comment above: x is ok, d is not
  6960. ("return%j", invalid(field, "integer|Long key"));
  6961. break;
  6962. case "bool": gen
  6963. ("if(!util.key2Re.test(%s))", ref)
  6964. ("return%j", invalid(field, "boolean key"));
  6965. break;
  6966. }
  6967. return gen;
  6968. /* eslint-enable no-unexpected-multiline */
  6969. }
  6970. /**
  6971. * Generates a verifier specific to the specified message type.
  6972. * @param {Type} mtype Message type
  6973. * @returns {Codegen} Codegen instance
  6974. */
  6975. function verifier(mtype) {
  6976. /* eslint-disable no-unexpected-multiline */
  6977. var gen = util.codegen(["m", "q"])
  6978. ("if(typeof m!==\"object\"||m===null)")
  6979. ("return%j", "object expected")
  6980. ("if(q===undefined)q=0")
  6981. ("if(q>util.recursionLimit)")
  6982. ("return%j", "max depth exceeded");
  6983. var oneofs = mtype.oneofsArray,
  6984. seenFirstField = {};
  6985. if (oneofs.length) gen
  6986. ("var p={}");
  6987. for (var i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {
  6988. var field = mtype._fieldsArray[i].resolve(),
  6989. ref = "m" + util.safeProp(field.name);
  6990. if (field.optional) gen
  6991. ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name); // !== undefined && !== null
  6992. // map fields
  6993. if (field.map) { gen
  6994. ("if(!util.isObject(%s))", ref)
  6995. ("return%j", invalid(field, "object"))
  6996. ("var k=Object.keys(%s)", ref)
  6997. ("for(var i=0;i<k.length;++i){");
  6998. genVerifyKey(gen, field, "k[i]");
  6999. genVerifyValue(gen, field, i, ref + "[k[i]]")
  7000. ("}");
  7001. // repeated fields
  7002. } else if (field.repeated) { gen
  7003. ("if(!Array.isArray(%s))", ref)
  7004. ("return%j", invalid(field, "array"))
  7005. ("for(var i=0;i<%s.length;++i){", ref);
  7006. genVerifyValue(gen, field, i, ref + "[i]")
  7007. ("}");
  7008. // required or present fields
  7009. } else {
  7010. if (field.partOf) {
  7011. var oneofProp = util.safeProp(field.partOf.name);
  7012. if (seenFirstField[field.partOf.name] === 1) gen
  7013. ("if(p%s===1)", oneofProp)
  7014. ("return%j", field.partOf.name + ": multiple values");
  7015. seenFirstField[field.partOf.name] = 1;
  7016. gen
  7017. ("p%s=1", oneofProp);
  7018. }
  7019. genVerifyValue(gen, field, i, ref);
  7020. }
  7021. if (field.optional) gen
  7022. ("}");
  7023. }
  7024. return gen
  7025. ("return null");
  7026. /* eslint-enable no-unexpected-multiline */
  7027. }
  7028. },{"24":24,"5":5}],39:[function(require,module,exports){
  7029. "use strict";
  7030. /**
  7031. * Wrappers for common types.
  7032. * @type {Object.<string,IWrapper>}
  7033. * @const
  7034. */
  7035. var wrappers = exports;
  7036. var Message = require(10),
  7037. util = require(33);
  7038. /**
  7039. * From object converter part of an {@link IWrapper}.
  7040. * @typedef WrapperFromObjectConverter
  7041. * @type {function}
  7042. * @param {Object.<string,*>} object Plain object
  7043. * @returns {Message<{}>} Message instance
  7044. * @this Type
  7045. */
  7046. /**
  7047. * To object converter part of an {@link IWrapper}.
  7048. * @typedef WrapperToObjectConverter
  7049. * @type {function}
  7050. * @param {Message<{}>} message Message instance
  7051. * @param {IConversionOptions} [options] Conversion options
  7052. * @returns {Object.<string,*>} Plain object
  7053. * @this Type
  7054. */
  7055. /**
  7056. * Common type wrapper part of {@link wrappers}.
  7057. * @interface IWrapper
  7058. * @property {WrapperFromObjectConverter} [fromObject] From object converter
  7059. * @property {WrapperToObjectConverter} [toObject] To object converter
  7060. */
  7061. // Custom wrapper for Any
  7062. wrappers[".google.protobuf.Any"] = {
  7063. fromObject: function(object, depth) {
  7064. // unwrap value type if mapped
  7065. if (object && object["@type"]) {
  7066. // Only use fully qualified type name after the last '/'
  7067. var name = object["@type"].substring(object["@type"].lastIndexOf("/") + 1);
  7068. var type = this.lookup(name);
  7069. /* istanbul ignore else */
  7070. if (type) {
  7071. // type_url does not accept leading "."
  7072. var type_url = object["@type"].charAt(0) === "." ?
  7073. object["@type"].slice(1) : object["@type"];
  7074. // type_url prefix is optional, but path seperator is required
  7075. if (type_url.indexOf("/") === -1) {
  7076. type_url = "/" + type_url;
  7077. }
  7078. return this.create({
  7079. type_url: type_url,
  7080. value: type.encode(type.fromObject(object, depth === undefined ? 1 : depth + 1)).finish()
  7081. });
  7082. }
  7083. }
  7084. return this.fromObject(object, depth);
  7085. },
  7086. toObject: function(message, options, depth) {
  7087. if (depth === undefined)
  7088. depth = 0;
  7089. if (depth > util.recursionLimit)
  7090. throw Error("max depth exceeded");
  7091. // Default prefix
  7092. var googleApi = "type.googleapis.com/";
  7093. var prefix = "";
  7094. var name = "";
  7095. // decode value if requested and unmapped
  7096. if (options && options.json && message.type_url && message.value) {
  7097. // Only use fully qualified type name after the last '/'
  7098. name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);
  7099. // Separate the prefix used
  7100. prefix = message.type_url.substring(0, message.type_url.lastIndexOf("/") + 1);
  7101. var type = this.lookup(name);
  7102. /* istanbul ignore else */
  7103. if (type)
  7104. message = type.decode(message.value, undefined, undefined, depth + 1);
  7105. }
  7106. // wrap value if unmapped
  7107. if (!(message instanceof this.ctor) && message instanceof Message) {
  7108. var object = message.$type.toObject(message, options, depth + 1);
  7109. var messageName = message.$type.fullName[0] === "." ?
  7110. message.$type.fullName.slice(1) : message.$type.fullName;
  7111. // Default to type.googleapis.com prefix if no prefix is used
  7112. if (prefix === "") {
  7113. prefix = googleApi;
  7114. }
  7115. name = prefix + messageName;
  7116. object["@type"] = name;
  7117. return object;
  7118. }
  7119. return this.toObject(message, options, depth);
  7120. }
  7121. };
  7122. },{"10":10,"33":33}],40:[function(require,module,exports){
  7123. "use strict";
  7124. module.exports = Writer;
  7125. var util = require(33);
  7126. var BufferWriter; // cyclic
  7127. var LongBits = util.LongBits,
  7128. base64 = util.base64,
  7129. utf8 = util.utf8;
  7130. /**
  7131. * Constructs a new writer operation instance.
  7132. * @classdesc Scheduled writer operation.
  7133. * @constructor
  7134. * @param {function(*, Uint8Array, number)} fn Function to call
  7135. * @param {number} len Value byte length
  7136. * @param {*} val Value to write
  7137. * @ignore
  7138. */
  7139. function Op(fn, len, val) {
  7140. /**
  7141. * Function to call.
  7142. * @type {function(Uint8Array, number, *)}
  7143. */
  7144. this.fn = fn;
  7145. /**
  7146. * Value byte length.
  7147. * @type {number}
  7148. */
  7149. this.len = len;
  7150. /**
  7151. * Next operation.
  7152. * @type {Writer.Op|undefined}
  7153. */
  7154. this.next = undefined;
  7155. /**
  7156. * Value to write.
  7157. * @type {*}
  7158. */
  7159. this.val = val; // type varies
  7160. }
  7161. /* istanbul ignore next */
  7162. function noop() {} // eslint-disable-line no-empty-function
  7163. /**
  7164. * Constructs a new writer state instance.
  7165. * @classdesc Copied writer state.
  7166. * @memberof Writer
  7167. * @constructor
  7168. * @param {Writer} writer Writer to copy state from
  7169. * @ignore
  7170. */
  7171. function State(writer) {
  7172. /**
  7173. * Current head.
  7174. * @type {Writer.Op}
  7175. */
  7176. this.head = writer.head;
  7177. /**
  7178. * Current tail.
  7179. * @type {Writer.Op}
  7180. */
  7181. this.tail = writer.tail;
  7182. /**
  7183. * Current buffer length.
  7184. * @type {number}
  7185. */
  7186. this.len = writer.len;
  7187. /**
  7188. * Next state.
  7189. * @type {State|null}
  7190. */
  7191. this.next = writer.states;
  7192. }
  7193. /**
  7194. * Constructs a new writer instance.
  7195. * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
  7196. * @constructor
  7197. */
  7198. function Writer() {
  7199. /**
  7200. * Current length.
  7201. * @type {number}
  7202. */
  7203. this.len = 0;
  7204. /**
  7205. * Operations head.
  7206. * @type {Object}
  7207. */
  7208. this.head = new Op(noop, 0, 0);
  7209. /**
  7210. * Operations tail
  7211. * @type {Object}
  7212. */
  7213. this.tail = this.head;
  7214. /**
  7215. * Linked forked states.
  7216. * @type {Object|null}
  7217. */
  7218. this.states = null;
  7219. // When a value is written, the writer calculates its byte length and puts it into a linked
  7220. // list of operations to perform when finish() is called. This both allows us to allocate
  7221. // buffers of the exact required size and reduces the amount of work we have to do compared
  7222. // to first calculating over objects and then encoding over objects. In our case, the encoding
  7223. // part is just a linked list walk calling operations with already prepared values.
  7224. }
  7225. var create = function create() {
  7226. return util.Buffer
  7227. ? function create_buffer_setup() {
  7228. return (Writer.create = function create_buffer() {
  7229. return new BufferWriter();
  7230. })();
  7231. }
  7232. /* istanbul ignore next */
  7233. : function create_array() {
  7234. return new Writer();
  7235. };
  7236. };
  7237. /**
  7238. * Creates a new writer.
  7239. * @function
  7240. * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
  7241. */
  7242. Writer.create = create();
  7243. /**
  7244. * Allocates a buffer of the specified size.
  7245. * @param {number} size Buffer size
  7246. * @returns {Uint8Array} Buffer
  7247. */
  7248. Writer.alloc = function alloc(size) {
  7249. return new util.Array(size);
  7250. };
  7251. // Use Uint8Array buffer pool in the browser, just like node does with buffers
  7252. /* istanbul ignore else */
  7253. if (util.Array !== Array)
  7254. Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
  7255. /**
  7256. * Pushes a new operation to the queue.
  7257. * @param {function(Uint8Array, number, *)} fn Function to call
  7258. * @param {number} len Value byte length
  7259. * @param {number} val Value to write
  7260. * @returns {Writer} `this`
  7261. * @private
  7262. */
  7263. Writer.prototype._push = function push(fn, len, val) {
  7264. this.tail = this.tail.next = new Op(fn, len, val);
  7265. this.len += len;
  7266. return this;
  7267. };
  7268. function writeByte(val, buf, pos) {
  7269. buf[pos] = val & 255;
  7270. }
  7271. function writeStringAscii(val, buf, pos) {
  7272. for (var i = 0; i < val.length;)
  7273. buf[pos++] = val.charCodeAt(i++);
  7274. }
  7275. function writeVarint32(val, buf, pos) {
  7276. while (val > 127) {
  7277. buf[pos++] = val & 127 | 128;
  7278. val >>>= 7;
  7279. }
  7280. buf[pos] = val;
  7281. }
  7282. /**
  7283. * Constructs a new varint writer operation instance.
  7284. * @classdesc Scheduled varint writer operation.
  7285. * @extends Op
  7286. * @constructor
  7287. * @param {number} len Value byte length
  7288. * @param {number} val Value to write
  7289. * @ignore
  7290. */
  7291. function VarintOp(len, val) {
  7292. this.len = len;
  7293. this.next = undefined;
  7294. this.val = val;
  7295. }
  7296. VarintOp.prototype = Object.create(Op.prototype);
  7297. VarintOp.prototype.fn = writeVarint32;
  7298. /**
  7299. * Writes an unsigned 32 bit value as a varint.
  7300. * @param {number} value Value to write
  7301. * @returns {Writer} `this`
  7302. */
  7303. Writer.prototype.uint32 = function write_uint32(value) {
  7304. // here, the call to this.push has been inlined and a varint specific Op subclass is used.
  7305. // uint32 is by far the most frequently used operation and benefits significantly from this.
  7306. this.len += (this.tail = this.tail.next = new VarintOp(
  7307. (value = value >>> 0)
  7308. < 128 ? 1
  7309. : value < 16384 ? 2
  7310. : value < 2097152 ? 3
  7311. : value < 268435456 ? 4
  7312. : 5,
  7313. value)).len;
  7314. return this;
  7315. };
  7316. /**
  7317. * Writes a signed 32 bit value as a varint.
  7318. * @function
  7319. * @param {number} value Value to write
  7320. * @returns {Writer} `this`
  7321. */
  7322. Writer.prototype.int32 = function write_int32(value) {
  7323. return (value |= 0) < 0
  7324. ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
  7325. : this.uint32(value);
  7326. };
  7327. /**
  7328. * Writes a 32 bit value as a varint, zig-zag encoded.
  7329. * @param {number} value Value to write
  7330. * @returns {Writer} `this`
  7331. */
  7332. Writer.prototype.sint32 = function write_sint32(value) {
  7333. return this.uint32((value << 1 ^ value >> 31) >>> 0);
  7334. };
  7335. function writeVarint64(val, buf, pos) {
  7336. var lo = val.lo,
  7337. hi = val.hi;
  7338. while (hi) {
  7339. buf[pos++] = lo & 127 | 128;
  7340. lo = (lo >>> 7 | hi << 25) >>> 0;
  7341. hi >>>= 7;
  7342. }
  7343. while (lo > 127) {
  7344. buf[pos++] = lo & 127 | 128;
  7345. lo = lo >>> 7;
  7346. }
  7347. buf[pos++] = lo;
  7348. }
  7349. /**
  7350. * Writes an unsigned 64 bit value as a varint.
  7351. * @param {Long|number|string} value Value to write
  7352. * @returns {Writer} `this`
  7353. * @throws {TypeError} If `value` is a string and no long library is present.
  7354. */
  7355. Writer.prototype.uint64 = function write_uint64(value) {
  7356. var bits = LongBits.from(value);
  7357. return this._push(writeVarint64, bits.length(), bits);
  7358. };
  7359. /**
  7360. * Writes a signed 64 bit value as a varint.
  7361. * @function
  7362. * @param {Long|number|string} value Value to write
  7363. * @returns {Writer} `this`
  7364. * @throws {TypeError} If `value` is a string and no long library is present.
  7365. */
  7366. Writer.prototype.int64 = Writer.prototype.uint64;
  7367. /**
  7368. * Writes a signed 64 bit value as a varint, zig-zag encoded.
  7369. * @param {Long|number|string} value Value to write
  7370. * @returns {Writer} `this`
  7371. * @throws {TypeError} If `value` is a string and no long library is present.
  7372. */
  7373. Writer.prototype.sint64 = function write_sint64(value) {
  7374. var bits = LongBits.from(value).zzEncode();
  7375. return this._push(writeVarint64, bits.length(), bits);
  7376. };
  7377. /**
  7378. * Writes a boolish value as a varint.
  7379. * @param {boolean} value Value to write
  7380. * @returns {Writer} `this`
  7381. */
  7382. Writer.prototype.bool = function write_bool(value) {
  7383. return this._push(writeByte, 1, value ? 1 : 0);
  7384. };
  7385. function writeFixed32(val, buf, pos) {
  7386. buf[pos ] = val & 255;
  7387. buf[pos + 1] = val >>> 8 & 255;
  7388. buf[pos + 2] = val >>> 16 & 255;
  7389. buf[pos + 3] = val >>> 24;
  7390. }
  7391. /**
  7392. * Writes an unsigned 32 bit value as fixed 32 bits.
  7393. * @param {number} value Value to write
  7394. * @returns {Writer} `this`
  7395. */
  7396. Writer.prototype.fixed32 = function write_fixed32(value) {
  7397. return this._push(writeFixed32, 4, value >>> 0);
  7398. };
  7399. /**
  7400. * Writes a signed 32 bit value as fixed 32 bits.
  7401. * @function
  7402. * @param {number} value Value to write
  7403. * @returns {Writer} `this`
  7404. */
  7405. Writer.prototype.sfixed32 = Writer.prototype.fixed32;
  7406. /**
  7407. * Writes an unsigned 64 bit value as fixed 64 bits.
  7408. * @param {Long|number|string} value Value to write
  7409. * @returns {Writer} `this`
  7410. * @throws {TypeError} If `value` is a string and no long library is present.
  7411. */
  7412. Writer.prototype.fixed64 = function write_fixed64(value) {
  7413. var bits = LongBits.from(value);
  7414. return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
  7415. };
  7416. /**
  7417. * Writes a signed 64 bit value as fixed 64 bits.
  7418. * @function
  7419. * @param {Long|number|string} value Value to write
  7420. * @returns {Writer} `this`
  7421. * @throws {TypeError} If `value` is a string and no long library is present.
  7422. */
  7423. Writer.prototype.sfixed64 = Writer.prototype.fixed64;
  7424. /**
  7425. * Writes a float (32 bit).
  7426. * @function
  7427. * @param {number} value Value to write
  7428. * @returns {Writer} `this`
  7429. */
  7430. Writer.prototype.float = function write_float(value) {
  7431. return this._push(util.float.writeFloatLE, 4, value);
  7432. };
  7433. /**
  7434. * Writes a double (64 bit float).
  7435. * @function
  7436. * @param {number} value Value to write
  7437. * @returns {Writer} `this`
  7438. */
  7439. Writer.prototype.double = function write_double(value) {
  7440. return this._push(util.float.writeDoubleLE, 8, value);
  7441. };
  7442. var writeBytes = util.Array.prototype.set
  7443. ? function writeBytes_set(val, buf, pos) {
  7444. buf.set(val, pos); // also works for plain array values
  7445. }
  7446. /* istanbul ignore next */
  7447. : function writeBytes_for(val, buf, pos) {
  7448. for (var i = 0; i < val.length; ++i)
  7449. buf[pos + i] = val[i];
  7450. };
  7451. /**
  7452. * Writes a sequence of bytes.
  7453. * @param {Uint8Array|string} value Buffer or base64 encoded string to write
  7454. * @returns {Writer} `this`
  7455. */
  7456. Writer.prototype.bytes = function write_bytes(value) {
  7457. var len = value.length >>> 0;
  7458. if (!len)
  7459. return this._push(writeByte, 1, 0);
  7460. if (util.isString(value)) {
  7461. var buf = Writer.alloc(len = base64.length(value));
  7462. base64.decode(value, buf, 0);
  7463. value = buf;
  7464. }
  7465. return this.uint32(len)._push(writeBytes, len, value);
  7466. };
  7467. /**
  7468. * Writes raw bytes without a tag or length prefix.
  7469. * @param {Uint8Array} value Raw bytes
  7470. * @returns {Writer} `this`
  7471. */
  7472. Writer.prototype.raw = function write_raw(value) {
  7473. var len = value.length >>> 0;
  7474. return len ? this._push(writeBytes, len, value) : this;
  7475. };
  7476. /**
  7477. * Writes a string.
  7478. * @param {string} value Value to write
  7479. * @returns {Writer} `this`
  7480. */
  7481. Writer.prototype.string = function write_string(value) {
  7482. var len = utf8.length(value);
  7483. return len
  7484. ? this.uint32(len)._push(len === value.length ? writeStringAscii : utf8.write, len, value)
  7485. : this._push(writeByte, 1, 0);
  7486. };
  7487. /**
  7488. * Forks this writer's state by pushing it to a stack.
  7489. * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
  7490. * @returns {Writer} `this`
  7491. */
  7492. Writer.prototype.fork = function fork() {
  7493. this.states = new State(this);
  7494. this.head = this.tail = new Op(noop, 0, 0);
  7495. this.len = 0;
  7496. return this;
  7497. };
  7498. /**
  7499. * Resets this instance to the last state.
  7500. * @returns {Writer} `this`
  7501. */
  7502. Writer.prototype.reset = function reset() {
  7503. if (this.states) {
  7504. this.head = this.states.head;
  7505. this.tail = this.states.tail;
  7506. this.len = this.states.len;
  7507. this.states = this.states.next;
  7508. } else {
  7509. this.head = this.tail = new Op(noop, 0, 0);
  7510. this.len = 0;
  7511. }
  7512. return this;
  7513. };
  7514. /**
  7515. * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
  7516. * @returns {Writer} `this`
  7517. */
  7518. Writer.prototype.ldelim = function ldelim() {
  7519. var head = this.head,
  7520. tail = this.tail,
  7521. len = this.len;
  7522. this.reset().uint32(len);
  7523. if (len) {
  7524. this.tail.next = head.next; // skip noop
  7525. this.tail = tail;
  7526. this.len += len;
  7527. }
  7528. return this;
  7529. };
  7530. /**
  7531. * Finishes the write operation.
  7532. * @returns {Uint8Array} Finished buffer
  7533. */
  7534. Writer.prototype.finish = function finish() {
  7535. return this.finishInto(this.constructor.alloc(this.len), 0);
  7536. };
  7537. /**
  7538. * Finishes the write operation, writing into the provided buffer.
  7539. * The caller must ensure that `buf` has enough space starting at `offset`
  7540. * to hold {@link Writer#len} bytes.
  7541. * @param {T} buf Target buffer
  7542. * @param {number} [offset=0] Offset to start writing at
  7543. * @returns {T} The provided buffer
  7544. * @template T extends Uint8Array
  7545. */
  7546. Writer.prototype.finishInto = function finishInto(buf, offset) {
  7547. if (offset === undefined)
  7548. offset = 0;
  7549. var head = this.head.next,
  7550. pos = offset;
  7551. while (head) {
  7552. head.fn(head.val, buf, pos);
  7553. pos += head.len;
  7554. head = head.next;
  7555. }
  7556. return buf;
  7557. };
  7558. Writer._configure = function(BufferWriter_) {
  7559. BufferWriter = BufferWriter_;
  7560. Writer.create = create();
  7561. BufferWriter._configure();
  7562. };
  7563. },{"33":33}],41:[function(require,module,exports){
  7564. "use strict";
  7565. module.exports = BufferWriter;
  7566. // extends Writer
  7567. var Writer = require(40);
  7568. (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
  7569. var util = require(33);
  7570. /**
  7571. * Constructs a new buffer writer instance.
  7572. * @classdesc Wire format writer using node buffers.
  7573. * @extends Writer
  7574. * @constructor
  7575. */
  7576. function BufferWriter() {
  7577. Writer.call(this);
  7578. }
  7579. BufferWriter._configure = function () {
  7580. /**
  7581. * Allocates a buffer of the specified size.
  7582. * @function
  7583. * @param {number} size Buffer size
  7584. * @returns {Buffer} Buffer
  7585. */
  7586. BufferWriter.alloc = util._Buffer_allocUnsafe;
  7587. BufferWriter.writeBytesBuffer = util.Buffer && util.Buffer.prototype instanceof Uint8Array && util.Buffer.prototype.set.name === "set"
  7588. ? function writeBytesBuffer_set(val, buf, pos) {
  7589. buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
  7590. // also works for plain array values
  7591. }
  7592. /* istanbul ignore next */
  7593. : function writeBytesBuffer_copy(val, buf, pos) {
  7594. if (val.copy) // Buffer values
  7595. val.copy(buf, pos, 0, val.length);
  7596. else for (var i = 0; i < val.length;) // plain array values
  7597. buf[pos++] = val[i++];
  7598. };
  7599. };
  7600. /**
  7601. * @override
  7602. */
  7603. BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
  7604. if (util.isString(value))
  7605. value = util._Buffer_from(value, "base64");
  7606. var len = value.length >>> 0;
  7607. this.uint32(len);
  7608. if (len)
  7609. this._push(BufferWriter.writeBytesBuffer, len, value);
  7610. return this;
  7611. };
  7612. /**
  7613. * Writes raw bytes without a tag or length prefix.
  7614. * @name BufferWriter#raw
  7615. * @function
  7616. * @param {Uint8Array} value Raw bytes
  7617. * @returns {BufferWriter} `this`
  7618. */
  7619. BufferWriter.prototype.raw = function write_raw_buffer(value) {
  7620. var len = value.length >>> 0;
  7621. return len ? this._push(BufferWriter.writeBytesBuffer, len, value) : this;
  7622. };
  7623. function writeStringBufferAscii(val, buf, pos) {
  7624. for (var i = 0; i < val.length;)
  7625. buf[pos++] = val.charCodeAt(i++);
  7626. }
  7627. function writeStringBuffer(val, buf, pos) {
  7628. if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
  7629. util.utf8.write(val, buf, pos);
  7630. else if (buf.utf8Write)
  7631. buf.utf8Write(val, pos);
  7632. else
  7633. buf.write(val, pos);
  7634. }
  7635. /**
  7636. * @override
  7637. */
  7638. BufferWriter.prototype.string = function write_string_buffer(value) {
  7639. var len = util.Buffer.byteLength(value);
  7640. this.uint32(len);
  7641. if (len)
  7642. this._push(len === value.length && len < 40 ? writeStringBufferAscii : writeStringBuffer, len, value);
  7643. return this;
  7644. };
  7645. /**
  7646. * Finishes the write operation.
  7647. * @name BufferWriter#finish
  7648. * @function
  7649. * @returns {Buffer} Finished buffer
  7650. */
  7651. BufferWriter._configure();
  7652. },{"33":33,"40":40}]},{},[7])
  7653. })();
  7654. //# sourceMappingURL=protobuf.js.map