"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x86/node_modules/npm/node_modules/ajv/lib/dot/properties.jst" (14 Feb 2020, 10652 Bytes) of package /windows/www/node-v12.18.4-win-x86.zip:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 {{# def.definitions }}
    2 {{# def.errors }}
    3 {{# def.setupKeyword }}
    4 {{# def.setupNextLevel }}
    5 
    6 
    7 {{## def.validateAdditional:
    8   {{ /* additionalProperties is schema */
    9     $it.schema = $aProperties;
   10     $it.schemaPath = it.schemaPath + '.additionalProperties';
   11     $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
   12     $it.errorPath = it.opts._errorDataPathProperty
   13                     ? it.errorPath
   14                     : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
   15     var $passData = $data + '[' + $key + ']';
   16     $it.dataPathArr[$dataNxt] = $key;
   17   }}
   18 
   19   {{# def.generateSubschemaCode }}
   20   {{# def.optimizeValidate }}
   21 #}}
   22 
   23 
   24 {{
   25   var $key = 'key' + $lvl
   26     , $idx = 'idx' + $lvl
   27     , $dataNxt = $it.dataLevel = it.dataLevel + 1
   28     , $nextData = 'data' + $dataNxt
   29     , $dataProperties = 'dataProperties' + $lvl;
   30 
   31   var $schemaKeys = Object.keys($schema || {})
   32     , $pProperties = it.schema.patternProperties || {}
   33     , $pPropertyKeys = Object.keys($pProperties)
   34     , $aProperties = it.schema.additionalProperties
   35     , $someProperties = $schemaKeys.length || $pPropertyKeys.length
   36     , $noAdditional = $aProperties === false
   37     , $additionalIsSchema = typeof $aProperties == 'object'
   38                               && Object.keys($aProperties).length
   39     , $removeAdditional = it.opts.removeAdditional
   40     , $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional
   41     , $ownProperties = it.opts.ownProperties
   42     , $currentBaseId = it.baseId;
   43 
   44   var $required = it.schema.required;
   45   if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired)
   46     var $requiredHash = it.util.toHash($required);
   47 
   48   if (it.opts.patternGroups) {
   49     var $pgProperties = it.schema.patternGroups || {}
   50       , $pgPropertyKeys = Object.keys($pgProperties);
   51   }
   52 }}
   53 
   54 
   55 var {{=$errs}} = errors;
   56 var {{=$nextValid}} = true;
   57 {{? $ownProperties }}
   58   var {{=$dataProperties}} = undefined;
   59 {{?}}
   60 
   61 {{? $checkAdditional }}
   62   {{# def.iterateProperties }}
   63     {{? $someProperties }}
   64       var isAdditional{{=$lvl}} = !(false
   65         {{? $schemaKeys.length }}
   66           {{? $schemaKeys.length > 5 }}
   67             || validate.schema{{=$schemaPath}}[{{=$key}}]
   68           {{??}}
   69             {{~ $schemaKeys:$propertyKey }}
   70               || {{=$key}} == {{= it.util.toQuotedString($propertyKey) }}
   71             {{~}}
   72           {{?}}
   73         {{?}}
   74         {{? $pPropertyKeys.length }}
   75           {{~ $pPropertyKeys:$pProperty:$i }}
   76             || {{= it.usePattern($pProperty) }}.test({{=$key}})
   77           {{~}}
   78         {{?}}
   79         {{? it.opts.patternGroups && $pgPropertyKeys.length }}
   80           {{~ $pgPropertyKeys:$pgProperty:$i }}
   81             || {{= it.usePattern($pgProperty) }}.test({{=$key}})
   82           {{~}}
   83         {{?}}
   84       );
   85 
   86       if (isAdditional{{=$lvl}}) {
   87     {{?}}
   88     {{? $removeAdditional == 'all' }}
   89       delete {{=$data}}[{{=$key}}];
   90     {{??}}
   91       {{
   92         var $currentErrorPath = it.errorPath;
   93         var $additionalProperty = '\' + ' + $key + ' + \'';
   94         if (it.opts._errorDataPathProperty) {
   95           it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
   96         }
   97       }}
   98       {{? $noAdditional }}
   99         {{? $removeAdditional }}
  100           delete {{=$data}}[{{=$key}}];
  101         {{??}}
  102           {{=$nextValid}} = false;
  103           {{
  104             var $currErrSchemaPath = $errSchemaPath;
  105             $errSchemaPath = it.errSchemaPath + '/additionalProperties';
  106           }}
  107           {{# def.error:'additionalProperties' }}
  108           {{ $errSchemaPath = $currErrSchemaPath; }}
  109           {{? $breakOnError }} break; {{?}}
  110         {{?}}
  111       {{?? $additionalIsSchema }}
  112         {{? $removeAdditional == 'failing' }}
  113           var {{=$errs}} = errors;
  114           {{# def.setCompositeRule }}
  115 
  116           {{# def.validateAdditional }}
  117 
  118           if (!{{=$nextValid}}) {
  119             errors = {{=$errs}};
  120             if (validate.errors !== null) {
  121               if (errors) validate.errors.length = errors;
  122               else validate.errors = null;
  123             }
  124             delete {{=$data}}[{{=$key}}];
  125           }
  126 
  127           {{# def.resetCompositeRule }}
  128         {{??}}
  129           {{# def.validateAdditional }}
  130           {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
  131         {{?}}
  132       {{?}}
  133       {{ it.errorPath = $currentErrorPath; }}
  134     {{?}}
  135     {{? $someProperties }}
  136       }
  137     {{?}}
  138   }
  139 
  140   {{# def.ifResultValid }}
  141 {{?}}
  142 
  143 {{ var $useDefaults = it.opts.useDefaults && !it.compositeRule; }}
  144 
  145 {{? $schemaKeys.length }}
  146   {{~ $schemaKeys:$propertyKey }}
  147     {{ var $sch = $schema[$propertyKey]; }}
  148 
  149     {{? {{# def.nonEmptySchema:$sch}} }}
  150       {{
  151         var $prop = it.util.getProperty($propertyKey)
  152           , $passData = $data + $prop
  153           , $hasDefault = $useDefaults && $sch.default !== undefined;
  154         $it.schema = $sch;
  155         $it.schemaPath = $schemaPath + $prop;
  156         $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
  157         $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
  158         $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
  159       }}
  160 
  161       {{# def.generateSubschemaCode }}
  162 
  163       {{? {{# def.willOptimize }} }}
  164         {{
  165           $code = {{# def._optimizeValidate }};
  166           var $useData = $passData;
  167         }}
  168       {{??}}
  169         {{ var $useData = $nextData; }}
  170         var {{=$nextData}} = {{=$passData}};
  171       {{?}}
  172 
  173       {{? $hasDefault }}
  174         {{= $code }}
  175       {{??}}
  176         {{? $requiredHash && $requiredHash[$propertyKey] }}
  177           if ({{# def.noPropertyInData }}) {
  178             {{=$nextValid}} = false;
  179             {{
  180               var $currentErrorPath = it.errorPath
  181                 , $currErrSchemaPath = $errSchemaPath
  182                 , $missingProperty = it.util.escapeQuotes($propertyKey);
  183               if (it.opts._errorDataPathProperty) {
  184                 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
  185               }
  186               $errSchemaPath = it.errSchemaPath + '/required';
  187             }}
  188             {{# def.error:'required' }}
  189             {{ $errSchemaPath = $currErrSchemaPath; }}
  190             {{ it.errorPath = $currentErrorPath; }}
  191           } else {
  192         {{??}}
  193           {{? $breakOnError }}
  194             if ({{# def.noPropertyInData }}) {
  195               {{=$nextValid}} = true;
  196             } else {
  197           {{??}}
  198             if ({{=$useData}} !== undefined
  199               {{? $ownProperties }}
  200                 && {{# def.isOwnProperty }}
  201               {{?}}
  202             ) {
  203           {{?}}
  204         {{?}}
  205 
  206           {{= $code }}
  207         }
  208       {{?}}  {{ /* $hasDefault */ }}
  209     {{?}} {{ /* def.nonEmptySchema */ }}
  210 
  211     {{# def.ifResultValid }}
  212   {{~}}
  213 {{?}}
  214 
  215 {{? $pPropertyKeys.length }}
  216   {{~ $pPropertyKeys:$pProperty }}
  217     {{ var $sch = $pProperties[$pProperty]; }}
  218 
  219     {{? {{# def.nonEmptySchema:$sch}} }}
  220       {{
  221         $it.schema = $sch;
  222         $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
  223         $it.errSchemaPath = it.errSchemaPath + '/patternProperties/'
  224                                              + it.util.escapeFragment($pProperty);
  225       }}
  226 
  227       {{# def.iterateProperties }}
  228         if ({{= it.usePattern($pProperty) }}.test({{=$key}})) {
  229           {{
  230             $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  231             var $passData = $data + '[' + $key + ']';
  232             $it.dataPathArr[$dataNxt] = $key;
  233           }}
  234 
  235           {{# def.generateSubschemaCode }}
  236           {{# def.optimizeValidate }}
  237 
  238           {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
  239         }
  240         {{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
  241       }
  242 
  243       {{# def.ifResultValid }}
  244     {{?}} {{ /* def.nonEmptySchema */ }}
  245   {{~}}
  246 {{?}}
  247 
  248 
  249 {{? it.opts.patternGroups && $pgPropertyKeys.length }}
  250   {{~ $pgPropertyKeys:$pgProperty }}
  251     {{
  252       var $pgSchema = $pgProperties[$pgProperty]
  253         , $sch = $pgSchema.schema;
  254     }}
  255 
  256     {{? {{# def.nonEmptySchema:$sch}} }}
  257       {{
  258         $it.schema = $sch;
  259         $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema';
  260         $it.errSchemaPath = it.errSchemaPath + '/patternGroups/'
  261                                              + it.util.escapeFragment($pgProperty)
  262                                              + '/schema';
  263       }}
  264 
  265       var pgPropCount{{=$lvl}} = 0;
  266 
  267       {{# def.iterateProperties }}
  268         if ({{= it.usePattern($pgProperty) }}.test({{=$key}})) {
  269           pgPropCount{{=$lvl}}++;
  270 
  271           {{
  272             $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  273             var $passData = $data + '[' + $key + ']';
  274             $it.dataPathArr[$dataNxt] = $key;
  275           }}
  276 
  277           {{# def.generateSubschemaCode }}
  278           {{# def.optimizeValidate }}
  279 
  280           {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
  281         }
  282         {{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
  283       }
  284 
  285       {{# def.ifResultValid }}
  286 
  287       {{
  288         var $pgMin = $pgSchema.minimum
  289           , $pgMax = $pgSchema.maximum;
  290       }}
  291       {{? $pgMin !== undefined || $pgMax !== undefined }}
  292         var {{=$valid}} = true;
  293 
  294         {{ var $currErrSchemaPath = $errSchemaPath; }}
  295 
  296         {{? $pgMin !== undefined }}
  297           {{ var $limit = $pgMin, $reason = 'minimum', $moreOrLess = 'less'; }}
  298           {{=$valid}} = pgPropCount{{=$lvl}} >= {{=$pgMin}};
  299           {{ $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum'; }}
  300           {{# def.checkError:'patternGroups' }}
  301           {{? $pgMax !== undefined }}
  302             else
  303           {{?}}
  304         {{?}}
  305 
  306         {{? $pgMax !== undefined }}
  307           {{ var $limit = $pgMax, $reason = 'maximum', $moreOrLess = 'more'; }}
  308           {{=$valid}} = pgPropCount{{=$lvl}} <= {{=$pgMax}};
  309           {{ $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum'; }}
  310           {{# def.checkError:'patternGroups' }}
  311         {{?}}
  312 
  313         {{ $errSchemaPath = $currErrSchemaPath; }}
  314 
  315         {{# def.ifValid }}
  316       {{?}}
  317     {{?}} {{ /* def.nonEmptySchema */ }}
  318   {{~}}
  319 {{?}}
  320 
  321 
  322 {{? $breakOnError }}
  323   {{= $closingBraces }}
  324   if ({{=$errs}} == errors) {
  325 {{?}}
  326 
  327 {{# def.cleanUp }}