ajv.bundle.js 264 KB

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