ajv.bundle.js 267 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Ajv = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. var KEYWORDS = [
  4. 'multipleOf',
  5. 'maximum',
  6. 'exclusiveMaximum',
  7. 'minimum',
  8. 'exclusiveMinimum',
  9. 'maxLength',
  10. 'minLength',
  11. 'pattern',
  12. 'additionalItems',
  13. 'maxItems',
  14. 'minItems',
  15. 'uniqueItems',
  16. 'maxProperties',
  17. 'minProperties',
  18. 'required',
  19. 'additionalProperties',
  20. 'enum',
  21. 'format',
  22. 'const'
  23. ];
  24. module.exports = function (metaSchema, keywordsJsonPointers) {
  25. for (var i=0; i<keywordsJsonPointers.length; i++) {
  26. metaSchema = JSON.parse(JSON.stringify(metaSchema));
  27. var segments = keywordsJsonPointers[i].split('/');
  28. var keywords = metaSchema;
  29. var j;
  30. for (j=1; j<segments.length; j++)
  31. keywords = keywords[segments[j]];
  32. for (j=0; j<KEYWORDS.length; j++) {
  33. var key = KEYWORDS[j];
  34. var schema = keywords[key];
  35. if (schema) {
  36. keywords[key] = {
  37. anyOf: [
  38. schema,
  39. { $ref: 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#' }
  40. ]
  41. };
  42. }
  43. }
  44. }
  45. return metaSchema;
  46. };
  47. },{}],2:[function(require,module,exports){
  48. 'use strict';
  49. var Cache = module.exports = function Cache() {
  50. this._cache = {};
  51. };
  52. Cache.prototype.put = function Cache_put(key, value) {
  53. this._cache[key] = value;
  54. };
  55. Cache.prototype.get = function Cache_get(key) {
  56. return this._cache[key];
  57. };
  58. Cache.prototype.del = function Cache_del(key) {
  59. delete this._cache[key];
  60. };
  61. Cache.prototype.clear = function Cache_clear() {
  62. this._cache = {};
  63. };
  64. },{}],3:[function(require,module,exports){
  65. 'use strict';
  66. //all requires must be explicit because browserify won't work with dynamic requires
  67. module.exports = {
  68. '$ref': require('../dotjs/ref'),
  69. allOf: require('../dotjs/allOf'),
  70. anyOf: require('../dotjs/anyOf'),
  71. const: require('../dotjs/const'),
  72. contains: require('../dotjs/contains'),
  73. dependencies: require('../dotjs/dependencies'),
  74. 'enum': require('../dotjs/enum'),
  75. format: require('../dotjs/format'),
  76. items: require('../dotjs/items'),
  77. maximum: require('../dotjs/_limit'),
  78. minimum: require('../dotjs/_limit'),
  79. maxItems: require('../dotjs/_limitItems'),
  80. minItems: require('../dotjs/_limitItems'),
  81. maxLength: require('../dotjs/_limitLength'),
  82. minLength: require('../dotjs/_limitLength'),
  83. maxProperties: require('../dotjs/_limitProperties'),
  84. minProperties: require('../dotjs/_limitProperties'),
  85. multipleOf: require('../dotjs/multipleOf'),
  86. not: require('../dotjs/not'),
  87. oneOf: require('../dotjs/oneOf'),
  88. pattern: require('../dotjs/pattern'),
  89. properties: require('../dotjs/properties'),
  90. propertyNames: require('../dotjs/propertyNames'),
  91. required: require('../dotjs/required'),
  92. uniqueItems: require('../dotjs/uniqueItems'),
  93. validate: require('../dotjs/validate')
  94. };
  95. },{"../dotjs/_limit":13,"../dotjs/_limitItems":14,"../dotjs/_limitLength":15,"../dotjs/_limitProperties":16,"../dotjs/allOf":17,"../dotjs/anyOf":18,"../dotjs/const":19,"../dotjs/contains":20,"../dotjs/dependencies":22,"../dotjs/enum":23,"../dotjs/format":24,"../dotjs/items":25,"../dotjs/multipleOf":26,"../dotjs/not":27,"../dotjs/oneOf":28,"../dotjs/pattern":29,"../dotjs/properties":30,"../dotjs/propertyNames":31,"../dotjs/ref":32,"../dotjs/required":33,"../dotjs/uniqueItems":34,"../dotjs/validate":35}],4:[function(require,module,exports){
  96. 'use strict';
  97. var MissingRefError = require('./error_classes').MissingRef;
  98. module.exports = compileAsync;
  99. /**
  100. * Creates validating function for passed schema with asynchronous loading of missing schemas.
  101. * `loadSchema` option should be a function that accepts schema uri and returns promise that resolves with the schema.
  102. * @this Ajv
  103. * @param {Object} schema schema object
  104. * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
  105. * @param {Function} callback an optional node-style callback, it is called with 2 parameters: error (or null) and validating function.
  106. * @return {Promise} promise that resolves with a validating function.
  107. */
  108. function compileAsync(schema, meta, callback) {
  109. /* eslint no-shadow: 0 */
  110. /* global Promise */
  111. /* jshint validthis: true */
  112. var self = this;
  113. if (typeof this._opts.loadSchema != 'function')
  114. throw new Error('options.loadSchema should be a function');
  115. if (typeof meta == 'function') {
  116. callback = meta;
  117. meta = undefined;
  118. }
  119. var p = loadMetaSchemaOf(schema).then(function () {
  120. var schemaObj = self._addSchema(schema, undefined, meta);
  121. return schemaObj.validate || _compileAsync(schemaObj);
  122. });
  123. if (callback) {
  124. p.then(
  125. function(v) { callback(null, v); },
  126. callback
  127. );
  128. }
  129. return p;
  130. function loadMetaSchemaOf(sch) {
  131. var $schema = sch.$schema;
  132. return $schema && !self.getSchema($schema)
  133. ? compileAsync.call(self, { $ref: $schema }, true)
  134. : Promise.resolve();
  135. }
  136. function _compileAsync(schemaObj) {
  137. try { return self._compile(schemaObj); }
  138. catch(e) {
  139. if (e instanceof MissingRefError) return loadMissingSchema(e);
  140. throw e;
  141. }
  142. function loadMissingSchema(e) {
  143. var ref = e.missingSchema;
  144. if (added(ref)) throw new Error('Schema ' + ref + ' is loaded but ' + e.missingRef + ' cannot be resolved');
  145. var schemaPromise = self._loadingSchemas[ref];
  146. if (!schemaPromise) {
  147. schemaPromise = self._loadingSchemas[ref] = self._opts.loadSchema(ref);
  148. schemaPromise.then(removePromise, removePromise);
  149. }
  150. return schemaPromise.then(function (sch) {
  151. if (!added(ref)) {
  152. return loadMetaSchemaOf(sch).then(function () {
  153. if (!added(ref)) self.addSchema(sch, ref, undefined, meta);
  154. });
  155. }
  156. }).then(function() {
  157. return _compileAsync(schemaObj);
  158. });
  159. function removePromise() {
  160. delete self._loadingSchemas[ref];
  161. }
  162. function added(ref) {
  163. return self._refs[ref] || self._schemas[ref];
  164. }
  165. }
  166. }
  167. }
  168. },{"./error_classes":5}],5:[function(require,module,exports){
  169. 'use strict';
  170. var resolve = require('./resolve');
  171. module.exports = {
  172. Validation: errorSubclass(ValidationError),
  173. MissingRef: errorSubclass(MissingRefError)
  174. };
  175. function ValidationError(errors) {
  176. this.message = 'validation failed';
  177. this.errors = errors;
  178. this.ajv = this.validation = true;
  179. }
  180. MissingRefError.message = function (baseId, ref) {
  181. return 'can\'t resolve reference ' + ref + ' from id ' + baseId;
  182. };
  183. function MissingRefError(baseId, ref, message) {
  184. this.message = message || MissingRefError.message(baseId, ref);
  185. this.missingRef = resolve.url(baseId, ref);
  186. this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
  187. }
  188. function errorSubclass(Subclass) {
  189. Subclass.prototype = Object.create(Error.prototype);
  190. Subclass.prototype.constructor = Subclass;
  191. return Subclass;
  192. }
  193. },{"./resolve":8}],6:[function(require,module,exports){
  194. 'use strict';
  195. var util = require('./util');
  196. var DATE = /^\d\d\d\d-(\d\d)-(\d\d)$/;
  197. var DAYS = [0,31,29,31,30,31,30,31,31,30,31,30,31];
  198. var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i;
  199. var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i;
  200. var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
  201. var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
  202. // uri-template: https://tools.ietf.org/html/rfc6570
  203. var URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
  204. // For the source: https://gist.github.com/dperini/729294
  205. // For test cases: https://mathiasbynens.be/demo/url-regex
  206. // @todo Delete current URL in favour of the commented out URL rule when this issue is fixed https://github.com/eslint/eslint/issues/7983.
  207. // var URL = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
  208. var URL = /^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i;
  209. var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
  210. var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$|^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
  211. var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
  212. module.exports = formats;
  213. function formats(mode) {
  214. mode = mode == 'full' ? 'full' : 'fast';
  215. return util.copy(formats[mode]);
  216. }
  217. formats.fast = {
  218. // date: http://tools.ietf.org/html/rfc3339#section-5.6
  219. date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
  220. // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
  221. time: /^[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i,
  222. 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s][0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i,
  223. // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
  224. uri: /^(?:[a-z][a-z0-9+-.]*)(?::|\/)\/?[^\s]*$/i,
  225. 'uri-reference': /^(?:(?:[a-z][a-z0-9+-.]*:)?\/\/)?[^\s]*$/i,
  226. 'uri-template': URITEMPLATE,
  227. url: URL,
  228. // email (sources from jsen validator):
  229. // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
  230. // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
  231. email: /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
  232. hostname: HOSTNAME,
  233. // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
  234. ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
  235. // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
  236. ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
  237. regex: regex,
  238. // uuid: http://tools.ietf.org/html/rfc4122
  239. uuid: UUID,
  240. // JSON-pointer: https://tools.ietf.org/html/rfc6901
  241. // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
  242. 'json-pointer': JSON_POINTER,
  243. // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
  244. 'relative-json-pointer': RELATIVE_JSON_POINTER
  245. };
  246. formats.full = {
  247. date: date,
  248. time: time,
  249. 'date-time': date_time,
  250. uri: uri,
  251. 'uri-reference': URIREF,
  252. 'uri-template': URITEMPLATE,
  253. url: URL,
  254. email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
  255. hostname: hostname,
  256. ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
  257. ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
  258. regex: regex,
  259. uuid: UUID,
  260. 'json-pointer': JSON_POINTER,
  261. 'relative-json-pointer': RELATIVE_JSON_POINTER
  262. };
  263. function date(str) {
  264. // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
  265. var matches = str.match(DATE);
  266. if (!matches) return false;
  267. var month = +matches[1];
  268. var day = +matches[2];
  269. return month >= 1 && month <= 12 && day >= 1 && day <= DAYS[month];
  270. }
  271. function time(str, full) {
  272. var matches = str.match(TIME);
  273. if (!matches) return false;
  274. var hour = matches[1];
  275. var minute = matches[2];
  276. var second = matches[3];
  277. var timeZone = matches[5];
  278. return hour <= 23 && minute <= 59 && second <= 59 && (!full || timeZone);
  279. }
  280. var DATE_TIME_SEPARATOR = /t|\s/i;
  281. function date_time(str) {
  282. // http://tools.ietf.org/html/rfc3339#section-5.6
  283. var dateTime = str.split(DATE_TIME_SEPARATOR);
  284. return dateTime.length == 2 && date(dateTime[0]) && time(dateTime[1], true);
  285. }
  286. function hostname(str) {
  287. // https://tools.ietf.org/html/rfc1034#section-3.5
  288. // https://tools.ietf.org/html/rfc1123#section-2
  289. return str.length <= 255 && HOSTNAME.test(str);
  290. }
  291. var NOT_URI_FRAGMENT = /\/|:/;
  292. function uri(str) {
  293. // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
  294. return NOT_URI_FRAGMENT.test(str) && URI.test(str);
  295. }
  296. var Z_ANCHOR = /[^\\]\\Z/;
  297. function regex(str) {
  298. if (Z_ANCHOR.test(str)) return false;
  299. try {
  300. new RegExp(str);
  301. return true;
  302. } catch(e) {
  303. return false;
  304. }
  305. }
  306. },{"./util":12}],7:[function(require,module,exports){
  307. 'use strict';
  308. var resolve = require('./resolve')
  309. , util = require('./util')
  310. , errorClasses = require('./error_classes')
  311. , stableStringify = require('json-stable-stringify');
  312. var validateGenerator = require('../dotjs/validate');
  313. /**
  314. * Functions below are used inside compiled validations function
  315. */
  316. var co = require('co');
  317. var ucs2length = util.ucs2length;
  318. var equal = require('fast-deep-equal');
  319. // this error is thrown by async schemas to return validation errors via exception
  320. var ValidationError = errorClasses.Validation;
  321. module.exports = compile;
  322. /**
  323. * Compiles schema to validation function
  324. * @this Ajv
  325. * @param {Object} schema schema object
  326. * @param {Object} root object with information about the root schema for this schema
  327. * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
  328. * @param {String} baseId base ID for IDs in the schema
  329. * @return {Function} validation function
  330. */
  331. function compile(schema, root, localRefs, baseId) {
  332. /* jshint validthis: true, evil: true */
  333. /* eslint no-shadow: 0 */
  334. var self = this
  335. , opts = this._opts
  336. , refVal = [ undefined ]
  337. , refs = {}
  338. , patterns = []
  339. , patternsHash = {}
  340. , defaults = []
  341. , defaultsHash = {}
  342. , customRules = [];
  343. root = root || { schema: schema, refVal: refVal, refs: refs };
  344. var c = checkCompiling.call(this, schema, root, baseId);
  345. var compilation = this._compilations[c.index];
  346. if (c.compiling) return (compilation.callValidate = callValidate);
  347. var formats = this._formats;
  348. var RULES = this.RULES;
  349. try {
  350. var v = localCompile(schema, root, localRefs, baseId);
  351. compilation.validate = v;
  352. var cv = compilation.callValidate;
  353. if (cv) {
  354. cv.schema = v.schema;
  355. cv.errors = null;
  356. cv.refs = v.refs;
  357. cv.refVal = v.refVal;
  358. cv.root = v.root;
  359. cv.$async = v.$async;
  360. if (opts.sourceCode) cv.source = v.source;
  361. }
  362. return v;
  363. } finally {
  364. endCompiling.call(this, schema, root, baseId);
  365. }
  366. function callValidate() {
  367. var validate = compilation.validate;
  368. var result = validate.apply(null, arguments);
  369. callValidate.errors = validate.errors;
  370. return result;
  371. }
  372. function localCompile(_schema, _root, localRefs, baseId) {
  373. var isRoot = !_root || (_root && _root.schema == _schema);
  374. if (_root.schema != root.schema)
  375. return compile.call(self, _schema, _root, localRefs, baseId);
  376. var $async = _schema.$async === true;
  377. var sourceCode = validateGenerator({
  378. isTop: true,
  379. schema: _schema,
  380. isRoot: isRoot,
  381. baseId: baseId,
  382. root: _root,
  383. schemaPath: '',
  384. errSchemaPath: '#',
  385. errorPath: '""',
  386. MissingRefError: errorClasses.MissingRef,
  387. RULES: RULES,
  388. validate: validateGenerator,
  389. util: util,
  390. resolve: resolve,
  391. resolveRef: resolveRef,
  392. usePattern: usePattern,
  393. useDefault: useDefault,
  394. useCustomRule: useCustomRule,
  395. opts: opts,
  396. formats: formats,
  397. self: self
  398. });
  399. sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
  400. + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
  401. + sourceCode;
  402. if (opts.processCode) sourceCode = opts.processCode(sourceCode);
  403. // console.log('\n\n\n *** \n', JSON.stringify(sourceCode));
  404. var validate;
  405. try {
  406. var makeValidate = new Function(
  407. 'self',
  408. 'RULES',
  409. 'formats',
  410. 'root',
  411. 'refVal',
  412. 'defaults',
  413. 'customRules',
  414. 'co',
  415. 'equal',
  416. 'ucs2length',
  417. 'ValidationError',
  418. sourceCode
  419. );
  420. validate = makeValidate(
  421. self,
  422. RULES,
  423. formats,
  424. root,
  425. refVal,
  426. defaults,
  427. customRules,
  428. co,
  429. equal,
  430. ucs2length,
  431. ValidationError
  432. );
  433. refVal[0] = validate;
  434. } catch(e) {
  435. console.error('Error compiling schema, function code:', sourceCode);
  436. throw e;
  437. }
  438. validate.schema = _schema;
  439. validate.errors = null;
  440. validate.refs = refs;
  441. validate.refVal = refVal;
  442. validate.root = isRoot ? validate : _root;
  443. if ($async) validate.$async = true;
  444. if (opts.sourceCode === true) {
  445. validate.source = {
  446. code: sourceCode,
  447. patterns: patterns,
  448. defaults: defaults
  449. };
  450. }
  451. return validate;
  452. }
  453. function resolveRef(baseId, ref, isRoot) {
  454. ref = resolve.url(baseId, ref);
  455. var refIndex = refs[ref];
  456. var _refVal, refCode;
  457. if (refIndex !== undefined) {
  458. _refVal = refVal[refIndex];
  459. refCode = 'refVal[' + refIndex + ']';
  460. return resolvedRef(_refVal, refCode);
  461. }
  462. if (!isRoot && root.refs) {
  463. var rootRefId = root.refs[ref];
  464. if (rootRefId !== undefined) {
  465. _refVal = root.refVal[rootRefId];
  466. refCode = addLocalRef(ref, _refVal);
  467. return resolvedRef(_refVal, refCode);
  468. }
  469. }
  470. refCode = addLocalRef(ref);
  471. var v = resolve.call(self, localCompile, root, ref);
  472. if (v === undefined) {
  473. var localSchema = localRefs && localRefs[ref];
  474. if (localSchema) {
  475. v = resolve.inlineRef(localSchema, opts.inlineRefs)
  476. ? localSchema
  477. : compile.call(self, localSchema, root, localRefs, baseId);
  478. }
  479. }
  480. if (v === undefined) {
  481. removeLocalRef(ref);
  482. } else {
  483. replaceLocalRef(ref, v);
  484. return resolvedRef(v, refCode);
  485. }
  486. }
  487. function addLocalRef(ref, v) {
  488. var refId = refVal.length;
  489. refVal[refId] = v;
  490. refs[ref] = refId;
  491. return 'refVal' + refId;
  492. }
  493. function removeLocalRef(ref) {
  494. delete refs[ref];
  495. }
  496. function replaceLocalRef(ref, v) {
  497. var refId = refs[ref];
  498. refVal[refId] = v;
  499. }
  500. function resolvedRef(refVal, code) {
  501. return typeof refVal == 'object' || typeof refVal == 'boolean'
  502. ? { code: code, schema: refVal, inline: true }
  503. : { code: code, $async: refVal && refVal.$async };
  504. }
  505. function usePattern(regexStr) {
  506. var index = patternsHash[regexStr];
  507. if (index === undefined) {
  508. index = patternsHash[regexStr] = patterns.length;
  509. patterns[index] = regexStr;
  510. }
  511. return 'pattern' + index;
  512. }
  513. function useDefault(value) {
  514. switch (typeof value) {
  515. case 'boolean':
  516. case 'number':
  517. return '' + value;
  518. case 'string':
  519. return util.toQuotedString(value);
  520. case 'object':
  521. if (value === null) return 'null';
  522. var valueStr = stableStringify(value);
  523. var index = defaultsHash[valueStr];
  524. if (index === undefined) {
  525. index = defaultsHash[valueStr] = defaults.length;
  526. defaults[index] = value;
  527. }
  528. return 'default' + index;
  529. }
  530. }
  531. function useCustomRule(rule, schema, parentSchema, it) {
  532. var validateSchema = rule.definition.validateSchema;
  533. if (validateSchema && self._opts.validateSchema !== false) {
  534. var valid = validateSchema(schema);
  535. if (!valid) {
  536. var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors);
  537. if (self._opts.validateSchema == 'log') console.error(message);
  538. else throw new Error(message);
  539. }
  540. }
  541. var compile = rule.definition.compile
  542. , inline = rule.definition.inline
  543. , macro = rule.definition.macro;
  544. var validate;
  545. if (compile) {
  546. validate = compile.call(self, schema, parentSchema, it);
  547. } else if (macro) {
  548. validate = macro.call(self, schema, parentSchema, it);
  549. if (opts.validateSchema !== false) self.validateSchema(validate, true);
  550. } else if (inline) {
  551. validate = inline.call(self, it, rule.keyword, schema, parentSchema);
  552. } else {
  553. validate = rule.definition.validate;
  554. if (!validate) return;
  555. }
  556. if (validate === undefined)
  557. throw new Error('custom keyword "' + rule.keyword + '"failed to compile');
  558. var index = customRules.length;
  559. customRules[index] = validate;
  560. return {
  561. code: 'customRule' + index,
  562. validate: validate
  563. };
  564. }
  565. }
  566. /**
  567. * Checks if the schema is currently compiled
  568. * @this Ajv
  569. * @param {Object} schema schema to compile
  570. * @param {Object} root root object
  571. * @param {String} baseId base schema ID
  572. * @return {Object} object with properties "index" (compilation index) and "compiling" (boolean)
  573. */
  574. function checkCompiling(schema, root, baseId) {
  575. /* jshint validthis: true */
  576. var index = compIndex.call(this, schema, root, baseId);
  577. if (index >= 0) return { index: index, compiling: true };
  578. index = this._compilations.length;
  579. this._compilations[index] = {
  580. schema: schema,
  581. root: root,
  582. baseId: baseId
  583. };
  584. return { index: index, compiling: false };
  585. }
  586. /**
  587. * Removes the schema from the currently compiled list
  588. * @this Ajv
  589. * @param {Object} schema schema to compile
  590. * @param {Object} root root object
  591. * @param {String} baseId base schema ID
  592. */
  593. function endCompiling(schema, root, baseId) {
  594. /* jshint validthis: true */
  595. var i = compIndex.call(this, schema, root, baseId);
  596. if (i >= 0) this._compilations.splice(i, 1);
  597. }
  598. /**
  599. * Index of schema compilation in the currently compiled list
  600. * @this Ajv
  601. * @param {Object} schema schema to compile
  602. * @param {Object} root root object
  603. * @param {String} baseId base schema ID
  604. * @return {Integer} compilation index
  605. */
  606. function compIndex(schema, root, baseId) {
  607. /* jshint validthis: true */
  608. for (var i=0; i<this._compilations.length; i++) {
  609. var c = this._compilations[i];
  610. if (c.schema == schema && c.root == root && c.baseId == baseId) return i;
  611. }
  612. return -1;
  613. }
  614. function patternCode(i, patterns) {
  615. return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');';
  616. }
  617. function defaultCode(i) {
  618. return 'var default' + i + ' = defaults[' + i + '];';
  619. }
  620. function refValCode(i, refVal) {
  621. return refVal[i] === undefined ? '' : 'var refVal' + i + ' = refVal[' + i + '];';
  622. }
  623. function customRuleCode(i) {
  624. return 'var customRule' + i + ' = customRules[' + i + '];';
  625. }
  626. function vars(arr, statement) {
  627. if (!arr.length) return '';
  628. var code = '';
  629. for (var i=0; i<arr.length; i++)
  630. code += statement(i, arr);
  631. return code;
  632. }
  633. },{"../dotjs/validate":35,"./error_classes":5,"./resolve":8,"./util":12,"co":40,"fast-deep-equal":41,"json-stable-stringify":43}],8:[function(require,module,exports){
  634. 'use strict';
  635. var url = require('url')
  636. , equal = require('fast-deep-equal')
  637. , util = require('./util')
  638. , SchemaObject = require('./schema_obj')
  639. , traverse = require('json-schema-traverse');
  640. module.exports = resolve;
  641. resolve.normalizeId = normalizeId;
  642. resolve.fullPath = getFullPath;
  643. resolve.url = resolveUrl;
  644. resolve.ids = resolveIds;
  645. resolve.inlineRef = inlineRef;
  646. resolve.schema = resolveSchema;
  647. /**
  648. * [resolve and compile the references ($ref)]
  649. * @this Ajv
  650. * @param {Function} compile reference to schema compilation funciton (localCompile)
  651. * @param {Object} root object with information about the root schema for the current schema
  652. * @param {String} ref reference to resolve
  653. * @return {Object|Function} schema object (if the schema can be inlined) or validation function
  654. */
  655. function resolve(compile, root, ref) {
  656. /* jshint validthis: true */
  657. var refVal = this._refs[ref];
  658. if (typeof refVal == 'string') {
  659. if (this._refs[refVal]) refVal = this._refs[refVal];
  660. else return resolve.call(this, compile, root, refVal);
  661. }
  662. refVal = refVal || this._schemas[ref];
  663. if (refVal instanceof SchemaObject) {
  664. return inlineRef(refVal.schema, this._opts.inlineRefs)
  665. ? refVal.schema
  666. : refVal.validate || this._compile(refVal);
  667. }
  668. var res = resolveSchema.call(this, root, ref);
  669. var schema, v, baseId;
  670. if (res) {
  671. schema = res.schema;
  672. root = res.root;
  673. baseId = res.baseId;
  674. }
  675. if (schema instanceof SchemaObject) {
  676. v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
  677. } else if (schema !== undefined) {
  678. v = inlineRef(schema, this._opts.inlineRefs)
  679. ? schema
  680. : compile.call(this, schema, root, undefined, baseId);
  681. }
  682. return v;
  683. }
  684. /**
  685. * Resolve schema, its root and baseId
  686. * @this Ajv
  687. * @param {Object} root root object with properties schema, refVal, refs
  688. * @param {String} ref reference to resolve
  689. * @return {Object} object with properties schema, root, baseId
  690. */
  691. function resolveSchema(root, ref) {
  692. /* jshint validthis: true */
  693. var p = url.parse(ref, false, true)
  694. , refPath = _getFullPath(p)
  695. , baseId = getFullPath(this._getId(root.schema));
  696. if (refPath !== baseId) {
  697. var id = normalizeId(refPath);
  698. var refVal = this._refs[id];
  699. if (typeof refVal == 'string') {
  700. return resolveRecursive.call(this, root, refVal, p);
  701. } else if (refVal instanceof SchemaObject) {
  702. if (!refVal.validate) this._compile(refVal);
  703. root = refVal;
  704. } else {
  705. refVal = this._schemas[id];
  706. if (refVal instanceof SchemaObject) {
  707. if (!refVal.validate) this._compile(refVal);
  708. if (id == normalizeId(ref))
  709. return { schema: refVal, root: root, baseId: baseId };
  710. root = refVal;
  711. } else {
  712. return;
  713. }
  714. }
  715. if (!root.schema) return;
  716. baseId = getFullPath(this._getId(root.schema));
  717. }
  718. return getJsonPointer.call(this, p, baseId, root.schema, root);
  719. }
  720. /* @this Ajv */
  721. function resolveRecursive(root, ref, parsedRef) {
  722. /* jshint validthis: true */
  723. var res = resolveSchema.call(this, root, ref);
  724. if (res) {
  725. var schema = res.schema;
  726. var baseId = res.baseId;
  727. root = res.root;
  728. var id = this._getId(schema);
  729. if (id) baseId = resolveUrl(baseId, id);
  730. return getJsonPointer.call(this, parsedRef, baseId, schema, root);
  731. }
  732. }
  733. var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
  734. /* @this Ajv */
  735. function getJsonPointer(parsedRef, baseId, schema, root) {
  736. /* jshint validthis: true */
  737. parsedRef.hash = parsedRef.hash || '';
  738. if (parsedRef.hash.slice(0,2) != '#/') return;
  739. var parts = parsedRef.hash.split('/');
  740. for (var i = 1; i < parts.length; i++) {
  741. var part = parts[i];
  742. if (part) {
  743. part = util.unescapeFragment(part);
  744. schema = schema[part];
  745. if (schema === undefined) break;
  746. var id;
  747. if (!PREVENT_SCOPE_CHANGE[part]) {
  748. id = this._getId(schema);
  749. if (id) baseId = resolveUrl(baseId, id);
  750. if (schema.$ref) {
  751. var $ref = resolveUrl(baseId, schema.$ref);
  752. var res = resolveSchema.call(this, root, $ref);
  753. if (res) {
  754. schema = res.schema;
  755. root = res.root;
  756. baseId = res.baseId;
  757. }
  758. }
  759. }
  760. }
  761. }
  762. if (schema !== undefined && schema !== root.schema)
  763. return { schema: schema, root: root, baseId: baseId };
  764. }
  765. var SIMPLE_INLINED = util.toHash([
  766. 'type', 'format', 'pattern',
  767. 'maxLength', 'minLength',
  768. 'maxProperties', 'minProperties',
  769. 'maxItems', 'minItems',
  770. 'maximum', 'minimum',
  771. 'uniqueItems', 'multipleOf',
  772. 'required', 'enum'
  773. ]);
  774. function inlineRef(schema, limit) {
  775. if (limit === false) return false;
  776. if (limit === undefined || limit === true) return checkNoRef(schema);
  777. else if (limit) return countKeys(schema) <= limit;
  778. }
  779. function checkNoRef(schema) {
  780. var item;
  781. if (Array.isArray(schema)) {
  782. for (var i=0; i<schema.length; i++) {
  783. item = schema[i];
  784. if (typeof item == 'object' && !checkNoRef(item)) return false;
  785. }
  786. } else {
  787. for (var key in schema) {
  788. if (key == '$ref') return false;
  789. item = schema[key];
  790. if (typeof item == 'object' && !checkNoRef(item)) return false;
  791. }
  792. }
  793. return true;
  794. }
  795. function countKeys(schema) {
  796. var count = 0, item;
  797. if (Array.isArray(schema)) {
  798. for (var i=0; i<schema.length; i++) {
  799. item = schema[i];
  800. if (typeof item == 'object') count += countKeys(item);
  801. if (count == Infinity) return Infinity;
  802. }
  803. } else {
  804. for (var key in schema) {
  805. if (key == '$ref') return Infinity;
  806. if (SIMPLE_INLINED[key]) {
  807. count++;
  808. } else {
  809. item = schema[key];
  810. if (typeof item == 'object') count += countKeys(item) + 1;
  811. if (count == Infinity) return Infinity;
  812. }
  813. }
  814. }
  815. return count;
  816. }
  817. function getFullPath(id, normalize) {
  818. if (normalize !== false) id = normalizeId(id);
  819. var p = url.parse(id, false, true);
  820. return _getFullPath(p);
  821. }
  822. function _getFullPath(p) {
  823. var protocolSeparator = p.protocol || p.href.slice(0,2) == '//' ? '//' : '';
  824. return (p.protocol||'') + protocolSeparator + (p.host||'') + (p.path||'') + '#';
  825. }
  826. var TRAILING_SLASH_HASH = /#\/?$/;
  827. function normalizeId(id) {
  828. return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
  829. }
  830. function resolveUrl(baseId, id) {
  831. id = normalizeId(id);
  832. return url.resolve(baseId, id);
  833. }
  834. /* @this Ajv */
  835. function resolveIds(schema) {
  836. var schemaId = normalizeId(this._getId(schema));
  837. var baseIds = {'': schemaId};
  838. var fullPaths = {'': getFullPath(schemaId, false)};
  839. var localRefs = {};
  840. var self = this;
  841. traverse(schema, {allKeys: true}, function(sch, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
  842. if (jsonPtr === '') return;
  843. var id = self._getId(sch);
  844. var baseId = baseIds[parentJsonPtr];
  845. var fullPath = fullPaths[parentJsonPtr] + '/' + parentKeyword;
  846. if (keyIndex !== undefined)
  847. fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex));
  848. if (typeof id == 'string') {
  849. id = baseId = normalizeId(baseId ? url.resolve(baseId, id) : id);
  850. var refVal = self._refs[id];
  851. if (typeof refVal == 'string') refVal = self._refs[refVal];
  852. if (refVal && refVal.schema) {
  853. if (!equal(sch, refVal.schema))
  854. throw new Error('id "' + id + '" resolves to more than one schema');
  855. } else if (id != normalizeId(fullPath)) {
  856. if (id[0] == '#') {
  857. if (localRefs[id] && !equal(sch, localRefs[id]))
  858. throw new Error('id "' + id + '" resolves to more than one schema');
  859. localRefs[id] = sch;
  860. } else {
  861. self._refs[id] = fullPath;
  862. }
  863. }
  864. }
  865. baseIds[jsonPtr] = baseId;
  866. fullPaths[jsonPtr] = fullPath;
  867. });
  868. return localRefs;
  869. }
  870. },{"./schema_obj":10,"./util":12,"fast-deep-equal":41,"json-schema-traverse":42,"url":51}],9:[function(require,module,exports){
  871. 'use strict';
  872. var ruleModules = require('./_rules')
  873. , toHash = require('./util').toHash;
  874. module.exports = function rules() {
  875. var RULES = [
  876. { type: 'number',
  877. rules: [ { 'maximum': ['exclusiveMaximum'] },
  878. { 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
  879. { type: 'string',
  880. rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
  881. { type: 'array',
  882. rules: [ 'maxItems', 'minItems', 'uniqueItems', 'contains', 'items' ] },
  883. { type: 'object',
  884. rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
  885. { 'properties': ['additionalProperties', 'patternProperties'] } ] },
  886. { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
  887. ];
  888. var ALL = [ 'type' ];
  889. var KEYWORDS = [
  890. 'additionalItems', '$schema', 'id', 'title',
  891. 'description', 'default', 'definitions'
  892. ];
  893. var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
  894. RULES.all = toHash(ALL);
  895. RULES.types = toHash(TYPES);
  896. RULES.forEach(function (group) {
  897. group.rules = group.rules.map(function (keyword) {
  898. var implKeywords;
  899. if (typeof keyword == 'object') {
  900. var key = Object.keys(keyword)[0];
  901. implKeywords = keyword[key];
  902. keyword = key;
  903. implKeywords.forEach(function (k) {
  904. ALL.push(k);
  905. RULES.all[k] = true;
  906. });
  907. }
  908. ALL.push(keyword);
  909. var rule = RULES.all[keyword] = {
  910. keyword: keyword,
  911. code: ruleModules[keyword],
  912. implements: implKeywords
  913. };
  914. return rule;
  915. });
  916. if (group.type) RULES.types[group.type] = group;
  917. });
  918. RULES.keywords = toHash(ALL.concat(KEYWORDS));
  919. RULES.custom = {};
  920. return RULES;
  921. };
  922. },{"./_rules":3,"./util":12}],10:[function(require,module,exports){
  923. 'use strict';
  924. var util = require('./util');
  925. module.exports = SchemaObject;
  926. function SchemaObject(obj) {
  927. util.copy(obj, this);
  928. }
  929. },{"./util":12}],11:[function(require,module,exports){
  930. 'use strict';
  931. // https://mathiasbynens.be/notes/javascript-encoding
  932. // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
  933. module.exports = function ucs2length(str) {
  934. var length = 0
  935. , len = str.length
  936. , pos = 0
  937. , value;
  938. while (pos < len) {
  939. length++;
  940. value = str.charCodeAt(pos++);
  941. if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
  942. // high surrogate, and there is a next character
  943. value = str.charCodeAt(pos);
  944. if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
  945. }
  946. }
  947. return length;
  948. };
  949. },{}],12:[function(require,module,exports){
  950. 'use strict';
  951. module.exports = {
  952. copy: copy,
  953. checkDataType: checkDataType,
  954. checkDataTypes: checkDataTypes,
  955. coerceToTypes: coerceToTypes,
  956. toHash: toHash,
  957. getProperty: getProperty,
  958. escapeQuotes: escapeQuotes,
  959. equal: require('fast-deep-equal'),
  960. ucs2length: require('./ucs2length'),
  961. varOccurences: varOccurences,
  962. varReplace: varReplace,
  963. cleanUpCode: cleanUpCode,
  964. finalCleanUpCode: finalCleanUpCode,
  965. schemaHasRules: schemaHasRules,
  966. schemaHasRulesExcept: schemaHasRulesExcept,
  967. toQuotedString: toQuotedString,
  968. getPathExpr: getPathExpr,
  969. getPath: getPath,
  970. getData: getData,
  971. unescapeFragment: unescapeFragment,
  972. unescapeJsonPointer: unescapeJsonPointer,
  973. escapeFragment: escapeFragment,
  974. escapeJsonPointer: escapeJsonPointer
  975. };
  976. function copy(o, to) {
  977. to = to || {};
  978. for (var key in o) to[key] = o[key];
  979. return to;
  980. }
  981. function checkDataType(dataType, data, negate) {
  982. var EQUAL = negate ? ' !== ' : ' === '
  983. , AND = negate ? ' || ' : ' && '
  984. , OK = negate ? '!' : ''
  985. , NOT = negate ? '' : '!';
  986. switch (dataType) {
  987. case 'null': return data + EQUAL + 'null';
  988. case 'array': return OK + 'Array.isArray(' + data + ')';
  989. case 'object': return '(' + OK + data + AND +
  990. 'typeof ' + data + EQUAL + '"object"' + AND +
  991. NOT + 'Array.isArray(' + data + '))';
  992. case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
  993. NOT + '(' + data + ' % 1)' +
  994. AND + data + EQUAL + data + ')';
  995. default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
  996. }
  997. }
  998. function checkDataTypes(dataTypes, data) {
  999. switch (dataTypes.length) {
  1000. case 1: return checkDataType(dataTypes[0], data, true);
  1001. default:
  1002. var code = '';
  1003. var types = toHash(dataTypes);
  1004. if (types.array && types.object) {
  1005. code = types.null ? '(': '(!' + data + ' || ';
  1006. code += 'typeof ' + data + ' !== "object")';
  1007. delete types.null;
  1008. delete types.array;
  1009. delete types.object;
  1010. }
  1011. if (types.number) delete types.integer;
  1012. for (var t in types)
  1013. code += (code ? ' && ' : '' ) + checkDataType(t, data, true);
  1014. return code;
  1015. }
  1016. }
  1017. var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
  1018. function coerceToTypes(optionCoerceTypes, dataTypes) {
  1019. if (Array.isArray(dataTypes)) {
  1020. var types = [];
  1021. for (var i=0; i<dataTypes.length; i++) {
  1022. var t = dataTypes[i];
  1023. if (COERCE_TO_TYPES[t]) types[types.length] = t;
  1024. else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t;
  1025. }
  1026. if (types.length) return types;
  1027. } else if (COERCE_TO_TYPES[dataTypes]) {
  1028. return [dataTypes];
  1029. } else if (optionCoerceTypes === 'array' && dataTypes === 'array') {
  1030. return ['array'];
  1031. }
  1032. }
  1033. function toHash(arr) {
  1034. var hash = {};
  1035. for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
  1036. return hash;
  1037. }
  1038. var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
  1039. var SINGLE_QUOTE = /'|\\/g;
  1040. function getProperty(key) {
  1041. return typeof key == 'number'
  1042. ? '[' + key + ']'
  1043. : IDENTIFIER.test(key)
  1044. ? '.' + key
  1045. : "['" + escapeQuotes(key) + "']";
  1046. }
  1047. function escapeQuotes(str) {
  1048. return str.replace(SINGLE_QUOTE, '\\$&')
  1049. .replace(/\n/g, '\\n')
  1050. .replace(/\r/g, '\\r')
  1051. .replace(/\f/g, '\\f')
  1052. .replace(/\t/g, '\\t');
  1053. }
  1054. function varOccurences(str, dataVar) {
  1055. dataVar += '[^0-9]';
  1056. var matches = str.match(new RegExp(dataVar, 'g'));
  1057. return matches ? matches.length : 0;
  1058. }
  1059. function varReplace(str, dataVar, expr) {
  1060. dataVar += '([^0-9])';
  1061. expr = expr.replace(/\$/g, '$$$$');
  1062. return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
  1063. }
  1064. var EMPTY_ELSE = /else\s*{\s*}/g
  1065. , EMPTY_IF_NO_ELSE = /if\s*\([^)]+\)\s*\{\s*\}(?!\s*else)/g
  1066. , EMPTY_IF_WITH_ELSE = /if\s*\(([^)]+)\)\s*\{\s*\}\s*else(?!\s*if)/g;
  1067. function cleanUpCode(out) {
  1068. return out.replace(EMPTY_ELSE, '')
  1069. .replace(EMPTY_IF_NO_ELSE, '')
  1070. .replace(EMPTY_IF_WITH_ELSE, 'if (!($1))');
  1071. }
  1072. var ERRORS_REGEXP = /[^v.]errors/g
  1073. , REMOVE_ERRORS = /var errors = 0;|var vErrors = null;|validate.errors = vErrors;/g
  1074. , REMOVE_ERRORS_ASYNC = /var errors = 0;|var vErrors = null;/g
  1075. , RETURN_VALID = 'return errors === 0;'
  1076. , RETURN_TRUE = 'validate.errors = null; return true;'
  1077. , RETURN_ASYNC = /if \(errors === 0\) return data;\s*else throw new ValidationError\(vErrors\);/
  1078. , RETURN_DATA_ASYNC = 'return data;'
  1079. , ROOTDATA_REGEXP = /[^A-Za-z_$]rootData[^A-Za-z0-9_$]/g
  1080. , REMOVE_ROOTDATA = /if \(rootData === undefined\) rootData = data;/;
  1081. function finalCleanUpCode(out, async) {
  1082. var matches = out.match(ERRORS_REGEXP);
  1083. if (matches && matches.length == 2) {
  1084. out = async
  1085. ? out.replace(REMOVE_ERRORS_ASYNC, '')
  1086. .replace(RETURN_ASYNC, RETURN_DATA_ASYNC)
  1087. : out.replace(REMOVE_ERRORS, '')
  1088. .replace(RETURN_VALID, RETURN_TRUE);
  1089. }
  1090. matches = out.match(ROOTDATA_REGEXP);
  1091. if (!matches || matches.length !== 3) return out;
  1092. return out.replace(REMOVE_ROOTDATA, '');
  1093. }
  1094. function schemaHasRules(schema, rules) {
  1095. if (typeof schema == 'boolean') return !schema;
  1096. for (var key in schema) if (rules[key]) return true;
  1097. }
  1098. function schemaHasRulesExcept(schema, rules, exceptKeyword) {
  1099. if (typeof schema == 'boolean') return !schema && exceptKeyword != 'not';
  1100. for (var key in schema) if (key != exceptKeyword && rules[key]) return true;
  1101. }
  1102. function toQuotedString(str) {
  1103. return '\'' + escapeQuotes(str) + '\'';
  1104. }
  1105. function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
  1106. var path = jsonPointers // false by default
  1107. ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
  1108. : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
  1109. return joinPaths(currentPath, path);
  1110. }
  1111. function getPath(currentPath, prop, jsonPointers) {
  1112. var path = jsonPointers // false by default
  1113. ? toQuotedString('/' + escapeJsonPointer(prop))
  1114. : toQuotedString(getProperty(prop));
  1115. return joinPaths(currentPath, path);
  1116. }
  1117. var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
  1118. var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
  1119. function getData($data, lvl, paths) {
  1120. var up, jsonPointer, data, matches;
  1121. if ($data === '') return 'rootData';
  1122. if ($data[0] == '/') {
  1123. if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data);
  1124. jsonPointer = $data;
  1125. data = 'rootData';
  1126. } else {
  1127. matches = $data.match(RELATIVE_JSON_POINTER);
  1128. if (!matches) throw new Error('Invalid JSON-pointer: ' + $data);
  1129. up = +matches[1];
  1130. jsonPointer = matches[2];
  1131. if (jsonPointer == '#') {
  1132. if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
  1133. return paths[lvl - up];
  1134. }
  1135. if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
  1136. data = 'data' + ((lvl - up) || '');
  1137. if (!jsonPointer) return data;
  1138. }
  1139. var expr = data;
  1140. var segments = jsonPointer.split('/');
  1141. for (var i=0; i<segments.length; i++) {
  1142. var segment = segments[i];
  1143. if (segment) {
  1144. data += getProperty(unescapeJsonPointer(segment));
  1145. expr += ' && ' + data;
  1146. }
  1147. }
  1148. return expr;
  1149. }
  1150. function joinPaths (a, b) {
  1151. if (a == '""') return b;
  1152. return (a + ' + ' + b).replace(/' \+ '/g, '');
  1153. }
  1154. function unescapeFragment(str) {
  1155. return unescapeJsonPointer(decodeURIComponent(str));
  1156. }
  1157. function escapeFragment(str) {
  1158. return encodeURIComponent(escapeJsonPointer(str));
  1159. }
  1160. function escapeJsonPointer(str) {
  1161. return str.replace(/~/g, '~0').replace(/\//g, '~1');
  1162. }
  1163. function unescapeJsonPointer(str) {
  1164. return str.replace(/~1/g, '/').replace(/~0/g, '~');
  1165. }
  1166. },{"./ucs2length":11,"fast-deep-equal":41}],13:[function(require,module,exports){
  1167. 'use strict';
  1168. module.exports = function generate__limit(it, $keyword, $ruleType) {
  1169. var out = ' ';
  1170. var $lvl = it.level;
  1171. var $dataLvl = it.dataLevel;
  1172. var $schema = it.schema[$keyword];
  1173. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1174. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1175. var $breakOnError = !it.opts.allErrors;
  1176. var $errorKeyword;
  1177. var $data = 'data' + ($dataLvl || '');
  1178. var $isData = it.opts.$data && $schema && $schema.$data,
  1179. $schemaValue;
  1180. if ($isData) {
  1181. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1182. $schemaValue = 'schema' + $lvl;
  1183. } else {
  1184. $schemaValue = $schema;
  1185. }
  1186. var $isMax = $keyword == 'maximum',
  1187. $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
  1188. $schemaExcl = it.schema[$exclusiveKeyword],
  1189. $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data,
  1190. $op = $isMax ? '<' : '>',
  1191. $notOp = $isMax ? '>' : '<',
  1192. $errorKeyword = undefined;
  1193. if ($isDataExcl) {
  1194. var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
  1195. $exclusive = 'exclusive' + $lvl,
  1196. $exclType = 'exclType' + $lvl,
  1197. $exclIsNumber = 'exclIsNumber' + $lvl,
  1198. $opExpr = 'op' + $lvl,
  1199. $opStr = '\' + ' + $opExpr + ' + \'';
  1200. out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
  1201. $schemaValueExcl = 'schemaExcl' + $lvl;
  1202. out += ' var ' + ($exclusive) + '; var ' + ($exclType) + ' = typeof ' + ($schemaValueExcl) + '; if (' + ($exclType) + ' != \'boolean\' && ' + ($exclType) + ' != \'undefined\' && ' + ($exclType) + ' != \'number\') { ';
  1203. var $errorKeyword = $exclusiveKeyword;
  1204. var $$outStack = $$outStack || [];
  1205. $$outStack.push(out);
  1206. out = ''; /* istanbul ignore else */
  1207. if (it.createErrors !== false) {
  1208. out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  1209. if (it.opts.messages !== false) {
  1210. out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
  1211. }
  1212. if (it.opts.verbose) {
  1213. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1214. }
  1215. out += ' } ';
  1216. } else {
  1217. out += ' {} ';
  1218. }
  1219. var __err = out;
  1220. out = $$outStack.pop();
  1221. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1222. if (it.async) {
  1223. out += ' throw new ValidationError([' + (__err) + ']); ';
  1224. } else {
  1225. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1226. }
  1227. } else {
  1228. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1229. }
  1230. out += ' } else if ( ';
  1231. if ($isData) {
  1232. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1233. }
  1234. out += ' ' + ($exclType) + ' == \'number\' ? ( (' + ($exclusive) + ' = ' + ($schemaValue) + ' === undefined || ' + ($schemaValueExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ') ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValueExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) : ( (' + ($exclusive) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = ' + ($exclusive) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
  1235. } else {
  1236. var $exclIsNumber = typeof $schemaExcl == 'number',
  1237. $opStr = $op;
  1238. if ($exclIsNumber && $isData) {
  1239. var $opExpr = '\'' + $opStr + '\'';
  1240. out += ' if ( ';
  1241. if ($isData) {
  1242. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1243. }
  1244. out += ' ( ' + ($schemaValue) + ' === undefined || ' + ($schemaExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ' ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { ';
  1245. } else {
  1246. if ($exclIsNumber && $schema === undefined) {
  1247. $exclusive = true;
  1248. $errorKeyword = $exclusiveKeyword;
  1249. $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
  1250. $schemaValue = $schemaExcl;
  1251. $notOp += '=';
  1252. } else {
  1253. if ($exclIsNumber) $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
  1254. if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
  1255. $exclusive = true;
  1256. $errorKeyword = $exclusiveKeyword;
  1257. $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
  1258. $notOp += '=';
  1259. } else {
  1260. $exclusive = false;
  1261. $opStr += '=';
  1262. }
  1263. }
  1264. var $opExpr = '\'' + $opStr + '\'';
  1265. out += ' if ( ';
  1266. if ($isData) {
  1267. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1268. }
  1269. out += ' ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') { ';
  1270. }
  1271. }
  1272. $errorKeyword = $errorKeyword || $keyword;
  1273. var $$outStack = $$outStack || [];
  1274. $$outStack.push(out);
  1275. out = ''; /* istanbul ignore else */
  1276. if (it.createErrors !== false) {
  1277. out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
  1278. if (it.opts.messages !== false) {
  1279. out += ' , message: \'should be ' + ($opStr) + ' ';
  1280. if ($isData) {
  1281. out += '\' + ' + ($schemaValue);
  1282. } else {
  1283. out += '' + ($schemaValue) + '\'';
  1284. }
  1285. }
  1286. if (it.opts.verbose) {
  1287. out += ' , schema: ';
  1288. if ($isData) {
  1289. out += 'validate.schema' + ($schemaPath);
  1290. } else {
  1291. out += '' + ($schema);
  1292. }
  1293. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1294. }
  1295. out += ' } ';
  1296. } else {
  1297. out += ' {} ';
  1298. }
  1299. var __err = out;
  1300. out = $$outStack.pop();
  1301. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1302. if (it.async) {
  1303. out += ' throw new ValidationError([' + (__err) + ']); ';
  1304. } else {
  1305. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1306. }
  1307. } else {
  1308. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1309. }
  1310. out += ' } ';
  1311. if ($breakOnError) {
  1312. out += ' else { ';
  1313. }
  1314. return out;
  1315. }
  1316. },{}],14:[function(require,module,exports){
  1317. 'use strict';
  1318. module.exports = function generate__limitItems(it, $keyword, $ruleType) {
  1319. var out = ' ';
  1320. var $lvl = it.level;
  1321. var $dataLvl = it.dataLevel;
  1322. var $schema = it.schema[$keyword];
  1323. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1324. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1325. var $breakOnError = !it.opts.allErrors;
  1326. var $errorKeyword;
  1327. var $data = 'data' + ($dataLvl || '');
  1328. var $isData = it.opts.$data && $schema && $schema.$data,
  1329. $schemaValue;
  1330. if ($isData) {
  1331. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1332. $schemaValue = 'schema' + $lvl;
  1333. } else {
  1334. $schemaValue = $schema;
  1335. }
  1336. var $op = $keyword == 'maxItems' ? '>' : '<';
  1337. out += 'if ( ';
  1338. if ($isData) {
  1339. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1340. }
  1341. out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
  1342. var $errorKeyword = $keyword;
  1343. var $$outStack = $$outStack || [];
  1344. $$outStack.push(out);
  1345. out = ''; /* istanbul ignore else */
  1346. if (it.createErrors !== false) {
  1347. out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
  1348. if (it.opts.messages !== false) {
  1349. out += ' , message: \'should NOT have ';
  1350. if ($keyword == 'maxItems') {
  1351. out += 'more';
  1352. } else {
  1353. out += 'less';
  1354. }
  1355. out += ' than ';
  1356. if ($isData) {
  1357. out += '\' + ' + ($schemaValue) + ' + \'';
  1358. } else {
  1359. out += '' + ($schema);
  1360. }
  1361. out += ' items\' ';
  1362. }
  1363. if (it.opts.verbose) {
  1364. out += ' , schema: ';
  1365. if ($isData) {
  1366. out += 'validate.schema' + ($schemaPath);
  1367. } else {
  1368. out += '' + ($schema);
  1369. }
  1370. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1371. }
  1372. out += ' } ';
  1373. } else {
  1374. out += ' {} ';
  1375. }
  1376. var __err = out;
  1377. out = $$outStack.pop();
  1378. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1379. if (it.async) {
  1380. out += ' throw new ValidationError([' + (__err) + ']); ';
  1381. } else {
  1382. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1383. }
  1384. } else {
  1385. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1386. }
  1387. out += '} ';
  1388. if ($breakOnError) {
  1389. out += ' else { ';
  1390. }
  1391. return out;
  1392. }
  1393. },{}],15:[function(require,module,exports){
  1394. 'use strict';
  1395. module.exports = function generate__limitLength(it, $keyword, $ruleType) {
  1396. var out = ' ';
  1397. var $lvl = it.level;
  1398. var $dataLvl = it.dataLevel;
  1399. var $schema = it.schema[$keyword];
  1400. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1401. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1402. var $breakOnError = !it.opts.allErrors;
  1403. var $errorKeyword;
  1404. var $data = 'data' + ($dataLvl || '');
  1405. var $isData = it.opts.$data && $schema && $schema.$data,
  1406. $schemaValue;
  1407. if ($isData) {
  1408. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1409. $schemaValue = 'schema' + $lvl;
  1410. } else {
  1411. $schemaValue = $schema;
  1412. }
  1413. var $op = $keyword == 'maxLength' ? '>' : '<';
  1414. out += 'if ( ';
  1415. if ($isData) {
  1416. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1417. }
  1418. if (it.opts.unicode === false) {
  1419. out += ' ' + ($data) + '.length ';
  1420. } else {
  1421. out += ' ucs2length(' + ($data) + ') ';
  1422. }
  1423. out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
  1424. var $errorKeyword = $keyword;
  1425. var $$outStack = $$outStack || [];
  1426. $$outStack.push(out);
  1427. out = ''; /* istanbul ignore else */
  1428. if (it.createErrors !== false) {
  1429. out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
  1430. if (it.opts.messages !== false) {
  1431. out += ' , message: \'should NOT be ';
  1432. if ($keyword == 'maxLength') {
  1433. out += 'longer';
  1434. } else {
  1435. out += 'shorter';
  1436. }
  1437. out += ' than ';
  1438. if ($isData) {
  1439. out += '\' + ' + ($schemaValue) + ' + \'';
  1440. } else {
  1441. out += '' + ($schema);
  1442. }
  1443. out += ' characters\' ';
  1444. }
  1445. if (it.opts.verbose) {
  1446. out += ' , schema: ';
  1447. if ($isData) {
  1448. out += 'validate.schema' + ($schemaPath);
  1449. } else {
  1450. out += '' + ($schema);
  1451. }
  1452. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1453. }
  1454. out += ' } ';
  1455. } else {
  1456. out += ' {} ';
  1457. }
  1458. var __err = out;
  1459. out = $$outStack.pop();
  1460. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1461. if (it.async) {
  1462. out += ' throw new ValidationError([' + (__err) + ']); ';
  1463. } else {
  1464. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1465. }
  1466. } else {
  1467. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1468. }
  1469. out += '} ';
  1470. if ($breakOnError) {
  1471. out += ' else { ';
  1472. }
  1473. return out;
  1474. }
  1475. },{}],16:[function(require,module,exports){
  1476. 'use strict';
  1477. module.exports = function generate__limitProperties(it, $keyword, $ruleType) {
  1478. var out = ' ';
  1479. var $lvl = it.level;
  1480. var $dataLvl = it.dataLevel;
  1481. var $schema = it.schema[$keyword];
  1482. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1483. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1484. var $breakOnError = !it.opts.allErrors;
  1485. var $errorKeyword;
  1486. var $data = 'data' + ($dataLvl || '');
  1487. var $isData = it.opts.$data && $schema && $schema.$data,
  1488. $schemaValue;
  1489. if ($isData) {
  1490. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1491. $schemaValue = 'schema' + $lvl;
  1492. } else {
  1493. $schemaValue = $schema;
  1494. }
  1495. var $op = $keyword == 'maxProperties' ? '>' : '<';
  1496. out += 'if ( ';
  1497. if ($isData) {
  1498. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1499. }
  1500. out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
  1501. var $errorKeyword = $keyword;
  1502. var $$outStack = $$outStack || [];
  1503. $$outStack.push(out);
  1504. out = ''; /* istanbul ignore else */
  1505. if (it.createErrors !== false) {
  1506. out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
  1507. if (it.opts.messages !== false) {
  1508. out += ' , message: \'should NOT have ';
  1509. if ($keyword == 'maxProperties') {
  1510. out += 'more';
  1511. } else {
  1512. out += 'less';
  1513. }
  1514. out += ' than ';
  1515. if ($isData) {
  1516. out += '\' + ' + ($schemaValue) + ' + \'';
  1517. } else {
  1518. out += '' + ($schema);
  1519. }
  1520. out += ' properties\' ';
  1521. }
  1522. if (it.opts.verbose) {
  1523. out += ' , schema: ';
  1524. if ($isData) {
  1525. out += 'validate.schema' + ($schemaPath);
  1526. } else {
  1527. out += '' + ($schema);
  1528. }
  1529. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1530. }
  1531. out += ' } ';
  1532. } else {
  1533. out += ' {} ';
  1534. }
  1535. var __err = out;
  1536. out = $$outStack.pop();
  1537. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1538. if (it.async) {
  1539. out += ' throw new ValidationError([' + (__err) + ']); ';
  1540. } else {
  1541. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1542. }
  1543. } else {
  1544. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1545. }
  1546. out += '} ';
  1547. if ($breakOnError) {
  1548. out += ' else { ';
  1549. }
  1550. return out;
  1551. }
  1552. },{}],17:[function(require,module,exports){
  1553. 'use strict';
  1554. module.exports = function generate_allOf(it, $keyword, $ruleType) {
  1555. var out = ' ';
  1556. var $schema = it.schema[$keyword];
  1557. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1558. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1559. var $breakOnError = !it.opts.allErrors;
  1560. var $it = it.util.copy(it);
  1561. var $closingBraces = '';
  1562. $it.level++;
  1563. var $nextValid = 'valid' + $it.level;
  1564. var $currentBaseId = $it.baseId,
  1565. $allSchemasEmpty = true;
  1566. var arr1 = $schema;
  1567. if (arr1) {
  1568. var $sch, $i = -1,
  1569. l1 = arr1.length - 1;
  1570. while ($i < l1) {
  1571. $sch = arr1[$i += 1];
  1572. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  1573. $allSchemasEmpty = false;
  1574. $it.schema = $sch;
  1575. $it.schemaPath = $schemaPath + '[' + $i + ']';
  1576. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  1577. out += ' ' + (it.validate($it)) + ' ';
  1578. $it.baseId = $currentBaseId;
  1579. if ($breakOnError) {
  1580. out += ' if (' + ($nextValid) + ') { ';
  1581. $closingBraces += '}';
  1582. }
  1583. }
  1584. }
  1585. }
  1586. if ($breakOnError) {
  1587. if ($allSchemasEmpty) {
  1588. out += ' if (true) { ';
  1589. } else {
  1590. out += ' ' + ($closingBraces.slice(0, -1)) + ' ';
  1591. }
  1592. }
  1593. out = it.util.cleanUpCode(out);
  1594. return out;
  1595. }
  1596. },{}],18:[function(require,module,exports){
  1597. 'use strict';
  1598. module.exports = function generate_anyOf(it, $keyword, $ruleType) {
  1599. var out = ' ';
  1600. var $lvl = it.level;
  1601. var $dataLvl = it.dataLevel;
  1602. var $schema = it.schema[$keyword];
  1603. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1604. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1605. var $breakOnError = !it.opts.allErrors;
  1606. var $data = 'data' + ($dataLvl || '');
  1607. var $valid = 'valid' + $lvl;
  1608. var $errs = 'errs__' + $lvl;
  1609. var $it = it.util.copy(it);
  1610. var $closingBraces = '';
  1611. $it.level++;
  1612. var $nextValid = 'valid' + $it.level;
  1613. var $noEmptySchema = $schema.every(function($sch) {
  1614. return it.util.schemaHasRules($sch, it.RULES.all);
  1615. });
  1616. if ($noEmptySchema) {
  1617. var $currentBaseId = $it.baseId;
  1618. out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
  1619. var $wasComposite = it.compositeRule;
  1620. it.compositeRule = $it.compositeRule = true;
  1621. var arr1 = $schema;
  1622. if (arr1) {
  1623. var $sch, $i = -1,
  1624. l1 = arr1.length - 1;
  1625. while ($i < l1) {
  1626. $sch = arr1[$i += 1];
  1627. $it.schema = $sch;
  1628. $it.schemaPath = $schemaPath + '[' + $i + ']';
  1629. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  1630. out += ' ' + (it.validate($it)) + ' ';
  1631. $it.baseId = $currentBaseId;
  1632. out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { ';
  1633. $closingBraces += '}';
  1634. }
  1635. }
  1636. it.compositeRule = $it.compositeRule = $wasComposite;
  1637. out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
  1638. if (it.createErrors !== false) {
  1639. out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  1640. if (it.opts.messages !== false) {
  1641. out += ' , message: \'should match some schema in anyOf\' ';
  1642. }
  1643. if (it.opts.verbose) {
  1644. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1645. }
  1646. out += ' } ';
  1647. } else {
  1648. out += ' {} ';
  1649. }
  1650. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1651. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1652. if (it.async) {
  1653. out += ' throw new ValidationError(vErrors); ';
  1654. } else {
  1655. out += ' validate.errors = vErrors; return false; ';
  1656. }
  1657. }
  1658. out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
  1659. if (it.opts.allErrors) {
  1660. out += ' } ';
  1661. }
  1662. out = it.util.cleanUpCode(out);
  1663. } else {
  1664. if ($breakOnError) {
  1665. out += ' if (true) { ';
  1666. }
  1667. }
  1668. return out;
  1669. }
  1670. },{}],19:[function(require,module,exports){
  1671. 'use strict';
  1672. module.exports = function generate_const(it, $keyword, $ruleType) {
  1673. var out = ' ';
  1674. var $lvl = it.level;
  1675. var $dataLvl = it.dataLevel;
  1676. var $schema = it.schema[$keyword];
  1677. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1678. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1679. var $breakOnError = !it.opts.allErrors;
  1680. var $data = 'data' + ($dataLvl || '');
  1681. var $valid = 'valid' + $lvl;
  1682. var $isData = it.opts.$data && $schema && $schema.$data,
  1683. $schemaValue;
  1684. if ($isData) {
  1685. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1686. $schemaValue = 'schema' + $lvl;
  1687. } else {
  1688. $schemaValue = $schema;
  1689. }
  1690. if (!$isData) {
  1691. out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
  1692. }
  1693. out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
  1694. var $$outStack = $$outStack || [];
  1695. $$outStack.push(out);
  1696. out = ''; /* istanbul ignore else */
  1697. if (it.createErrors !== false) {
  1698. out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  1699. if (it.opts.messages !== false) {
  1700. out += ' , message: \'should be equal to constant\' ';
  1701. }
  1702. if (it.opts.verbose) {
  1703. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1704. }
  1705. out += ' } ';
  1706. } else {
  1707. out += ' {} ';
  1708. }
  1709. var __err = out;
  1710. out = $$outStack.pop();
  1711. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1712. if (it.async) {
  1713. out += ' throw new ValidationError([' + (__err) + ']); ';
  1714. } else {
  1715. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1716. }
  1717. } else {
  1718. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1719. }
  1720. out += ' }';
  1721. if ($breakOnError) {
  1722. out += ' else { ';
  1723. }
  1724. return out;
  1725. }
  1726. },{}],20:[function(require,module,exports){
  1727. 'use strict';
  1728. module.exports = function generate_contains(it, $keyword, $ruleType) {
  1729. var out = ' ';
  1730. var $lvl = it.level;
  1731. var $dataLvl = it.dataLevel;
  1732. var $schema = it.schema[$keyword];
  1733. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1734. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1735. var $breakOnError = !it.opts.allErrors;
  1736. var $data = 'data' + ($dataLvl || '');
  1737. var $valid = 'valid' + $lvl;
  1738. var $errs = 'errs__' + $lvl;
  1739. var $it = it.util.copy(it);
  1740. var $closingBraces = '';
  1741. $it.level++;
  1742. var $nextValid = 'valid' + $it.level;
  1743. var $idx = 'i' + $lvl,
  1744. $dataNxt = $it.dataLevel = it.dataLevel + 1,
  1745. $nextData = 'data' + $dataNxt,
  1746. $currentBaseId = it.baseId,
  1747. $nonEmptySchema = it.util.schemaHasRules($schema, it.RULES.all);
  1748. out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
  1749. if ($nonEmptySchema) {
  1750. var $wasComposite = it.compositeRule;
  1751. it.compositeRule = $it.compositeRule = true;
  1752. $it.schema = $schema;
  1753. $it.schemaPath = $schemaPath;
  1754. $it.errSchemaPath = $errSchemaPath;
  1755. out += ' var ' + ($nextValid) + ' = false; for (var ' + ($idx) + ' = 0; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
  1756. $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
  1757. var $passData = $data + '[' + $idx + ']';
  1758. $it.dataPathArr[$dataNxt] = $idx;
  1759. var $code = it.validate($it);
  1760. $it.baseId = $currentBaseId;
  1761. if (it.util.varOccurences($code, $nextData) < 2) {
  1762. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  1763. } else {
  1764. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  1765. }
  1766. out += ' if (' + ($nextValid) + ') break; } ';
  1767. it.compositeRule = $it.compositeRule = $wasComposite;
  1768. out += ' ' + ($closingBraces) + ' if (!' + ($nextValid) + ') {';
  1769. } else {
  1770. out += ' if (' + ($data) + '.length == 0) {';
  1771. }
  1772. var $$outStack = $$outStack || [];
  1773. $$outStack.push(out);
  1774. out = ''; /* istanbul ignore else */
  1775. if (it.createErrors !== false) {
  1776. out += ' { keyword: \'' + ('contains') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  1777. if (it.opts.messages !== false) {
  1778. out += ' , message: \'should contain a valid item\' ';
  1779. }
  1780. if (it.opts.verbose) {
  1781. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1782. }
  1783. out += ' } ';
  1784. } else {
  1785. out += ' {} ';
  1786. }
  1787. var __err = out;
  1788. out = $$outStack.pop();
  1789. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1790. if (it.async) {
  1791. out += ' throw new ValidationError([' + (__err) + ']); ';
  1792. } else {
  1793. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1794. }
  1795. } else {
  1796. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1797. }
  1798. out += ' } else { ';
  1799. if ($nonEmptySchema) {
  1800. out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
  1801. }
  1802. if (it.opts.allErrors) {
  1803. out += ' } ';
  1804. }
  1805. out = it.util.cleanUpCode(out);
  1806. return out;
  1807. }
  1808. },{}],21:[function(require,module,exports){
  1809. 'use strict';
  1810. module.exports = function generate_custom(it, $keyword, $ruleType) {
  1811. var out = ' ';
  1812. var $lvl = it.level;
  1813. var $dataLvl = it.dataLevel;
  1814. var $schema = it.schema[$keyword];
  1815. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1816. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1817. var $breakOnError = !it.opts.allErrors;
  1818. var $errorKeyword;
  1819. var $data = 'data' + ($dataLvl || '');
  1820. var $valid = 'valid' + $lvl;
  1821. var $errs = 'errs__' + $lvl;
  1822. var $isData = it.opts.$data && $schema && $schema.$data,
  1823. $schemaValue;
  1824. if ($isData) {
  1825. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1826. $schemaValue = 'schema' + $lvl;
  1827. } else {
  1828. $schemaValue = $schema;
  1829. }
  1830. var $rule = this,
  1831. $definition = 'definition' + $lvl,
  1832. $rDef = $rule.definition,
  1833. $closingBraces = '';
  1834. var $compile, $inline, $macro, $ruleValidate, $validateCode;
  1835. if ($isData && $rDef.$data) {
  1836. $validateCode = 'keywordValidate' + $lvl;
  1837. var $validateSchema = $rDef.validateSchema;
  1838. out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;';
  1839. } else {
  1840. $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
  1841. if (!$ruleValidate) return;
  1842. $schemaValue = 'validate.schema' + $schemaPath;
  1843. $validateCode = $ruleValidate.code;
  1844. $compile = $rDef.compile;
  1845. $inline = $rDef.inline;
  1846. $macro = $rDef.macro;
  1847. }
  1848. var $ruleErrs = $validateCode + '.errors',
  1849. $i = 'i' + $lvl,
  1850. $ruleErr = 'ruleErr' + $lvl,
  1851. $asyncKeyword = $rDef.async;
  1852. if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
  1853. if (!($inline || $macro)) {
  1854. out += '' + ($ruleErrs) + ' = null;';
  1855. }
  1856. out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
  1857. if ($isData && $rDef.$data) {
  1858. $closingBraces += '}';
  1859. out += ' if (' + ($schemaValue) + ' === undefined) { ' + ($valid) + ' = true; } else { ';
  1860. if ($validateSchema) {
  1861. $closingBraces += '}';
  1862. out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') { ';
  1863. }
  1864. }
  1865. if ($inline) {
  1866. if ($rDef.statements) {
  1867. out += ' ' + ($ruleValidate.validate) + ' ';
  1868. } else {
  1869. out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; ';
  1870. }
  1871. } else if ($macro) {
  1872. var $it = it.util.copy(it);
  1873. var $closingBraces = '';
  1874. $it.level++;
  1875. var $nextValid = 'valid' + $it.level;
  1876. $it.schema = $ruleValidate.validate;
  1877. $it.schemaPath = '';
  1878. var $wasComposite = it.compositeRule;
  1879. it.compositeRule = $it.compositeRule = true;
  1880. var $code = it.validate($it).replace(/validate\.schema/g, $validateCode);
  1881. it.compositeRule = $it.compositeRule = $wasComposite;
  1882. out += ' ' + ($code);
  1883. } else {
  1884. var $$outStack = $$outStack || [];
  1885. $$outStack.push(out);
  1886. out = '';
  1887. out += ' ' + ($validateCode) + '.call( ';
  1888. if (it.opts.passContext) {
  1889. out += 'this';
  1890. } else {
  1891. out += 'self';
  1892. }
  1893. if ($compile || $rDef.schema === false) {
  1894. out += ' , ' + ($data) + ' ';
  1895. } else {
  1896. out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
  1897. }
  1898. out += ' , (dataPath || \'\')';
  1899. if (it.errorPath != '""') {
  1900. out += ' + ' + (it.errorPath);
  1901. }
  1902. var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
  1903. $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
  1904. out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) ';
  1905. var def_callRuleValidate = out;
  1906. out = $$outStack.pop();
  1907. if ($rDef.errors === false) {
  1908. out += ' ' + ($valid) + ' = ';
  1909. if ($asyncKeyword) {
  1910. out += '' + (it.yieldAwait);
  1911. }
  1912. out += '' + (def_callRuleValidate) + '; ';
  1913. } else {
  1914. if ($asyncKeyword) {
  1915. $ruleErrs = 'customErrors' + $lvl;
  1916. out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = ' + (it.yieldAwait) + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
  1917. } else {
  1918. out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; ';
  1919. }
  1920. }
  1921. }
  1922. if ($rDef.modifying) {
  1923. out += ' if (' + ($parentData) + ') ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];';
  1924. }
  1925. out += '' + ($closingBraces);
  1926. if ($rDef.valid) {
  1927. if ($breakOnError) {
  1928. out += ' if (true) { ';
  1929. }
  1930. } else {
  1931. out += ' if ( ';
  1932. if ($rDef.valid === undefined) {
  1933. out += ' !';
  1934. if ($macro) {
  1935. out += '' + ($nextValid);
  1936. } else {
  1937. out += '' + ($valid);
  1938. }
  1939. } else {
  1940. out += ' ' + (!$rDef.valid) + ' ';
  1941. }
  1942. out += ') { ';
  1943. $errorKeyword = $rule.keyword;
  1944. var $$outStack = $$outStack || [];
  1945. $$outStack.push(out);
  1946. out = '';
  1947. var $$outStack = $$outStack || [];
  1948. $$outStack.push(out);
  1949. out = ''; /* istanbul ignore else */
  1950. if (it.createErrors !== false) {
  1951. out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
  1952. if (it.opts.messages !== false) {
  1953. out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
  1954. }
  1955. if (it.opts.verbose) {
  1956. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1957. }
  1958. out += ' } ';
  1959. } else {
  1960. out += ' {} ';
  1961. }
  1962. var __err = out;
  1963. out = $$outStack.pop();
  1964. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1965. if (it.async) {
  1966. out += ' throw new ValidationError([' + (__err) + ']); ';
  1967. } else {
  1968. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1969. }
  1970. } else {
  1971. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1972. }
  1973. var def_customError = out;
  1974. out = $$outStack.pop();
  1975. if ($inline) {
  1976. if ($rDef.errors) {
  1977. if ($rDef.errors != 'full') {
  1978. out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
  1979. if (it.opts.verbose) {
  1980. out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  1981. }
  1982. out += ' } ';
  1983. }
  1984. } else {
  1985. if ($rDef.errors === false) {
  1986. out += ' ' + (def_customError) + ' ';
  1987. } else {
  1988. out += ' if (' + ($errs) + ' == errors) { ' + (def_customError) + ' } else { for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
  1989. if (it.opts.verbose) {
  1990. out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  1991. }
  1992. out += ' } } ';
  1993. }
  1994. }
  1995. } else if ($macro) {
  1996. out += ' var err = '; /* istanbul ignore else */
  1997. if (it.createErrors !== false) {
  1998. out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
  1999. if (it.opts.messages !== false) {
  2000. out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
  2001. }
  2002. if (it.opts.verbose) {
  2003. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2004. }
  2005. out += ' } ';
  2006. } else {
  2007. out += ' {} ';
  2008. }
  2009. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2010. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2011. if (it.async) {
  2012. out += ' throw new ValidationError(vErrors); ';
  2013. } else {
  2014. out += ' validate.errors = vErrors; return false; ';
  2015. }
  2016. }
  2017. } else {
  2018. if ($rDef.errors === false) {
  2019. out += ' ' + (def_customError) + ' ';
  2020. } else {
  2021. out += ' if (Array.isArray(' + ($ruleErrs) + ')) { if (vErrors === null) vErrors = ' + ($ruleErrs) + '; else vErrors = vErrors.concat(' + ($ruleErrs) + '); errors = vErrors.length; for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; ';
  2022. if (it.opts.verbose) {
  2023. out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  2024. }
  2025. out += ' } } else { ' + (def_customError) + ' } ';
  2026. }
  2027. }
  2028. out += ' } ';
  2029. if ($breakOnError) {
  2030. out += ' else { ';
  2031. }
  2032. }
  2033. return out;
  2034. }
  2035. },{}],22:[function(require,module,exports){
  2036. 'use strict';
  2037. module.exports = function generate_dependencies(it, $keyword, $ruleType) {
  2038. var out = ' ';
  2039. var $lvl = it.level;
  2040. var $dataLvl = it.dataLevel;
  2041. var $schema = it.schema[$keyword];
  2042. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2043. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2044. var $breakOnError = !it.opts.allErrors;
  2045. var $data = 'data' + ($dataLvl || '');
  2046. var $errs = 'errs__' + $lvl;
  2047. var $it = it.util.copy(it);
  2048. var $closingBraces = '';
  2049. $it.level++;
  2050. var $nextValid = 'valid' + $it.level;
  2051. var $schemaDeps = {},
  2052. $propertyDeps = {},
  2053. $ownProperties = it.opts.ownProperties;
  2054. for ($property in $schema) {
  2055. var $sch = $schema[$property];
  2056. var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
  2057. $deps[$property] = $sch;
  2058. }
  2059. out += 'var ' + ($errs) + ' = errors;';
  2060. var $currentErrorPath = it.errorPath;
  2061. out += 'var missing' + ($lvl) + ';';
  2062. for (var $property in $propertyDeps) {
  2063. $deps = $propertyDeps[$property];
  2064. if ($deps.length) {
  2065. out += ' if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
  2066. if ($ownProperties) {
  2067. out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
  2068. }
  2069. if ($breakOnError) {
  2070. out += ' && ( ';
  2071. var arr1 = $deps;
  2072. if (arr1) {
  2073. var $propertyKey, $i = -1,
  2074. l1 = arr1.length - 1;
  2075. while ($i < l1) {
  2076. $propertyKey = arr1[$i += 1];
  2077. if ($i) {
  2078. out += ' || ';
  2079. }
  2080. var $prop = it.util.getProperty($propertyKey),
  2081. $useData = $data + $prop;
  2082. out += ' ( ( ' + ($useData) + ' === undefined ';
  2083. if ($ownProperties) {
  2084. out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
  2085. }
  2086. out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
  2087. }
  2088. }
  2089. out += ')) { ';
  2090. var $propertyPath = 'missing' + $lvl,
  2091. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  2092. if (it.opts._errorDataPathProperty) {
  2093. it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
  2094. }
  2095. var $$outStack = $$outStack || [];
  2096. $$outStack.push(out);
  2097. out = ''; /* istanbul ignore else */
  2098. if (it.createErrors !== false) {
  2099. out += ' { keyword: \'' + ('dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
  2100. if (it.opts.messages !== false) {
  2101. out += ' , message: \'should have ';
  2102. if ($deps.length == 1) {
  2103. out += 'property ' + (it.util.escapeQuotes($deps[0]));
  2104. } else {
  2105. out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
  2106. }
  2107. out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
  2108. }
  2109. if (it.opts.verbose) {
  2110. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2111. }
  2112. out += ' } ';
  2113. } else {
  2114. out += ' {} ';
  2115. }
  2116. var __err = out;
  2117. out = $$outStack.pop();
  2118. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2119. if (it.async) {
  2120. out += ' throw new ValidationError([' + (__err) + ']); ';
  2121. } else {
  2122. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2123. }
  2124. } else {
  2125. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2126. }
  2127. } else {
  2128. out += ' ) { ';
  2129. var arr2 = $deps;
  2130. if (arr2) {
  2131. var $propertyKey, i2 = -1,
  2132. l2 = arr2.length - 1;
  2133. while (i2 < l2) {
  2134. $propertyKey = arr2[i2 += 1];
  2135. var $prop = it.util.getProperty($propertyKey),
  2136. $missingProperty = it.util.escapeQuotes($propertyKey),
  2137. $useData = $data + $prop;
  2138. if (it.opts._errorDataPathProperty) {
  2139. it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
  2140. }
  2141. out += ' if ( ' + ($useData) + ' === undefined ';
  2142. if ($ownProperties) {
  2143. out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
  2144. }
  2145. out += ') { var err = '; /* istanbul ignore else */
  2146. if (it.createErrors !== false) {
  2147. out += ' { keyword: \'' + ('dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
  2148. if (it.opts.messages !== false) {
  2149. out += ' , message: \'should have ';
  2150. if ($deps.length == 1) {
  2151. out += 'property ' + (it.util.escapeQuotes($deps[0]));
  2152. } else {
  2153. out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
  2154. }
  2155. out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
  2156. }
  2157. if (it.opts.verbose) {
  2158. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2159. }
  2160. out += ' } ';
  2161. } else {
  2162. out += ' {} ';
  2163. }
  2164. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
  2165. }
  2166. }
  2167. }
  2168. out += ' } ';
  2169. if ($breakOnError) {
  2170. $closingBraces += '}';
  2171. out += ' else { ';
  2172. }
  2173. }
  2174. }
  2175. it.errorPath = $currentErrorPath;
  2176. var $currentBaseId = $it.baseId;
  2177. for (var $property in $schemaDeps) {
  2178. var $sch = $schemaDeps[$property];
  2179. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  2180. out += ' ' + ($nextValid) + ' = true; if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
  2181. if ($ownProperties) {
  2182. out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
  2183. }
  2184. out += ') { ';
  2185. $it.schema = $sch;
  2186. $it.schemaPath = $schemaPath + it.util.getProperty($property);
  2187. $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
  2188. out += ' ' + (it.validate($it)) + ' ';
  2189. $it.baseId = $currentBaseId;
  2190. out += ' } ';
  2191. if ($breakOnError) {
  2192. out += ' if (' + ($nextValid) + ') { ';
  2193. $closingBraces += '}';
  2194. }
  2195. }
  2196. }
  2197. if ($breakOnError) {
  2198. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  2199. }
  2200. out = it.util.cleanUpCode(out);
  2201. return out;
  2202. }
  2203. },{}],23:[function(require,module,exports){
  2204. 'use strict';
  2205. module.exports = function generate_enum(it, $keyword, $ruleType) {
  2206. var out = ' ';
  2207. var $lvl = it.level;
  2208. var $dataLvl = it.dataLevel;
  2209. var $schema = it.schema[$keyword];
  2210. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2211. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2212. var $breakOnError = !it.opts.allErrors;
  2213. var $data = 'data' + ($dataLvl || '');
  2214. var $valid = 'valid' + $lvl;
  2215. var $isData = it.opts.$data && $schema && $schema.$data,
  2216. $schemaValue;
  2217. if ($isData) {
  2218. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  2219. $schemaValue = 'schema' + $lvl;
  2220. } else {
  2221. $schemaValue = $schema;
  2222. }
  2223. var $i = 'i' + $lvl,
  2224. $vSchema = 'schema' + $lvl;
  2225. if (!$isData) {
  2226. out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + ';';
  2227. }
  2228. out += 'var ' + ($valid) + ';';
  2229. if ($isData) {
  2230. out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
  2231. }
  2232. out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<' + ($vSchema) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
  2233. if ($isData) {
  2234. out += ' } ';
  2235. }
  2236. out += ' if (!' + ($valid) + ') { ';
  2237. var $$outStack = $$outStack || [];
  2238. $$outStack.push(out);
  2239. out = ''; /* istanbul ignore else */
  2240. if (it.createErrors !== false) {
  2241. out += ' { keyword: \'' + ('enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValues: schema' + ($lvl) + ' } ';
  2242. if (it.opts.messages !== false) {
  2243. out += ' , message: \'should be equal to one of the allowed values\' ';
  2244. }
  2245. if (it.opts.verbose) {
  2246. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2247. }
  2248. out += ' } ';
  2249. } else {
  2250. out += ' {} ';
  2251. }
  2252. var __err = out;
  2253. out = $$outStack.pop();
  2254. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2255. if (it.async) {
  2256. out += ' throw new ValidationError([' + (__err) + ']); ';
  2257. } else {
  2258. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2259. }
  2260. } else {
  2261. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2262. }
  2263. out += ' }';
  2264. if ($breakOnError) {
  2265. out += ' else { ';
  2266. }
  2267. return out;
  2268. }
  2269. },{}],24:[function(require,module,exports){
  2270. 'use strict';
  2271. module.exports = function generate_format(it, $keyword, $ruleType) {
  2272. var out = ' ';
  2273. var $lvl = it.level;
  2274. var $dataLvl = it.dataLevel;
  2275. var $schema = it.schema[$keyword];
  2276. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2277. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2278. var $breakOnError = !it.opts.allErrors;
  2279. var $data = 'data' + ($dataLvl || '');
  2280. if (it.opts.format === false) {
  2281. if ($breakOnError) {
  2282. out += ' if (true) { ';
  2283. }
  2284. return out;
  2285. }
  2286. var $isData = it.opts.$data && $schema && $schema.$data,
  2287. $schemaValue;
  2288. if ($isData) {
  2289. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  2290. $schemaValue = 'schema' + $lvl;
  2291. } else {
  2292. $schemaValue = $schema;
  2293. }
  2294. var $unknownFormats = it.opts.unknownFormats,
  2295. $allowUnknown = Array.isArray($unknownFormats);
  2296. if ($isData) {
  2297. var $format = 'format' + $lvl,
  2298. $isObject = 'isObject' + $lvl,
  2299. $formatType = 'formatType' + $lvl;
  2300. out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var ' + ($isObject) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; var ' + ($formatType) + ' = ' + ($isObject) + ' && ' + ($format) + '.type || \'string\'; if (' + ($isObject) + ') { ';
  2301. if (it.async) {
  2302. out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; ';
  2303. }
  2304. out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
  2305. if ($isData) {
  2306. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
  2307. }
  2308. out += ' (';
  2309. if ($unknownFormats != 'ignore') {
  2310. out += ' (' + ($schemaValue) + ' && !' + ($format) + ' ';
  2311. if ($allowUnknown) {
  2312. out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 ';
  2313. }
  2314. out += ') || ';
  2315. }
  2316. out += ' (' + ($format) + ' && ' + ($formatType) + ' == \'' + ($ruleType) + '\' && !(typeof ' + ($format) + ' == \'function\' ? ';
  2317. if (it.async) {
  2318. out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
  2319. } else {
  2320. out += ' ' + ($format) + '(' + ($data) + ') ';
  2321. }
  2322. out += ' : ' + ($format) + '.test(' + ($data) + '))))) {';
  2323. } else {
  2324. var $format = it.formats[$schema];
  2325. if (!$format) {
  2326. if ($unknownFormats == 'ignore') {
  2327. console.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
  2328. if ($breakOnError) {
  2329. out += ' if (true) { ';
  2330. }
  2331. return out;
  2332. } else if ($allowUnknown && $unknownFormats.indexOf($schema) >= 0) {
  2333. if ($breakOnError) {
  2334. out += ' if (true) { ';
  2335. }
  2336. return out;
  2337. } else {
  2338. throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"');
  2339. }
  2340. }
  2341. var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
  2342. var $formatType = $isObject && $format.type || 'string';
  2343. if ($isObject) {
  2344. var $async = $format.async === true;
  2345. $format = $format.validate;
  2346. }
  2347. if ($formatType != $ruleType) {
  2348. if ($breakOnError) {
  2349. out += ' if (true) { ';
  2350. }
  2351. return out;
  2352. }
  2353. if ($async) {
  2354. if (!it.async) throw new Error('async format in sync schema');
  2355. var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
  2356. out += ' if (!(' + (it.yieldAwait) + ' ' + ($formatRef) + '(' + ($data) + '))) { ';
  2357. } else {
  2358. out += ' if (! ';
  2359. var $formatRef = 'formats' + it.util.getProperty($schema);
  2360. if ($isObject) $formatRef += '.validate';
  2361. if (typeof $format == 'function') {
  2362. out += ' ' + ($formatRef) + '(' + ($data) + ') ';
  2363. } else {
  2364. out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
  2365. }
  2366. out += ') { ';
  2367. }
  2368. }
  2369. var $$outStack = $$outStack || [];
  2370. $$outStack.push(out);
  2371. out = ''; /* istanbul ignore else */
  2372. if (it.createErrors !== false) {
  2373. out += ' { keyword: \'' + ('format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format: ';
  2374. if ($isData) {
  2375. out += '' + ($schemaValue);
  2376. } else {
  2377. out += '' + (it.util.toQuotedString($schema));
  2378. }
  2379. out += ' } ';
  2380. if (it.opts.messages !== false) {
  2381. out += ' , message: \'should match format "';
  2382. if ($isData) {
  2383. out += '\' + ' + ($schemaValue) + ' + \'';
  2384. } else {
  2385. out += '' + (it.util.escapeQuotes($schema));
  2386. }
  2387. out += '"\' ';
  2388. }
  2389. if (it.opts.verbose) {
  2390. out += ' , schema: ';
  2391. if ($isData) {
  2392. out += 'validate.schema' + ($schemaPath);
  2393. } else {
  2394. out += '' + (it.util.toQuotedString($schema));
  2395. }
  2396. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2397. }
  2398. out += ' } ';
  2399. } else {
  2400. out += ' {} ';
  2401. }
  2402. var __err = out;
  2403. out = $$outStack.pop();
  2404. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2405. if (it.async) {
  2406. out += ' throw new ValidationError([' + (__err) + ']); ';
  2407. } else {
  2408. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2409. }
  2410. } else {
  2411. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2412. }
  2413. out += ' } ';
  2414. if ($breakOnError) {
  2415. out += ' else { ';
  2416. }
  2417. return out;
  2418. }
  2419. },{}],25:[function(require,module,exports){
  2420. 'use strict';
  2421. module.exports = function generate_items(it, $keyword, $ruleType) {
  2422. var out = ' ';
  2423. var $lvl = it.level;
  2424. var $dataLvl = it.dataLevel;
  2425. var $schema = it.schema[$keyword];
  2426. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2427. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2428. var $breakOnError = !it.opts.allErrors;
  2429. var $data = 'data' + ($dataLvl || '');
  2430. var $valid = 'valid' + $lvl;
  2431. var $errs = 'errs__' + $lvl;
  2432. var $it = it.util.copy(it);
  2433. var $closingBraces = '';
  2434. $it.level++;
  2435. var $nextValid = 'valid' + $it.level;
  2436. var $idx = 'i' + $lvl,
  2437. $dataNxt = $it.dataLevel = it.dataLevel + 1,
  2438. $nextData = 'data' + $dataNxt,
  2439. $currentBaseId = it.baseId;
  2440. out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
  2441. if (Array.isArray($schema)) {
  2442. var $additionalItems = it.schema.additionalItems;
  2443. if ($additionalItems === false) {
  2444. out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; ';
  2445. var $currErrSchemaPath = $errSchemaPath;
  2446. $errSchemaPath = it.errSchemaPath + '/additionalItems';
  2447. out += ' if (!' + ($valid) + ') { ';
  2448. var $$outStack = $$outStack || [];
  2449. $$outStack.push(out);
  2450. out = ''; /* istanbul ignore else */
  2451. if (it.createErrors !== false) {
  2452. out += ' { keyword: \'' + ('additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schema.length) + ' } ';
  2453. if (it.opts.messages !== false) {
  2454. out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
  2455. }
  2456. if (it.opts.verbose) {
  2457. out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2458. }
  2459. out += ' } ';
  2460. } else {
  2461. out += ' {} ';
  2462. }
  2463. var __err = out;
  2464. out = $$outStack.pop();
  2465. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2466. if (it.async) {
  2467. out += ' throw new ValidationError([' + (__err) + ']); ';
  2468. } else {
  2469. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2470. }
  2471. } else {
  2472. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2473. }
  2474. out += ' } ';
  2475. $errSchemaPath = $currErrSchemaPath;
  2476. if ($breakOnError) {
  2477. $closingBraces += '}';
  2478. out += ' else { ';
  2479. }
  2480. }
  2481. var arr1 = $schema;
  2482. if (arr1) {
  2483. var $sch, $i = -1,
  2484. l1 = arr1.length - 1;
  2485. while ($i < l1) {
  2486. $sch = arr1[$i += 1];
  2487. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  2488. out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
  2489. var $passData = $data + '[' + $i + ']';
  2490. $it.schema = $sch;
  2491. $it.schemaPath = $schemaPath + '[' + $i + ']';
  2492. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  2493. $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
  2494. $it.dataPathArr[$dataNxt] = $i;
  2495. var $code = it.validate($it);
  2496. $it.baseId = $currentBaseId;
  2497. if (it.util.varOccurences($code, $nextData) < 2) {
  2498. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  2499. } else {
  2500. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  2501. }
  2502. out += ' } ';
  2503. if ($breakOnError) {
  2504. out += ' if (' + ($nextValid) + ') { ';
  2505. $closingBraces += '}';
  2506. }
  2507. }
  2508. }
  2509. }
  2510. if (typeof $additionalItems == 'object' && it.util.schemaHasRules($additionalItems, it.RULES.all)) {
  2511. $it.schema = $additionalItems;
  2512. $it.schemaPath = it.schemaPath + '.additionalItems';
  2513. $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
  2514. out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var ' + ($idx) + ' = ' + ($schema.length) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
  2515. $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
  2516. var $passData = $data + '[' + $idx + ']';
  2517. $it.dataPathArr[$dataNxt] = $idx;
  2518. var $code = it.validate($it);
  2519. $it.baseId = $currentBaseId;
  2520. if (it.util.varOccurences($code, $nextData) < 2) {
  2521. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  2522. } else {
  2523. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  2524. }
  2525. if ($breakOnError) {
  2526. out += ' if (!' + ($nextValid) + ') break; ';
  2527. }
  2528. out += ' } } ';
  2529. if ($breakOnError) {
  2530. out += ' if (' + ($nextValid) + ') { ';
  2531. $closingBraces += '}';
  2532. }
  2533. }
  2534. } else if (it.util.schemaHasRules($schema, it.RULES.all)) {
  2535. $it.schema = $schema;
  2536. $it.schemaPath = $schemaPath;
  2537. $it.errSchemaPath = $errSchemaPath;
  2538. out += ' for (var ' + ($idx) + ' = ' + (0) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
  2539. $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
  2540. var $passData = $data + '[' + $idx + ']';
  2541. $it.dataPathArr[$dataNxt] = $idx;
  2542. var $code = it.validate($it);
  2543. $it.baseId = $currentBaseId;
  2544. if (it.util.varOccurences($code, $nextData) < 2) {
  2545. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  2546. } else {
  2547. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  2548. }
  2549. if ($breakOnError) {
  2550. out += ' if (!' + ($nextValid) + ') break; ';
  2551. }
  2552. out += ' }';
  2553. }
  2554. if ($breakOnError) {
  2555. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  2556. }
  2557. out = it.util.cleanUpCode(out);
  2558. return out;
  2559. }
  2560. },{}],26:[function(require,module,exports){
  2561. 'use strict';
  2562. module.exports = function generate_multipleOf(it, $keyword, $ruleType) {
  2563. var out = ' ';
  2564. var $lvl = it.level;
  2565. var $dataLvl = it.dataLevel;
  2566. var $schema = it.schema[$keyword];
  2567. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2568. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2569. var $breakOnError = !it.opts.allErrors;
  2570. var $data = 'data' + ($dataLvl || '');
  2571. var $isData = it.opts.$data && $schema && $schema.$data,
  2572. $schemaValue;
  2573. if ($isData) {
  2574. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  2575. $schemaValue = 'schema' + $lvl;
  2576. } else {
  2577. $schemaValue = $schema;
  2578. }
  2579. out += 'var division' + ($lvl) + ';if (';
  2580. if ($isData) {
  2581. out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
  2582. }
  2583. out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
  2584. if (it.opts.multipleOfPrecision) {
  2585. out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
  2586. } else {
  2587. out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
  2588. }
  2589. out += ' ) ';
  2590. if ($isData) {
  2591. out += ' ) ';
  2592. }
  2593. out += ' ) { ';
  2594. var $$outStack = $$outStack || [];
  2595. $$outStack.push(out);
  2596. out = ''; /* istanbul ignore else */
  2597. if (it.createErrors !== false) {
  2598. out += ' { keyword: \'' + ('multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { multipleOf: ' + ($schemaValue) + ' } ';
  2599. if (it.opts.messages !== false) {
  2600. out += ' , message: \'should be multiple of ';
  2601. if ($isData) {
  2602. out += '\' + ' + ($schemaValue);
  2603. } else {
  2604. out += '' + ($schemaValue) + '\'';
  2605. }
  2606. }
  2607. if (it.opts.verbose) {
  2608. out += ' , schema: ';
  2609. if ($isData) {
  2610. out += 'validate.schema' + ($schemaPath);
  2611. } else {
  2612. out += '' + ($schema);
  2613. }
  2614. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2615. }
  2616. out += ' } ';
  2617. } else {
  2618. out += ' {} ';
  2619. }
  2620. var __err = out;
  2621. out = $$outStack.pop();
  2622. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2623. if (it.async) {
  2624. out += ' throw new ValidationError([' + (__err) + ']); ';
  2625. } else {
  2626. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2627. }
  2628. } else {
  2629. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2630. }
  2631. out += '} ';
  2632. if ($breakOnError) {
  2633. out += ' else { ';
  2634. }
  2635. return out;
  2636. }
  2637. },{}],27:[function(require,module,exports){
  2638. 'use strict';
  2639. module.exports = function generate_not(it, $keyword, $ruleType) {
  2640. var out = ' ';
  2641. var $lvl = it.level;
  2642. var $dataLvl = it.dataLevel;
  2643. var $schema = it.schema[$keyword];
  2644. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2645. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2646. var $breakOnError = !it.opts.allErrors;
  2647. var $data = 'data' + ($dataLvl || '');
  2648. var $errs = 'errs__' + $lvl;
  2649. var $it = it.util.copy(it);
  2650. $it.level++;
  2651. var $nextValid = 'valid' + $it.level;
  2652. if (it.util.schemaHasRules($schema, it.RULES.all)) {
  2653. $it.schema = $schema;
  2654. $it.schemaPath = $schemaPath;
  2655. $it.errSchemaPath = $errSchemaPath;
  2656. out += ' var ' + ($errs) + ' = errors; ';
  2657. var $wasComposite = it.compositeRule;
  2658. it.compositeRule = $it.compositeRule = true;
  2659. $it.createErrors = false;
  2660. var $allErrorsOption;
  2661. if ($it.opts.allErrors) {
  2662. $allErrorsOption = $it.opts.allErrors;
  2663. $it.opts.allErrors = false;
  2664. }
  2665. out += ' ' + (it.validate($it)) + ' ';
  2666. $it.createErrors = true;
  2667. if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
  2668. it.compositeRule = $it.compositeRule = $wasComposite;
  2669. out += ' if (' + ($nextValid) + ') { ';
  2670. var $$outStack = $$outStack || [];
  2671. $$outStack.push(out);
  2672. out = ''; /* istanbul ignore else */
  2673. if (it.createErrors !== false) {
  2674. out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  2675. if (it.opts.messages !== false) {
  2676. out += ' , message: \'should NOT be valid\' ';
  2677. }
  2678. if (it.opts.verbose) {
  2679. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2680. }
  2681. out += ' } ';
  2682. } else {
  2683. out += ' {} ';
  2684. }
  2685. var __err = out;
  2686. out = $$outStack.pop();
  2687. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2688. if (it.async) {
  2689. out += ' throw new ValidationError([' + (__err) + ']); ';
  2690. } else {
  2691. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2692. }
  2693. } else {
  2694. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2695. }
  2696. out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
  2697. if (it.opts.allErrors) {
  2698. out += ' } ';
  2699. }
  2700. } else {
  2701. out += ' var err = '; /* istanbul ignore else */
  2702. if (it.createErrors !== false) {
  2703. out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  2704. if (it.opts.messages !== false) {
  2705. out += ' , message: \'should NOT be valid\' ';
  2706. }
  2707. if (it.opts.verbose) {
  2708. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2709. }
  2710. out += ' } ';
  2711. } else {
  2712. out += ' {} ';
  2713. }
  2714. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2715. if ($breakOnError) {
  2716. out += ' if (false) { ';
  2717. }
  2718. }
  2719. return out;
  2720. }
  2721. },{}],28:[function(require,module,exports){
  2722. 'use strict';
  2723. module.exports = function generate_oneOf(it, $keyword, $ruleType) {
  2724. var out = ' ';
  2725. var $lvl = it.level;
  2726. var $dataLvl = it.dataLevel;
  2727. var $schema = it.schema[$keyword];
  2728. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2729. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2730. var $breakOnError = !it.opts.allErrors;
  2731. var $data = 'data' + ($dataLvl || '');
  2732. var $valid = 'valid' + $lvl;
  2733. var $errs = 'errs__' + $lvl;
  2734. var $it = it.util.copy(it);
  2735. var $closingBraces = '';
  2736. $it.level++;
  2737. var $nextValid = 'valid' + $it.level;
  2738. out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false;';
  2739. var $currentBaseId = $it.baseId;
  2740. var $wasComposite = it.compositeRule;
  2741. it.compositeRule = $it.compositeRule = true;
  2742. var arr1 = $schema;
  2743. if (arr1) {
  2744. var $sch, $i = -1,
  2745. l1 = arr1.length - 1;
  2746. while ($i < l1) {
  2747. $sch = arr1[$i += 1];
  2748. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  2749. $it.schema = $sch;
  2750. $it.schemaPath = $schemaPath + '[' + $i + ']';
  2751. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  2752. out += ' ' + (it.validate($it)) + ' ';
  2753. $it.baseId = $currentBaseId;
  2754. } else {
  2755. out += ' var ' + ($nextValid) + ' = true; ';
  2756. }
  2757. if ($i) {
  2758. out += ' if (' + ($nextValid) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { ';
  2759. $closingBraces += '}';
  2760. }
  2761. out += ' if (' + ($nextValid) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;';
  2762. }
  2763. }
  2764. it.compositeRule = $it.compositeRule = $wasComposite;
  2765. out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
  2766. if (it.createErrors !== false) {
  2767. out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  2768. if (it.opts.messages !== false) {
  2769. out += ' , message: \'should match exactly one schema in oneOf\' ';
  2770. }
  2771. if (it.opts.verbose) {
  2772. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2773. }
  2774. out += ' } ';
  2775. } else {
  2776. out += ' {} ';
  2777. }
  2778. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2779. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2780. if (it.async) {
  2781. out += ' throw new ValidationError(vErrors); ';
  2782. } else {
  2783. out += ' validate.errors = vErrors; return false; ';
  2784. }
  2785. }
  2786. out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
  2787. if (it.opts.allErrors) {
  2788. out += ' } ';
  2789. }
  2790. return out;
  2791. }
  2792. },{}],29:[function(require,module,exports){
  2793. 'use strict';
  2794. module.exports = function generate_pattern(it, $keyword, $ruleType) {
  2795. var out = ' ';
  2796. var $lvl = it.level;
  2797. var $dataLvl = it.dataLevel;
  2798. var $schema = it.schema[$keyword];
  2799. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2800. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2801. var $breakOnError = !it.opts.allErrors;
  2802. var $data = 'data' + ($dataLvl || '');
  2803. var $isData = it.opts.$data && $schema && $schema.$data,
  2804. $schemaValue;
  2805. if ($isData) {
  2806. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  2807. $schemaValue = 'schema' + $lvl;
  2808. } else {
  2809. $schemaValue = $schema;
  2810. }
  2811. var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
  2812. out += 'if ( ';
  2813. if ($isData) {
  2814. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
  2815. }
  2816. out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { ';
  2817. var $$outStack = $$outStack || [];
  2818. $$outStack.push(out);
  2819. out = ''; /* istanbul ignore else */
  2820. if (it.createErrors !== false) {
  2821. out += ' { keyword: \'' + ('pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { pattern: ';
  2822. if ($isData) {
  2823. out += '' + ($schemaValue);
  2824. } else {
  2825. out += '' + (it.util.toQuotedString($schema));
  2826. }
  2827. out += ' } ';
  2828. if (it.opts.messages !== false) {
  2829. out += ' , message: \'should match pattern "';
  2830. if ($isData) {
  2831. out += '\' + ' + ($schemaValue) + ' + \'';
  2832. } else {
  2833. out += '' + (it.util.escapeQuotes($schema));
  2834. }
  2835. out += '"\' ';
  2836. }
  2837. if (it.opts.verbose) {
  2838. out += ' , schema: ';
  2839. if ($isData) {
  2840. out += 'validate.schema' + ($schemaPath);
  2841. } else {
  2842. out += '' + (it.util.toQuotedString($schema));
  2843. }
  2844. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2845. }
  2846. out += ' } ';
  2847. } else {
  2848. out += ' {} ';
  2849. }
  2850. var __err = out;
  2851. out = $$outStack.pop();
  2852. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2853. if (it.async) {
  2854. out += ' throw new ValidationError([' + (__err) + ']); ';
  2855. } else {
  2856. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2857. }
  2858. } else {
  2859. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2860. }
  2861. out += '} ';
  2862. if ($breakOnError) {
  2863. out += ' else { ';
  2864. }
  2865. return out;
  2866. }
  2867. },{}],30:[function(require,module,exports){
  2868. 'use strict';
  2869. module.exports = function generate_properties(it, $keyword, $ruleType) {
  2870. var out = ' ';
  2871. var $lvl = it.level;
  2872. var $dataLvl = it.dataLevel;
  2873. var $schema = it.schema[$keyword];
  2874. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2875. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2876. var $breakOnError = !it.opts.allErrors;
  2877. var $data = 'data' + ($dataLvl || '');
  2878. var $valid = 'valid' + $lvl;
  2879. var $errs = 'errs__' + $lvl;
  2880. var $it = it.util.copy(it);
  2881. var $closingBraces = '';
  2882. $it.level++;
  2883. var $nextValid = 'valid' + $it.level;
  2884. var $key = 'key' + $lvl,
  2885. $idx = 'idx' + $lvl,
  2886. $dataNxt = $it.dataLevel = it.dataLevel + 1,
  2887. $nextData = 'data' + $dataNxt,
  2888. $dataProperties = 'dataProperties' + $lvl;
  2889. var $schemaKeys = Object.keys($schema || {}),
  2890. $pProperties = it.schema.patternProperties || {},
  2891. $pPropertyKeys = Object.keys($pProperties),
  2892. $aProperties = it.schema.additionalProperties,
  2893. $someProperties = $schemaKeys.length || $pPropertyKeys.length,
  2894. $noAdditional = $aProperties === false,
  2895. $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
  2896. $removeAdditional = it.opts.removeAdditional,
  2897. $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional,
  2898. $ownProperties = it.opts.ownProperties,
  2899. $currentBaseId = it.baseId;
  2900. var $required = it.schema.required;
  2901. if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required);
  2902. if (it.opts.patternGroups) {
  2903. var $pgProperties = it.schema.patternGroups || {},
  2904. $pgPropertyKeys = Object.keys($pgProperties);
  2905. }
  2906. out += 'var ' + ($errs) + ' = errors;var ' + ($nextValid) + ' = true;';
  2907. if ($ownProperties) {
  2908. out += ' var ' + ($dataProperties) + ' = undefined;';
  2909. }
  2910. if ($checkAdditional) {
  2911. if ($ownProperties) {
  2912. out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
  2913. } else {
  2914. out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
  2915. }
  2916. if ($someProperties) {
  2917. out += ' var isAdditional' + ($lvl) + ' = !(false ';
  2918. if ($schemaKeys.length) {
  2919. if ($schemaKeys.length > 5) {
  2920. out += ' || validate.schema' + ($schemaPath) + '[' + ($key) + '] ';
  2921. } else {
  2922. var arr1 = $schemaKeys;
  2923. if (arr1) {
  2924. var $propertyKey, i1 = -1,
  2925. l1 = arr1.length - 1;
  2926. while (i1 < l1) {
  2927. $propertyKey = arr1[i1 += 1];
  2928. out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
  2929. }
  2930. }
  2931. }
  2932. }
  2933. if ($pPropertyKeys.length) {
  2934. var arr2 = $pPropertyKeys;
  2935. if (arr2) {
  2936. var $pProperty, $i = -1,
  2937. l2 = arr2.length - 1;
  2938. while ($i < l2) {
  2939. $pProperty = arr2[$i += 1];
  2940. out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') ';
  2941. }
  2942. }
  2943. }
  2944. if (it.opts.patternGroups && $pgPropertyKeys.length) {
  2945. var arr3 = $pgPropertyKeys;
  2946. if (arr3) {
  2947. var $pgProperty, $i = -1,
  2948. l3 = arr3.length - 1;
  2949. while ($i < l3) {
  2950. $pgProperty = arr3[$i += 1];
  2951. out += ' || ' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ') ';
  2952. }
  2953. }
  2954. }
  2955. out += ' ); if (isAdditional' + ($lvl) + ') { ';
  2956. }
  2957. if ($removeAdditional == 'all') {
  2958. out += ' delete ' + ($data) + '[' + ($key) + ']; ';
  2959. } else {
  2960. var $currentErrorPath = it.errorPath;
  2961. var $additionalProperty = '\' + ' + $key + ' + \'';
  2962. if (it.opts._errorDataPathProperty) {
  2963. it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  2964. }
  2965. if ($noAdditional) {
  2966. if ($removeAdditional) {
  2967. out += ' delete ' + ($data) + '[' + ($key) + ']; ';
  2968. } else {
  2969. out += ' ' + ($nextValid) + ' = false; ';
  2970. var $currErrSchemaPath = $errSchemaPath;
  2971. $errSchemaPath = it.errSchemaPath + '/additionalProperties';
  2972. var $$outStack = $$outStack || [];
  2973. $$outStack.push(out);
  2974. out = ''; /* istanbul ignore else */
  2975. if (it.createErrors !== false) {
  2976. out += ' { keyword: \'' + ('additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { additionalProperty: \'' + ($additionalProperty) + '\' } ';
  2977. if (it.opts.messages !== false) {
  2978. out += ' , message: \'should NOT have additional properties\' ';
  2979. }
  2980. if (it.opts.verbose) {
  2981. out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2982. }
  2983. out += ' } ';
  2984. } else {
  2985. out += ' {} ';
  2986. }
  2987. var __err = out;
  2988. out = $$outStack.pop();
  2989. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2990. if (it.async) {
  2991. out += ' throw new ValidationError([' + (__err) + ']); ';
  2992. } else {
  2993. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2994. }
  2995. } else {
  2996. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2997. }
  2998. $errSchemaPath = $currErrSchemaPath;
  2999. if ($breakOnError) {
  3000. out += ' break; ';
  3001. }
  3002. }
  3003. } else if ($additionalIsSchema) {
  3004. if ($removeAdditional == 'failing') {
  3005. out += ' var ' + ($errs) + ' = errors; ';
  3006. var $wasComposite = it.compositeRule;
  3007. it.compositeRule = $it.compositeRule = true;
  3008. $it.schema = $aProperties;
  3009. $it.schemaPath = it.schemaPath + '.additionalProperties';
  3010. $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
  3011. $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3012. var $passData = $data + '[' + $key + ']';
  3013. $it.dataPathArr[$dataNxt] = $key;
  3014. var $code = it.validate($it);
  3015. $it.baseId = $currentBaseId;
  3016. if (it.util.varOccurences($code, $nextData) < 2) {
  3017. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3018. } else {
  3019. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3020. }
  3021. out += ' if (!' + ($nextValid) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[' + ($key) + ']; } ';
  3022. it.compositeRule = $it.compositeRule = $wasComposite;
  3023. } else {
  3024. $it.schema = $aProperties;
  3025. $it.schemaPath = it.schemaPath + '.additionalProperties';
  3026. $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
  3027. $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3028. var $passData = $data + '[' + $key + ']';
  3029. $it.dataPathArr[$dataNxt] = $key;
  3030. var $code = it.validate($it);
  3031. $it.baseId = $currentBaseId;
  3032. if (it.util.varOccurences($code, $nextData) < 2) {
  3033. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3034. } else {
  3035. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3036. }
  3037. if ($breakOnError) {
  3038. out += ' if (!' + ($nextValid) + ') break; ';
  3039. }
  3040. }
  3041. }
  3042. it.errorPath = $currentErrorPath;
  3043. }
  3044. if ($someProperties) {
  3045. out += ' } ';
  3046. }
  3047. out += ' } ';
  3048. if ($breakOnError) {
  3049. out += ' if (' + ($nextValid) + ') { ';
  3050. $closingBraces += '}';
  3051. }
  3052. }
  3053. var $useDefaults = it.opts.useDefaults && !it.compositeRule;
  3054. if ($schemaKeys.length) {
  3055. var arr4 = $schemaKeys;
  3056. if (arr4) {
  3057. var $propertyKey, i4 = -1,
  3058. l4 = arr4.length - 1;
  3059. while (i4 < l4) {
  3060. $propertyKey = arr4[i4 += 1];
  3061. var $sch = $schema[$propertyKey];
  3062. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  3063. var $prop = it.util.getProperty($propertyKey),
  3064. $passData = $data + $prop,
  3065. $hasDefault = $useDefaults && $sch.default !== undefined;
  3066. $it.schema = $sch;
  3067. $it.schemaPath = $schemaPath + $prop;
  3068. $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
  3069. $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
  3070. $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
  3071. var $code = it.validate($it);
  3072. $it.baseId = $currentBaseId;
  3073. if (it.util.varOccurences($code, $nextData) < 2) {
  3074. $code = it.util.varReplace($code, $nextData, $passData);
  3075. var $useData = $passData;
  3076. } else {
  3077. var $useData = $nextData;
  3078. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
  3079. }
  3080. if ($hasDefault) {
  3081. out += ' ' + ($code) + ' ';
  3082. } else {
  3083. if ($requiredHash && $requiredHash[$propertyKey]) {
  3084. out += ' if ( ' + ($useData) + ' === undefined ';
  3085. if ($ownProperties) {
  3086. out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
  3087. }
  3088. out += ') { ' + ($nextValid) + ' = false; ';
  3089. var $currentErrorPath = it.errorPath,
  3090. $currErrSchemaPath = $errSchemaPath,
  3091. $missingProperty = it.util.escapeQuotes($propertyKey);
  3092. if (it.opts._errorDataPathProperty) {
  3093. it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
  3094. }
  3095. $errSchemaPath = it.errSchemaPath + '/required';
  3096. var $$outStack = $$outStack || [];
  3097. $$outStack.push(out);
  3098. out = ''; /* istanbul ignore else */
  3099. if (it.createErrors !== false) {
  3100. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3101. if (it.opts.messages !== false) {
  3102. out += ' , message: \'';
  3103. if (it.opts._errorDataPathProperty) {
  3104. out += 'is a required property';
  3105. } else {
  3106. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3107. }
  3108. out += '\' ';
  3109. }
  3110. if (it.opts.verbose) {
  3111. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3112. }
  3113. out += ' } ';
  3114. } else {
  3115. out += ' {} ';
  3116. }
  3117. var __err = out;
  3118. out = $$outStack.pop();
  3119. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3120. if (it.async) {
  3121. out += ' throw new ValidationError([' + (__err) + ']); ';
  3122. } else {
  3123. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3124. }
  3125. } else {
  3126. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3127. }
  3128. $errSchemaPath = $currErrSchemaPath;
  3129. it.errorPath = $currentErrorPath;
  3130. out += ' } else { ';
  3131. } else {
  3132. if ($breakOnError) {
  3133. out += ' if ( ' + ($useData) + ' === undefined ';
  3134. if ($ownProperties) {
  3135. out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
  3136. }
  3137. out += ') { ' + ($nextValid) + ' = true; } else { ';
  3138. } else {
  3139. out += ' if (' + ($useData) + ' !== undefined ';
  3140. if ($ownProperties) {
  3141. out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
  3142. }
  3143. out += ' ) { ';
  3144. }
  3145. }
  3146. out += ' ' + ($code) + ' } ';
  3147. }
  3148. }
  3149. if ($breakOnError) {
  3150. out += ' if (' + ($nextValid) + ') { ';
  3151. $closingBraces += '}';
  3152. }
  3153. }
  3154. }
  3155. }
  3156. if ($pPropertyKeys.length) {
  3157. var arr5 = $pPropertyKeys;
  3158. if (arr5) {
  3159. var $pProperty, i5 = -1,
  3160. l5 = arr5.length - 1;
  3161. while (i5 < l5) {
  3162. $pProperty = arr5[i5 += 1];
  3163. var $sch = $pProperties[$pProperty];
  3164. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  3165. $it.schema = $sch;
  3166. $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
  3167. $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty);
  3168. if ($ownProperties) {
  3169. out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
  3170. } else {
  3171. out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
  3172. }
  3173. out += ' if (' + (it.usePattern($pProperty)) + '.test(' + ($key) + ')) { ';
  3174. $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3175. var $passData = $data + '[' + $key + ']';
  3176. $it.dataPathArr[$dataNxt] = $key;
  3177. var $code = it.validate($it);
  3178. $it.baseId = $currentBaseId;
  3179. if (it.util.varOccurences($code, $nextData) < 2) {
  3180. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3181. } else {
  3182. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3183. }
  3184. if ($breakOnError) {
  3185. out += ' if (!' + ($nextValid) + ') break; ';
  3186. }
  3187. out += ' } ';
  3188. if ($breakOnError) {
  3189. out += ' else ' + ($nextValid) + ' = true; ';
  3190. }
  3191. out += ' } ';
  3192. if ($breakOnError) {
  3193. out += ' if (' + ($nextValid) + ') { ';
  3194. $closingBraces += '}';
  3195. }
  3196. }
  3197. }
  3198. }
  3199. }
  3200. if (it.opts.patternGroups && $pgPropertyKeys.length) {
  3201. var arr6 = $pgPropertyKeys;
  3202. if (arr6) {
  3203. var $pgProperty, i6 = -1,
  3204. l6 = arr6.length - 1;
  3205. while (i6 < l6) {
  3206. $pgProperty = arr6[i6 += 1];
  3207. var $pgSchema = $pgProperties[$pgProperty],
  3208. $sch = $pgSchema.schema;
  3209. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  3210. $it.schema = $sch;
  3211. $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema';
  3212. $it.errSchemaPath = it.errSchemaPath + '/patternGroups/' + it.util.escapeFragment($pgProperty) + '/schema';
  3213. out += ' var pgPropCount' + ($lvl) + ' = 0; ';
  3214. if ($ownProperties) {
  3215. out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
  3216. } else {
  3217. out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
  3218. }
  3219. out += ' if (' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ')) { pgPropCount' + ($lvl) + '++; ';
  3220. $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3221. var $passData = $data + '[' + $key + ']';
  3222. $it.dataPathArr[$dataNxt] = $key;
  3223. var $code = it.validate($it);
  3224. $it.baseId = $currentBaseId;
  3225. if (it.util.varOccurences($code, $nextData) < 2) {
  3226. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3227. } else {
  3228. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3229. }
  3230. if ($breakOnError) {
  3231. out += ' if (!' + ($nextValid) + ') break; ';
  3232. }
  3233. out += ' } ';
  3234. if ($breakOnError) {
  3235. out += ' else ' + ($nextValid) + ' = true; ';
  3236. }
  3237. out += ' } ';
  3238. if ($breakOnError) {
  3239. out += ' if (' + ($nextValid) + ') { ';
  3240. $closingBraces += '}';
  3241. }
  3242. var $pgMin = $pgSchema.minimum,
  3243. $pgMax = $pgSchema.maximum;
  3244. if ($pgMin !== undefined || $pgMax !== undefined) {
  3245. out += ' var ' + ($valid) + ' = true; ';
  3246. var $currErrSchemaPath = $errSchemaPath;
  3247. if ($pgMin !== undefined) {
  3248. var $limit = $pgMin,
  3249. $reason = 'minimum',
  3250. $moreOrLess = 'less';
  3251. out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' >= ' + ($pgMin) + '; ';
  3252. $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum';
  3253. out += ' if (!' + ($valid) + ') { ';
  3254. var $$outStack = $$outStack || [];
  3255. $$outStack.push(out);
  3256. out = ''; /* istanbul ignore else */
  3257. if (it.createErrors !== false) {
  3258. out += ' { keyword: \'' + ('patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } ';
  3259. if (it.opts.messages !== false) {
  3260. out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' ';
  3261. }
  3262. if (it.opts.verbose) {
  3263. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3264. }
  3265. out += ' } ';
  3266. } else {
  3267. out += ' {} ';
  3268. }
  3269. var __err = out;
  3270. out = $$outStack.pop();
  3271. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3272. if (it.async) {
  3273. out += ' throw new ValidationError([' + (__err) + ']); ';
  3274. } else {
  3275. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3276. }
  3277. } else {
  3278. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3279. }
  3280. out += ' } ';
  3281. if ($pgMax !== undefined) {
  3282. out += ' else ';
  3283. }
  3284. }
  3285. if ($pgMax !== undefined) {
  3286. var $limit = $pgMax,
  3287. $reason = 'maximum',
  3288. $moreOrLess = 'more';
  3289. out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' <= ' + ($pgMax) + '; ';
  3290. $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum';
  3291. out += ' if (!' + ($valid) + ') { ';
  3292. var $$outStack = $$outStack || [];
  3293. $$outStack.push(out);
  3294. out = ''; /* istanbul ignore else */
  3295. if (it.createErrors !== false) {
  3296. out += ' { keyword: \'' + ('patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } ';
  3297. if (it.opts.messages !== false) {
  3298. out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' ';
  3299. }
  3300. if (it.opts.verbose) {
  3301. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3302. }
  3303. out += ' } ';
  3304. } else {
  3305. out += ' {} ';
  3306. }
  3307. var __err = out;
  3308. out = $$outStack.pop();
  3309. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3310. if (it.async) {
  3311. out += ' throw new ValidationError([' + (__err) + ']); ';
  3312. } else {
  3313. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3314. }
  3315. } else {
  3316. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3317. }
  3318. out += ' } ';
  3319. }
  3320. $errSchemaPath = $currErrSchemaPath;
  3321. if ($breakOnError) {
  3322. out += ' if (' + ($valid) + ') { ';
  3323. $closingBraces += '}';
  3324. }
  3325. }
  3326. }
  3327. }
  3328. }
  3329. }
  3330. if ($breakOnError) {
  3331. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  3332. }
  3333. out = it.util.cleanUpCode(out);
  3334. return out;
  3335. }
  3336. },{}],31:[function(require,module,exports){
  3337. 'use strict';
  3338. module.exports = function generate_propertyNames(it, $keyword, $ruleType) {
  3339. var out = ' ';
  3340. var $lvl = it.level;
  3341. var $dataLvl = it.dataLevel;
  3342. var $schema = it.schema[$keyword];
  3343. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  3344. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3345. var $breakOnError = !it.opts.allErrors;
  3346. var $data = 'data' + ($dataLvl || '');
  3347. var $errs = 'errs__' + $lvl;
  3348. var $it = it.util.copy(it);
  3349. var $closingBraces = '';
  3350. $it.level++;
  3351. var $nextValid = 'valid' + $it.level;
  3352. if (it.util.schemaHasRules($schema, it.RULES.all)) {
  3353. $it.schema = $schema;
  3354. $it.schemaPath = $schemaPath;
  3355. $it.errSchemaPath = $errSchemaPath;
  3356. var $key = 'key' + $lvl,
  3357. $idx = 'idx' + $lvl,
  3358. $i = 'i' + $lvl,
  3359. $invalidName = '\' + ' + $key + ' + \'',
  3360. $dataNxt = $it.dataLevel = it.dataLevel + 1,
  3361. $nextData = 'data' + $dataNxt,
  3362. $dataProperties = 'dataProperties' + $lvl,
  3363. $ownProperties = it.opts.ownProperties,
  3364. $currentBaseId = it.baseId;
  3365. out += ' var ' + ($errs) + ' = errors; ';
  3366. if ($ownProperties) {
  3367. out += ' var ' + ($dataProperties) + ' = undefined; ';
  3368. }
  3369. if ($ownProperties) {
  3370. out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
  3371. } else {
  3372. out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
  3373. }
  3374. out += ' var startErrs' + ($lvl) + ' = errors; ';
  3375. var $passData = $key;
  3376. var $wasComposite = it.compositeRule;
  3377. it.compositeRule = $it.compositeRule = true;
  3378. var $code = it.validate($it);
  3379. $it.baseId = $currentBaseId;
  3380. if (it.util.varOccurences($code, $nextData) < 2) {
  3381. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3382. } else {
  3383. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3384. }
  3385. it.compositeRule = $it.compositeRule = $wasComposite;
  3386. out += ' if (!' + ($nextValid) + ') { for (var ' + ($i) + '=startErrs' + ($lvl) + '; ' + ($i) + '<errors; ' + ($i) + '++) { vErrors[' + ($i) + '].propertyName = ' + ($key) + '; } var err = '; /* istanbul ignore else */
  3387. if (it.createErrors !== false) {
  3388. out += ' { keyword: \'' + ('propertyNames') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { propertyName: \'' + ($invalidName) + '\' } ';
  3389. if (it.opts.messages !== false) {
  3390. out += ' , message: \'property name \\\'' + ($invalidName) + '\\\' is invalid\' ';
  3391. }
  3392. if (it.opts.verbose) {
  3393. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3394. }
  3395. out += ' } ';
  3396. } else {
  3397. out += ' {} ';
  3398. }
  3399. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3400. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3401. if (it.async) {
  3402. out += ' throw new ValidationError(vErrors); ';
  3403. } else {
  3404. out += ' validate.errors = vErrors; return false; ';
  3405. }
  3406. }
  3407. if ($breakOnError) {
  3408. out += ' break; ';
  3409. }
  3410. out += ' } }';
  3411. }
  3412. if ($breakOnError) {
  3413. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  3414. }
  3415. out = it.util.cleanUpCode(out);
  3416. return out;
  3417. }
  3418. },{}],32:[function(require,module,exports){
  3419. 'use strict';
  3420. module.exports = function generate_ref(it, $keyword, $ruleType) {
  3421. var out = ' ';
  3422. var $lvl = it.level;
  3423. var $dataLvl = it.dataLevel;
  3424. var $schema = it.schema[$keyword];
  3425. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3426. var $breakOnError = !it.opts.allErrors;
  3427. var $data = 'data' + ($dataLvl || '');
  3428. var $valid = 'valid' + $lvl;
  3429. var $async, $refCode;
  3430. if ($schema == '#' || $schema == '#/') {
  3431. if (it.isRoot) {
  3432. $async = it.async;
  3433. $refCode = 'validate';
  3434. } else {
  3435. $async = it.root.schema.$async === true;
  3436. $refCode = 'root.refVal[0]';
  3437. }
  3438. } else {
  3439. var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
  3440. if ($refVal === undefined) {
  3441. var $message = it.MissingRefError.message(it.baseId, $schema);
  3442. if (it.opts.missingRefs == 'fail') {
  3443. console.error($message);
  3444. var $$outStack = $$outStack || [];
  3445. $$outStack.push(out);
  3446. out = ''; /* istanbul ignore else */
  3447. if (it.createErrors !== false) {
  3448. out += ' { keyword: \'' + ('$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } ';
  3449. if (it.opts.messages !== false) {
  3450. out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
  3451. }
  3452. if (it.opts.verbose) {
  3453. out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3454. }
  3455. out += ' } ';
  3456. } else {
  3457. out += ' {} ';
  3458. }
  3459. var __err = out;
  3460. out = $$outStack.pop();
  3461. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3462. if (it.async) {
  3463. out += ' throw new ValidationError([' + (__err) + ']); ';
  3464. } else {
  3465. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3466. }
  3467. } else {
  3468. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3469. }
  3470. if ($breakOnError) {
  3471. out += ' if (false) { ';
  3472. }
  3473. } else if (it.opts.missingRefs == 'ignore') {
  3474. console.warn($message);
  3475. if ($breakOnError) {
  3476. out += ' if (true) { ';
  3477. }
  3478. } else {
  3479. throw new it.MissingRefError(it.baseId, $schema, $message);
  3480. }
  3481. } else if ($refVal.inline) {
  3482. var $it = it.util.copy(it);
  3483. $it.level++;
  3484. var $nextValid = 'valid' + $it.level;
  3485. $it.schema = $refVal.schema;
  3486. $it.schemaPath = '';
  3487. $it.errSchemaPath = $schema;
  3488. var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code);
  3489. out += ' ' + ($code) + ' ';
  3490. if ($breakOnError) {
  3491. out += ' if (' + ($nextValid) + ') { ';
  3492. }
  3493. } else {
  3494. $async = $refVal.$async === true;
  3495. $refCode = $refVal.code;
  3496. }
  3497. }
  3498. if ($refCode) {
  3499. var $$outStack = $$outStack || [];
  3500. $$outStack.push(out);
  3501. out = '';
  3502. if (it.opts.passContext) {
  3503. out += ' ' + ($refCode) + '.call(this, ';
  3504. } else {
  3505. out += ' ' + ($refCode) + '( ';
  3506. }
  3507. out += ' ' + ($data) + ', (dataPath || \'\')';
  3508. if (it.errorPath != '""') {
  3509. out += ' + ' + (it.errorPath);
  3510. }
  3511. var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
  3512. $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
  3513. out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ', rootData) ';
  3514. var __callValidate = out;
  3515. out = $$outStack.pop();
  3516. if ($async) {
  3517. if (!it.async) throw new Error('async schema referenced by sync schema');
  3518. if ($breakOnError) {
  3519. out += ' var ' + ($valid) + '; ';
  3520. }
  3521. out += ' try { ' + (it.yieldAwait) + ' ' + (__callValidate) + '; ';
  3522. if ($breakOnError) {
  3523. out += ' ' + ($valid) + ' = true; ';
  3524. }
  3525. out += ' } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ';
  3526. if ($breakOnError) {
  3527. out += ' ' + ($valid) + ' = false; ';
  3528. }
  3529. out += ' } ';
  3530. if ($breakOnError) {
  3531. out += ' if (' + ($valid) + ') { ';
  3532. }
  3533. } else {
  3534. out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
  3535. if ($breakOnError) {
  3536. out += ' else { ';
  3537. }
  3538. }
  3539. }
  3540. return out;
  3541. }
  3542. },{}],33:[function(require,module,exports){
  3543. 'use strict';
  3544. module.exports = function generate_required(it, $keyword, $ruleType) {
  3545. var out = ' ';
  3546. var $lvl = it.level;
  3547. var $dataLvl = it.dataLevel;
  3548. var $schema = it.schema[$keyword];
  3549. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  3550. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3551. var $breakOnError = !it.opts.allErrors;
  3552. var $data = 'data' + ($dataLvl || '');
  3553. var $valid = 'valid' + $lvl;
  3554. var $isData = it.opts.$data && $schema && $schema.$data,
  3555. $schemaValue;
  3556. if ($isData) {
  3557. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  3558. $schemaValue = 'schema' + $lvl;
  3559. } else {
  3560. $schemaValue = $schema;
  3561. }
  3562. var $vSchema = 'schema' + $lvl;
  3563. if (!$isData) {
  3564. if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
  3565. var $required = [];
  3566. var arr1 = $schema;
  3567. if (arr1) {
  3568. var $property, i1 = -1,
  3569. l1 = arr1.length - 1;
  3570. while (i1 < l1) {
  3571. $property = arr1[i1 += 1];
  3572. var $propertySch = it.schema.properties[$property];
  3573. if (!($propertySch && it.util.schemaHasRules($propertySch, it.RULES.all))) {
  3574. $required[$required.length] = $property;
  3575. }
  3576. }
  3577. }
  3578. } else {
  3579. var $required = $schema;
  3580. }
  3581. }
  3582. if ($isData || $required.length) {
  3583. var $currentErrorPath = it.errorPath,
  3584. $loopRequired = $isData || $required.length >= it.opts.loopRequired,
  3585. $ownProperties = it.opts.ownProperties;
  3586. if ($breakOnError) {
  3587. out += ' var missing' + ($lvl) + '; ';
  3588. if ($loopRequired) {
  3589. if (!$isData) {
  3590. out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
  3591. }
  3592. var $i = 'i' + $lvl,
  3593. $propertyPath = 'schema' + $lvl + '[' + $i + ']',
  3594. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  3595. if (it.opts._errorDataPathProperty) {
  3596. it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
  3597. }
  3598. out += ' var ' + ($valid) + ' = true; ';
  3599. if ($isData) {
  3600. out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
  3601. }
  3602. out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] !== undefined ';
  3603. if ($ownProperties) {
  3604. out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
  3605. }
  3606. out += '; if (!' + ($valid) + ') break; } ';
  3607. if ($isData) {
  3608. out += ' } ';
  3609. }
  3610. out += ' if (!' + ($valid) + ') { ';
  3611. var $$outStack = $$outStack || [];
  3612. $$outStack.push(out);
  3613. out = ''; /* istanbul ignore else */
  3614. if (it.createErrors !== false) {
  3615. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3616. if (it.opts.messages !== false) {
  3617. out += ' , message: \'';
  3618. if (it.opts._errorDataPathProperty) {
  3619. out += 'is a required property';
  3620. } else {
  3621. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3622. }
  3623. out += '\' ';
  3624. }
  3625. if (it.opts.verbose) {
  3626. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3627. }
  3628. out += ' } ';
  3629. } else {
  3630. out += ' {} ';
  3631. }
  3632. var __err = out;
  3633. out = $$outStack.pop();
  3634. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3635. if (it.async) {
  3636. out += ' throw new ValidationError([' + (__err) + ']); ';
  3637. } else {
  3638. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3639. }
  3640. } else {
  3641. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3642. }
  3643. out += ' } else { ';
  3644. } else {
  3645. out += ' if ( ';
  3646. var arr2 = $required;
  3647. if (arr2) {
  3648. var $propertyKey, $i = -1,
  3649. l2 = arr2.length - 1;
  3650. while ($i < l2) {
  3651. $propertyKey = arr2[$i += 1];
  3652. if ($i) {
  3653. out += ' || ';
  3654. }
  3655. var $prop = it.util.getProperty($propertyKey),
  3656. $useData = $data + $prop;
  3657. out += ' ( ( ' + ($useData) + ' === undefined ';
  3658. if ($ownProperties) {
  3659. out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
  3660. }
  3661. out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
  3662. }
  3663. }
  3664. out += ') { ';
  3665. var $propertyPath = 'missing' + $lvl,
  3666. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  3667. if (it.opts._errorDataPathProperty) {
  3668. it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
  3669. }
  3670. var $$outStack = $$outStack || [];
  3671. $$outStack.push(out);
  3672. out = ''; /* istanbul ignore else */
  3673. if (it.createErrors !== false) {
  3674. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3675. if (it.opts.messages !== false) {
  3676. out += ' , message: \'';
  3677. if (it.opts._errorDataPathProperty) {
  3678. out += 'is a required property';
  3679. } else {
  3680. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3681. }
  3682. out += '\' ';
  3683. }
  3684. if (it.opts.verbose) {
  3685. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3686. }
  3687. out += ' } ';
  3688. } else {
  3689. out += ' {} ';
  3690. }
  3691. var __err = out;
  3692. out = $$outStack.pop();
  3693. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3694. if (it.async) {
  3695. out += ' throw new ValidationError([' + (__err) + ']); ';
  3696. } else {
  3697. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3698. }
  3699. } else {
  3700. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3701. }
  3702. out += ' } else { ';
  3703. }
  3704. } else {
  3705. if ($loopRequired) {
  3706. if (!$isData) {
  3707. out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
  3708. }
  3709. var $i = 'i' + $lvl,
  3710. $propertyPath = 'schema' + $lvl + '[' + $i + ']',
  3711. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  3712. if (it.opts._errorDataPathProperty) {
  3713. it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
  3714. }
  3715. if ($isData) {
  3716. out += ' if (' + ($vSchema) + ' && !Array.isArray(' + ($vSchema) + ')) { var err = '; /* istanbul ignore else */
  3717. if (it.createErrors !== false) {
  3718. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3719. if (it.opts.messages !== false) {
  3720. out += ' , message: \'';
  3721. if (it.opts._errorDataPathProperty) {
  3722. out += 'is a required property';
  3723. } else {
  3724. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3725. }
  3726. out += '\' ';
  3727. }
  3728. if (it.opts.verbose) {
  3729. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3730. }
  3731. out += ' } ';
  3732. } else {
  3733. out += ' {} ';
  3734. }
  3735. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (' + ($vSchema) + ' !== undefined) { ';
  3736. }
  3737. out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { if (' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] === undefined ';
  3738. if ($ownProperties) {
  3739. out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
  3740. }
  3741. out += ') { var err = '; /* istanbul ignore else */
  3742. if (it.createErrors !== false) {
  3743. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3744. if (it.opts.messages !== false) {
  3745. out += ' , message: \'';
  3746. if (it.opts._errorDataPathProperty) {
  3747. out += 'is a required property';
  3748. } else {
  3749. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3750. }
  3751. out += '\' ';
  3752. }
  3753. if (it.opts.verbose) {
  3754. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3755. }
  3756. out += ' } ';
  3757. } else {
  3758. out += ' {} ';
  3759. }
  3760. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
  3761. if ($isData) {
  3762. out += ' } ';
  3763. }
  3764. } else {
  3765. var arr3 = $required;
  3766. if (arr3) {
  3767. var $propertyKey, i3 = -1,
  3768. l3 = arr3.length - 1;
  3769. while (i3 < l3) {
  3770. $propertyKey = arr3[i3 += 1];
  3771. var $prop = it.util.getProperty($propertyKey),
  3772. $missingProperty = it.util.escapeQuotes($propertyKey),
  3773. $useData = $data + $prop;
  3774. if (it.opts._errorDataPathProperty) {
  3775. it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
  3776. }
  3777. out += ' if ( ' + ($useData) + ' === undefined ';
  3778. if ($ownProperties) {
  3779. out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
  3780. }
  3781. out += ') { var err = '; /* istanbul ignore else */
  3782. if (it.createErrors !== false) {
  3783. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3784. if (it.opts.messages !== false) {
  3785. out += ' , message: \'';
  3786. if (it.opts._errorDataPathProperty) {
  3787. out += 'is a required property';
  3788. } else {
  3789. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3790. }
  3791. out += '\' ';
  3792. }
  3793. if (it.opts.verbose) {
  3794. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3795. }
  3796. out += ' } ';
  3797. } else {
  3798. out += ' {} ';
  3799. }
  3800. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
  3801. }
  3802. }
  3803. }
  3804. }
  3805. it.errorPath = $currentErrorPath;
  3806. } else if ($breakOnError) {
  3807. out += ' if (true) {';
  3808. }
  3809. return out;
  3810. }
  3811. },{}],34:[function(require,module,exports){
  3812. 'use strict';
  3813. module.exports = function generate_uniqueItems(it, $keyword, $ruleType) {
  3814. var out = ' ';
  3815. var $lvl = it.level;
  3816. var $dataLvl = it.dataLevel;
  3817. var $schema = it.schema[$keyword];
  3818. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  3819. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3820. var $breakOnError = !it.opts.allErrors;
  3821. var $data = 'data' + ($dataLvl || '');
  3822. var $valid = 'valid' + $lvl;
  3823. var $isData = it.opts.$data && $schema && $schema.$data,
  3824. $schemaValue;
  3825. if ($isData) {
  3826. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  3827. $schemaValue = 'schema' + $lvl;
  3828. } else {
  3829. $schemaValue = $schema;
  3830. }
  3831. if (($schema || $isData) && it.opts.uniqueItems !== false) {
  3832. if ($isData) {
  3833. out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
  3834. }
  3835. out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } ';
  3836. if ($isData) {
  3837. out += ' } ';
  3838. }
  3839. out += ' if (!' + ($valid) + ') { ';
  3840. var $$outStack = $$outStack || [];
  3841. $$outStack.push(out);
  3842. out = ''; /* istanbul ignore else */
  3843. if (it.createErrors !== false) {
  3844. out += ' { keyword: \'' + ('uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { i: i, j: j } ';
  3845. if (it.opts.messages !== false) {
  3846. out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
  3847. }
  3848. if (it.opts.verbose) {
  3849. out += ' , schema: ';
  3850. if ($isData) {
  3851. out += 'validate.schema' + ($schemaPath);
  3852. } else {
  3853. out += '' + ($schema);
  3854. }
  3855. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3856. }
  3857. out += ' } ';
  3858. } else {
  3859. out += ' {} ';
  3860. }
  3861. var __err = out;
  3862. out = $$outStack.pop();
  3863. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3864. if (it.async) {
  3865. out += ' throw new ValidationError([' + (__err) + ']); ';
  3866. } else {
  3867. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3868. }
  3869. } else {
  3870. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3871. }
  3872. out += ' } ';
  3873. if ($breakOnError) {
  3874. out += ' else { ';
  3875. }
  3876. } else {
  3877. if ($breakOnError) {
  3878. out += ' if (true) { ';
  3879. }
  3880. }
  3881. return out;
  3882. }
  3883. },{}],35:[function(require,module,exports){
  3884. 'use strict';
  3885. module.exports = function generate_validate(it, $keyword, $ruleType) {
  3886. var out = '';
  3887. var $async = it.schema.$async === true,
  3888. $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'),
  3889. $id = it.self._getId(it.schema);
  3890. if (it.isTop) {
  3891. if ($async) {
  3892. it.async = true;
  3893. var $es7 = it.opts.async == 'es7';
  3894. it.yieldAwait = $es7 ? 'await' : 'yield';
  3895. }
  3896. out += ' var validate = ';
  3897. if ($async) {
  3898. if ($es7) {
  3899. out += ' (async function ';
  3900. } else {
  3901. if (it.opts.async != '*') {
  3902. out += 'co.wrap';
  3903. }
  3904. out += '(function* ';
  3905. }
  3906. } else {
  3907. out += ' (function ';
  3908. }
  3909. out += ' (data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; ';
  3910. if ($id && (it.opts.sourceCode || it.opts.processCode)) {
  3911. out += ' ' + ('/\*# sourceURL=' + $id + ' */') + ' ';
  3912. }
  3913. }
  3914. if (typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref)) {
  3915. var $keyword = 'false schema';
  3916. var $lvl = it.level;
  3917. var $dataLvl = it.dataLevel;
  3918. var $schema = it.schema[$keyword];
  3919. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  3920. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3921. var $breakOnError = !it.opts.allErrors;
  3922. var $errorKeyword;
  3923. var $data = 'data' + ($dataLvl || '');
  3924. var $valid = 'valid' + $lvl;
  3925. if (it.schema === false) {
  3926. if (it.isTop) {
  3927. $breakOnError = true;
  3928. } else {
  3929. out += ' var ' + ($valid) + ' = false; ';
  3930. }
  3931. var $$outStack = $$outStack || [];
  3932. $$outStack.push(out);
  3933. out = ''; /* istanbul ignore else */
  3934. if (it.createErrors !== false) {
  3935. out += ' { keyword: \'' + ($errorKeyword || 'false schema') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  3936. if (it.opts.messages !== false) {
  3937. out += ' , message: \'boolean schema is false\' ';
  3938. }
  3939. if (it.opts.verbose) {
  3940. out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3941. }
  3942. out += ' } ';
  3943. } else {
  3944. out += ' {} ';
  3945. }
  3946. var __err = out;
  3947. out = $$outStack.pop();
  3948. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3949. if (it.async) {
  3950. out += ' throw new ValidationError([' + (__err) + ']); ';
  3951. } else {
  3952. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3953. }
  3954. } else {
  3955. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3956. }
  3957. } else {
  3958. if (it.isTop) {
  3959. if ($async) {
  3960. out += ' return data; ';
  3961. } else {
  3962. out += ' validate.errors = null; return true; ';
  3963. }
  3964. } else {
  3965. out += ' var ' + ($valid) + ' = true; ';
  3966. }
  3967. }
  3968. if (it.isTop) {
  3969. out += ' }); return validate; ';
  3970. }
  3971. return out;
  3972. }
  3973. if (it.isTop) {
  3974. var $top = it.isTop,
  3975. $lvl = it.level = 0,
  3976. $dataLvl = it.dataLevel = 0,
  3977. $data = 'data';
  3978. it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema));
  3979. it.baseId = it.baseId || it.rootId;
  3980. delete it.isTop;
  3981. it.dataPathArr = [undefined];
  3982. out += ' var vErrors = null; ';
  3983. out += ' var errors = 0; ';
  3984. out += ' if (rootData === undefined) rootData = data; ';
  3985. } else {
  3986. var $lvl = it.level,
  3987. $dataLvl = it.dataLevel,
  3988. $data = 'data' + ($dataLvl || '');
  3989. if ($id) it.baseId = it.resolve.url(it.baseId, $id);
  3990. if ($async && !it.async) throw new Error('async schema in sync schema');
  3991. out += ' var errs_' + ($lvl) + ' = errors;';
  3992. }
  3993. var $valid = 'valid' + $lvl,
  3994. $breakOnError = !it.opts.allErrors,
  3995. $closingBraces1 = '',
  3996. $closingBraces2 = '';
  3997. var $errorKeyword;
  3998. var $typeSchema = it.schema.type,
  3999. $typeIsArray = Array.isArray($typeSchema);
  4000. if ($typeIsArray && $typeSchema.length == 1) {
  4001. $typeSchema = $typeSchema[0];
  4002. $typeIsArray = false;
  4003. }
  4004. if (it.schema.$ref && $refKeywords) {
  4005. if (it.opts.extendRefs == 'fail') {
  4006. throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)');
  4007. } else if (it.opts.extendRefs !== true) {
  4008. $refKeywords = false;
  4009. console.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
  4010. }
  4011. }
  4012. if ($typeSchema) {
  4013. if (it.opts.coerceTypes) {
  4014. var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema);
  4015. }
  4016. var $rulesGroup = it.RULES.types[$typeSchema];
  4017. if ($coerceToTypes || $typeIsArray || $rulesGroup === true || ($rulesGroup && !$shouldUseGroup($rulesGroup))) {
  4018. var $schemaPath = it.schemaPath + '.type',
  4019. $errSchemaPath = it.errSchemaPath + '/type';
  4020. var $schemaPath = it.schemaPath + '.type',
  4021. $errSchemaPath = it.errSchemaPath + '/type',
  4022. $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
  4023. out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
  4024. if ($coerceToTypes) {
  4025. var $dataType = 'dataType' + $lvl,
  4026. $coerced = 'coerced' + $lvl;
  4027. out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; ';
  4028. if (it.opts.coerceTypes == 'array') {
  4029. out += ' if (' + ($dataType) + ' == \'object\' && Array.isArray(' + ($data) + ')) ' + ($dataType) + ' = \'array\'; ';
  4030. }
  4031. out += ' var ' + ($coerced) + ' = undefined; ';
  4032. var $bracesCoercion = '';
  4033. var arr1 = $coerceToTypes;
  4034. if (arr1) {
  4035. var $type, $i = -1,
  4036. l1 = arr1.length - 1;
  4037. while ($i < l1) {
  4038. $type = arr1[$i += 1];
  4039. if ($i) {
  4040. out += ' if (' + ($coerced) + ' === undefined) { ';
  4041. $bracesCoercion += '}';
  4042. }
  4043. if (it.opts.coerceTypes == 'array' && $type != 'array') {
  4044. out += ' if (' + ($dataType) + ' == \'array\' && ' + ($data) + '.length == 1) { ' + ($coerced) + ' = ' + ($data) + ' = ' + ($data) + '[0]; ' + ($dataType) + ' = typeof ' + ($data) + '; } ';
  4045. }
  4046. if ($type == 'string') {
  4047. out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
  4048. } else if ($type == 'number' || $type == 'integer') {
  4049. out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
  4050. if ($type == 'integer') {
  4051. out += ' && !(' + ($data) + ' % 1)';
  4052. }
  4053. out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
  4054. } else if ($type == 'boolean') {
  4055. out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
  4056. } else if ($type == 'null') {
  4057. out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
  4058. } else if (it.opts.coerceTypes == 'array' && $type == 'array') {
  4059. out += ' if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; ';
  4060. }
  4061. }
  4062. }
  4063. out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { ';
  4064. var $$outStack = $$outStack || [];
  4065. $$outStack.push(out);
  4066. out = ''; /* istanbul ignore else */
  4067. if (it.createErrors !== false) {
  4068. out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
  4069. if ($typeIsArray) {
  4070. out += '' + ($typeSchema.join(","));
  4071. } else {
  4072. out += '' + ($typeSchema);
  4073. }
  4074. out += '\' } ';
  4075. if (it.opts.messages !== false) {
  4076. out += ' , message: \'should be ';
  4077. if ($typeIsArray) {
  4078. out += '' + ($typeSchema.join(","));
  4079. } else {
  4080. out += '' + ($typeSchema);
  4081. }
  4082. out += '\' ';
  4083. }
  4084. if (it.opts.verbose) {
  4085. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4086. }
  4087. out += ' } ';
  4088. } else {
  4089. out += ' {} ';
  4090. }
  4091. var __err = out;
  4092. out = $$outStack.pop();
  4093. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4094. if (it.async) {
  4095. out += ' throw new ValidationError([' + (__err) + ']); ';
  4096. } else {
  4097. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4098. }
  4099. } else {
  4100. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4101. }
  4102. out += ' } else { ';
  4103. var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
  4104. $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
  4105. out += ' ' + ($data) + ' = ' + ($coerced) + '; ';
  4106. if (!$dataLvl) {
  4107. out += 'if (' + ($parentData) + ' !== undefined)';
  4108. }
  4109. out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } ';
  4110. } else {
  4111. var $$outStack = $$outStack || [];
  4112. $$outStack.push(out);
  4113. out = ''; /* istanbul ignore else */
  4114. if (it.createErrors !== false) {
  4115. out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
  4116. if ($typeIsArray) {
  4117. out += '' + ($typeSchema.join(","));
  4118. } else {
  4119. out += '' + ($typeSchema);
  4120. }
  4121. out += '\' } ';
  4122. if (it.opts.messages !== false) {
  4123. out += ' , message: \'should be ';
  4124. if ($typeIsArray) {
  4125. out += '' + ($typeSchema.join(","));
  4126. } else {
  4127. out += '' + ($typeSchema);
  4128. }
  4129. out += '\' ';
  4130. }
  4131. if (it.opts.verbose) {
  4132. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4133. }
  4134. out += ' } ';
  4135. } else {
  4136. out += ' {} ';
  4137. }
  4138. var __err = out;
  4139. out = $$outStack.pop();
  4140. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4141. if (it.async) {
  4142. out += ' throw new ValidationError([' + (__err) + ']); ';
  4143. } else {
  4144. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4145. }
  4146. } else {
  4147. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4148. }
  4149. }
  4150. out += ' } ';
  4151. }
  4152. }
  4153. if (it.schema.$ref && !$refKeywords) {
  4154. out += ' ' + (it.RULES.all.$ref.code(it, '$ref')) + ' ';
  4155. if ($breakOnError) {
  4156. out += ' } if (errors === ';
  4157. if ($top) {
  4158. out += '0';
  4159. } else {
  4160. out += 'errs_' + ($lvl);
  4161. }
  4162. out += ') { ';
  4163. $closingBraces2 += '}';
  4164. }
  4165. } else {
  4166. if (it.opts.v5 && it.schema.patternGroups) {
  4167. console.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.');
  4168. }
  4169. var arr2 = it.RULES;
  4170. if (arr2) {
  4171. var $rulesGroup, i2 = -1,
  4172. l2 = arr2.length - 1;
  4173. while (i2 < l2) {
  4174. $rulesGroup = arr2[i2 += 1];
  4175. if ($shouldUseGroup($rulesGroup)) {
  4176. if ($rulesGroup.type) {
  4177. out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { ';
  4178. }
  4179. if (it.opts.useDefaults && !it.compositeRule) {
  4180. if ($rulesGroup.type == 'object' && it.schema.properties) {
  4181. var $schema = it.schema.properties,
  4182. $schemaKeys = Object.keys($schema);
  4183. var arr3 = $schemaKeys;
  4184. if (arr3) {
  4185. var $propertyKey, i3 = -1,
  4186. l3 = arr3.length - 1;
  4187. while (i3 < l3) {
  4188. $propertyKey = arr3[i3 += 1];
  4189. var $sch = $schema[$propertyKey];
  4190. if ($sch.default !== undefined) {
  4191. var $passData = $data + it.util.getProperty($propertyKey);
  4192. out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = ';
  4193. if (it.opts.useDefaults == 'shared') {
  4194. out += ' ' + (it.useDefault($sch.default)) + ' ';
  4195. } else {
  4196. out += ' ' + (JSON.stringify($sch.default)) + ' ';
  4197. }
  4198. out += '; ';
  4199. }
  4200. }
  4201. }
  4202. } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
  4203. var arr4 = it.schema.items;
  4204. if (arr4) {
  4205. var $sch, $i = -1,
  4206. l4 = arr4.length - 1;
  4207. while ($i < l4) {
  4208. $sch = arr4[$i += 1];
  4209. if ($sch.default !== undefined) {
  4210. var $passData = $data + '[' + $i + ']';
  4211. out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = ';
  4212. if (it.opts.useDefaults == 'shared') {
  4213. out += ' ' + (it.useDefault($sch.default)) + ' ';
  4214. } else {
  4215. out += ' ' + (JSON.stringify($sch.default)) + ' ';
  4216. }
  4217. out += '; ';
  4218. }
  4219. }
  4220. }
  4221. }
  4222. }
  4223. var arr5 = $rulesGroup.rules;
  4224. if (arr5) {
  4225. var $rule, i5 = -1,
  4226. l5 = arr5.length - 1;
  4227. while (i5 < l5) {
  4228. $rule = arr5[i5 += 1];
  4229. if ($shouldUseRule($rule)) {
  4230. var $code = $rule.code(it, $rule.keyword, $rulesGroup.type);
  4231. if ($code) {
  4232. out += ' ' + ($code) + ' ';
  4233. if ($breakOnError) {
  4234. $closingBraces1 += '}';
  4235. }
  4236. }
  4237. }
  4238. }
  4239. }
  4240. if ($breakOnError) {
  4241. out += ' ' + ($closingBraces1) + ' ';
  4242. $closingBraces1 = '';
  4243. }
  4244. if ($rulesGroup.type) {
  4245. out += ' } ';
  4246. if ($typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes) {
  4247. out += ' else { ';
  4248. var $schemaPath = it.schemaPath + '.type',
  4249. $errSchemaPath = it.errSchemaPath + '/type';
  4250. var $$outStack = $$outStack || [];
  4251. $$outStack.push(out);
  4252. out = ''; /* istanbul ignore else */
  4253. if (it.createErrors !== false) {
  4254. out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
  4255. if ($typeIsArray) {
  4256. out += '' + ($typeSchema.join(","));
  4257. } else {
  4258. out += '' + ($typeSchema);
  4259. }
  4260. out += '\' } ';
  4261. if (it.opts.messages !== false) {
  4262. out += ' , message: \'should be ';
  4263. if ($typeIsArray) {
  4264. out += '' + ($typeSchema.join(","));
  4265. } else {
  4266. out += '' + ($typeSchema);
  4267. }
  4268. out += '\' ';
  4269. }
  4270. if (it.opts.verbose) {
  4271. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4272. }
  4273. out += ' } ';
  4274. } else {
  4275. out += ' {} ';
  4276. }
  4277. var __err = out;
  4278. out = $$outStack.pop();
  4279. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4280. if (it.async) {
  4281. out += ' throw new ValidationError([' + (__err) + ']); ';
  4282. } else {
  4283. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4284. }
  4285. } else {
  4286. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4287. }
  4288. out += ' } ';
  4289. }
  4290. }
  4291. if ($breakOnError) {
  4292. out += ' if (errors === ';
  4293. if ($top) {
  4294. out += '0';
  4295. } else {
  4296. out += 'errs_' + ($lvl);
  4297. }
  4298. out += ') { ';
  4299. $closingBraces2 += '}';
  4300. }
  4301. }
  4302. }
  4303. }
  4304. }
  4305. if ($breakOnError) {
  4306. out += ' ' + ($closingBraces2) + ' ';
  4307. }
  4308. if ($top) {
  4309. if ($async) {
  4310. out += ' if (errors === 0) return data; ';
  4311. out += ' else throw new ValidationError(vErrors); ';
  4312. } else {
  4313. out += ' validate.errors = vErrors; ';
  4314. out += ' return errors === 0; ';
  4315. }
  4316. out += ' }); return validate;';
  4317. } else {
  4318. out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
  4319. }
  4320. out = it.util.cleanUpCode(out);
  4321. if ($top) {
  4322. out = it.util.finalCleanUpCode(out, $async);
  4323. }
  4324. function $shouldUseGroup($rulesGroup) {
  4325. var rules = $rulesGroup.rules;
  4326. for (var i = 0; i < rules.length; i++)
  4327. if ($shouldUseRule(rules[i])) return true;
  4328. }
  4329. function $shouldUseRule($rule) {
  4330. return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImlementsSomeKeyword($rule));
  4331. }
  4332. function $ruleImlementsSomeKeyword($rule) {
  4333. var impl = $rule.implements;
  4334. for (var i = 0; i < impl.length; i++)
  4335. if (it.schema[impl[i]] !== undefined) return true;
  4336. }
  4337. return out;
  4338. }
  4339. },{}],36:[function(require,module,exports){
  4340. 'use strict';
  4341. var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
  4342. var customRuleCode = require('./dotjs/custom');
  4343. module.exports = {
  4344. add: addKeyword,
  4345. get: getKeyword,
  4346. remove: removeKeyword
  4347. };
  4348. /**
  4349. * Define custom keyword
  4350. * @this Ajv
  4351. * @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords).
  4352. * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
  4353. */
  4354. function addKeyword(keyword, definition) {
  4355. /* jshint validthis: true */
  4356. /* eslint no-shadow: 0 */
  4357. var RULES = this.RULES;
  4358. if (RULES.keywords[keyword])
  4359. throw new Error('Keyword ' + keyword + ' is already defined');
  4360. if (!IDENTIFIER.test(keyword))
  4361. throw new Error('Keyword ' + keyword + ' is not a valid identifier');
  4362. if (definition) {
  4363. if (definition.macro && definition.valid !== undefined)
  4364. throw new Error('"valid" option cannot be used with macro keywords');
  4365. var dataType = definition.type;
  4366. if (Array.isArray(dataType)) {
  4367. var i, len = dataType.length;
  4368. for (i=0; i<len; i++) checkDataType(dataType[i]);
  4369. for (i=0; i<len; i++) _addRule(keyword, dataType[i], definition);
  4370. } else {
  4371. if (dataType) checkDataType(dataType);
  4372. _addRule(keyword, dataType, definition);
  4373. }
  4374. var $data = definition.$data === true && this._opts.$data;
  4375. if ($data && !definition.validate)
  4376. throw new Error('$data support: "validate" function is not defined');
  4377. var metaSchema = definition.metaSchema;
  4378. if (metaSchema) {
  4379. if ($data) {
  4380. metaSchema = {
  4381. anyOf: [
  4382. metaSchema,
  4383. { '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#' }
  4384. ]
  4385. };
  4386. }
  4387. definition.validateSchema = this.compile(metaSchema, true);
  4388. }
  4389. }
  4390. RULES.keywords[keyword] = RULES.all[keyword] = true;
  4391. function _addRule(keyword, dataType, definition) {
  4392. var ruleGroup;
  4393. for (var i=0; i<RULES.length; i++) {
  4394. var rg = RULES[i];
  4395. if (rg.type == dataType) {
  4396. ruleGroup = rg;
  4397. break;
  4398. }
  4399. }
  4400. if (!ruleGroup) {
  4401. ruleGroup = { type: dataType, rules: [] };
  4402. RULES.push(ruleGroup);
  4403. }
  4404. var rule = {
  4405. keyword: keyword,
  4406. definition: definition,
  4407. custom: true,
  4408. code: customRuleCode,
  4409. implements: definition.implements
  4410. };
  4411. ruleGroup.rules.push(rule);
  4412. RULES.custom[keyword] = rule;
  4413. }
  4414. function checkDataType(dataType) {
  4415. if (!RULES.types[dataType]) throw new Error('Unknown type ' + dataType);
  4416. }
  4417. }
  4418. /**
  4419. * Get keyword
  4420. * @this Ajv
  4421. * @param {String} keyword pre-defined or custom keyword.
  4422. * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
  4423. */
  4424. function getKeyword(keyword) {
  4425. /* jshint validthis: true */
  4426. var rule = this.RULES.custom[keyword];
  4427. return rule ? rule.definition : this.RULES.keywords[keyword] || false;
  4428. }
  4429. /**
  4430. * Remove keyword
  4431. * @this Ajv
  4432. * @param {String} keyword pre-defined or custom keyword.
  4433. */
  4434. function removeKeyword(keyword) {
  4435. /* jshint validthis: true */
  4436. var RULES = this.RULES;
  4437. delete RULES.keywords[keyword];
  4438. delete RULES.all[keyword];
  4439. delete RULES.custom[keyword];
  4440. for (var i=0; i<RULES.length; i++) {
  4441. var rules = RULES[i].rules;
  4442. for (var j=0; j<rules.length; j++) {
  4443. if (rules[j].keyword == keyword) {
  4444. rules.splice(j, 1);
  4445. break;
  4446. }
  4447. }
  4448. }
  4449. }
  4450. },{"./dotjs/custom":21}],37:[function(require,module,exports){
  4451. 'use strict';
  4452. var META_SCHEMA_ID = 'http://json-schema.org/draft-06/schema';
  4453. module.exports = function (ajv) {
  4454. var defaultMeta = ajv._opts.defaultMeta;
  4455. var metaSchemaRef = typeof defaultMeta == 'string'
  4456. ? { $ref: defaultMeta }
  4457. : ajv.getSchema(META_SCHEMA_ID)
  4458. ? { $ref: META_SCHEMA_ID }
  4459. : {};
  4460. ajv.addKeyword('patternGroups', {
  4461. // implemented in properties.jst
  4462. metaSchema: {
  4463. type: 'object',
  4464. additionalProperties: {
  4465. type: 'object',
  4466. required: [ 'schema' ],
  4467. properties: {
  4468. maximum: {
  4469. type: 'integer',
  4470. minimum: 0
  4471. },
  4472. minimum: {
  4473. type: 'integer',
  4474. minimum: 0
  4475. },
  4476. schema: metaSchemaRef
  4477. },
  4478. additionalProperties: false
  4479. }
  4480. }
  4481. });
  4482. ajv.RULES.all.properties.implements.push('patternGroups');
  4483. };
  4484. },{}],38:[function(require,module,exports){
  4485. module.exports={
  4486. "$schema": "http://json-schema.org/draft-06/schema#",
  4487. "$id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#",
  4488. "description": "Meta-schema for $data reference (JSON-schema extension proposal)",
  4489. "type": "object",
  4490. "required": [ "$data" ],
  4491. "properties": {
  4492. "$data": {
  4493. "type": "string",
  4494. "anyOf": [
  4495. { "format": "relative-json-pointer" },
  4496. { "format": "json-pointer" }
  4497. ]
  4498. }
  4499. },
  4500. "additionalProperties": false
  4501. }
  4502. },{}],39:[function(require,module,exports){
  4503. module.exports={
  4504. "$schema": "http://json-schema.org/draft-06/schema#",
  4505. "$id": "http://json-schema.org/draft-06/schema#",
  4506. "title": "Core schema meta-schema",
  4507. "definitions": {
  4508. "schemaArray": {
  4509. "type": "array",
  4510. "minItems": 1,
  4511. "items": { "$ref": "#" }
  4512. },
  4513. "nonNegativeInteger": {
  4514. "type": "integer",
  4515. "minimum": 0
  4516. },
  4517. "nonNegativeIntegerDefault0": {
  4518. "allOf": [
  4519. { "$ref": "#/definitions/nonNegativeInteger" },
  4520. { "default": 0 }
  4521. ]
  4522. },
  4523. "simpleTypes": {
  4524. "enum": [
  4525. "array",
  4526. "boolean",
  4527. "integer",
  4528. "null",
  4529. "number",
  4530. "object",
  4531. "string"
  4532. ]
  4533. },
  4534. "stringArray": {
  4535. "type": "array",
  4536. "items": { "type": "string" },
  4537. "uniqueItems": true,
  4538. "default": []
  4539. }
  4540. },
  4541. "type": ["object", "boolean"],
  4542. "properties": {
  4543. "$id": {
  4544. "type": "string",
  4545. "format": "uri-reference"
  4546. },
  4547. "$schema": {
  4548. "type": "string",
  4549. "format": "uri"
  4550. },
  4551. "$ref": {
  4552. "type": "string",
  4553. "format": "uri-reference"
  4554. },
  4555. "title": {
  4556. "type": "string"
  4557. },
  4558. "description": {
  4559. "type": "string"
  4560. },
  4561. "default": {},
  4562. "multipleOf": {
  4563. "type": "number",
  4564. "exclusiveMinimum": 0
  4565. },
  4566. "maximum": {
  4567. "type": "number"
  4568. },
  4569. "exclusiveMaximum": {
  4570. "type": "number"
  4571. },
  4572. "minimum": {
  4573. "type": "number"
  4574. },
  4575. "exclusiveMinimum": {
  4576. "type": "number"
  4577. },
  4578. "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
  4579. "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
  4580. "pattern": {
  4581. "type": "string",
  4582. "format": "regex"
  4583. },
  4584. "additionalItems": { "$ref": "#" },
  4585. "items": {
  4586. "anyOf": [
  4587. { "$ref": "#" },
  4588. { "$ref": "#/definitions/schemaArray" }
  4589. ],
  4590. "default": {}
  4591. },
  4592. "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
  4593. "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
  4594. "uniqueItems": {
  4595. "type": "boolean",
  4596. "default": false
  4597. },
  4598. "contains": { "$ref": "#" },
  4599. "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
  4600. "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
  4601. "required": { "$ref": "#/definitions/stringArray" },
  4602. "additionalProperties": { "$ref": "#" },
  4603. "definitions": {
  4604. "type": "object",
  4605. "additionalProperties": { "$ref": "#" },
  4606. "default": {}
  4607. },
  4608. "properties": {
  4609. "type": "object",
  4610. "additionalProperties": { "$ref": "#" },
  4611. "default": {}
  4612. },
  4613. "patternProperties": {
  4614. "type": "object",
  4615. "additionalProperties": { "$ref": "#" },
  4616. "default": {}
  4617. },
  4618. "dependencies": {
  4619. "type": "object",
  4620. "additionalProperties": {
  4621. "anyOf": [
  4622. { "$ref": "#" },
  4623. { "$ref": "#/definitions/stringArray" }
  4624. ]
  4625. }
  4626. },
  4627. "propertyNames": { "$ref": "#" },
  4628. "const": {},
  4629. "enum": {
  4630. "type": "array",
  4631. "minItems": 1,
  4632. "uniqueItems": true
  4633. },
  4634. "type": {
  4635. "anyOf": [
  4636. { "$ref": "#/definitions/simpleTypes" },
  4637. {
  4638. "type": "array",
  4639. "items": { "$ref": "#/definitions/simpleTypes" },
  4640. "minItems": 1,
  4641. "uniqueItems": true
  4642. }
  4643. ]
  4644. },
  4645. "format": { "type": "string" },
  4646. "allOf": { "$ref": "#/definitions/schemaArray" },
  4647. "anyOf": { "$ref": "#/definitions/schemaArray" },
  4648. "oneOf": { "$ref": "#/definitions/schemaArray" },
  4649. "not": { "$ref": "#" }
  4650. },
  4651. "default": {}
  4652. }
  4653. },{}],40:[function(require,module,exports){
  4654. /**
  4655. * slice() reference.
  4656. */
  4657. var slice = Array.prototype.slice;
  4658. /**
  4659. * Expose `co`.
  4660. */
  4661. module.exports = co['default'] = co.co = co;
  4662. /**
  4663. * Wrap the given generator `fn` into a
  4664. * function that returns a promise.
  4665. * This is a separate function so that
  4666. * every `co()` call doesn't create a new,
  4667. * unnecessary closure.
  4668. *
  4669. * @param {GeneratorFunction} fn
  4670. * @return {Function}
  4671. * @api public
  4672. */
  4673. co.wrap = function (fn) {
  4674. createPromise.__generatorFunction__ = fn;
  4675. return createPromise;
  4676. function createPromise() {
  4677. return co.call(this, fn.apply(this, arguments));
  4678. }
  4679. };
  4680. /**
  4681. * Execute the generator function or a generator
  4682. * and return a promise.
  4683. *
  4684. * @param {Function} fn
  4685. * @return {Promise}
  4686. * @api public
  4687. */
  4688. function co(gen) {
  4689. var ctx = this;
  4690. var args = slice.call(arguments, 1)
  4691. // we wrap everything in a promise to avoid promise chaining,
  4692. // which leads to memory leak errors.
  4693. // see https://github.com/tj/co/issues/180
  4694. return new Promise(function(resolve, reject) {
  4695. if (typeof gen === 'function') gen = gen.apply(ctx, args);
  4696. if (!gen || typeof gen.next !== 'function') return resolve(gen);
  4697. onFulfilled();
  4698. /**
  4699. * @param {Mixed} res
  4700. * @return {Promise}
  4701. * @api private
  4702. */
  4703. function onFulfilled(res) {
  4704. var ret;
  4705. try {
  4706. ret = gen.next(res);
  4707. } catch (e) {
  4708. return reject(e);
  4709. }
  4710. next(ret);
  4711. }
  4712. /**
  4713. * @param {Error} err
  4714. * @return {Promise}
  4715. * @api private
  4716. */
  4717. function onRejected(err) {
  4718. var ret;
  4719. try {
  4720. ret = gen.throw(err);
  4721. } catch (e) {
  4722. return reject(e);
  4723. }
  4724. next(ret);
  4725. }
  4726. /**
  4727. * Get the next value in the generator,
  4728. * return a promise.
  4729. *
  4730. * @param {Object} ret
  4731. * @return {Promise}
  4732. * @api private
  4733. */
  4734. function next(ret) {
  4735. if (ret.done) return resolve(ret.value);
  4736. var value = toPromise.call(ctx, ret.value);
  4737. if (value && isPromise(value)) return value.then(onFulfilled, onRejected);
  4738. return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, '
  4739. + 'but the following object was passed: "' + String(ret.value) + '"'));
  4740. }
  4741. });
  4742. }
  4743. /**
  4744. * Convert a `yield`ed value into a promise.
  4745. *
  4746. * @param {Mixed} obj
  4747. * @return {Promise}
  4748. * @api private
  4749. */
  4750. function toPromise(obj) {
  4751. if (!obj) return obj;
  4752. if (isPromise(obj)) return obj;
  4753. if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj);
  4754. if ('function' == typeof obj) return thunkToPromise.call(this, obj);
  4755. if (Array.isArray(obj)) return arrayToPromise.call(this, obj);
  4756. if (isObject(obj)) return objectToPromise.call(this, obj);
  4757. return obj;
  4758. }
  4759. /**
  4760. * Convert a thunk to a promise.
  4761. *
  4762. * @param {Function}
  4763. * @return {Promise}
  4764. * @api private
  4765. */
  4766. function thunkToPromise(fn) {
  4767. var ctx = this;
  4768. return new Promise(function (resolve, reject) {
  4769. fn.call(ctx, function (err, res) {
  4770. if (err) return reject(err);
  4771. if (arguments.length > 2) res = slice.call(arguments, 1);
  4772. resolve(res);
  4773. });
  4774. });
  4775. }
  4776. /**
  4777. * Convert an array of "yieldables" to a promise.
  4778. * Uses `Promise.all()` internally.
  4779. *
  4780. * @param {Array} obj
  4781. * @return {Promise}
  4782. * @api private
  4783. */
  4784. function arrayToPromise(obj) {
  4785. return Promise.all(obj.map(toPromise, this));
  4786. }
  4787. /**
  4788. * Convert an object of "yieldables" to a promise.
  4789. * Uses `Promise.all()` internally.
  4790. *
  4791. * @param {Object} obj
  4792. * @return {Promise}
  4793. * @api private
  4794. */
  4795. function objectToPromise(obj){
  4796. var results = new obj.constructor();
  4797. var keys = Object.keys(obj);
  4798. var promises = [];
  4799. for (var i = 0; i < keys.length; i++) {
  4800. var key = keys[i];
  4801. var promise = toPromise.call(this, obj[key]);
  4802. if (promise && isPromise(promise)) defer(promise, key);
  4803. else results[key] = obj[key];
  4804. }
  4805. return Promise.all(promises).then(function () {
  4806. return results;
  4807. });
  4808. function defer(promise, key) {
  4809. // predefine the key in the result
  4810. results[key] = undefined;
  4811. promises.push(promise.then(function (res) {
  4812. results[key] = res;
  4813. }));
  4814. }
  4815. }
  4816. /**
  4817. * Check if `obj` is a promise.
  4818. *
  4819. * @param {Object} obj
  4820. * @return {Boolean}
  4821. * @api private
  4822. */
  4823. function isPromise(obj) {
  4824. return 'function' == typeof obj.then;
  4825. }
  4826. /**
  4827. * Check if `obj` is a generator.
  4828. *
  4829. * @param {Mixed} obj
  4830. * @return {Boolean}
  4831. * @api private
  4832. */
  4833. function isGenerator(obj) {
  4834. return 'function' == typeof obj.next && 'function' == typeof obj.throw;
  4835. }
  4836. /**
  4837. * Check if `obj` is a generator function.
  4838. *
  4839. * @param {Mixed} obj
  4840. * @return {Boolean}
  4841. * @api private
  4842. */
  4843. function isGeneratorFunction(obj) {
  4844. var constructor = obj.constructor;
  4845. if (!constructor) return false;
  4846. if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true;
  4847. return isGenerator(constructor.prototype);
  4848. }
  4849. /**
  4850. * Check for plain object.
  4851. *
  4852. * @param {Mixed} val
  4853. * @return {Boolean}
  4854. * @api private
  4855. */
  4856. function isObject(val) {
  4857. return Object == val.constructor;
  4858. }
  4859. },{}],41:[function(require,module,exports){
  4860. 'use strict';
  4861. module.exports = function equal(a, b) {
  4862. if (a === b) return true;
  4863. var arrA = Array.isArray(a)
  4864. , arrB = Array.isArray(b)
  4865. , i;
  4866. if (arrA && arrB) {
  4867. if (a.length != b.length) return false;
  4868. for (i = 0; i < a.length; i++)
  4869. if (!equal(a[i], b[i])) return false;
  4870. return true;
  4871. }
  4872. if (arrA != arrB) return false;
  4873. if (a && b && typeof a === 'object' && typeof b === 'object') {
  4874. var keys = Object.keys(a);
  4875. if (keys.length !== Object.keys(b).length) return false;
  4876. var dateA = a instanceof Date
  4877. , dateB = b instanceof Date;
  4878. if (dateA && dateB) return a.getTime() == b.getTime();
  4879. if (dateA != dateB) return false;
  4880. var regexpA = a instanceof RegExp
  4881. , regexpB = b instanceof RegExp;
  4882. if (regexpA && regexpB) return a.toString() == b.toString();
  4883. if (regexpA != regexpB) return false;
  4884. for (i = 0; i < keys.length; i++)
  4885. if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
  4886. for (i = 0; i < keys.length; i++)
  4887. if(!equal(a[keys[i]], b[keys[i]])) return false;
  4888. return true;
  4889. }
  4890. return false;
  4891. };
  4892. },{}],42:[function(require,module,exports){
  4893. 'use strict';
  4894. var traverse = module.exports = function (schema, opts, cb) {
  4895. if (typeof opts == 'function') {
  4896. cb = opts;
  4897. opts = {};
  4898. }
  4899. _traverse(opts, cb, schema, '', schema);
  4900. };
  4901. traverse.keywords = {
  4902. additionalItems: true,
  4903. items: true,
  4904. contains: true,
  4905. additionalProperties: true,
  4906. propertyNames: true,
  4907. not: true
  4908. };
  4909. traverse.arrayKeywords = {
  4910. items: true,
  4911. allOf: true,
  4912. anyOf: true,
  4913. oneOf: true
  4914. };
  4915. traverse.propsKeywords = {
  4916. definitions: true,
  4917. properties: true,
  4918. patternProperties: true,
  4919. dependencies: true
  4920. };
  4921. traverse.skipKeywords = {
  4922. enum: true,
  4923. const: true,
  4924. required: true,
  4925. maximum: true,
  4926. minimum: true,
  4927. exclusiveMaximum: true,
  4928. exclusiveMinimum: true,
  4929. multipleOf: true,
  4930. maxLength: true,
  4931. minLength: true,
  4932. pattern: true,
  4933. format: true,
  4934. maxItems: true,
  4935. minItems: true,
  4936. uniqueItems: true,
  4937. maxProperties: true,
  4938. minProperties: true
  4939. };
  4940. function _traverse(opts, cb, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
  4941. if (schema && typeof schema == 'object' && !Array.isArray(schema)) {
  4942. cb(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
  4943. for (var key in schema) {
  4944. var sch = schema[key];
  4945. if (Array.isArray(sch)) {
  4946. if (key in traverse.arrayKeywords) {
  4947. for (var i=0; i<sch.length; i++)
  4948. _traverse(opts, cb, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i);
  4949. }
  4950. } else if (key in traverse.propsKeywords) {
  4951. if (sch && typeof sch == 'object') {
  4952. for (var prop in sch)
  4953. _traverse(opts, cb, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
  4954. }
  4955. } else if (key in traverse.keywords || (opts.allKeys && !(key in traverse.skipKeywords))) {
  4956. _traverse(opts, cb, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema);
  4957. }
  4958. }
  4959. }
  4960. }
  4961. function escapeJsonPtr(str) {
  4962. return str.replace(/~/g, '~0').replace(/\//g, '~1');
  4963. }
  4964. },{}],43:[function(require,module,exports){
  4965. var json = typeof JSON !== 'undefined' ? JSON : require('jsonify');
  4966. module.exports = function (obj, opts) {
  4967. if (!opts) opts = {};
  4968. if (typeof opts === 'function') opts = { cmp: opts };
  4969. var space = opts.space || '';
  4970. if (typeof space === 'number') space = Array(space+1).join(' ');
  4971. var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
  4972. var replacer = opts.replacer || function(key, value) { return value; };
  4973. var cmp = opts.cmp && (function (f) {
  4974. return function (node) {
  4975. return function (a, b) {
  4976. var aobj = { key: a, value: node[a] };
  4977. var bobj = { key: b, value: node[b] };
  4978. return f(aobj, bobj);
  4979. };
  4980. };
  4981. })(opts.cmp);
  4982. var seen = [];
  4983. return (function stringify (parent, key, node, level) {
  4984. var indent = space ? ('\n' + new Array(level + 1).join(space)) : '';
  4985. var colonSeparator = space ? ': ' : ':';
  4986. if (node && node.toJSON && typeof node.toJSON === 'function') {
  4987. node = node.toJSON();
  4988. }
  4989. node = replacer.call(parent, key, node);
  4990. if (node === undefined) {
  4991. return;
  4992. }
  4993. if (typeof node !== 'object' || node === null) {
  4994. return json.stringify(node);
  4995. }
  4996. if (isArray(node)) {
  4997. var out = [];
  4998. for (var i = 0; i < node.length; i++) {
  4999. var item = stringify(node, i, node[i], level+1) || json.stringify(null);
  5000. out.push(indent + space + item);
  5001. }
  5002. return '[' + out.join(',') + indent + ']';
  5003. }
  5004. else {
  5005. if (seen.indexOf(node) !== -1) {
  5006. if (cycles) return json.stringify('__cycle__');
  5007. throw new TypeError('Converting circular structure to JSON');
  5008. }
  5009. else seen.push(node);
  5010. var keys = objectKeys(node).sort(cmp && cmp(node));
  5011. var out = [];
  5012. for (var i = 0; i < keys.length; i++) {
  5013. var key = keys[i];
  5014. var value = stringify(node, key, node[key], level+1);
  5015. if(!value) continue;
  5016. var keyValue = json.stringify(key)
  5017. + colonSeparator
  5018. + value;
  5019. ;
  5020. out.push(indent + space + keyValue);
  5021. }
  5022. seen.splice(seen.indexOf(node), 1);
  5023. return '{' + out.join(',') + indent + '}';
  5024. }
  5025. })({ '': obj }, '', obj, 0);
  5026. };
  5027. var isArray = Array.isArray || function (x) {
  5028. return {}.toString.call(x) === '[object Array]';
  5029. };
  5030. var objectKeys = Object.keys || function (obj) {
  5031. var has = Object.prototype.hasOwnProperty || function () { return true };
  5032. var keys = [];
  5033. for (var key in obj) {
  5034. if (has.call(obj, key)) keys.push(key);
  5035. }
  5036. return keys;
  5037. };
  5038. },{"jsonify":44}],44:[function(require,module,exports){
  5039. exports.parse = require('./lib/parse');
  5040. exports.stringify = require('./lib/stringify');
  5041. },{"./lib/parse":45,"./lib/stringify":46}],45:[function(require,module,exports){
  5042. var at, // The index of the current character
  5043. ch, // The current character
  5044. escapee = {
  5045. '"': '"',
  5046. '\\': '\\',
  5047. '/': '/',
  5048. b: '\b',
  5049. f: '\f',
  5050. n: '\n',
  5051. r: '\r',
  5052. t: '\t'
  5053. },
  5054. text,
  5055. error = function (m) {
  5056. // Call error when something is wrong.
  5057. throw {
  5058. name: 'SyntaxError',
  5059. message: m,
  5060. at: at,
  5061. text: text
  5062. };
  5063. },
  5064. next = function (c) {
  5065. // If a c parameter is provided, verify that it matches the current character.
  5066. if (c && c !== ch) {
  5067. error("Expected '" + c + "' instead of '" + ch + "'");
  5068. }
  5069. // Get the next character. When there are no more characters,
  5070. // return the empty string.
  5071. ch = text.charAt(at);
  5072. at += 1;
  5073. return ch;
  5074. },
  5075. number = function () {
  5076. // Parse a number value.
  5077. var number,
  5078. string = '';
  5079. if (ch === '-') {
  5080. string = '-';
  5081. next('-');
  5082. }
  5083. while (ch >= '0' && ch <= '9') {
  5084. string += ch;
  5085. next();
  5086. }
  5087. if (ch === '.') {
  5088. string += '.';
  5089. while (next() && ch >= '0' && ch <= '9') {
  5090. string += ch;
  5091. }
  5092. }
  5093. if (ch === 'e' || ch === 'E') {
  5094. string += ch;
  5095. next();
  5096. if (ch === '-' || ch === '+') {
  5097. string += ch;
  5098. next();
  5099. }
  5100. while (ch >= '0' && ch <= '9') {
  5101. string += ch;
  5102. next();
  5103. }
  5104. }
  5105. number = +string;
  5106. if (!isFinite(number)) {
  5107. error("Bad number");
  5108. } else {
  5109. return number;
  5110. }
  5111. },
  5112. string = function () {
  5113. // Parse a string value.
  5114. var hex,
  5115. i,
  5116. string = '',
  5117. uffff;
  5118. // When parsing for string values, we must look for " and \ characters.
  5119. if (ch === '"') {
  5120. while (next()) {
  5121. if (ch === '"') {
  5122. next();
  5123. return string;
  5124. } else if (ch === '\\') {
  5125. next();
  5126. if (ch === 'u') {
  5127. uffff = 0;
  5128. for (i = 0; i < 4; i += 1) {
  5129. hex = parseInt(next(), 16);
  5130. if (!isFinite(hex)) {
  5131. break;
  5132. }
  5133. uffff = uffff * 16 + hex;
  5134. }
  5135. string += String.fromCharCode(uffff);
  5136. } else if (typeof escapee[ch] === 'string') {
  5137. string += escapee[ch];
  5138. } else {
  5139. break;
  5140. }
  5141. } else {
  5142. string += ch;
  5143. }
  5144. }
  5145. }
  5146. error("Bad string");
  5147. },
  5148. white = function () {
  5149. // Skip whitespace.
  5150. while (ch && ch <= ' ') {
  5151. next();
  5152. }
  5153. },
  5154. word = function () {
  5155. // true, false, or null.
  5156. switch (ch) {
  5157. case 't':
  5158. next('t');
  5159. next('r');
  5160. next('u');
  5161. next('e');
  5162. return true;
  5163. case 'f':
  5164. next('f');
  5165. next('a');
  5166. next('l');
  5167. next('s');
  5168. next('e');
  5169. return false;
  5170. case 'n':
  5171. next('n');
  5172. next('u');
  5173. next('l');
  5174. next('l');
  5175. return null;
  5176. }
  5177. error("Unexpected '" + ch + "'");
  5178. },
  5179. value, // Place holder for the value function.
  5180. array = function () {
  5181. // Parse an array value.
  5182. var array = [];
  5183. if (ch === '[') {
  5184. next('[');
  5185. white();
  5186. if (ch === ']') {
  5187. next(']');
  5188. return array; // empty array
  5189. }
  5190. while (ch) {
  5191. array.push(value());
  5192. white();
  5193. if (ch === ']') {
  5194. next(']');
  5195. return array;
  5196. }
  5197. next(',');
  5198. white();
  5199. }
  5200. }
  5201. error("Bad array");
  5202. },
  5203. object = function () {
  5204. // Parse an object value.
  5205. var key,
  5206. object = {};
  5207. if (ch === '{') {
  5208. next('{');
  5209. white();
  5210. if (ch === '}') {
  5211. next('}');
  5212. return object; // empty object
  5213. }
  5214. while (ch) {
  5215. key = string();
  5216. white();
  5217. next(':');
  5218. if (Object.hasOwnProperty.call(object, key)) {
  5219. error('Duplicate key "' + key + '"');
  5220. }
  5221. object[key] = value();
  5222. white();
  5223. if (ch === '}') {
  5224. next('}');
  5225. return object;
  5226. }
  5227. next(',');
  5228. white();
  5229. }
  5230. }
  5231. error("Bad object");
  5232. };
  5233. value = function () {
  5234. // Parse a JSON value. It could be an object, an array, a string, a number,
  5235. // or a word.
  5236. white();
  5237. switch (ch) {
  5238. case '{':
  5239. return object();
  5240. case '[':
  5241. return array();
  5242. case '"':
  5243. return string();
  5244. case '-':
  5245. return number();
  5246. default:
  5247. return ch >= '0' && ch <= '9' ? number() : word();
  5248. }
  5249. };
  5250. // Return the json_parse function. It will have access to all of the above
  5251. // functions and variables.
  5252. module.exports = function (source, reviver) {
  5253. var result;
  5254. text = source;
  5255. at = 0;
  5256. ch = ' ';
  5257. result = value();
  5258. white();
  5259. if (ch) {
  5260. error("Syntax error");
  5261. }
  5262. // If there is a reviver function, we recursively walk the new structure,
  5263. // passing each name/value pair to the reviver function for possible
  5264. // transformation, starting with a temporary root object that holds the result
  5265. // in an empty key. If there is not a reviver function, we simply return the
  5266. // result.
  5267. return typeof reviver === 'function' ? (function walk(holder, key) {
  5268. var k, v, value = holder[key];
  5269. if (value && typeof value === 'object') {
  5270. for (k in value) {
  5271. if (Object.prototype.hasOwnProperty.call(value, k)) {
  5272. v = walk(value, k);
  5273. if (v !== undefined) {
  5274. value[k] = v;
  5275. } else {
  5276. delete value[k];
  5277. }
  5278. }
  5279. }
  5280. }
  5281. return reviver.call(holder, key, value);
  5282. }({'': result}, '')) : result;
  5283. };
  5284. },{}],46:[function(require,module,exports){
  5285. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  5286. escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  5287. gap,
  5288. indent,
  5289. meta = { // table of character substitutions
  5290. '\b': '\\b',
  5291. '\t': '\\t',
  5292. '\n': '\\n',
  5293. '\f': '\\f',
  5294. '\r': '\\r',
  5295. '"' : '\\"',
  5296. '\\': '\\\\'
  5297. },
  5298. rep;
  5299. function quote(string) {
  5300. // If the string contains no control characters, no quote characters, and no
  5301. // backslash characters, then we can safely slap some quotes around it.
  5302. // Otherwise we must also replace the offending characters with safe escape
  5303. // sequences.
  5304. escapable.lastIndex = 0;
  5305. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  5306. var c = meta[a];
  5307. return typeof c === 'string' ? c :
  5308. '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  5309. }) + '"' : '"' + string + '"';
  5310. }
  5311. function str(key, holder) {
  5312. // Produce a string from holder[key].
  5313. var i, // The loop counter.
  5314. k, // The member key.
  5315. v, // The member value.
  5316. length,
  5317. mind = gap,
  5318. partial,
  5319. value = holder[key];
  5320. // If the value has a toJSON method, call it to obtain a replacement value.
  5321. if (value && typeof value === 'object' &&
  5322. typeof value.toJSON === 'function') {
  5323. value = value.toJSON(key);
  5324. }
  5325. // If we were called with a replacer function, then call the replacer to
  5326. // obtain a replacement value.
  5327. if (typeof rep === 'function') {
  5328. value = rep.call(holder, key, value);
  5329. }
  5330. // What happens next depends on the value's type.
  5331. switch (typeof value) {
  5332. case 'string':
  5333. return quote(value);
  5334. case 'number':
  5335. // JSON numbers must be finite. Encode non-finite numbers as null.
  5336. return isFinite(value) ? String(value) : 'null';
  5337. case 'boolean':
  5338. case 'null':
  5339. // If the value is a boolean or null, convert it to a string. Note:
  5340. // typeof null does not produce 'null'. The case is included here in
  5341. // the remote chance that this gets fixed someday.
  5342. return String(value);
  5343. case 'object':
  5344. if (!value) return 'null';
  5345. gap += indent;
  5346. partial = [];
  5347. // Array.isArray
  5348. if (Object.prototype.toString.apply(value) === '[object Array]') {
  5349. length = value.length;
  5350. for (i = 0; i < length; i += 1) {
  5351. partial[i] = str(i, value) || 'null';
  5352. }
  5353. // Join all of the elements together, separated with commas, and
  5354. // wrap them in brackets.
  5355. v = partial.length === 0 ? '[]' : gap ?
  5356. '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
  5357. '[' + partial.join(',') + ']';
  5358. gap = mind;
  5359. return v;
  5360. }
  5361. // If the replacer is an array, use it to select the members to be
  5362. // stringified.
  5363. if (rep && typeof rep === 'object') {
  5364. length = rep.length;
  5365. for (i = 0; i < length; i += 1) {
  5366. k = rep[i];
  5367. if (typeof k === 'string') {
  5368. v = str(k, value);
  5369. if (v) {
  5370. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  5371. }
  5372. }
  5373. }
  5374. }
  5375. else {
  5376. // Otherwise, iterate through all of the keys in the object.
  5377. for (k in value) {
  5378. if (Object.prototype.hasOwnProperty.call(value, k)) {
  5379. v = str(k, value);
  5380. if (v) {
  5381. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  5382. }
  5383. }
  5384. }
  5385. }
  5386. // Join all of the member texts together, separated with commas,
  5387. // and wrap them in braces.
  5388. v = partial.length === 0 ? '{}' : gap ?
  5389. '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
  5390. '{' + partial.join(',') + '}';
  5391. gap = mind;
  5392. return v;
  5393. }
  5394. }
  5395. module.exports = function (value, replacer, space) {
  5396. var i;
  5397. gap = '';
  5398. indent = '';
  5399. // If the space parameter is a number, make an indent string containing that
  5400. // many spaces.
  5401. if (typeof space === 'number') {
  5402. for (i = 0; i < space; i += 1) {
  5403. indent += ' ';
  5404. }
  5405. }
  5406. // If the space parameter is a string, it will be used as the indent string.
  5407. else if (typeof space === 'string') {
  5408. indent = space;
  5409. }
  5410. // If there is a replacer, it must be a function or an array.
  5411. // Otherwise, throw an error.
  5412. rep = replacer;
  5413. if (replacer && typeof replacer !== 'function'
  5414. && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
  5415. throw new Error('JSON.stringify');
  5416. }
  5417. // Make a fake root object containing our value under the key of ''.
  5418. // Return the result of stringifying the value.
  5419. return str('', {'': value});
  5420. };
  5421. },{}],47:[function(require,module,exports){
  5422. (function (global){
  5423. /*! https://mths.be/punycode v1.4.1 by @mathias */
  5424. ;(function(root) {
  5425. /** Detect free variables */
  5426. var freeExports = typeof exports == 'object' && exports &&
  5427. !exports.nodeType && exports;
  5428. var freeModule = typeof module == 'object' && module &&
  5429. !module.nodeType && module;
  5430. var freeGlobal = typeof global == 'object' && global;
  5431. if (
  5432. freeGlobal.global === freeGlobal ||
  5433. freeGlobal.window === freeGlobal ||
  5434. freeGlobal.self === freeGlobal
  5435. ) {
  5436. root = freeGlobal;
  5437. }
  5438. /**
  5439. * The `punycode` object.
  5440. * @name punycode
  5441. * @type Object
  5442. */
  5443. var punycode,
  5444. /** Highest positive signed 32-bit float value */
  5445. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  5446. /** Bootstring parameters */
  5447. base = 36,
  5448. tMin = 1,
  5449. tMax = 26,
  5450. skew = 38,
  5451. damp = 700,
  5452. initialBias = 72,
  5453. initialN = 128, // 0x80
  5454. delimiter = '-', // '\x2D'
  5455. /** Regular expressions */
  5456. regexPunycode = /^xn--/,
  5457. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  5458. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  5459. /** Error messages */
  5460. errors = {
  5461. 'overflow': 'Overflow: input needs wider integers to process',
  5462. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  5463. 'invalid-input': 'Invalid input'
  5464. },
  5465. /** Convenience shortcuts */
  5466. baseMinusTMin = base - tMin,
  5467. floor = Math.floor,
  5468. stringFromCharCode = String.fromCharCode,
  5469. /** Temporary variable */
  5470. key;
  5471. /*--------------------------------------------------------------------------*/
  5472. /**
  5473. * A generic error utility function.
  5474. * @private
  5475. * @param {String} type The error type.
  5476. * @returns {Error} Throws a `RangeError` with the applicable error message.
  5477. */
  5478. function error(type) {
  5479. throw new RangeError(errors[type]);
  5480. }
  5481. /**
  5482. * A generic `Array#map` utility function.
  5483. * @private
  5484. * @param {Array} array The array to iterate over.
  5485. * @param {Function} callback The function that gets called for every array
  5486. * item.
  5487. * @returns {Array} A new array of values returned by the callback function.
  5488. */
  5489. function map(array, fn) {
  5490. var length = array.length;
  5491. var result = [];
  5492. while (length--) {
  5493. result[length] = fn(array[length]);
  5494. }
  5495. return result;
  5496. }
  5497. /**
  5498. * A simple `Array#map`-like wrapper to work with domain name strings or email
  5499. * addresses.
  5500. * @private
  5501. * @param {String} domain The domain name or email address.
  5502. * @param {Function} callback The function that gets called for every
  5503. * character.
  5504. * @returns {Array} A new string of characters returned by the callback
  5505. * function.
  5506. */
  5507. function mapDomain(string, fn) {
  5508. var parts = string.split('@');
  5509. var result = '';
  5510. if (parts.length > 1) {
  5511. // In email addresses, only the domain name should be punycoded. Leave
  5512. // the local part (i.e. everything up to `@`) intact.
  5513. result = parts[0] + '@';
  5514. string = parts[1];
  5515. }
  5516. // Avoid `split(regex)` for IE8 compatibility. See #17.
  5517. string = string.replace(regexSeparators, '\x2E');
  5518. var labels = string.split('.');
  5519. var encoded = map(labels, fn).join('.');
  5520. return result + encoded;
  5521. }
  5522. /**
  5523. * Creates an array containing the numeric code points of each Unicode
  5524. * character in the string. While JavaScript uses UCS-2 internally,
  5525. * this function will convert a pair of surrogate halves (each of which
  5526. * UCS-2 exposes as separate characters) into a single code point,
  5527. * matching UTF-16.
  5528. * @see `punycode.ucs2.encode`
  5529. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  5530. * @memberOf punycode.ucs2
  5531. * @name decode
  5532. * @param {String} string The Unicode input string (UCS-2).
  5533. * @returns {Array} The new array of code points.
  5534. */
  5535. function ucs2decode(string) {
  5536. var output = [],
  5537. counter = 0,
  5538. length = string.length,
  5539. value,
  5540. extra;
  5541. while (counter < length) {
  5542. value = string.charCodeAt(counter++);
  5543. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  5544. // high surrogate, and there is a next character
  5545. extra = string.charCodeAt(counter++);
  5546. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  5547. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  5548. } else {
  5549. // unmatched surrogate; only append this code unit, in case the next
  5550. // code unit is the high surrogate of a surrogate pair
  5551. output.push(value);
  5552. counter--;
  5553. }
  5554. } else {
  5555. output.push(value);
  5556. }
  5557. }
  5558. return output;
  5559. }
  5560. /**
  5561. * Creates a string based on an array of numeric code points.
  5562. * @see `punycode.ucs2.decode`
  5563. * @memberOf punycode.ucs2
  5564. * @name encode
  5565. * @param {Array} codePoints The array of numeric code points.
  5566. * @returns {String} The new Unicode string (UCS-2).
  5567. */
  5568. function ucs2encode(array) {
  5569. return map(array, function(value) {
  5570. var output = '';
  5571. if (value > 0xFFFF) {
  5572. value -= 0x10000;
  5573. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  5574. value = 0xDC00 | value & 0x3FF;
  5575. }
  5576. output += stringFromCharCode(value);
  5577. return output;
  5578. }).join('');
  5579. }
  5580. /**
  5581. * Converts a basic code point into a digit/integer.
  5582. * @see `digitToBasic()`
  5583. * @private
  5584. * @param {Number} codePoint The basic numeric code point value.
  5585. * @returns {Number} The numeric value of a basic code point (for use in
  5586. * representing integers) in the range `0` to `base - 1`, or `base` if
  5587. * the code point does not represent a value.
  5588. */
  5589. function basicToDigit(codePoint) {
  5590. if (codePoint - 48 < 10) {
  5591. return codePoint - 22;
  5592. }
  5593. if (codePoint - 65 < 26) {
  5594. return codePoint - 65;
  5595. }
  5596. if (codePoint - 97 < 26) {
  5597. return codePoint - 97;
  5598. }
  5599. return base;
  5600. }
  5601. /**
  5602. * Converts a digit/integer into a basic code point.
  5603. * @see `basicToDigit()`
  5604. * @private
  5605. * @param {Number} digit The numeric value of a basic code point.
  5606. * @returns {Number} The basic code point whose value (when used for
  5607. * representing integers) is `digit`, which needs to be in the range
  5608. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  5609. * used; else, the lowercase form is used. The behavior is undefined
  5610. * if `flag` is non-zero and `digit` has no uppercase form.
  5611. */
  5612. function digitToBasic(digit, flag) {
  5613. // 0..25 map to ASCII a..z or A..Z
  5614. // 26..35 map to ASCII 0..9
  5615. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  5616. }
  5617. /**
  5618. * Bias adaptation function as per section 3.4 of RFC 3492.
  5619. * https://tools.ietf.org/html/rfc3492#section-3.4
  5620. * @private
  5621. */
  5622. function adapt(delta, numPoints, firstTime) {
  5623. var k = 0;
  5624. delta = firstTime ? floor(delta / damp) : delta >> 1;
  5625. delta += floor(delta / numPoints);
  5626. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  5627. delta = floor(delta / baseMinusTMin);
  5628. }
  5629. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  5630. }
  5631. /**
  5632. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  5633. * symbols.
  5634. * @memberOf punycode
  5635. * @param {String} input The Punycode string of ASCII-only symbols.
  5636. * @returns {String} The resulting string of Unicode symbols.
  5637. */
  5638. function decode(input) {
  5639. // Don't use UCS-2
  5640. var output = [],
  5641. inputLength = input.length,
  5642. out,
  5643. i = 0,
  5644. n = initialN,
  5645. bias = initialBias,
  5646. basic,
  5647. j,
  5648. index,
  5649. oldi,
  5650. w,
  5651. k,
  5652. digit,
  5653. t,
  5654. /** Cached calculation results */
  5655. baseMinusT;
  5656. // Handle the basic code points: let `basic` be the number of input code
  5657. // points before the last delimiter, or `0` if there is none, then copy
  5658. // the first basic code points to the output.
  5659. basic = input.lastIndexOf(delimiter);
  5660. if (basic < 0) {
  5661. basic = 0;
  5662. }
  5663. for (j = 0; j < basic; ++j) {
  5664. // if it's not a basic code point
  5665. if (input.charCodeAt(j) >= 0x80) {
  5666. error('not-basic');
  5667. }
  5668. output.push(input.charCodeAt(j));
  5669. }
  5670. // Main decoding loop: start just after the last delimiter if any basic code
  5671. // points were copied; start at the beginning otherwise.
  5672. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  5673. // `index` is the index of the next character to be consumed.
  5674. // Decode a generalized variable-length integer into `delta`,
  5675. // which gets added to `i`. The overflow checking is easier
  5676. // if we increase `i` as we go, then subtract off its starting
  5677. // value at the end to obtain `delta`.
  5678. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  5679. if (index >= inputLength) {
  5680. error('invalid-input');
  5681. }
  5682. digit = basicToDigit(input.charCodeAt(index++));
  5683. if (digit >= base || digit > floor((maxInt - i) / w)) {
  5684. error('overflow');
  5685. }
  5686. i += digit * w;
  5687. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  5688. if (digit < t) {
  5689. break;
  5690. }
  5691. baseMinusT = base - t;
  5692. if (w > floor(maxInt / baseMinusT)) {
  5693. error('overflow');
  5694. }
  5695. w *= baseMinusT;
  5696. }
  5697. out = output.length + 1;
  5698. bias = adapt(i - oldi, out, oldi == 0);
  5699. // `i` was supposed to wrap around from `out` to `0`,
  5700. // incrementing `n` each time, so we'll fix that now:
  5701. if (floor(i / out) > maxInt - n) {
  5702. error('overflow');
  5703. }
  5704. n += floor(i / out);
  5705. i %= out;
  5706. // Insert `n` at position `i` of the output
  5707. output.splice(i++, 0, n);
  5708. }
  5709. return ucs2encode(output);
  5710. }
  5711. /**
  5712. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  5713. * Punycode string of ASCII-only symbols.
  5714. * @memberOf punycode
  5715. * @param {String} input The string of Unicode symbols.
  5716. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  5717. */
  5718. function encode(input) {
  5719. var n,
  5720. delta,
  5721. handledCPCount,
  5722. basicLength,
  5723. bias,
  5724. j,
  5725. m,
  5726. q,
  5727. k,
  5728. t,
  5729. currentValue,
  5730. output = [],
  5731. /** `inputLength` will hold the number of code points in `input`. */
  5732. inputLength,
  5733. /** Cached calculation results */
  5734. handledCPCountPlusOne,
  5735. baseMinusT,
  5736. qMinusT;
  5737. // Convert the input in UCS-2 to Unicode
  5738. input = ucs2decode(input);
  5739. // Cache the length
  5740. inputLength = input.length;
  5741. // Initialize the state
  5742. n = initialN;
  5743. delta = 0;
  5744. bias = initialBias;
  5745. // Handle the basic code points
  5746. for (j = 0; j < inputLength; ++j) {
  5747. currentValue = input[j];
  5748. if (currentValue < 0x80) {
  5749. output.push(stringFromCharCode(currentValue));
  5750. }
  5751. }
  5752. handledCPCount = basicLength = output.length;
  5753. // `handledCPCount` is the number of code points that have been handled;
  5754. // `basicLength` is the number of basic code points.
  5755. // Finish the basic string - if it is not empty - with a delimiter
  5756. if (basicLength) {
  5757. output.push(delimiter);
  5758. }
  5759. // Main encoding loop:
  5760. while (handledCPCount < inputLength) {
  5761. // All non-basic code points < n have been handled already. Find the next
  5762. // larger one:
  5763. for (m = maxInt, j = 0; j < inputLength; ++j) {
  5764. currentValue = input[j];
  5765. if (currentValue >= n && currentValue < m) {
  5766. m = currentValue;
  5767. }
  5768. }
  5769. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  5770. // but guard against overflow
  5771. handledCPCountPlusOne = handledCPCount + 1;
  5772. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  5773. error('overflow');
  5774. }
  5775. delta += (m - n) * handledCPCountPlusOne;
  5776. n = m;
  5777. for (j = 0; j < inputLength; ++j) {
  5778. currentValue = input[j];
  5779. if (currentValue < n && ++delta > maxInt) {
  5780. error('overflow');
  5781. }
  5782. if (currentValue == n) {
  5783. // Represent delta as a generalized variable-length integer
  5784. for (q = delta, k = base; /* no condition */; k += base) {
  5785. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  5786. if (q < t) {
  5787. break;
  5788. }
  5789. qMinusT = q - t;
  5790. baseMinusT = base - t;
  5791. output.push(
  5792. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  5793. );
  5794. q = floor(qMinusT / baseMinusT);
  5795. }
  5796. output.push(stringFromCharCode(digitToBasic(q, 0)));
  5797. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  5798. delta = 0;
  5799. ++handledCPCount;
  5800. }
  5801. }
  5802. ++delta;
  5803. ++n;
  5804. }
  5805. return output.join('');
  5806. }
  5807. /**
  5808. * Converts a Punycode string representing a domain name or an email address
  5809. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  5810. * it doesn't matter if you call it on a string that has already been
  5811. * converted to Unicode.
  5812. * @memberOf punycode
  5813. * @param {String} input The Punycoded domain name or email address to
  5814. * convert to Unicode.
  5815. * @returns {String} The Unicode representation of the given Punycode
  5816. * string.
  5817. */
  5818. function toUnicode(input) {
  5819. return mapDomain(input, function(string) {
  5820. return regexPunycode.test(string)
  5821. ? decode(string.slice(4).toLowerCase())
  5822. : string;
  5823. });
  5824. }
  5825. /**
  5826. * Converts a Unicode string representing a domain name or an email address to
  5827. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  5828. * i.e. it doesn't matter if you call it with a domain that's already in
  5829. * ASCII.
  5830. * @memberOf punycode
  5831. * @param {String} input The domain name or email address to convert, as a
  5832. * Unicode string.
  5833. * @returns {String} The Punycode representation of the given domain name or
  5834. * email address.
  5835. */
  5836. function toASCII(input) {
  5837. return mapDomain(input, function(string) {
  5838. return regexNonASCII.test(string)
  5839. ? 'xn--' + encode(string)
  5840. : string;
  5841. });
  5842. }
  5843. /*--------------------------------------------------------------------------*/
  5844. /** Define the public API */
  5845. punycode = {
  5846. /**
  5847. * A string representing the current Punycode.js version number.
  5848. * @memberOf punycode
  5849. * @type String
  5850. */
  5851. 'version': '1.4.1',
  5852. /**
  5853. * An object of methods to convert from JavaScript's internal character
  5854. * representation (UCS-2) to Unicode code points, and back.
  5855. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  5856. * @memberOf punycode
  5857. * @type Object
  5858. */
  5859. 'ucs2': {
  5860. 'decode': ucs2decode,
  5861. 'encode': ucs2encode
  5862. },
  5863. 'decode': decode,
  5864. 'encode': encode,
  5865. 'toASCII': toASCII,
  5866. 'toUnicode': toUnicode
  5867. };
  5868. /** Expose `punycode` */
  5869. // Some AMD build optimizers, like r.js, check for specific condition patterns
  5870. // like the following:
  5871. if (
  5872. typeof define == 'function' &&
  5873. typeof define.amd == 'object' &&
  5874. define.amd
  5875. ) {
  5876. define('punycode', function() {
  5877. return punycode;
  5878. });
  5879. } else if (freeExports && freeModule) {
  5880. if (module.exports == freeExports) {
  5881. // in Node.js, io.js, or RingoJS v0.8.0+
  5882. freeModule.exports = punycode;
  5883. } else {
  5884. // in Narwhal or RingoJS v0.7.0-
  5885. for (key in punycode) {
  5886. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  5887. }
  5888. }
  5889. } else {
  5890. // in Rhino or a web browser
  5891. root.punycode = punycode;
  5892. }
  5893. }(this));
  5894. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5895. },{}],48:[function(require,module,exports){
  5896. // Copyright Joyent, Inc. and other Node contributors.
  5897. //
  5898. // Permission is hereby granted, free of charge, to any person obtaining a
  5899. // copy of this software and associated documentation files (the
  5900. // "Software"), to deal in the Software without restriction, including
  5901. // without limitation the rights to use, copy, modify, merge, publish,
  5902. // distribute, sublicense, and/or sell copies of the Software, and to permit
  5903. // persons to whom the Software is furnished to do so, subject to the
  5904. // following conditions:
  5905. //
  5906. // The above copyright notice and this permission notice shall be included
  5907. // in all copies or substantial portions of the Software.
  5908. //
  5909. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  5910. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5911. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  5912. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  5913. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  5914. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  5915. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  5916. 'use strict';
  5917. // If obj.hasOwnProperty has been overridden, then calling
  5918. // obj.hasOwnProperty(prop) will break.
  5919. // See: https://github.com/joyent/node/issues/1707
  5920. function hasOwnProperty(obj, prop) {
  5921. return Object.prototype.hasOwnProperty.call(obj, prop);
  5922. }
  5923. module.exports = function(qs, sep, eq, options) {
  5924. sep = sep || '&';
  5925. eq = eq || '=';
  5926. var obj = {};
  5927. if (typeof qs !== 'string' || qs.length === 0) {
  5928. return obj;
  5929. }
  5930. var regexp = /\+/g;
  5931. qs = qs.split(sep);
  5932. var maxKeys = 1000;
  5933. if (options && typeof options.maxKeys === 'number') {
  5934. maxKeys = options.maxKeys;
  5935. }
  5936. var len = qs.length;
  5937. // maxKeys <= 0 means that we should not limit keys count
  5938. if (maxKeys > 0 && len > maxKeys) {
  5939. len = maxKeys;
  5940. }
  5941. for (var i = 0; i < len; ++i) {
  5942. var x = qs[i].replace(regexp, '%20'),
  5943. idx = x.indexOf(eq),
  5944. kstr, vstr, k, v;
  5945. if (idx >= 0) {
  5946. kstr = x.substr(0, idx);
  5947. vstr = x.substr(idx + 1);
  5948. } else {
  5949. kstr = x;
  5950. vstr = '';
  5951. }
  5952. k = decodeURIComponent(kstr);
  5953. v = decodeURIComponent(vstr);
  5954. if (!hasOwnProperty(obj, k)) {
  5955. obj[k] = v;
  5956. } else if (isArray(obj[k])) {
  5957. obj[k].push(v);
  5958. } else {
  5959. obj[k] = [obj[k], v];
  5960. }
  5961. }
  5962. return obj;
  5963. };
  5964. var isArray = Array.isArray || function (xs) {
  5965. return Object.prototype.toString.call(xs) === '[object Array]';
  5966. };
  5967. },{}],49:[function(require,module,exports){
  5968. // Copyright Joyent, Inc. and other Node contributors.
  5969. //
  5970. // Permission is hereby granted, free of charge, to any person obtaining a
  5971. // copy of this software and associated documentation files (the
  5972. // "Software"), to deal in the Software without restriction, including
  5973. // without limitation the rights to use, copy, modify, merge, publish,
  5974. // distribute, sublicense, and/or sell copies of the Software, and to permit
  5975. // persons to whom the Software is furnished to do so, subject to the
  5976. // following conditions:
  5977. //
  5978. // The above copyright notice and this permission notice shall be included
  5979. // in all copies or substantial portions of the Software.
  5980. //
  5981. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  5982. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5983. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  5984. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  5985. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  5986. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  5987. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  5988. 'use strict';
  5989. var stringifyPrimitive = function(v) {
  5990. switch (typeof v) {
  5991. case 'string':
  5992. return v;
  5993. case 'boolean':
  5994. return v ? 'true' : 'false';
  5995. case 'number':
  5996. return isFinite(v) ? v : '';
  5997. default:
  5998. return '';
  5999. }
  6000. };
  6001. module.exports = function(obj, sep, eq, name) {
  6002. sep = sep || '&';
  6003. eq = eq || '=';
  6004. if (obj === null) {
  6005. obj = undefined;
  6006. }
  6007. if (typeof obj === 'object') {
  6008. return map(objectKeys(obj), function(k) {
  6009. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  6010. if (isArray(obj[k])) {
  6011. return map(obj[k], function(v) {
  6012. return ks + encodeURIComponent(stringifyPrimitive(v));
  6013. }).join(sep);
  6014. } else {
  6015. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  6016. }
  6017. }).join(sep);
  6018. }
  6019. if (!name) return '';
  6020. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  6021. encodeURIComponent(stringifyPrimitive(obj));
  6022. };
  6023. var isArray = Array.isArray || function (xs) {
  6024. return Object.prototype.toString.call(xs) === '[object Array]';
  6025. };
  6026. function map (xs, f) {
  6027. if (xs.map) return xs.map(f);
  6028. var res = [];
  6029. for (var i = 0; i < xs.length; i++) {
  6030. res.push(f(xs[i], i));
  6031. }
  6032. return res;
  6033. }
  6034. var objectKeys = Object.keys || function (obj) {
  6035. var res = [];
  6036. for (var key in obj) {
  6037. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  6038. }
  6039. return res;
  6040. };
  6041. },{}],50:[function(require,module,exports){
  6042. 'use strict';
  6043. exports.decode = exports.parse = require('./decode');
  6044. exports.encode = exports.stringify = require('./encode');
  6045. },{"./decode":48,"./encode":49}],51:[function(require,module,exports){
  6046. // Copyright Joyent, Inc. and other Node contributors.
  6047. //
  6048. // Permission is hereby granted, free of charge, to any person obtaining a
  6049. // copy of this software and associated documentation files (the
  6050. // "Software"), to deal in the Software without restriction, including
  6051. // without limitation the rights to use, copy, modify, merge, publish,
  6052. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6053. // persons to whom the Software is furnished to do so, subject to the
  6054. // following conditions:
  6055. //
  6056. // The above copyright notice and this permission notice shall be included
  6057. // in all copies or substantial portions of the Software.
  6058. //
  6059. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6060. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6061. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6062. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6063. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6064. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6065. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6066. 'use strict';
  6067. var punycode = require('punycode');
  6068. var util = require('./util');
  6069. exports.parse = urlParse;
  6070. exports.resolve = urlResolve;
  6071. exports.resolveObject = urlResolveObject;
  6072. exports.format = urlFormat;
  6073. exports.Url = Url;
  6074. function Url() {
  6075. this.protocol = null;
  6076. this.slashes = null;
  6077. this.auth = null;
  6078. this.host = null;
  6079. this.port = null;
  6080. this.hostname = null;
  6081. this.hash = null;
  6082. this.search = null;
  6083. this.query = null;
  6084. this.pathname = null;
  6085. this.path = null;
  6086. this.href = null;
  6087. }
  6088. // Reference: RFC 3986, RFC 1808, RFC 2396
  6089. // define these here so at least they only have to be
  6090. // compiled once on the first module load.
  6091. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  6092. portPattern = /:[0-9]*$/,
  6093. // Special case for a simple path URL
  6094. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  6095. // RFC 2396: characters reserved for delimiting URLs.
  6096. // We actually just auto-escape these.
  6097. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  6098. // RFC 2396: characters not allowed for various reasons.
  6099. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  6100. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  6101. autoEscape = ['\''].concat(unwise),
  6102. // Characters that are never ever allowed in a hostname.
  6103. // Note that any invalid chars are also handled, but these
  6104. // are the ones that are *expected* to be seen, so we fast-path
  6105. // them.
  6106. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  6107. hostEndingChars = ['/', '?', '#'],
  6108. hostnameMaxLen = 255,
  6109. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  6110. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  6111. // protocols that can allow "unsafe" and "unwise" chars.
  6112. unsafeProtocol = {
  6113. 'javascript': true,
  6114. 'javascript:': true
  6115. },
  6116. // protocols that never have a hostname.
  6117. hostlessProtocol = {
  6118. 'javascript': true,
  6119. 'javascript:': true
  6120. },
  6121. // protocols that always contain a // bit.
  6122. slashedProtocol = {
  6123. 'http': true,
  6124. 'https': true,
  6125. 'ftp': true,
  6126. 'gopher': true,
  6127. 'file': true,
  6128. 'http:': true,
  6129. 'https:': true,
  6130. 'ftp:': true,
  6131. 'gopher:': true,
  6132. 'file:': true
  6133. },
  6134. querystring = require('querystring');
  6135. function urlParse(url, parseQueryString, slashesDenoteHost) {
  6136. if (url && util.isObject(url) && url instanceof Url) return url;
  6137. var u = new Url;
  6138. u.parse(url, parseQueryString, slashesDenoteHost);
  6139. return u;
  6140. }
  6141. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  6142. if (!util.isString(url)) {
  6143. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  6144. }
  6145. // Copy chrome, IE, opera backslash-handling behavior.
  6146. // Back slashes before the query string get converted to forward slashes
  6147. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  6148. var queryIndex = url.indexOf('?'),
  6149. splitter =
  6150. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  6151. uSplit = url.split(splitter),
  6152. slashRegex = /\\/g;
  6153. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  6154. url = uSplit.join(splitter);
  6155. var rest = url;
  6156. // trim before proceeding.
  6157. // This is to support parse stuff like " http://foo.com \n"
  6158. rest = rest.trim();
  6159. if (!slashesDenoteHost && url.split('#').length === 1) {
  6160. // Try fast path regexp
  6161. var simplePath = simplePathPattern.exec(rest);
  6162. if (simplePath) {
  6163. this.path = rest;
  6164. this.href = rest;
  6165. this.pathname = simplePath[1];
  6166. if (simplePath[2]) {
  6167. this.search = simplePath[2];
  6168. if (parseQueryString) {
  6169. this.query = querystring.parse(this.search.substr(1));
  6170. } else {
  6171. this.query = this.search.substr(1);
  6172. }
  6173. } else if (parseQueryString) {
  6174. this.search = '';
  6175. this.query = {};
  6176. }
  6177. return this;
  6178. }
  6179. }
  6180. var proto = protocolPattern.exec(rest);
  6181. if (proto) {
  6182. proto = proto[0];
  6183. var lowerProto = proto.toLowerCase();
  6184. this.protocol = lowerProto;
  6185. rest = rest.substr(proto.length);
  6186. }
  6187. // figure out if it's got a host
  6188. // user@server is *always* interpreted as a hostname, and url
  6189. // resolution will treat //foo/bar as host=foo,path=bar because that's
  6190. // how the browser resolves relative URLs.
  6191. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  6192. var slashes = rest.substr(0, 2) === '//';
  6193. if (slashes && !(proto && hostlessProtocol[proto])) {
  6194. rest = rest.substr(2);
  6195. this.slashes = true;
  6196. }
  6197. }
  6198. if (!hostlessProtocol[proto] &&
  6199. (slashes || (proto && !slashedProtocol[proto]))) {
  6200. // there's a hostname.
  6201. // the first instance of /, ?, ;, or # ends the host.
  6202. //
  6203. // If there is an @ in the hostname, then non-host chars *are* allowed
  6204. // to the left of the last @ sign, unless some host-ending character
  6205. // comes *before* the @-sign.
  6206. // URLs are obnoxious.
  6207. //
  6208. // ex:
  6209. // http://a@b@c/ => user:a@b host:c
  6210. // http://a@b?@c => user:a host:c path:/?@c
  6211. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  6212. // Review our test case against browsers more comprehensively.
  6213. // find the first instance of any hostEndingChars
  6214. var hostEnd = -1;
  6215. for (var i = 0; i < hostEndingChars.length; i++) {
  6216. var hec = rest.indexOf(hostEndingChars[i]);
  6217. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  6218. hostEnd = hec;
  6219. }
  6220. // at this point, either we have an explicit point where the
  6221. // auth portion cannot go past, or the last @ char is the decider.
  6222. var auth, atSign;
  6223. if (hostEnd === -1) {
  6224. // atSign can be anywhere.
  6225. atSign = rest.lastIndexOf('@');
  6226. } else {
  6227. // atSign must be in auth portion.
  6228. // http://a@b/c@d => host:b auth:a path:/c@d
  6229. atSign = rest.lastIndexOf('@', hostEnd);
  6230. }
  6231. // Now we have a portion which is definitely the auth.
  6232. // Pull that off.
  6233. if (atSign !== -1) {
  6234. auth = rest.slice(0, atSign);
  6235. rest = rest.slice(atSign + 1);
  6236. this.auth = decodeURIComponent(auth);
  6237. }
  6238. // the host is the remaining to the left of the first non-host char
  6239. hostEnd = -1;
  6240. for (var i = 0; i < nonHostChars.length; i++) {
  6241. var hec = rest.indexOf(nonHostChars[i]);
  6242. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  6243. hostEnd = hec;
  6244. }
  6245. // if we still have not hit it, then the entire thing is a host.
  6246. if (hostEnd === -1)
  6247. hostEnd = rest.length;
  6248. this.host = rest.slice(0, hostEnd);
  6249. rest = rest.slice(hostEnd);
  6250. // pull out port.
  6251. this.parseHost();
  6252. // we've indicated that there is a hostname,
  6253. // so even if it's empty, it has to be present.
  6254. this.hostname = this.hostname || '';
  6255. // if hostname begins with [ and ends with ]
  6256. // assume that it's an IPv6 address.
  6257. var ipv6Hostname = this.hostname[0] === '[' &&
  6258. this.hostname[this.hostname.length - 1] === ']';
  6259. // validate a little.
  6260. if (!ipv6Hostname) {
  6261. var hostparts = this.hostname.split(/\./);
  6262. for (var i = 0, l = hostparts.length; i < l; i++) {
  6263. var part = hostparts[i];
  6264. if (!part) continue;
  6265. if (!part.match(hostnamePartPattern)) {
  6266. var newpart = '';
  6267. for (var j = 0, k = part.length; j < k; j++) {
  6268. if (part.charCodeAt(j) > 127) {
  6269. // we replace non-ASCII char with a temporary placeholder
  6270. // we need this to make sure size of hostname is not
  6271. // broken by replacing non-ASCII by nothing
  6272. newpart += 'x';
  6273. } else {
  6274. newpart += part[j];
  6275. }
  6276. }
  6277. // we test again with ASCII char only
  6278. if (!newpart.match(hostnamePartPattern)) {
  6279. var validParts = hostparts.slice(0, i);
  6280. var notHost = hostparts.slice(i + 1);
  6281. var bit = part.match(hostnamePartStart);
  6282. if (bit) {
  6283. validParts.push(bit[1]);
  6284. notHost.unshift(bit[2]);
  6285. }
  6286. if (notHost.length) {
  6287. rest = '/' + notHost.join('.') + rest;
  6288. }
  6289. this.hostname = validParts.join('.');
  6290. break;
  6291. }
  6292. }
  6293. }
  6294. }
  6295. if (this.hostname.length > hostnameMaxLen) {
  6296. this.hostname = '';
  6297. } else {
  6298. // hostnames are always lower case.
  6299. this.hostname = this.hostname.toLowerCase();
  6300. }
  6301. if (!ipv6Hostname) {
  6302. // IDNA Support: Returns a punycoded representation of "domain".
  6303. // It only converts parts of the domain name that
  6304. // have non-ASCII characters, i.e. it doesn't matter if
  6305. // you call it with a domain that already is ASCII-only.
  6306. this.hostname = punycode.toASCII(this.hostname);
  6307. }
  6308. var p = this.port ? ':' + this.port : '';
  6309. var h = this.hostname || '';
  6310. this.host = h + p;
  6311. this.href += this.host;
  6312. // strip [ and ] from the hostname
  6313. // the host field still retains them, though
  6314. if (ipv6Hostname) {
  6315. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  6316. if (rest[0] !== '/') {
  6317. rest = '/' + rest;
  6318. }
  6319. }
  6320. }
  6321. // now rest is set to the post-host stuff.
  6322. // chop off any delim chars.
  6323. if (!unsafeProtocol[lowerProto]) {
  6324. // First, make 100% sure that any "autoEscape" chars get
  6325. // escaped, even if encodeURIComponent doesn't think they
  6326. // need to be.
  6327. for (var i = 0, l = autoEscape.length; i < l; i++) {
  6328. var ae = autoEscape[i];
  6329. if (rest.indexOf(ae) === -1)
  6330. continue;
  6331. var esc = encodeURIComponent(ae);
  6332. if (esc === ae) {
  6333. esc = escape(ae);
  6334. }
  6335. rest = rest.split(ae).join(esc);
  6336. }
  6337. }
  6338. // chop off from the tail first.
  6339. var hash = rest.indexOf('#');
  6340. if (hash !== -1) {
  6341. // got a fragment string.
  6342. this.hash = rest.substr(hash);
  6343. rest = rest.slice(0, hash);
  6344. }
  6345. var qm = rest.indexOf('?');
  6346. if (qm !== -1) {
  6347. this.search = rest.substr(qm);
  6348. this.query = rest.substr(qm + 1);
  6349. if (parseQueryString) {
  6350. this.query = querystring.parse(this.query);
  6351. }
  6352. rest = rest.slice(0, qm);
  6353. } else if (parseQueryString) {
  6354. // no query string, but parseQueryString still requested
  6355. this.search = '';
  6356. this.query = {};
  6357. }
  6358. if (rest) this.pathname = rest;
  6359. if (slashedProtocol[lowerProto] &&
  6360. this.hostname && !this.pathname) {
  6361. this.pathname = '/';
  6362. }
  6363. //to support http.request
  6364. if (this.pathname || this.search) {
  6365. var p = this.pathname || '';
  6366. var s = this.search || '';
  6367. this.path = p + s;
  6368. }
  6369. // finally, reconstruct the href based on what has been validated.
  6370. this.href = this.format();
  6371. return this;
  6372. };
  6373. // format a parsed object into a url string
  6374. function urlFormat(obj) {
  6375. // ensure it's an object, and not a string url.
  6376. // If it's an obj, this is a no-op.
  6377. // this way, you can call url_format() on strings
  6378. // to clean up potentially wonky urls.
  6379. if (util.isString(obj)) obj = urlParse(obj);
  6380. if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
  6381. return obj.format();
  6382. }
  6383. Url.prototype.format = function() {
  6384. var auth = this.auth || '';
  6385. if (auth) {
  6386. auth = encodeURIComponent(auth);
  6387. auth = auth.replace(/%3A/i, ':');
  6388. auth += '@';
  6389. }
  6390. var protocol = this.protocol || '',
  6391. pathname = this.pathname || '',
  6392. hash = this.hash || '',
  6393. host = false,
  6394. query = '';
  6395. if (this.host) {
  6396. host = auth + this.host;
  6397. } else if (this.hostname) {
  6398. host = auth + (this.hostname.indexOf(':') === -1 ?
  6399. this.hostname :
  6400. '[' + this.hostname + ']');
  6401. if (this.port) {
  6402. host += ':' + this.port;
  6403. }
  6404. }
  6405. if (this.query &&
  6406. util.isObject(this.query) &&
  6407. Object.keys(this.query).length) {
  6408. query = querystring.stringify(this.query);
  6409. }
  6410. var search = this.search || (query && ('?' + query)) || '';
  6411. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  6412. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  6413. // unless they had them to begin with.
  6414. if (this.slashes ||
  6415. (!protocol || slashedProtocol[protocol]) && host !== false) {
  6416. host = '//' + (host || '');
  6417. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  6418. } else if (!host) {
  6419. host = '';
  6420. }
  6421. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  6422. if (search && search.charAt(0) !== '?') search = '?' + search;
  6423. pathname = pathname.replace(/[?#]/g, function(match) {
  6424. return encodeURIComponent(match);
  6425. });
  6426. search = search.replace('#', '%23');
  6427. return protocol + host + pathname + search + hash;
  6428. };
  6429. function urlResolve(source, relative) {
  6430. return urlParse(source, false, true).resolve(relative);
  6431. }
  6432. Url.prototype.resolve = function(relative) {
  6433. return this.resolveObject(urlParse(relative, false, true)).format();
  6434. };
  6435. function urlResolveObject(source, relative) {
  6436. if (!source) return relative;
  6437. return urlParse(source, false, true).resolveObject(relative);
  6438. }
  6439. Url.prototype.resolveObject = function(relative) {
  6440. if (util.isString(relative)) {
  6441. var rel = new Url();
  6442. rel.parse(relative, false, true);
  6443. relative = rel;
  6444. }
  6445. var result = new Url();
  6446. var tkeys = Object.keys(this);
  6447. for (var tk = 0; tk < tkeys.length; tk++) {
  6448. var tkey = tkeys[tk];
  6449. result[tkey] = this[tkey];
  6450. }
  6451. // hash is always overridden, no matter what.
  6452. // even href="" will remove it.
  6453. result.hash = relative.hash;
  6454. // if the relative url is empty, then there's nothing left to do here.
  6455. if (relative.href === '') {
  6456. result.href = result.format();
  6457. return result;
  6458. }
  6459. // hrefs like //foo/bar always cut to the protocol.
  6460. if (relative.slashes && !relative.protocol) {
  6461. // take everything except the protocol from relative
  6462. var rkeys = Object.keys(relative);
  6463. for (var rk = 0; rk < rkeys.length; rk++) {
  6464. var rkey = rkeys[rk];
  6465. if (rkey !== 'protocol')
  6466. result[rkey] = relative[rkey];
  6467. }
  6468. //urlParse appends trailing / to urls like http://www.example.com
  6469. if (slashedProtocol[result.protocol] &&
  6470. result.hostname && !result.pathname) {
  6471. result.path = result.pathname = '/';
  6472. }
  6473. result.href = result.format();
  6474. return result;
  6475. }
  6476. if (relative.protocol && relative.protocol !== result.protocol) {
  6477. // if it's a known url protocol, then changing
  6478. // the protocol does weird things
  6479. // first, if it's not file:, then we MUST have a host,
  6480. // and if there was a path
  6481. // to begin with, then we MUST have a path.
  6482. // if it is file:, then the host is dropped,
  6483. // because that's known to be hostless.
  6484. // anything else is assumed to be absolute.
  6485. if (!slashedProtocol[relative.protocol]) {
  6486. var keys = Object.keys(relative);
  6487. for (var v = 0; v < keys.length; v++) {
  6488. var k = keys[v];
  6489. result[k] = relative[k];
  6490. }
  6491. result.href = result.format();
  6492. return result;
  6493. }
  6494. result.protocol = relative.protocol;
  6495. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  6496. var relPath = (relative.pathname || '').split('/');
  6497. while (relPath.length && !(relative.host = relPath.shift()));
  6498. if (!relative.host) relative.host = '';
  6499. if (!relative.hostname) relative.hostname = '';
  6500. if (relPath[0] !== '') relPath.unshift('');
  6501. if (relPath.length < 2) relPath.unshift('');
  6502. result.pathname = relPath.join('/');
  6503. } else {
  6504. result.pathname = relative.pathname;
  6505. }
  6506. result.search = relative.search;
  6507. result.query = relative.query;
  6508. result.host = relative.host || '';
  6509. result.auth = relative.auth;
  6510. result.hostname = relative.hostname || relative.host;
  6511. result.port = relative.port;
  6512. // to support http.request
  6513. if (result.pathname || result.search) {
  6514. var p = result.pathname || '';
  6515. var s = result.search || '';
  6516. result.path = p + s;
  6517. }
  6518. result.slashes = result.slashes || relative.slashes;
  6519. result.href = result.format();
  6520. return result;
  6521. }
  6522. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  6523. isRelAbs = (
  6524. relative.host ||
  6525. relative.pathname && relative.pathname.charAt(0) === '/'
  6526. ),
  6527. mustEndAbs = (isRelAbs || isSourceAbs ||
  6528. (result.host && relative.pathname)),
  6529. removeAllDots = mustEndAbs,
  6530. srcPath = result.pathname && result.pathname.split('/') || [],
  6531. relPath = relative.pathname && relative.pathname.split('/') || [],
  6532. psychotic = result.protocol && !slashedProtocol[result.protocol];
  6533. // if the url is a non-slashed url, then relative
  6534. // links like ../.. should be able
  6535. // to crawl up to the hostname, as well. This is strange.
  6536. // result.protocol has already been set by now.
  6537. // Later on, put the first path part into the host field.
  6538. if (psychotic) {
  6539. result.hostname = '';
  6540. result.port = null;
  6541. if (result.host) {
  6542. if (srcPath[0] === '') srcPath[0] = result.host;
  6543. else srcPath.unshift(result.host);
  6544. }
  6545. result.host = '';
  6546. if (relative.protocol) {
  6547. relative.hostname = null;
  6548. relative.port = null;
  6549. if (relative.host) {
  6550. if (relPath[0] === '') relPath[0] = relative.host;
  6551. else relPath.unshift(relative.host);
  6552. }
  6553. relative.host = null;
  6554. }
  6555. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  6556. }
  6557. if (isRelAbs) {
  6558. // it's absolute.
  6559. result.host = (relative.host || relative.host === '') ?
  6560. relative.host : result.host;
  6561. result.hostname = (relative.hostname || relative.hostname === '') ?
  6562. relative.hostname : result.hostname;
  6563. result.search = relative.search;
  6564. result.query = relative.query;
  6565. srcPath = relPath;
  6566. // fall through to the dot-handling below.
  6567. } else if (relPath.length) {
  6568. // it's relative
  6569. // throw away the existing file, and take the new path instead.
  6570. if (!srcPath) srcPath = [];
  6571. srcPath.pop();
  6572. srcPath = srcPath.concat(relPath);
  6573. result.search = relative.search;
  6574. result.query = relative.query;
  6575. } else if (!util.isNullOrUndefined(relative.search)) {
  6576. // just pull out the search.
  6577. // like href='?foo'.
  6578. // Put this after the other two cases because it simplifies the booleans
  6579. if (psychotic) {
  6580. result.hostname = result.host = srcPath.shift();
  6581. //occationaly the auth can get stuck only in host
  6582. //this especially happens in cases like
  6583. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  6584. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  6585. result.host.split('@') : false;
  6586. if (authInHost) {
  6587. result.auth = authInHost.shift();
  6588. result.host = result.hostname = authInHost.shift();
  6589. }
  6590. }
  6591. result.search = relative.search;
  6592. result.query = relative.query;
  6593. //to support http.request
  6594. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  6595. result.path = (result.pathname ? result.pathname : '') +
  6596. (result.search ? result.search : '');
  6597. }
  6598. result.href = result.format();
  6599. return result;
  6600. }
  6601. if (!srcPath.length) {
  6602. // no path at all. easy.
  6603. // we've already handled the other stuff above.
  6604. result.pathname = null;
  6605. //to support http.request
  6606. if (result.search) {
  6607. result.path = '/' + result.search;
  6608. } else {
  6609. result.path = null;
  6610. }
  6611. result.href = result.format();
  6612. return result;
  6613. }
  6614. // if a url ENDs in . or .., then it must get a trailing slash.
  6615. // however, if it ends in anything else non-slashy,
  6616. // then it must NOT get a trailing slash.
  6617. var last = srcPath.slice(-1)[0];
  6618. var hasTrailingSlash = (
  6619. (result.host || relative.host || srcPath.length > 1) &&
  6620. (last === '.' || last === '..') || last === '');
  6621. // strip single dots, resolve double dots to parent dir
  6622. // if the path tries to go above the root, `up` ends up > 0
  6623. var up = 0;
  6624. for (var i = srcPath.length; i >= 0; i--) {
  6625. last = srcPath[i];
  6626. if (last === '.') {
  6627. srcPath.splice(i, 1);
  6628. } else if (last === '..') {
  6629. srcPath.splice(i, 1);
  6630. up++;
  6631. } else if (up) {
  6632. srcPath.splice(i, 1);
  6633. up--;
  6634. }
  6635. }
  6636. // if the path is allowed to go above the root, restore leading ..s
  6637. if (!mustEndAbs && !removeAllDots) {
  6638. for (; up--; up) {
  6639. srcPath.unshift('..');
  6640. }
  6641. }
  6642. if (mustEndAbs && srcPath[0] !== '' &&
  6643. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  6644. srcPath.unshift('');
  6645. }
  6646. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  6647. srcPath.push('');
  6648. }
  6649. var isAbsolute = srcPath[0] === '' ||
  6650. (srcPath[0] && srcPath[0].charAt(0) === '/');
  6651. // put the host back
  6652. if (psychotic) {
  6653. result.hostname = result.host = isAbsolute ? '' :
  6654. srcPath.length ? srcPath.shift() : '';
  6655. //occationaly the auth can get stuck only in host
  6656. //this especially happens in cases like
  6657. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  6658. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  6659. result.host.split('@') : false;
  6660. if (authInHost) {
  6661. result.auth = authInHost.shift();
  6662. result.host = result.hostname = authInHost.shift();
  6663. }
  6664. }
  6665. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  6666. if (mustEndAbs && !isAbsolute) {
  6667. srcPath.unshift('');
  6668. }
  6669. if (!srcPath.length) {
  6670. result.pathname = null;
  6671. result.path = null;
  6672. } else {
  6673. result.pathname = srcPath.join('/');
  6674. }
  6675. //to support request.http
  6676. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  6677. result.path = (result.pathname ? result.pathname : '') +
  6678. (result.search ? result.search : '');
  6679. }
  6680. result.auth = relative.auth || result.auth;
  6681. result.slashes = result.slashes || relative.slashes;
  6682. result.href = result.format();
  6683. return result;
  6684. };
  6685. Url.prototype.parseHost = function() {
  6686. var host = this.host;
  6687. var port = portPattern.exec(host);
  6688. if (port) {
  6689. port = port[0];
  6690. if (port !== ':') {
  6691. this.port = port.substr(1);
  6692. }
  6693. host = host.substr(0, host.length - port.length);
  6694. }
  6695. if (host) this.hostname = host;
  6696. };
  6697. },{"./util":52,"punycode":47,"querystring":50}],52:[function(require,module,exports){
  6698. 'use strict';
  6699. module.exports = {
  6700. isString: function(arg) {
  6701. return typeof(arg) === 'string';
  6702. },
  6703. isObject: function(arg) {
  6704. return typeof(arg) === 'object' && arg !== null;
  6705. },
  6706. isNull: function(arg) {
  6707. return arg === null;
  6708. },
  6709. isNullOrUndefined: function(arg) {
  6710. return arg == null;
  6711. }
  6712. };
  6713. },{}],"ajv":[function(require,module,exports){
  6714. 'use strict';
  6715. var compileSchema = require('./compile')
  6716. , resolve = require('./compile/resolve')
  6717. , Cache = require('./cache')
  6718. , SchemaObject = require('./compile/schema_obj')
  6719. , stableStringify = require('json-stable-stringify')
  6720. , formats = require('./compile/formats')
  6721. , rules = require('./compile/rules')
  6722. , $dataMetaSchema = require('./$data')
  6723. , patternGroups = require('./patternGroups')
  6724. , util = require('./compile/util')
  6725. , co = require('co');
  6726. module.exports = Ajv;
  6727. Ajv.prototype.validate = validate;
  6728. Ajv.prototype.compile = compile;
  6729. Ajv.prototype.addSchema = addSchema;
  6730. Ajv.prototype.addMetaSchema = addMetaSchema;
  6731. Ajv.prototype.validateSchema = validateSchema;
  6732. Ajv.prototype.getSchema = getSchema;
  6733. Ajv.prototype.removeSchema = removeSchema;
  6734. Ajv.prototype.addFormat = addFormat;
  6735. Ajv.prototype.errorsText = errorsText;
  6736. Ajv.prototype._addSchema = _addSchema;
  6737. Ajv.prototype._compile = _compile;
  6738. Ajv.prototype.compileAsync = require('./compile/async');
  6739. var customKeyword = require('./keyword');
  6740. Ajv.prototype.addKeyword = customKeyword.add;
  6741. Ajv.prototype.getKeyword = customKeyword.get;
  6742. Ajv.prototype.removeKeyword = customKeyword.remove;
  6743. var errorClasses = require('./compile/error_classes');
  6744. Ajv.ValidationError = errorClasses.Validation;
  6745. Ajv.MissingRefError = errorClasses.MissingRef;
  6746. Ajv.$dataMetaSchema = $dataMetaSchema;
  6747. var META_SCHEMA_ID = 'http://json-schema.org/draft-06/schema';
  6748. var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes' ];
  6749. var META_SUPPORT_DATA = ['/properties'];
  6750. /**
  6751. * Creates validator instance.
  6752. * Usage: `Ajv(opts)`
  6753. * @param {Object} opts optional options
  6754. * @return {Object} ajv instance
  6755. */
  6756. function Ajv(opts) {
  6757. if (!(this instanceof Ajv)) return new Ajv(opts);
  6758. opts = this._opts = util.copy(opts) || {};
  6759. this._schemas = {};
  6760. this._refs = {};
  6761. this._fragments = {};
  6762. this._formats = formats(opts.format);
  6763. var schemaUriFormat = this._schemaUriFormat = this._formats['uri-reference'];
  6764. this._schemaUriFormatFunc = function (str) { return schemaUriFormat.test(str); };
  6765. this._cache = opts.cache || new Cache;
  6766. this._loadingSchemas = {};
  6767. this._compilations = [];
  6768. this.RULES = rules();
  6769. this._getId = chooseGetId(opts);
  6770. opts.loopRequired = opts.loopRequired || Infinity;
  6771. if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
  6772. if (opts.serialize === undefined) opts.serialize = stableStringify;
  6773. this._metaOpts = getMetaSchemaOptions(this);
  6774. if (opts.formats) addInitialFormats(this);
  6775. addDraft6MetaSchema(this);
  6776. if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
  6777. addInitialSchemas(this);
  6778. if (opts.patternGroups) patternGroups(this);
  6779. }
  6780. /**
  6781. * Validate data using schema
  6782. * Schema will be compiled and cached (using serialized JSON as key. [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize.
  6783. * @this Ajv
  6784. * @param {String|Object} schemaKeyRef key, ref or schema object
  6785. * @param {Any} data to be validated
  6786. * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
  6787. */
  6788. function validate(schemaKeyRef, data) {
  6789. var v;
  6790. if (typeof schemaKeyRef == 'string') {
  6791. v = this.getSchema(schemaKeyRef);
  6792. if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
  6793. } else {
  6794. var schemaObj = this._addSchema(schemaKeyRef);
  6795. v = schemaObj.validate || this._compile(schemaObj);
  6796. }
  6797. var valid = v(data);
  6798. if (v.$async === true)
  6799. return this._opts.async == '*' ? co(valid) : valid;
  6800. this.errors = v.errors;
  6801. return valid;
  6802. }
  6803. /**
  6804. * Create validating function for passed schema.
  6805. * @this Ajv
  6806. * @param {Object} schema schema object
  6807. * @param {Boolean} _meta true if schema is a meta-schema. Used internally to compile meta schemas of custom keywords.
  6808. * @return {Function} validating function
  6809. */
  6810. function compile(schema, _meta) {
  6811. var schemaObj = this._addSchema(schema, undefined, _meta);
  6812. return schemaObj.validate || this._compile(schemaObj);
  6813. }
  6814. /**
  6815. * Adds schema to the instance.
  6816. * @this Ajv
  6817. * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
  6818. * @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
  6819. * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
  6820. * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
  6821. */
  6822. function addSchema(schema, key, _skipValidation, _meta) {
  6823. if (Array.isArray(schema)){
  6824. for (var i=0; i<schema.length; i++) this.addSchema(schema[i], undefined, _skipValidation, _meta);
  6825. return;
  6826. }
  6827. var id = this._getId(schema);
  6828. if (id !== undefined && typeof id != 'string')
  6829. throw new Error('schema id must be string');
  6830. key = resolve.normalizeId(key || id);
  6831. checkUnique(this, key);
  6832. this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
  6833. }
  6834. /**
  6835. * Add schema that will be used to validate other schemas
  6836. * options in META_IGNORE_OPTIONS are alway set to false
  6837. * @this Ajv
  6838. * @param {Object} schema schema object
  6839. * @param {String} key optional schema key
  6840. * @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema
  6841. */
  6842. function addMetaSchema(schema, key, skipValidation) {
  6843. this.addSchema(schema, key, skipValidation, true);
  6844. }
  6845. /**
  6846. * Validate schema
  6847. * @this Ajv
  6848. * @param {Object} schema schema to validate
  6849. * @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid
  6850. * @return {Boolean} true if schema is valid
  6851. */
  6852. function validateSchema(schema, throwOrLogError) {
  6853. var $schema = schema.$schema;
  6854. if ($schema !== undefined && typeof $schema != 'string')
  6855. throw new Error('$schema must be a string');
  6856. $schema = $schema || this._opts.defaultMeta || defaultMeta(this);
  6857. if (!$schema) {
  6858. console.warn('meta-schema not available');
  6859. this.errors = null;
  6860. return true;
  6861. }
  6862. var currentUriFormat = this._formats.uri;
  6863. this._formats.uri = typeof currentUriFormat == 'function'
  6864. ? this._schemaUriFormatFunc
  6865. : this._schemaUriFormat;
  6866. var valid;
  6867. try { valid = this.validate($schema, schema); }
  6868. finally { this._formats.uri = currentUriFormat; }
  6869. if (!valid && throwOrLogError) {
  6870. var message = 'schema is invalid: ' + this.errorsText();
  6871. if (this._opts.validateSchema == 'log') console.error(message);
  6872. else throw new Error(message);
  6873. }
  6874. return valid;
  6875. }
  6876. function defaultMeta(self) {
  6877. var meta = self._opts.meta;
  6878. self._opts.defaultMeta = typeof meta == 'object'
  6879. ? self._getId(meta) || meta
  6880. : self.getSchema(META_SCHEMA_ID)
  6881. ? META_SCHEMA_ID
  6882. : undefined;
  6883. return self._opts.defaultMeta;
  6884. }
  6885. /**
  6886. * Get compiled schema from the instance by `key` or `ref`.
  6887. * @this Ajv
  6888. * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
  6889. * @return {Function} schema validating function (with property `schema`).
  6890. */
  6891. function getSchema(keyRef) {
  6892. var schemaObj = _getSchemaObj(this, keyRef);
  6893. switch (typeof schemaObj) {
  6894. case 'object': return schemaObj.validate || this._compile(schemaObj);
  6895. case 'string': return this.getSchema(schemaObj);
  6896. case 'undefined': return _getSchemaFragment(this, keyRef);
  6897. }
  6898. }
  6899. function _getSchemaFragment(self, ref) {
  6900. var res = resolve.schema.call(self, { schema: {} }, ref);
  6901. if (res) {
  6902. var schema = res.schema
  6903. , root = res.root
  6904. , baseId = res.baseId;
  6905. var v = compileSchema.call(self, schema, root, undefined, baseId);
  6906. self._fragments[ref] = new SchemaObject({
  6907. ref: ref,
  6908. fragment: true,
  6909. schema: schema,
  6910. root: root,
  6911. baseId: baseId,
  6912. validate: v
  6913. });
  6914. return v;
  6915. }
  6916. }
  6917. function _getSchemaObj(self, keyRef) {
  6918. keyRef = resolve.normalizeId(keyRef);
  6919. return self._schemas[keyRef] || self._refs[keyRef] || self._fragments[keyRef];
  6920. }
  6921. /**
  6922. * Remove cached schema(s).
  6923. * If no parameter is passed all schemas but meta-schemas are removed.
  6924. * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
  6925. * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
  6926. * @this Ajv
  6927. * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
  6928. */
  6929. function removeSchema(schemaKeyRef) {
  6930. if (schemaKeyRef instanceof RegExp) {
  6931. _removeAllSchemas(this, this._schemas, schemaKeyRef);
  6932. _removeAllSchemas(this, this._refs, schemaKeyRef);
  6933. return;
  6934. }
  6935. switch (typeof schemaKeyRef) {
  6936. case 'undefined':
  6937. _removeAllSchemas(this, this._schemas);
  6938. _removeAllSchemas(this, this._refs);
  6939. this._cache.clear();
  6940. return;
  6941. case 'string':
  6942. var schemaObj = _getSchemaObj(this, schemaKeyRef);
  6943. if (schemaObj) this._cache.del(schemaObj.cacheKey);
  6944. delete this._schemas[schemaKeyRef];
  6945. delete this._refs[schemaKeyRef];
  6946. return;
  6947. case 'object':
  6948. var serialize = this._opts.serialize;
  6949. var cacheKey = serialize ? serialize(schemaKeyRef) : schemaKeyRef;
  6950. this._cache.del(cacheKey);
  6951. var id = this._getId(schemaKeyRef);
  6952. if (id) {
  6953. id = resolve.normalizeId(id);
  6954. delete this._schemas[id];
  6955. delete this._refs[id];
  6956. }
  6957. }
  6958. }
  6959. function _removeAllSchemas(self, schemas, regex) {
  6960. for (var keyRef in schemas) {
  6961. var schemaObj = schemas[keyRef];
  6962. if (!schemaObj.meta && (!regex || regex.test(keyRef))) {
  6963. self._cache.del(schemaObj.cacheKey);
  6964. delete schemas[keyRef];
  6965. }
  6966. }
  6967. }
  6968. /* @this Ajv */
  6969. function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
  6970. if (typeof schema != 'object' && typeof schema != 'boolean')
  6971. throw new Error('schema should be object or boolean');
  6972. var serialize = this._opts.serialize;
  6973. var cacheKey = serialize ? serialize(schema) : schema;
  6974. var cached = this._cache.get(cacheKey);
  6975. if (cached) return cached;
  6976. shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
  6977. var id = resolve.normalizeId(this._getId(schema));
  6978. if (id && shouldAddSchema) checkUnique(this, id);
  6979. var willValidate = this._opts.validateSchema !== false && !skipValidation;
  6980. var recursiveMeta;
  6981. if (willValidate && !(recursiveMeta = id && id == resolve.normalizeId(schema.$schema)))
  6982. this.validateSchema(schema, true);
  6983. var localRefs = resolve.ids.call(this, schema);
  6984. var schemaObj = new SchemaObject({
  6985. id: id,
  6986. schema: schema,
  6987. localRefs: localRefs,
  6988. cacheKey: cacheKey,
  6989. meta: meta
  6990. });
  6991. if (id[0] != '#' && shouldAddSchema) this._refs[id] = schemaObj;
  6992. this._cache.put(cacheKey, schemaObj);
  6993. if (willValidate && recursiveMeta) this.validateSchema(schema, true);
  6994. return schemaObj;
  6995. }
  6996. /* @this Ajv */
  6997. function _compile(schemaObj, root) {
  6998. if (schemaObj.compiling) {
  6999. schemaObj.validate = callValidate;
  7000. callValidate.schema = schemaObj.schema;
  7001. callValidate.errors = null;
  7002. callValidate.root = root ? root : callValidate;
  7003. if (schemaObj.schema.$async === true)
  7004. callValidate.$async = true;
  7005. return callValidate;
  7006. }
  7007. schemaObj.compiling = true;
  7008. var currentOpts;
  7009. if (schemaObj.meta) {
  7010. currentOpts = this._opts;
  7011. this._opts = this._metaOpts;
  7012. }
  7013. var v;
  7014. try { v = compileSchema.call(this, schemaObj.schema, root, schemaObj.localRefs); }
  7015. finally {
  7016. schemaObj.compiling = false;
  7017. if (schemaObj.meta) this._opts = currentOpts;
  7018. }
  7019. schemaObj.validate = v;
  7020. schemaObj.refs = v.refs;
  7021. schemaObj.refVal = v.refVal;
  7022. schemaObj.root = v.root;
  7023. return v;
  7024. function callValidate() {
  7025. var _validate = schemaObj.validate;
  7026. var result = _validate.apply(null, arguments);
  7027. callValidate.errors = _validate.errors;
  7028. return result;
  7029. }
  7030. }
  7031. function chooseGetId(opts) {
  7032. switch (opts.schemaId) {
  7033. case '$id': return _get$Id;
  7034. case 'id': return _getId;
  7035. default: return _get$IdOrId;
  7036. }
  7037. }
  7038. function _getId(schema) {
  7039. if (schema.$id) console.warn('schema $id ignored', schema.$id);
  7040. return schema.id;
  7041. }
  7042. function _get$Id(schema) {
  7043. if (schema.id) console.warn('schema id ignored', schema.id);
  7044. return schema.$id;
  7045. }
  7046. function _get$IdOrId(schema) {
  7047. if (schema.$id && schema.id && schema.$id != schema.id)
  7048. throw new Error('schema $id is different from id');
  7049. return schema.$id || schema.id;
  7050. }
  7051. /**
  7052. * Convert array of error message objects to string
  7053. * @this Ajv
  7054. * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
  7055. * @param {Object} options optional options with properties `separator` and `dataVar`.
  7056. * @return {String} human readable string with all errors descriptions
  7057. */
  7058. function errorsText(errors, options) {
  7059. errors = errors || this.errors;
  7060. if (!errors) return 'No errors';
  7061. options = options || {};
  7062. var separator = options.separator === undefined ? ', ' : options.separator;
  7063. var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
  7064. var text = '';
  7065. for (var i=0; i<errors.length; i++) {
  7066. var e = errors[i];
  7067. if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
  7068. }
  7069. return text.slice(0, -separator.length);
  7070. }
  7071. /**
  7072. * Add custom format
  7073. * @this Ajv
  7074. * @param {String} name format name
  7075. * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
  7076. */
  7077. function addFormat(name, format) {
  7078. if (typeof format == 'string') format = new RegExp(format);
  7079. this._formats[name] = format;
  7080. }
  7081. function addDraft6MetaSchema(self) {
  7082. var $dataSchema;
  7083. if (self._opts.$data) {
  7084. $dataSchema = require('./refs/$data.json');
  7085. self.addMetaSchema($dataSchema, $dataSchema.$id, true);
  7086. }
  7087. if (self._opts.meta === false) return;
  7088. var metaSchema = require('./refs/json-schema-draft-06.json');
  7089. if (self._opts.$data) metaSchema = $dataMetaSchema(metaSchema, META_SUPPORT_DATA);
  7090. self.addMetaSchema(metaSchema, META_SCHEMA_ID, true);
  7091. self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID;
  7092. }
  7093. function addInitialSchemas(self) {
  7094. var optsSchemas = self._opts.schemas;
  7095. if (!optsSchemas) return;
  7096. if (Array.isArray(optsSchemas)) self.addSchema(optsSchemas);
  7097. else for (var key in optsSchemas) self.addSchema(optsSchemas[key], key);
  7098. }
  7099. function addInitialFormats(self) {
  7100. for (var name in self._opts.formats) {
  7101. var format = self._opts.formats[name];
  7102. self.addFormat(name, format);
  7103. }
  7104. }
  7105. function checkUnique(self, id) {
  7106. if (self._schemas[id] || self._refs[id])
  7107. throw new Error('schema with key or id "' + id + '" already exists');
  7108. }
  7109. function getMetaSchemaOptions(self) {
  7110. var metaOpts = util.copy(self._opts);
  7111. for (var i=0; i<META_IGNORE_OPTIONS.length; i++)
  7112. delete metaOpts[META_IGNORE_OPTIONS[i]];
  7113. return metaOpts;
  7114. }
  7115. },{"./$data":1,"./cache":2,"./compile":7,"./compile/async":4,"./compile/error_classes":5,"./compile/formats":6,"./compile/resolve":8,"./compile/rules":9,"./compile/schema_obj":10,"./compile/util":12,"./keyword":36,"./patternGroups":37,"./refs/$data.json":38,"./refs/json-schema-draft-06.json":39,"co":40,"json-stable-stringify":43}]},{},[])("ajv")
  7116. });