ajv.bundle.js 261 KB

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