UNPKG

2.72 kBJavaScriptView Raw
1import { getMetadataStorage } from './metadata/MetadataStorage';
2import { Validator } from './validation/Validator';
3import { getFromContainer } from './container';
4// -------------------------------------------------------------------------
5// Export everything api users needs
6// -------------------------------------------------------------------------
7export * from './container';
8export * from './decorator/decorators';
9export * from './decorator/ValidationOptions';
10export * from './validation/ValidatorConstraintInterface';
11export * from './validation/ValidationError';
12export * from './validation/ValidatorOptions';
13export * from './validation/ValidationArguments';
14export * from './validation/ValidationTypes';
15export * from './validation/Validator';
16export * from './validation-schema/ValidationSchema';
17export * from './register-decorator';
18export * from './metadata/MetadataStorage';
19/**
20 * Validates given object by object's decorators or given validation schema.
21 */
22export function validate(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions) {
23 if (typeof schemaNameOrObject === 'string') {
24 return getFromContainer(Validator).validate(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions);
25 }
26 else {
27 return getFromContainer(Validator).validate(schemaNameOrObject, objectOrValidationOptions);
28 }
29}
30/**
31 * Validates given object by object's decorators or given validation schema and reject on error.
32 */
33export function validateOrReject(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions) {
34 if (typeof schemaNameOrObject === 'string') {
35 return getFromContainer(Validator).validateOrReject(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions);
36 }
37 else {
38 return getFromContainer(Validator).validateOrReject(schemaNameOrObject, objectOrValidationOptions);
39 }
40}
41/**
42 * Validates given object by object's decorators or given validation schema.
43 * Note that this method completely ignores async validations.
44 * If you want to properly perform validation you need to call validate method instead.
45 */
46export function validateSync(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions) {
47 if (typeof schemaNameOrObject === 'string') {
48 return getFromContainer(Validator).validateSync(schemaNameOrObject, objectOrValidationOptions, maybeValidatorOptions);
49 }
50 else {
51 return getFromContainer(Validator).validateSync(schemaNameOrObject, objectOrValidationOptions);
52 }
53}
54/**
55 * Registers a new validation schema.
56 */
57export function registerSchema(schema) {
58 getMetadataStorage().addValidationSchema(schema);
59}
60//# sourceMappingURL=index.js.map
\No newline at end of file