ajv.bundle.js 254 KB

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