twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

errors.def (8282B)


      1 {{# def.definitions }}
      2 
      3 {{## def._error:_rule:
      4   {{ 'istanbul ignore else'; }}
      5   {{? it.createErrors !== false }}
      6     {
      7       keyword: '{{= $errorKeyword || _rule }}'
      8       , dataPath: (dataPath || '') + {{= it.errorPath }}
      9       , schemaPath: {{=it.util.toQuotedString($errSchemaPath)}}
     10       , params: {{# def._errorParams[_rule] }}
     11       {{? it.opts.messages !== false }}
     12         , message: {{# def._errorMessages[_rule] }}
     13       {{?}}
     14       {{? it.opts.verbose }}
     15         , schema: {{# def._errorSchemas[_rule] }}
     16         , parentSchema: validate.schema{{=it.schemaPath}}
     17         , data: {{=$data}}
     18       {{?}}
     19     }
     20   {{??}}
     21     {}
     22   {{?}}
     23 #}}
     24 
     25 
     26 {{## def._addError:_rule:
     27   if (vErrors === null) vErrors = [err];
     28   else vErrors.push(err);
     29   errors++;
     30 #}}
     31 
     32 
     33 {{## def.addError:_rule:
     34   var err = {{# def._error:_rule }};
     35   {{# def._addError:_rule }}
     36 #}}
     37 
     38 
     39 {{## def.error:_rule:
     40   {{# def.beginDefOut}}
     41     {{# def._error:_rule }}
     42   {{# def.storeDefOut:__err }}
     43 
     44   {{? !it.compositeRule && $breakOnError }}
     45     {{ 'istanbul ignore if'; }}
     46     {{? it.async }}
     47       throw new ValidationError([{{=__err}}]);
     48     {{??}}
     49       validate.errors = [{{=__err}}];
     50       return false;
     51     {{?}}
     52   {{??}}
     53     var err = {{=__err}};
     54     {{# def._addError:_rule }}
     55   {{?}}
     56 #}}
     57 
     58 
     59 {{## def.extraError:_rule:
     60   {{# def.addError:_rule}}
     61   {{? !it.compositeRule && $breakOnError }}
     62     {{ 'istanbul ignore if'; }}
     63     {{? it.async }}
     64       throw new ValidationError(vErrors);
     65     {{??}}
     66       validate.errors = vErrors;
     67       return false;
     68     {{?}}
     69   {{?}}
     70 #}}
     71 
     72 
     73 {{## def.checkError:_rule:
     74   if (!{{=$valid}}) {
     75     {{# def.error:_rule }}
     76   }
     77 #}}
     78 
     79 
     80 {{## def.resetErrors:
     81   errors = {{=$errs}};
     82   if (vErrors !== null) {
     83     if ({{=$errs}}) vErrors.length = {{=$errs}};
     84     else vErrors = null;
     85   }
     86 #}}
     87 
     88 
     89 {{## def.concatSchema:{{?$isData}}' + {{=$schemaValue}} + '{{??}}{{=$schema}}{{?}}#}}
     90 {{## def.appendSchema:{{?$isData}}' + {{=$schemaValue}}{{??}}{{=$schemaValue}}'{{?}}#}}
     91 {{## def.concatSchemaEQ:{{?$isData}}' + {{=$schemaValue}} + '{{??}}{{=it.util.escapeQuotes($schema)}}{{?}}#}}
     92 
     93 {{## def._errorMessages = {
     94   'false schema':  "'boolean schema is false'",
     95   $ref:            "'can\\\'t resolve reference {{=it.util.escapeQuotes($schema)}}'",
     96   additionalItems: "'should NOT have more than {{=$schema.length}} items'",
     97   additionalProperties: "'{{? it.opts._errorDataPathProperty }}is an invalid additional property{{??}}should NOT have additional properties{{?}}'",
     98   anyOf:           "'should match some schema in anyOf'",
     99   const:           "'should be equal to constant'",
    100   contains:        "'should contain a valid item'",
    101   dependencies:    "'should have {{? $deps.length == 1 }}property {{= it.util.escapeQuotes($deps[0]) }}{{??}}properties {{= it.util.escapeQuotes($deps.join(\", \")) }}{{?}} when property {{= it.util.escapeQuotes($property) }} is present'",
    102   'enum':          "'should be equal to one of the allowed values'",
    103   format:          "'should match format \"{{#def.concatSchemaEQ}}\"'",
    104   'if':            "'should match \"' + {{=$ifClause}} + '\" schema'",
    105   _limit:          "'should be {{=$opStr}} {{#def.appendSchema}}",
    106   _exclusiveLimit: "'{{=$exclusiveKeyword}} should be boolean'",
    107   _limitItems:     "'should NOT have {{?$keyword=='maxItems'}}more{{??}}fewer{{?}} than {{#def.concatSchema}} items'",
    108   _limitLength:    "'should NOT be {{?$keyword=='maxLength'}}longer{{??}}shorter{{?}} than {{#def.concatSchema}} characters'",
    109   _limitProperties:"'should NOT have {{?$keyword=='maxProperties'}}more{{??}}fewer{{?}} than {{#def.concatSchema}} properties'",
    110   multipleOf:      "'should be multiple of {{#def.appendSchema}}",
    111   not:             "'should NOT be valid'",
    112   oneOf:           "'should match exactly one schema in oneOf'",
    113   pattern:         "'should match pattern \"{{#def.concatSchemaEQ}}\"'",
    114   propertyNames:   "'property name \\'{{=$invalidName}}\\' is invalid'",
    115   required:        "'{{? it.opts._errorDataPathProperty }}is a required property{{??}}should have required property \\'{{=$missingProperty}}\\'{{?}}'",
    116   type:            "'should be {{? $typeIsArray }}{{= $typeSchema.join(\",\") }}{{??}}{{=$typeSchema}}{{?}}'",
    117   uniqueItems:     "'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)'",
    118   custom:          "'should pass \"{{=$rule.keyword}}\" keyword validation'",
    119   patternRequired: "'should have property matching pattern \\'{{=$missingPattern}}\\''",
    120   switch:          "'should pass \"switch\" keyword validation'",
    121   _formatLimit:    "'should be {{=$opStr}} \"{{#def.concatSchemaEQ}}\"'",
    122   _formatExclusiveLimit: "'{{=$exclusiveKeyword}} should be boolean'"
    123 } #}}
    124 
    125 
    126 {{## def.schemaRefOrVal: {{?$isData}}validate.schema{{=$schemaPath}}{{??}}{{=$schema}}{{?}} #}}
    127 {{## def.schemaRefOrQS: {{?$isData}}validate.schema{{=$schemaPath}}{{??}}{{=it.util.toQuotedString($schema)}}{{?}} #}}
    128 
    129 {{## def._errorSchemas = {
    130   'false schema':  "false",
    131   $ref:            "{{=it.util.toQuotedString($schema)}}",
    132   additionalItems: "false",
    133   additionalProperties: "false",
    134   anyOf:           "validate.schema{{=$schemaPath}}",
    135   const:           "validate.schema{{=$schemaPath}}",
    136   contains:        "validate.schema{{=$schemaPath}}",
    137   dependencies:    "validate.schema{{=$schemaPath}}",
    138   'enum':          "validate.schema{{=$schemaPath}}",
    139   format:          "{{#def.schemaRefOrQS}}",
    140   'if':            "validate.schema{{=$schemaPath}}",
    141   _limit:          "{{#def.schemaRefOrVal}}",
    142   _exclusiveLimit: "validate.schema{{=$schemaPath}}",
    143   _limitItems:     "{{#def.schemaRefOrVal}}",
    144   _limitLength:    "{{#def.schemaRefOrVal}}",
    145   _limitProperties:"{{#def.schemaRefOrVal}}",
    146   multipleOf:      "{{#def.schemaRefOrVal}}",
    147   not:             "validate.schema{{=$schemaPath}}",
    148   oneOf:           "validate.schema{{=$schemaPath}}",
    149   pattern:         "{{#def.schemaRefOrQS}}",
    150   propertyNames:   "validate.schema{{=$schemaPath}}",
    151   required:        "validate.schema{{=$schemaPath}}",
    152   type:            "validate.schema{{=$schemaPath}}",
    153   uniqueItems:     "{{#def.schemaRefOrVal}}",
    154   custom:          "validate.schema{{=$schemaPath}}",
    155   patternRequired: "validate.schema{{=$schemaPath}}",
    156   switch:          "validate.schema{{=$schemaPath}}",
    157   _formatLimit:    "{{#def.schemaRefOrQS}}",
    158   _formatExclusiveLimit: "validate.schema{{=$schemaPath}}"
    159 } #}}
    160 
    161 
    162 {{## def.schemaValueQS: {{?$isData}}{{=$schemaValue}}{{??}}{{=it.util.toQuotedString($schema)}}{{?}} #}}
    163 
    164 {{## def._errorParams = {
    165   'false schema':  "{}",
    166   $ref:            "{ ref: '{{=it.util.escapeQuotes($schema)}}' }",
    167   additionalItems: "{ limit: {{=$schema.length}} }",
    168   additionalProperties: "{ additionalProperty: '{{=$additionalProperty}}' }",
    169   anyOf:           "{}",
    170   const:           "{ allowedValue: schema{{=$lvl}} }",
    171   contains:        "{}",
    172   dependencies:    "{ property: '{{= it.util.escapeQuotes($property) }}', missingProperty: '{{=$missingProperty}}', depsCount: {{=$deps.length}}, deps: '{{= it.util.escapeQuotes($deps.length==1 ? $deps[0] : $deps.join(\", \")) }}' }",
    173   'enum':          "{ allowedValues: schema{{=$lvl}} }",
    174   format:          "{ format: {{#def.schemaValueQS}} }",
    175   'if':            "{ failingKeyword: {{=$ifClause}} }",
    176   _limit:          "{ comparison: {{=$opExpr}}, limit: {{=$schemaValue}}, exclusive: {{=$exclusive}} }",
    177   _exclusiveLimit: "{}",
    178   _limitItems:     "{ limit: {{=$schemaValue}} }",
    179   _limitLength:    "{ limit: {{=$schemaValue}} }",
    180   _limitProperties:"{ limit: {{=$schemaValue}} }",
    181   multipleOf:      "{ multipleOf: {{=$schemaValue}} }",
    182   not:             "{}",
    183   oneOf:           "{ passingSchemas: {{=$passingSchemas}} }",
    184   pattern:         "{ pattern: {{#def.schemaValueQS}} }",
    185   propertyNames:   "{ propertyName: '{{=$invalidName}}' }",
    186   required:        "{ missingProperty: '{{=$missingProperty}}' }",
    187   type:            "{ type: '{{? $typeIsArray }}{{= $typeSchema.join(\",\") }}{{??}}{{=$typeSchema}}{{?}}' }",
    188   uniqueItems:     "{ i: i, j: j }",
    189   custom:          "{ keyword: '{{=$rule.keyword}}' }",
    190   patternRequired: "{ missingPattern: '{{=$missingPattern}}' }",
    191   switch:          "{ caseIndex: {{=$caseIndex}} }",
    192   _formatLimit:    "{ comparison: {{=$opExpr}}, limit: {{#def.schemaValueQS}}, exclusive: {{=$exclusive}} }",
    193   _formatExclusiveLimit: "{}"
    194 } #}}