ajv-4.1.1.js 261 KB

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