ajv.bundle.js 260 KB

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