ajv.bundle.js 267 KB

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