ajv.bundle.js 267 KB

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