schema.d.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { ValidationChain, ValidatorOptions, CustomValidator } from './check';
  2. import { Location } from './location';
  3. import { CustomSanitizer } from '../filter/sanitize';
  4. export function checkSchema(schema: ValidationSchema): ValidationChain[];
  5. type ValidationSchema = Record<string, ValidationParamSchema>;
  6. type ValidatorSchemaOptions<T = any> = true | {
  7. options?: T | T[];
  8. errorMessage?: any;
  9. negated?: boolean;
  10. };
  11. type SanitizerSchemaOptions<T = any> = true | {
  12. options?: T | T[];
  13. };
  14. interface ValidationParamSchema extends ValidatorsSchema, SanitizersSchema {
  15. in: Location | Location[],
  16. errorMessage?: any
  17. custom?: ValidatorSchemaOptions<CustomValidator>;
  18. exists?: ValidatorSchemaOptions<ValidatorOptions.ExistsOptions>;
  19. optional?: boolean | ValidatorOptions.OptionalOptions;
  20. customSanitizer?: SanitizerSchemaOptions<CustomSanitizer>;
  21. }
  22. interface ValidatorsSchema {
  23. contains?: ValidatorSchemaOptions;
  24. equals?: ValidatorSchemaOptions;
  25. isAfter?: ValidatorSchemaOptions;
  26. isAlpha?: ValidatorSchemaOptions;
  27. isAlphanumeric?: ValidatorSchemaOptions;
  28. isArray?: ValidatorSchemaOptions;
  29. isAscii?: ValidatorSchemaOptions;
  30. isBase64?: ValidatorSchemaOptions;
  31. isBefore?: ValidatorSchemaOptions;
  32. isBoolean?: ValidatorSchemaOptions;
  33. isByteLength?: ValidatorSchemaOptions;
  34. isCreditCard?: ValidatorSchemaOptions;
  35. isCurrency?: ValidatorSchemaOptions;
  36. isDataURI?: ValidatorSchemaOptions;
  37. isDecimal?: ValidatorSchemaOptions;
  38. isDivisibleBy?: ValidatorSchemaOptions;
  39. isEmail?: ValidatorSchemaOptions;
  40. isEmpty?: ValidatorSchemaOptions;
  41. isFloat?: ValidatorSchemaOptions;
  42. isFQDN?: ValidatorSchemaOptions;
  43. isFullWidth?: ValidatorSchemaOptions;
  44. isHalfWidth?: ValidatorSchemaOptions;
  45. isHash?: ValidatorSchemaOptions;
  46. isHexadecimal?: ValidatorSchemaOptions;
  47. isHexColor?: ValidatorSchemaOptions;
  48. isIn?: ValidatorSchemaOptions;
  49. isInt?: ValidatorSchemaOptions;
  50. isIP?: ValidatorSchemaOptions;
  51. isIPRange?: ValidatorSchemaOptions;
  52. isISIN?: ValidatorSchemaOptions;
  53. isISO31661Alpha2?: ValidatorSchemaOptions;
  54. isISO31661Alpha3?: ValidatorSchemaOptions;
  55. isISO8601?: ValidatorSchemaOptions;
  56. isISRC?: ValidatorSchemaOptions;
  57. isISBN?: ValidatorSchemaOptions;
  58. isISSN?: ValidatorSchemaOptions;
  59. isJSON?: ValidatorSchemaOptions;
  60. isNumeric?: ValidatorSchemaOptions;
  61. isLatLong?: ValidatorSchemaOptions;
  62. isLength?: ValidatorSchemaOptions;
  63. isLowercase?: ValidatorSchemaOptions;
  64. isMACAddress?: ValidatorSchemaOptions;
  65. isMD5?: ValidatorSchemaOptions;
  66. isMimeType?: ValidatorSchemaOptions;
  67. isMobilePhone?: ValidatorSchemaOptions;
  68. isMongoId?: ValidatorSchemaOptions;
  69. isMultibyte?: ValidatorSchemaOptions;
  70. isPostalCode?: ValidatorSchemaOptions;
  71. isPort?: ValidatorSchemaOptions;
  72. isString?: ValidatorSchemaOptions;
  73. isSurrogatePair?: ValidatorSchemaOptions;
  74. isUppercase?: ValidatorSchemaOptions;
  75. isURL?: ValidatorSchemaOptions;
  76. isUUID?: ValidatorSchemaOptions;
  77. isVariableWidth?: ValidatorSchemaOptions;
  78. isWhitelisted?: ValidatorSchemaOptions;
  79. matches?: ValidatorSchemaOptions;
  80. }
  81. interface SanitizersSchema {
  82. blacklist?: SanitizerSchemaOptions;
  83. escape?: true;
  84. unescape?: true;
  85. ltrim?: true | SanitizerSchemaOptions;
  86. normalizeEmail?: true | SanitizerSchemaOptions;
  87. rtrim?: true | SanitizerSchemaOptions;
  88. stripLow?: true | SanitizerSchemaOptions;
  89. toBoolean?: true | SanitizerSchemaOptions;
  90. toDate?: true;
  91. toFloat?: true;
  92. toInt?: true | SanitizerSchemaOptions;
  93. trim?: true | SanitizerSchemaOptions;
  94. whitelist?: true | SanitizerSchemaOptions;
  95. }