ajv.bundle.js 263 KB

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