index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __exportStar = (this && this.__exportStar) || function(m, exports) {
  14. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  15. };
  16. Object.defineProperty(exports, "__esModule", { value: true });
  17. exports.registerSchema = exports.validateSync = exports.validateOrReject = exports.validate = void 0;
  18. const MetadataStorage_1 = require("./metadata/MetadataStorage");
  19. const Validator_1 = require("./validation/Validator");
  20. const container_1 = require("./container");
  21. // -------------------------------------------------------------------------
  22. // Export everything api users needs
  23. // -------------------------------------------------------------------------
  24. __exportStar(require("./container"), exports);
  25. __exportStar(require("./decorator/decorators"), exports);
  26. __exportStar(require("./decorator/ValidationOptions"), exports);
  27. __exportStar(require("./validation/ValidatorConstraintInterface"), exports);
  28. __exportStar(require("./validation/ValidationError"), exports);
  29. __exportStar(require("./validation/ValidatorOptions"), exports);
  30. __exportStar(require("./validation/ValidationArguments"), exports);
  31. __exportStar(require("./validation/ValidationTypes"), exports);
  32. __exportStar(require("./validation/Validator"), exports);
  33. __exportStar(require("./validation-schema/ValidationSchema"), exports);
  34. __exportStar(require("./register-decorator"), exports);
  35. __exportStar(require("./metadata/MetadataStorage"), exports);
  36. /**
  37. * Validates given object by object's decorators or given validation schema.
  38. */
  39. function validate(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions) {
  40. if (typeof schemaNameOrObject === 'string') {
  41. return (0, container_1.getFromContainer)(Validator_1.Validator).validate(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions);
  42. }
  43. else {
  44. return (0, container_1.getFromContainer)(Validator_1.Validator).validate(schemaNameOrObject, objectOrValidationOptions);
  45. }
  46. }
  47. exports.validate = validate;
  48. /**
  49. * Validates given object by object's decorators or given validation schema and reject on error.
  50. */
  51. function validateOrReject(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions) {
  52. if (typeof schemaNameOrObject === 'string') {
  53. return (0, container_1.getFromContainer)(Validator_1.Validator).validateOrReject(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions);
  54. }
  55. else {
  56. return (0, container_1.getFromContainer)(Validator_1.Validator).validateOrReject(schemaNameOrObject, objectOrValidationOptions);
  57. }
  58. }
  59. exports.validateOrReject = validateOrReject;
  60. /**
  61. * Validates given object by object's decorators or given validation schema.
  62. * Note that this method completely ignores async validations.
  63. * If you want to properly perform validation you need to call validate method instead.
  64. */
  65. function validateSync(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions) {
  66. if (typeof schemaNameOrObject === 'string') {
  67. return (0, container_1.getFromContainer)(Validator_1.Validator).validateSync(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions);
  68. }
  69. else {
  70. return (0, container_1.getFromContainer)(Validator_1.Validator).validateSync(schemaNameOrObject, objectOrValidationOptions);
  71. }
  72. }
  73. exports.validateSync = validateSync;
  74. /**
  75. * Registers a new validation schema.
  76. */
  77. function registerSchema(schema) {
  78. (0, MetadataStorage_1.getMetadataStorage)().addValidationSchema(schema);
  79. }
  80. exports.registerSchema = registerSchema;
  81. //# sourceMappingURL=index.js.map