backend v4 half
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2015-2020 TypeStack
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+949
@@ -0,0 +1,949 @@
|
||||
# class-validator
|
||||
|
||||

|
||||
[](https://codecov.io/gh/typestack/class-validator)
|
||||
[](https://badge.fury.io/js/class-validator)
|
||||
[](https://packagephobia.now.sh/result?p=class-validator)
|
||||
|
||||
Allows use of decorator and non-decorator based validation.
|
||||
Internally uses [validator.js][1] to perform validation.
|
||||
Class-validator works on both browser and node.js platforms.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [class-validator](#class-validator)
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Passing options](#passing-options)
|
||||
- [Validation errors](#validation-errors)
|
||||
- [Validation messages](#validation-messages)
|
||||
- [Validating arrays](#validating-arrays)
|
||||
- [Validating sets](#validating-sets)
|
||||
- [Validating maps](#validating-maps)
|
||||
- [Validating nested objects](#validating-nested-objects)
|
||||
- [Validating promises](#validating-promises)
|
||||
- [Inheriting Validation decorators](#inheriting-validation-decorators)
|
||||
- [Conditional validation](#conditional-validation)
|
||||
- [Whitelisting](#whitelisting)
|
||||
- [Passing context to decorators](#passing-context-to-decorators)
|
||||
- [Skipping missing properties](#skipping-missing-properties)
|
||||
- [Validation groups](#validation-groups)
|
||||
- [Custom validation classes](#custom-validation-classes)
|
||||
- [Custom validation decorators](#custom-validation-decorators)
|
||||
- [Using service container](#using-service-container)
|
||||
- [Synchronous validation](#synchronous-validation)
|
||||
- [Manual validation](#manual-validation)
|
||||
- [Validation decorators](#validation-decorators)
|
||||
- [Defining validation schema without decorators](#defining-validation-schema-without-decorators)
|
||||
- [Validating plain objects](#validating-plain-objects)
|
||||
- [Samples](#samples)
|
||||
- [Extensions](#extensions)
|
||||
- [Release notes](#release-notes)
|
||||
- [Contributing](#contributing)
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install class-validator --save
|
||||
```
|
||||
|
||||
> Note: Please use at least npm@6 when using class-validator. From npm@6 the dependency tree is flattened, which is required by `class-validator` to function properly.
|
||||
|
||||
## Usage
|
||||
|
||||
Create your class and put some validation decorators on the properties you want to validate:
|
||||
|
||||
```typescript
|
||||
import {
|
||||
validate,
|
||||
validateOrReject,
|
||||
Contains,
|
||||
IsInt,
|
||||
Length,
|
||||
IsEmail,
|
||||
IsFQDN,
|
||||
IsDate,
|
||||
Min,
|
||||
Max,
|
||||
} from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@Length(10, 20)
|
||||
title: string;
|
||||
|
||||
@Contains('hello')
|
||||
text: string;
|
||||
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
@Max(10)
|
||||
rating: number;
|
||||
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@IsFQDN()
|
||||
site: string;
|
||||
|
||||
@IsDate()
|
||||
createDate: Date;
|
||||
}
|
||||
|
||||
let post = new Post();
|
||||
post.title = 'Hello'; // should not pass
|
||||
post.text = 'this is a great post about hell world'; // should not pass
|
||||
post.rating = 11; // should not pass
|
||||
post.email = 'google.com'; // should not pass
|
||||
post.site = 'googlecom'; // should not pass
|
||||
|
||||
validate(post).then(errors => {
|
||||
// errors is an array of validation errors
|
||||
if (errors.length > 0) {
|
||||
console.log('validation failed. errors: ', errors);
|
||||
} else {
|
||||
console.log('validation succeed');
|
||||
}
|
||||
});
|
||||
|
||||
validateOrReject(post).catch(errors => {
|
||||
console.log('Promise rejected (validation failed). Errors: ', errors);
|
||||
});
|
||||
// or
|
||||
async function validateOrRejectExample(input) {
|
||||
try {
|
||||
await validateOrReject(input);
|
||||
} catch (errors) {
|
||||
console.log('Caught promise rejection (validation failed). Errors: ', errors);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Passing options
|
||||
|
||||
The `validate` function optionally expects a `ValidatorOptions` object as a second parameter:
|
||||
|
||||
```ts
|
||||
export interface ValidatorOptions {
|
||||
skipMissingProperties?: boolean;
|
||||
whitelist?: boolean;
|
||||
forbidNonWhitelisted?: boolean;
|
||||
groups?: string[];
|
||||
dismissDefaultMessages?: boolean;
|
||||
validationError?: {
|
||||
target?: boolean;
|
||||
value?: boolean;
|
||||
};
|
||||
|
||||
forbidUnknownValues?: boolean;
|
||||
stopAtFirstError?: boolean;
|
||||
}
|
||||
```
|
||||
|
||||
> **IMPORTANT**
|
||||
> The `forbidUnknownValues` value is set to `true` by default and **it is highly advised to keep the default**.
|
||||
> Setting it to `false` will result unknown objects passing the validation!
|
||||
|
||||
## Validation errors
|
||||
|
||||
The `validate` method returns an array of `ValidationError` objects. Each `ValidationError` is:
|
||||
|
||||
```typescript
|
||||
{
|
||||
target: Object; // Object that was validated.
|
||||
property: string; // Object's property that haven't pass validation.
|
||||
value: any; // Value that haven't pass a validation.
|
||||
constraints?: { // Constraints that failed validation with error messages.
|
||||
[type: string]: string;
|
||||
};
|
||||
children?: ValidationError[]; // Contains all nested validation errors of the property
|
||||
}
|
||||
```
|
||||
|
||||
In our case, when we validated a Post object, we have such an array of `ValidationError` objects:
|
||||
|
||||
```typescript
|
||||
[{
|
||||
target: /* post object */,
|
||||
property: "title",
|
||||
value: "Hello",
|
||||
constraints: {
|
||||
length: "$property must be longer than or equal to 10 characters"
|
||||
}
|
||||
}, {
|
||||
target: /* post object */,
|
||||
property: "text",
|
||||
value: "this is a great post about hell world",
|
||||
constraints: {
|
||||
contains: "text must contain a hello string"
|
||||
}
|
||||
},
|
||||
// and other errors
|
||||
]
|
||||
```
|
||||
|
||||
If you don't want a `target` to be exposed in validation errors, there is a special option when you use validator:
|
||||
|
||||
```typescript
|
||||
validator.validate(post, { validationError: { target: false } });
|
||||
```
|
||||
|
||||
This is especially useful when you send errors back over http, and you most probably don't want to expose
|
||||
the whole target object.
|
||||
|
||||
## Validation messages
|
||||
|
||||
You can specify validation message in the decorator options and that message will be returned in the `ValidationError`
|
||||
returned by the `validate` method (in the case that validation for this field fails).
|
||||
|
||||
```typescript
|
||||
import { MinLength, MaxLength } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@MinLength(10, {
|
||||
message: 'Title is too short',
|
||||
})
|
||||
@MaxLength(50, {
|
||||
message: 'Title is too long',
|
||||
})
|
||||
title: string;
|
||||
}
|
||||
```
|
||||
|
||||
There are few special tokens you can use in your messages:
|
||||
|
||||
- `$value` - the value that is being validated
|
||||
- `$property` - name of the object's property being validated
|
||||
- `$target` - name of the object's class being validated
|
||||
- `$constraint1`, `$constraint2`, ... `$constraintN` - constraints defined by specific validation type
|
||||
|
||||
Example of usage:
|
||||
|
||||
```typescript
|
||||
import { MinLength, MaxLength } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@MinLength(10, {
|
||||
// here, $constraint1 will be replaced with "10", and $value with actual supplied value
|
||||
message: 'Title is too short. Minimal length is $constraint1 characters, but actual is $value',
|
||||
})
|
||||
@MaxLength(50, {
|
||||
// here, $constraint1 will be replaced with "50", and $value with actual supplied value
|
||||
message: 'Title is too long. Maximal length is $constraint1 characters, but actual is $value',
|
||||
})
|
||||
title: string;
|
||||
}
|
||||
```
|
||||
|
||||
Also you can provide a function, that returns a message. This allows you to create more granular messages:
|
||||
|
||||
```typescript
|
||||
import { MinLength, MaxLength, ValidationArguments } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@MinLength(10, {
|
||||
message: (args: ValidationArguments) => {
|
||||
if (args.value.length === 1) {
|
||||
return 'Too short, minimum length is 1 character';
|
||||
} else {
|
||||
return 'Too short, minimum length is ' + args.constraints[0] + ' characters';
|
||||
}
|
||||
},
|
||||
})
|
||||
title: string;
|
||||
}
|
||||
```
|
||||
|
||||
Message function accepts `ValidationArguments` which contains the following information:
|
||||
|
||||
- `value` - the value that is being validated
|
||||
- `constraints` - array of constraints defined by specific validation type
|
||||
- `targetName` - name of the object's class being validated
|
||||
- `object` - object that is being validated
|
||||
- `property` - name of the object's property being validated
|
||||
|
||||
## Validating arrays
|
||||
|
||||
If your field is an array and you want to perform validation of each item in the array you must specify a
|
||||
special `each: true` decorator option:
|
||||
|
||||
```typescript
|
||||
import { MinLength, MaxLength } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@MaxLength(20, {
|
||||
each: true,
|
||||
})
|
||||
tags: string[];
|
||||
}
|
||||
```
|
||||
|
||||
This will validate each item in `post.tags` array.
|
||||
|
||||
## Validating sets
|
||||
|
||||
If your field is a set and you want to perform validation of each item in the set you must specify a
|
||||
special `each: true` decorator option:
|
||||
|
||||
```typescript
|
||||
import { MinLength, MaxLength } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@MaxLength(20, {
|
||||
each: true,
|
||||
})
|
||||
tags: Set<string>;
|
||||
}
|
||||
```
|
||||
|
||||
This will validate each item in `post.tags` set.
|
||||
|
||||
## Validating maps
|
||||
|
||||
If your field is a map and you want to perform validation of each item in the map you must specify a
|
||||
special `each: true` decorator option:
|
||||
|
||||
```typescript
|
||||
import { MinLength, MaxLength } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@MaxLength(20, {
|
||||
each: true,
|
||||
})
|
||||
tags: Map<string, string>;
|
||||
}
|
||||
```
|
||||
|
||||
This will validate each item in `post.tags` map.
|
||||
|
||||
## Validating nested objects
|
||||
|
||||
If your object contains nested objects and you want the validator to perform their validation too, then you need to
|
||||
use the `@ValidateNested()` decorator:
|
||||
|
||||
```typescript
|
||||
import { ValidateNested } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@ValidateNested()
|
||||
user: User;
|
||||
}
|
||||
```
|
||||
|
||||
Please note that nested object _must_ be an instance of a class, otherwise `@ValidateNested` won't know what class is target of validation. Check also [Validating plain objects](#validating-plain-objects).
|
||||
|
||||
It also works with multi-dimensional array, like :
|
||||
|
||||
```typescript
|
||||
import { ValidateNested } from 'class-validator';
|
||||
|
||||
export class Plan2D {
|
||||
@ValidateNested()
|
||||
matrix: Point[][];
|
||||
}
|
||||
```
|
||||
|
||||
## Validating promises
|
||||
|
||||
If your object contains property with `Promise`-returned value that should be validated, then you need to use the `@ValidatePromise()` decorator:
|
||||
|
||||
```typescript
|
||||
import { ValidatePromise, Min } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@Min(0)
|
||||
@ValidatePromise()
|
||||
userId: Promise<number>;
|
||||
}
|
||||
```
|
||||
|
||||
It also works great with `@ValidateNested` decorator:
|
||||
|
||||
```typescript
|
||||
import { ValidateNested, ValidatePromise } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
@ValidateNested()
|
||||
@ValidatePromise()
|
||||
user: Promise<User>;
|
||||
}
|
||||
```
|
||||
|
||||
## Inheriting Validation decorators
|
||||
|
||||
When you define a subclass which extends from another one, the subclass will automatically inherit the parent's decorators. If a property is redefined in the descendant, class decorators will be applied on it from both its own class and the base class.
|
||||
|
||||
```typescript
|
||||
import { validate } from 'class-validator';
|
||||
|
||||
class BaseContent {
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
|
||||
class User extends BaseContent {
|
||||
@MinLength(10)
|
||||
@MaxLength(20)
|
||||
name: string;
|
||||
|
||||
@Contains('hello')
|
||||
welcome: string;
|
||||
|
||||
@MinLength(20)
|
||||
password: string;
|
||||
}
|
||||
|
||||
let user = new User();
|
||||
|
||||
user.email = 'invalid email'; // inherited property
|
||||
user.password = 'too short'; // password wil be validated not only against IsString, but against MinLength as well
|
||||
user.name = 'not valid';
|
||||
user.welcome = 'helo';
|
||||
|
||||
validate(user).then(errors => {
|
||||
// ...
|
||||
}); // it will return errors for email, password, name and welcome properties
|
||||
```
|
||||
|
||||
## Conditional validation
|
||||
|
||||
The conditional validation decorator (`@ValidateIf`) can be used to ignore the validators on a property when the provided condition function returns false. The condition function takes the object being validated and must return a `boolean`.
|
||||
|
||||
```typescript
|
||||
import { ValidateIf, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class Post {
|
||||
otherProperty: string;
|
||||
|
||||
@ValidateIf(o => o.otherProperty === 'value')
|
||||
@IsNotEmpty()
|
||||
example: string;
|
||||
}
|
||||
```
|
||||
|
||||
In the example above, the validation rules applied to `example` won't be run unless the object's `otherProperty` is `"value"`.
|
||||
|
||||
Note that when the condition is false all validation decorators are ignored, including `isDefined`.
|
||||
|
||||
## Whitelisting
|
||||
|
||||
Even if your object is an instance of a validation class it can contain additional properties that are not defined.
|
||||
If you do not want to have such properties on your object, pass special flag to `validate` method:
|
||||
|
||||
```typescript
|
||||
import { validate } from 'class-validator';
|
||||
// ...
|
||||
validate(post, { whitelist: true });
|
||||
```
|
||||
|
||||
This will strip all properties that don't have any decorators. If no other decorator is suitable for your property,
|
||||
you can use @Allow decorator:
|
||||
|
||||
```typescript
|
||||
import {validate, Allow, Min} from "class-validator";
|
||||
|
||||
export class Post {
|
||||
|
||||
@Allow()
|
||||
title: string;
|
||||
|
||||
@Min(0)
|
||||
views: number;
|
||||
|
||||
nonWhitelistedProperty: number;
|
||||
}
|
||||
|
||||
let post = new Post();
|
||||
post.title = 'Hello world!';
|
||||
post.views = 420;
|
||||
|
||||
post.nonWhitelistedProperty = 69;
|
||||
(post as any).anotherNonWhitelistedProperty = "something";
|
||||
|
||||
validate(post).then(errors => {
|
||||
// post.nonWhitelistedProperty is not defined
|
||||
// (post as any).anotherNonWhitelistedProperty is not defined
|
||||
...
|
||||
});
|
||||
```
|
||||
|
||||
If you would rather to have an error thrown when any non-whitelisted properties are present, pass another flag to
|
||||
`validate` method:
|
||||
|
||||
```typescript
|
||||
import { validate } from 'class-validator';
|
||||
// ...
|
||||
validate(post, { whitelist: true, forbidNonWhitelisted: true });
|
||||
```
|
||||
|
||||
## Passing context to decorators
|
||||
|
||||
It's possible to pass a custom object to decorators which will be accessible on the `ValidationError` instance of the property if validation failed.
|
||||
|
||||
```ts
|
||||
import { validate } from 'class-validator';
|
||||
|
||||
class MyClass {
|
||||
@MinLength(32, {
|
||||
message: 'EIC code must be at least 32 characters',
|
||||
context: {
|
||||
errorCode: 1003,
|
||||
developerNote: 'The validated string must contain 32 or more characters.',
|
||||
},
|
||||
})
|
||||
eicCode: string;
|
||||
}
|
||||
|
||||
const model = new MyClass();
|
||||
|
||||
validate(model).then(errors => {
|
||||
//errors[0].contexts['minLength'].errorCode === 1003
|
||||
});
|
||||
```
|
||||
|
||||
## Skipping missing properties
|
||||
|
||||
Sometimes you may want to skip validation of the properties that do not exist in the validating object. This is
|
||||
usually desirable when you want to update some parts of the object, and want to validate only updated parts,
|
||||
but skip everything else, e.g. skip missing properties.
|
||||
In such situations you will need to pass a special flag to `validate` method:
|
||||
|
||||
```typescript
|
||||
import { validate } from 'class-validator';
|
||||
// ...
|
||||
validate(post, { skipMissingProperties: true });
|
||||
```
|
||||
|
||||
When skipping missing properties, sometimes you want not to skip all missing properties, some of them maybe required
|
||||
for you, even if skipMissingProperties is set to true. For such cases you should use `@IsDefined()` decorator.
|
||||
`@IsDefined()` is the only decorator that ignores `skipMissingProperties` option.
|
||||
|
||||
## Validation groups
|
||||
|
||||
In different situations you may want to use different validation schemas of the same object.
|
||||
In such cases you can use validation groups.
|
||||
|
||||
> **IMPORTANT**
|
||||
> Calling a validation with a group combination that would not result in a validation (eg: non existent group name)
|
||||
> will result in a unknown value error. When validating with groups the provided group combination should match at least one decorator.
|
||||
|
||||
```typescript
|
||||
import { validate, Min, Length } from 'class-validator';
|
||||
|
||||
export class User {
|
||||
@Min(12, {
|
||||
groups: ['registration'],
|
||||
})
|
||||
age: number;
|
||||
|
||||
@Length(2, 20, {
|
||||
groups: ['registration', 'admin'],
|
||||
})
|
||||
name: string;
|
||||
}
|
||||
|
||||
let user = new User();
|
||||
user.age = 10;
|
||||
user.name = 'Alex';
|
||||
|
||||
validate(user, {
|
||||
groups: ['registration'],
|
||||
}); // this will not pass validation
|
||||
|
||||
validate(user, {
|
||||
groups: ['admin'],
|
||||
}); // this will pass validation
|
||||
|
||||
validate(user, {
|
||||
groups: ['registration', 'admin'],
|
||||
}); // this will not pass validation
|
||||
|
||||
validate(user, {
|
||||
groups: undefined, // the default
|
||||
}); // this will not pass validation since all properties get validated regardless of their groups
|
||||
|
||||
validate(user, {
|
||||
groups: [],
|
||||
}); // this will not pass validation, (equivalent to 'groups: undefined', see above)
|
||||
```
|
||||
|
||||
There is also a special flag `always: true` in validation options that you can use. This flag says that this validation
|
||||
must be applied always no matter which group is used.
|
||||
|
||||
## Custom validation classes
|
||||
|
||||
If you have custom validation logic you can create a _Constraint class_:
|
||||
|
||||
1. First create a file, lets say `CustomTextLength.ts`, and define a new class:
|
||||
|
||||
```typescript
|
||||
import { ValidatorConstraint, ValidatorConstraintInterface, ValidationArguments } from 'class-validator';
|
||||
|
||||
@ValidatorConstraint({ name: 'customText', async: false })
|
||||
export class CustomTextLength implements ValidatorConstraintInterface {
|
||||
validate(text: string, args: ValidationArguments) {
|
||||
return text.length > 1 && text.length < 10; // for async validations you must return a Promise<boolean> here
|
||||
}
|
||||
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
// here you can provide default error message if validation failed
|
||||
return 'Text ($value) is too short or too long!';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
We marked our class with `@ValidatorConstraint` decorator.
|
||||
You can also supply a validation constraint name - this name will be used as "error type" in ValidationError.
|
||||
If you will not supply a constraint name - it will be auto-generated.
|
||||
|
||||
Our class must implement `ValidatorConstraintInterface` interface and its `validate` method,
|
||||
which defines validation logic. If validation succeeds, method returns true, otherwise false.
|
||||
Custom validator can be asynchronous, if you want to perform validation after some asynchronous
|
||||
operations, simply return a promise with boolean inside in `validate` method.
|
||||
|
||||
Also we defined optional method `defaultMessage` which defines a default error message,
|
||||
in the case that the decorator's implementation doesn't set an error message.
|
||||
|
||||
2. Then you can use your new validation constraint in your class:
|
||||
|
||||
```typescript
|
||||
import { Validate } from 'class-validator';
|
||||
import { CustomTextLength } from './CustomTextLength';
|
||||
|
||||
export class Post {
|
||||
@Validate(CustomTextLength, {
|
||||
message: 'Title is too short or long!',
|
||||
})
|
||||
title: string;
|
||||
}
|
||||
```
|
||||
|
||||
Here we set our newly created `CustomTextLength` validation constraint for `Post.title`.
|
||||
|
||||
3. And use validator as usual:
|
||||
|
||||
```typescript
|
||||
import { validate } from 'class-validator';
|
||||
|
||||
validate(post).then(errors => {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
You can also pass constraints to your validator, like this:
|
||||
|
||||
```typescript
|
||||
import { Validate } from 'class-validator';
|
||||
import { CustomTextLength } from './CustomTextLength';
|
||||
|
||||
export class Post {
|
||||
@Validate(CustomTextLength, [3, 20], {
|
||||
message: 'Wrong post title',
|
||||
})
|
||||
title: string;
|
||||
}
|
||||
```
|
||||
|
||||
And use them from `validationArguments` object:
|
||||
|
||||
```typescript
|
||||
import { ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator';
|
||||
|
||||
@ValidatorConstraint()
|
||||
export class CustomTextLength implements ValidatorConstraintInterface {
|
||||
validate(text: string, validationArguments: ValidationArguments) {
|
||||
return text.length > validationArguments.constraints[0] && text.length < validationArguments.constraints[1];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Custom validation decorators
|
||||
|
||||
You can also create a custom decorators. Its the most elegant way of using a custom validations.
|
||||
Lets create a decorator called `@IsLongerThan`:
|
||||
|
||||
1. Create a decorator itself:
|
||||
|
||||
```typescript
|
||||
import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator';
|
||||
|
||||
export function IsLongerThan(property: string, validationOptions?: ValidationOptions) {
|
||||
return function (object: Object, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: 'isLongerThan',
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
constraints: [property],
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(value: any, args: ValidationArguments) {
|
||||
const [relatedPropertyName] = args.constraints;
|
||||
const relatedValue = (args.object as any)[relatedPropertyName];
|
||||
return typeof value === 'string' && typeof relatedValue === 'string' && value.length > relatedValue.length; // you can return a Promise<boolean> here as well, if you want to make async validation
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
2. Put it to use:
|
||||
|
||||
```typescript
|
||||
import { IsLongerThan } from './IsLongerThan';
|
||||
|
||||
export class Post {
|
||||
title: string;
|
||||
|
||||
@IsLongerThan('title', {
|
||||
/* you can also use additional validation options, like "groups" in your custom validation decorators. "each" is not supported */
|
||||
message: 'Text must be longer than the title',
|
||||
})
|
||||
text: string;
|
||||
}
|
||||
```
|
||||
|
||||
In your custom decorators you can also use `ValidationConstraint`.
|
||||
Lets create another custom validation decorator called `IsUserAlreadyExist`:
|
||||
|
||||
1. Create a ValidationConstraint and decorator:
|
||||
|
||||
```typescript
|
||||
import {
|
||||
registerDecorator,
|
||||
ValidationOptions,
|
||||
ValidatorConstraint,
|
||||
ValidatorConstraintInterface,
|
||||
ValidationArguments,
|
||||
} from 'class-validator';
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
export class IsUserAlreadyExistConstraint implements ValidatorConstraintInterface {
|
||||
validate(userName: any, args: ValidationArguments) {
|
||||
return UserRepository.findOneByName(userName).then(user => {
|
||||
if (user) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function IsUserAlreadyExist(validationOptions?: ValidationOptions) {
|
||||
return function (object: Object, propertyName: string) {
|
||||
registerDecorator({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
constraints: [],
|
||||
validator: IsUserAlreadyExistConstraint,
|
||||
});
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
note that we marked our constraint that it will by async by adding `{ async: true }` in validation options.
|
||||
|
||||
2. And put it to use:
|
||||
|
||||
```typescript
|
||||
import { IsUserAlreadyExist } from './IsUserAlreadyExist';
|
||||
|
||||
export class User {
|
||||
@IsUserAlreadyExist({
|
||||
message: 'User $value already exists. Choose another name.',
|
||||
})
|
||||
name: string;
|
||||
}
|
||||
```
|
||||
|
||||
## Using service container
|
||||
|
||||
Validator supports service container in the case if want to inject dependencies into your custom validator constraint
|
||||
classes. Here is example how to integrate it with [typedi][2]:
|
||||
|
||||
```typescript
|
||||
import { Container } from 'typedi';
|
||||
import { useContainer, Validator } from 'class-validator';
|
||||
|
||||
// do this somewhere in the global application level:
|
||||
useContainer(Container);
|
||||
let validator = Container.get(Validator);
|
||||
|
||||
// now everywhere you can inject Validator class which will go from the container
|
||||
// also you can inject classes using constructor injection into your custom ValidatorConstraint-s
|
||||
```
|
||||
|
||||
## Synchronous validation
|
||||
|
||||
If you want to perform a simple non async validation you can use `validateSync` method instead of regular `validate`
|
||||
method. It has the same arguments as `validate` method. But note, this method **ignores** all async validations
|
||||
you have.
|
||||
|
||||
## Manual validation
|
||||
|
||||
There are several method exist in the Validator that allows to perform non-decorator based validation:
|
||||
|
||||
```typescript
|
||||
import { isEmpty, isBoolean } from 'class-validator';
|
||||
|
||||
isEmpty(value);
|
||||
isBoolean(value);
|
||||
```
|
||||
|
||||
## Validation decorators
|
||||
|
||||
| Decorator | Description |
|
||||
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **Common validation decorators** | |
|
||||
| `@IsDefined(value: any)` | Checks if value is defined (!== undefined, !== null). This is the only decorator that ignores skipMissingProperties option. |
|
||||
| `@IsOptional()` | Checks if given value is empty (=== null, === undefined) and if so, ignores all the validators on the property. |
|
||||
| `@Equals(comparison: any)` | Checks if value equals ("===") comparison. |
|
||||
| `@NotEquals(comparison: any)` | Checks if value not equal ("!==") comparison. |
|
||||
| `@IsEmpty()` | Checks if given value is empty (=== '', === null, === undefined). |
|
||||
| `@IsNotEmpty()` | Checks if given value is not empty (!== '', !== null, !== undefined). |
|
||||
| `@IsIn(values: any[])` | Checks if value is in an array of allowed values. |
|
||||
| `@IsNotIn(values: any[])` | Checks if value is not in an array of disallowed values. |
|
||||
| **Type validation decorators** | |
|
||||
| `@IsBoolean()` | Checks if a value is a boolean. |
|
||||
| `@IsDate()` | Checks if the value is a date. |
|
||||
| `@IsString()` | Checks if the value is a string. |
|
||||
| `@IsNumber(options: IsNumberOptions)` | Checks if the value is a number. |
|
||||
| `@IsInt()` | Checks if the value is an integer number. |
|
||||
| `@IsArray()` | Checks if the value is an array |
|
||||
| `@IsEnum(entity: object)` | Checks if the value is a valid enum |
|
||||
| **Number validation decorators** |
|
||||
| `@IsDivisibleBy(num: number)` | Checks if the value is a number that's divisible by another. |
|
||||
| `@IsPositive()` | Checks if the value is a positive number greater than zero. |
|
||||
| `@IsNegative()` | Checks if the value is a negative number smaller than zero. |
|
||||
| `@Min(min: number)` | Checks if the given number is greater than or equal to given number. |
|
||||
| `@Max(max: number)` | Checks if the given number is less than or equal to given number. |
|
||||
| **Date validation decorators** |
|
||||
| `@MinDate(date: Date \| (() => Date))` | Checks if the value is a date that's after the specified date. |
|
||||
| `@MaxDate(date: Date \| (() => Date))` | Checks if the value is a date that's before the specified date. |
|
||||
| **String-type validation decorators** | |
|
||||
| `@IsBooleanString()` | Checks if a string is a boolean (e.g. is "true" or "false" or "1", "0"). |
|
||||
| `@IsDateString()` | Alias for `@IsISO8601()`. |
|
||||
| `@IsNumberString(options?: IsNumericOptions)` | Checks if a string is a number. |
|
||||
| **String validation decorators** | |
|
||||
| `@Contains(seed: string)` | Checks if the string contains the seed. |
|
||||
| `@NotContains(seed: string)` | Checks if the string not contains the seed. |
|
||||
| `@IsAlpha()` | Checks if the string contains only letters (a-zA-Z). |
|
||||
| `@IsAlphanumeric()` | Checks if the string contains only letters and numbers. |
|
||||
| `@IsDecimal(options?: IsDecimalOptions)` | Checks if the string is a valid decimal value. Default IsDecimalOptions are `force_decimal=False`, `decimal_digits: '1,'`, `locale: 'en-US'` |
|
||||
| `@IsAscii()` | Checks if the string contains ASCII chars only. |
|
||||
| `@IsBase32()` | Checks if a string is base32 encoded. |
|
||||
| `@IsBase58()` | Checks if a string is base58 encoded. |
|
||||
| `@IsBase64(options?: IsBase64Options)` | Checks if a string is base64 encoded. |
|
||||
| `@IsIBAN()` | Checks if a string is a IBAN (International Bank Account Number). |
|
||||
| `@IsBIC()` | Checks if a string is a BIC (Bank Identification Code) or SWIFT code. |
|
||||
| `@IsByteLength(min: number, max?: number)` | Checks if the string's length (in bytes) falls in a range. |
|
||||
| `@IsCreditCard()` | Checks if the string is a credit card. |
|
||||
| `@IsCurrency(options?: IsCurrencyOptions)` | Checks if the string is a valid currency amount. |
|
||||
| `@IsISO4217CurrencyCode()` | Checks if the string is an ISO 4217 currency code. |
|
||||
| `@IsEthereumAddress()` | Checks if the string is an Ethereum address using basic regex. Does not validate address checksums. |
|
||||
| `@IsBtcAddress()` | Checks if the string is a valid BTC address. |
|
||||
| `@IsDataURI()` | Checks if the string is a data uri format. |
|
||||
| `@IsEmail(options?: IsEmailOptions)` | Checks if the string is an email. |
|
||||
| `@IsFQDN(options?: IsFQDNOptions)` | Checks if the string is a fully qualified domain name (e.g. domain.com). |
|
||||
| `@IsFullWidth()` | Checks if the string contains any full-width chars. |
|
||||
| `@IsHalfWidth()` | Checks if the string contains any half-width chars. |
|
||||
| `@IsVariableWidth()` | Checks if the string contains a mixture of full and half-width chars. |
|
||||
| `@IsHexColor()` | Checks if the string is a hexadecimal color. |
|
||||
| `@IsHSL()` | Checks if the string is an HSL color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). |
|
||||
| `@IsRgbColor(options?: IsRgbOptions)` | Checks if the string is a rgb or rgba color. |
|
||||
| `@IsIdentityCard(locale?: string)` | Checks if the string is a valid identity card code. |
|
||||
| `@IsPassportNumber(countryCode?: string)` | Checks if the string is a valid passport number relative to a specific country code. |
|
||||
| `@IsPostalCode(locale?: string)` | Checks if the string is a postal code. |
|
||||
| `@IsHexadecimal()` | Checks if the string is a hexadecimal number. |
|
||||
| `@IsOctal()` | Checks if the string is a octal number. |
|
||||
| `@IsMACAddress(options?: IsMACAddressOptions)` | Checks if the string is a MAC Address. |
|
||||
| `@IsIP(version?: "4"\|"6")` | Checks if the string is an IP (version 4 or 6). |
|
||||
| `@IsPort()` | Checks if the string is a valid port number. |
|
||||
| `@IsISBN(version?: "10"\|"13")` | Checks if the string is an ISBN (version 10 or 13). |
|
||||
| `@IsEAN()` | Checks if the string is an if the string is an EAN (European Article Number). |
|
||||
| `@IsISIN()` | Checks if the string is an ISIN (stock/security identifier). |
|
||||
| `@IsISO8601(options?: IsISO8601Options)` | Checks if the string is a valid ISO 8601 date format. Use the option strict = true for additional checks for a valid date. |
|
||||
| `@IsJSON()` | Checks if the string is valid JSON. |
|
||||
| `@IsJWT()` | Checks if the string is valid JWT. |
|
||||
| `@IsObject()` | Checks if the object is valid Object (null, functions, arrays will return false). |
|
||||
| `@IsNotEmptyObject()` | Checks if the object is not empty. |
|
||||
| `@IsLowercase()` | Checks if the string is lowercase. |
|
||||
| `@IsLatLong()` | Checks if the string is a valid latitude-longitude coordinate in the format lat, long. |
|
||||
| `@IsLatitude()` | Checks if the string or number is a valid latitude coordinate. |
|
||||
| `@IsLongitude()` | Checks if the string or number is a valid longitude coordinate. |
|
||||
| `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. |
|
||||
| `@IsISO31661Alpha2()` | Checks if the string is a valid ISO 3166-1 alpha-2 officially assigned country code. |
|
||||
| `@IsISO31661Alpha3()` | Checks if the string is a valid ISO 3166-1 alpha-3 officially assigned country code. |
|
||||
| `@IsLocale()` | Checks if the string is a locale. |
|
||||
| `@IsPhoneNumber(region: string)` | Checks if the string is a valid phone number using libphonenumber-js. |
|
||||
| `@IsMongoId()` | Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId. |
|
||||
| `@IsMultibyte()` | Checks if the string contains one or more multibyte chars. |
|
||||
| `@IsNumberString(options?: IsNumericOptions)` | Checks if the string is numeric. |
|
||||
| `@IsSurrogatePair()` | Checks if the string contains any surrogate pairs chars. |
|
||||
| `@IsTaxId()` | Checks if the string is a valid tax ID. Default locale is `en-US`. |
|
||||
| `@IsUrl(options?: IsURLOptions)` | Checks if the string is a URL. |
|
||||
| `@IsMagnetURI()` | Checks if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). |
|
||||
| `@IsUUID(version?: UUIDVersion)` | Checks if the string is a UUID (version 3, 4, 5 or all ). |
|
||||
| `@IsFirebasePushId()` | Checks if the string is a [Firebase Push ID](https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html) |
|
||||
| `@IsUppercase()` | Checks if the string is uppercase. |
|
||||
| `@Length(min: number, max?: number)` | Checks if the string's length falls in a range. |
|
||||
| `@MinLength(min: number)` | Checks if the string's length is not less than given number. |
|
||||
| `@MaxLength(max: number)` | Checks if the string's length is not more than given number. |
|
||||
| `@Matches(pattern: RegExp, modifiers?: string)` | Checks if string matches the pattern. Either matches('foo', /foo/i) or matches('foo', 'foo', 'i'). |
|
||||
| `@IsMilitaryTime()` | Checks if the string is a valid representation of military time in the format HH:MM. |
|
||||
| `@IsTimeZone()` | Checks if the string represents a valid IANA time-zone. |
|
||||
| `@IsHash(algorithm: string)` | Checks if the string is a hash The following types are supported:`md4`, `md5`, `sha1`, `sha256`, `sha384`, `sha512`, `ripemd128`, `ripemd160`, `tiger128`, `tiger160`, `tiger192`, `crc32`, `crc32b`. |
|
||||
| `@IsMimeType()` | Checks if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format |
|
||||
| `@IsSemVer()` | Checks if the string is a Semantic Versioning Specification (SemVer). |
|
||||
| `@IsISSN(options?: IsISSNOptions)` | Checks if the string is a ISSN. |
|
||||
| `@IsISRC()` | Checks if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code). |
|
||||
| `@IsRFC3339()` | Checks if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. |
|
||||
| `@IsStrongPassword(options?: IsStrongPasswordOptions)` | Checks if the string is a strong password. |
|
||||
| **Array validation decorators** | |
|
||||
| `@ArrayContains(values: any[])` | Checks if array contains all values from the given array of values. |
|
||||
| `@ArrayNotContains(values: any[])` | Checks if array does not contain any of the given values. |
|
||||
| `@ArrayNotEmpty()` | Checks if given array is not empty. |
|
||||
| `@ArrayMinSize(min: number)` | Checks if the array's length is greater than or equal to the specified number. |
|
||||
| `@ArrayMaxSize(max: number)` | Checks if the array's length is less or equal to the specified number. |
|
||||
| `@ArrayUnique(identifier?: (o) => any)` | Checks if all array's values are unique. Comparison for objects is reference-based. Optional function can be speciefied which return value will be used for the comparsion. |
|
||||
| **Object validation decorators** |
|
||||
| `@IsInstance(value: any)` | Checks if the property is an instance of the passed value. |
|
||||
| **Other decorators** | |
|
||||
| `@Allow()` | Prevent stripping off the property when no other constraint is specified for it. |
|
||||
|
||||
## Defining validation schema without decorators
|
||||
|
||||
Schema-based validation without decorators is no longer supported by `class-validator`. This feature was broken in version 0.12 and it will not be fixed. If you are interested in schema-based validation, you can find several such frameworks in [the zod readme's comparison section](https://github.com/colinhacks/zod#comparison).
|
||||
|
||||
## Validating plain objects
|
||||
|
||||
Due to nature of the decorators, the validated object has to be instantiated using `new Class()` syntax. If you have your class defined using class-validator decorators and you want to validate plain JS object (literal object or returned by JSON.parse), you need to transform it to the class instance via using [class-transformer](https://github.com/pleerock/class-transformer)).
|
||||
|
||||
## Samples
|
||||
|
||||
Take a look on samples in [./sample](https://github.com/pleerock/class-validator/tree/master/sample) for more examples of
|
||||
usages.
|
||||
|
||||
## Extensions
|
||||
|
||||
There are several extensions that simplify class-validator integration with other modules or add additional validations:
|
||||
|
||||
- [class-validator integration](https://github.com/19majkel94/class-transformer-validator) with [class-transformer](https://github.com/pleerock/class-transformer)
|
||||
- [class-validator-rule](https://github.com/yantrab/class-validator-rule)
|
||||
- [ngx-dynamic-form-builder](https://github.com/EndyKaufman/ngx-dynamic-form-builder)
|
||||
- [abarghoud/ngx-reactive-form-class-validator](https://github.com/abarghoud/ngx-reactive-form-class-validator)
|
||||
- [class-validator-extended](https://github.com/pigulla/class-validator-extended)
|
||||
|
||||
## Release notes
|
||||
|
||||
See information about breaking changes and release notes [here][3].
|
||||
|
||||
[1]: https://github.com/chriso/validator.js
|
||||
[2]: https://github.com/pleerock/typedi
|
||||
[3]: CHANGELOG.md
|
||||
|
||||
## Contributing
|
||||
|
||||
For information about how to contribute to this project, see [TypeStack's general contribution guide](https://github.com/typestack/.github/blob/master/CONTRIBUTING.md).
|
||||
+14928
File diff suppressed because one or more lines are too long
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+2
File diff suppressed because one or more lines are too long
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
+51
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getFromContainer = exports.useContainer = void 0;
|
||||
/**
|
||||
* Container to be used by this library for inversion control. If container was not implicitly set then by default
|
||||
* container simply creates a new instance of the given class.
|
||||
*/
|
||||
const defaultContainer = new (class {
|
||||
constructor() {
|
||||
this.instances = [];
|
||||
}
|
||||
get(someClass) {
|
||||
let instance = this.instances.find(instance => instance.type === someClass);
|
||||
if (!instance) {
|
||||
instance = { type: someClass, object: new someClass() };
|
||||
this.instances.push(instance);
|
||||
}
|
||||
return instance.object;
|
||||
}
|
||||
})();
|
||||
let userContainer;
|
||||
let userContainerOptions;
|
||||
/**
|
||||
* Sets container to be used by this library.
|
||||
*/
|
||||
function useContainer(iocContainer, options) {
|
||||
userContainer = iocContainer;
|
||||
userContainerOptions = options;
|
||||
}
|
||||
exports.useContainer = useContainer;
|
||||
/**
|
||||
* Gets the IOC container used by this library.
|
||||
*/
|
||||
function getFromContainer(someClass) {
|
||||
if (userContainer) {
|
||||
try {
|
||||
const instance = userContainer.get(someClass);
|
||||
if (instance)
|
||||
return instance;
|
||||
if (!userContainerOptions || !userContainerOptions.fallback)
|
||||
return instance;
|
||||
}
|
||||
catch (error) {
|
||||
if (!userContainerOptions || !userContainerOptions.fallbackOnErrors)
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return defaultContainer.get(someClass);
|
||||
}
|
||||
exports.getFromContainer = getFromContainer;
|
||||
//# sourceMappingURL=container.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/container.ts"],"names":[],"mappings":";;;AAeA;;;GAGG;AACH,MAAM,gBAAgB,GAAqE,IAAI,CAAC;IAAA;QACtF,cAAS,GAAsC,EAAE,CAAC;IAU5D,CAAC;IATC,GAAG,CAAI,SAAsC;QAC3C,IAAI,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QAC5E,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,SAAS,EAAE,EAAE,CAAC;YACxD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,QAAQ,CAAC,MAAM,CAAC;IACzB,CAAC;CACF,CAAC,EAAE,CAAC;AAEL,IAAI,aAA+E,CAAC;AACpF,IAAI,oBAAyC,CAAC;AAE9C;;GAEG;AACH,SAAgB,YAAY,CAAC,YAA0C,EAAE,OAA6B;IACpG,aAAa,GAAG,YAAY,CAAC;IAC7B,oBAAoB,GAAG,OAAO,CAAC;AACjC,CAAC;AAHD,oCAGC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAI,SAAiD;IACnF,IAAI,aAAa,EAAE,CAAC;QAClB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAC9C,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC;YAE9B,IAAI,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,QAAQ;gBAAE,OAAO,QAAQ,CAAC;QAC/E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,gBAAgB;gBAAE,MAAM,KAAK,CAAC;QACnF,CAAC;IACH,CAAC;IACD,OAAO,gBAAgB,CAAC,GAAG,CAAI,SAAS,CAAC,CAAC;AAC5C,CAAC;AAZD,4CAYC","sourcesContent":["/**\n * Container options.\n */\nexport interface UseContainerOptions {\n /**\n * If set to true, then default container will be used in the case if given container haven't returned anything.\n */\n fallback?: boolean;\n\n /**\n * If set to true, then default container will be used in the case if given container thrown an exception.\n */\n fallbackOnErrors?: boolean;\n}\n\n/**\n * Container to be used by this library for inversion control. If container was not implicitly set then by default\n * container simply creates a new instance of the given class.\n */\nconst defaultContainer: { get<T>(someClass: { new (...args: any[]): T } | Function): T } = new (class {\n private instances: { type: Function; object: any }[] = [];\n get<T>(someClass: { new (...args: any[]): T }): T {\n let instance = this.instances.find(instance => instance.type === someClass);\n if (!instance) {\n instance = { type: someClass, object: new someClass() };\n this.instances.push(instance);\n }\n\n return instance.object;\n }\n})();\n\nlet userContainer: { get<T>(someClass: { new (...args: any[]): T } | Function): T };\nlet userContainerOptions: UseContainerOptions;\n\n/**\n * Sets container to be used by this library.\n */\nexport function useContainer(iocContainer: { get(someClass: any): any }, options?: UseContainerOptions): void {\n userContainer = iocContainer;\n userContainerOptions = options;\n}\n\n/**\n * Gets the IOC container used by this library.\n */\nexport function getFromContainer<T>(someClass: { new (...args: any[]): T } | Function): T {\n if (userContainer) {\n try {\n const instance = userContainer.get(someClass);\n if (instance) return instance;\n\n if (!userContainerOptions || !userContainerOptions.fallback) return instance;\n } catch (error) {\n if (!userContainerOptions || !userContainerOptions.fallbackOnErrors) throw error;\n }\n }\n return defaultContainer.get<T>(someClass);\n}\n"]}
|
||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isValidationOptions = void 0;
|
||||
function isValidationOptions(val) {
|
||||
if (!val) {
|
||||
return false;
|
||||
}
|
||||
return 'each' in val || 'message' in val || 'groups' in val || 'always' in val || 'context' in val;
|
||||
}
|
||||
exports.isValidationOptions = isValidationOptions;
|
||||
//# sourceMappingURL=ValidationOptions.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ValidationOptions.js","sourceRoot":"","sources":["../../../src/decorator/ValidationOptions.ts"],"names":[],"mappings":";;;AAiCA,SAAgB,mBAAmB,CAAC,GAAQ;IAC1C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,MAAM,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,CAAC;AACrG,CAAC;AALD,kDAKC","sourcesContent":["import { ValidationArguments } from '../validation/ValidationArguments';\n\n/**\n * Options used to pass to validation decorators.\n */\nexport interface ValidationOptions {\n /**\n * Specifies if validated value is an array and each of its items must be validated.\n */\n each?: boolean;\n\n /**\n * Error message to be used on validation fail.\n * Message can be either string or a function that returns a string.\n */\n message?: string | ((validationArguments: ValidationArguments) => string);\n\n /**\n * Validation groups used for this validation.\n */\n groups?: string[];\n\n /**\n * Indicates if validation must be performed always, no matter of validation groups used.\n */\n always?: boolean;\n\n /*\n * A transient set of data passed through to the validation result for response mapping\n */\n context?: any;\n}\n\nexport function isValidationOptions(val: any): val is ValidationOptions {\n if (!val) {\n return false;\n }\n return 'each' in val || 'message' in val || 'groups' in val || 'always' in val || 'context' in val;\n}\n"]}
|
||||
Generated
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArrayContains = exports.arrayContains = exports.ARRAY_CONTAINS = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.ARRAY_CONTAINS = 'arrayContains';
|
||||
/**
|
||||
* Checks if array contains all values from the given array of values.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function arrayContains(array, values) {
|
||||
if (!Array.isArray(array))
|
||||
return false;
|
||||
return values.every(value => array.indexOf(value) !== -1);
|
||||
}
|
||||
exports.arrayContains = arrayContains;
|
||||
/**
|
||||
* Checks if array contains all values from the given array of values.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function ArrayContains(values, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.ARRAY_CONTAINS,
|
||||
constraints: [values],
|
||||
validator: {
|
||||
validate: (value, args) => arrayContains(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must contain $constraint1 values', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.ArrayContains = ArrayContains;
|
||||
//# sourceMappingURL=ArrayContains.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ArrayContains.js","sourceRoot":"","sources":["../../../../src/decorator/array/ArrayContains.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,cAAc,GAAG,eAAe,CAAC;AAE9C;;;GAGG;AACH,SAAgB,aAAa,CAAC,KAAc,EAAE,MAAa;IACzD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAExC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAJD,sCAIC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAC,MAAa,EAAE,iBAAqC;IAChF,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,sBAAc;QACpB,WAAW,EAAE,CAAC,MAAM,CAAC;QACrB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YAC9E,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,4CAA4C,EACvE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,sCAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const ARRAY_CONTAINS = 'arrayContains';\n\n/**\n * Checks if array contains all values from the given array of values.\n * If null or undefined is given then this function returns false.\n */\nexport function arrayContains(array: unknown, values: any[]): boolean {\n if (!Array.isArray(array)) return false;\n\n return values.every(value => array.indexOf(value) !== -1);\n}\n\n/**\n * Checks if array contains all values from the given array of values.\n * If null or undefined is given then this function returns false.\n */\nexport function ArrayContains(values: any[], validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: ARRAY_CONTAINS,\n constraints: [values],\n validator: {\n validate: (value, args): boolean => arrayContains(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must contain $constraint1 values',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArrayMaxSize = exports.arrayMaxSize = exports.ARRAY_MAX_SIZE = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.ARRAY_MAX_SIZE = 'arrayMaxSize';
|
||||
/**
|
||||
* Checks if the array's length is less or equal to the specified number.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function arrayMaxSize(array, max) {
|
||||
return Array.isArray(array) && array.length <= max;
|
||||
}
|
||||
exports.arrayMaxSize = arrayMaxSize;
|
||||
/**
|
||||
* Checks if the array's length is less or equal to the specified number.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function ArrayMaxSize(max, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.ARRAY_MAX_SIZE,
|
||||
constraints: [max],
|
||||
validator: {
|
||||
validate: (value, args) => arrayMaxSize(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must contain no more than $constraint1 elements', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.ArrayMaxSize = ArrayMaxSize;
|
||||
//# sourceMappingURL=ArrayMaxSize.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ArrayMaxSize.js","sourceRoot":"","sources":["../../../../src/decorator/array/ArrayMaxSize.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,cAAc,GAAG,cAAc,CAAC;AAE7C;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAc,EAAE,GAAW;IACtD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;AACrD,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,iBAAqC;IAC7E,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,sBAAc;QACpB,WAAW,EAAE,CAAC,GAAG,CAAC;QAClB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YAC7E,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,2DAA2D,EACtF,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,oCAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const ARRAY_MAX_SIZE = 'arrayMaxSize';\n\n/**\n * Checks if the array's length is less or equal to the specified number.\n * If null or undefined is given then this function returns false.\n */\nexport function arrayMaxSize(array: unknown, max: number): boolean {\n return Array.isArray(array) && array.length <= max;\n}\n\n/**\n * Checks if the array's length is less or equal to the specified number.\n * If null or undefined is given then this function returns false.\n */\nexport function ArrayMaxSize(max: number, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: ARRAY_MAX_SIZE,\n constraints: [max],\n validator: {\n validate: (value, args): boolean => arrayMaxSize(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must contain no more than $constraint1 elements',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArrayMinSize = exports.arrayMinSize = exports.ARRAY_MIN_SIZE = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.ARRAY_MIN_SIZE = 'arrayMinSize';
|
||||
/**
|
||||
* Checks if the array's length is greater than or equal to the specified number.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function arrayMinSize(array, min) {
|
||||
return Array.isArray(array) && array.length >= min;
|
||||
}
|
||||
exports.arrayMinSize = arrayMinSize;
|
||||
/**
|
||||
* Checks if the array's length is greater than or equal to the specified number.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function ArrayMinSize(min, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.ARRAY_MIN_SIZE,
|
||||
constraints: [min],
|
||||
validator: {
|
||||
validate: (value, args) => arrayMinSize(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must contain at least $constraint1 elements', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.ArrayMinSize = ArrayMinSize;
|
||||
//# sourceMappingURL=ArrayMinSize.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ArrayMinSize.js","sourceRoot":"","sources":["../../../../src/decorator/array/ArrayMinSize.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,cAAc,GAAG,cAAc,CAAC;AAE7C;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAc,EAAE,GAAW;IACtD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;AACrD,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,iBAAqC;IAC7E,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,sBAAc;QACpB,WAAW,EAAE,CAAC,GAAG,CAAC;QAClB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YAC7E,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,uDAAuD,EAClF,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,oCAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const ARRAY_MIN_SIZE = 'arrayMinSize';\n\n/**\n * Checks if the array's length is greater than or equal to the specified number.\n * If null or undefined is given then this function returns false.\n */\nexport function arrayMinSize(array: unknown, min: number): boolean {\n return Array.isArray(array) && array.length >= min;\n}\n\n/**\n * Checks if the array's length is greater than or equal to the specified number.\n * If null or undefined is given then this function returns false.\n */\nexport function ArrayMinSize(min: number, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: ARRAY_MIN_SIZE,\n constraints: [min],\n validator: {\n validate: (value, args): boolean => arrayMinSize(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must contain at least $constraint1 elements',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArrayNotContains = exports.arrayNotContains = exports.ARRAY_NOT_CONTAINS = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.ARRAY_NOT_CONTAINS = 'arrayNotContains';
|
||||
/**
|
||||
* Checks if array does not contain any of the given values.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function arrayNotContains(array, values) {
|
||||
if (!Array.isArray(array))
|
||||
return false;
|
||||
return values.every(value => array.indexOf(value) === -1);
|
||||
}
|
||||
exports.arrayNotContains = arrayNotContains;
|
||||
/**
|
||||
* Checks if array does not contain any of the given values.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function ArrayNotContains(values, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.ARRAY_NOT_CONTAINS,
|
||||
constraints: [values],
|
||||
validator: {
|
||||
validate: (value, args) => arrayNotContains(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property should not contain $constraint1 values', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.ArrayNotContains = ArrayNotContains;
|
||||
//# sourceMappingURL=ArrayNotContains.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ArrayNotContains.js","sourceRoot":"","sources":["../../../../src/decorator/array/ArrayNotContains.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,kBAAkB,GAAG,kBAAkB,CAAC;AAErD;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,KAAc,EAAE,MAAa;IAC5D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAExC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAJD,4CAIC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,MAAa,EAAE,iBAAqC;IACnF,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,0BAAkB;QACxB,WAAW,EAAE,CAAC,MAAM,CAAC;QACrB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACjF,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,kDAAkD,EAC7E,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,4CAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const ARRAY_NOT_CONTAINS = 'arrayNotContains';\n\n/**\n * Checks if array does not contain any of the given values.\n * If null or undefined is given then this function returns false.\n */\nexport function arrayNotContains(array: unknown, values: any[]): boolean {\n if (!Array.isArray(array)) return false;\n\n return values.every(value => array.indexOf(value) === -1);\n}\n\n/**\n * Checks if array does not contain any of the given values.\n * If null or undefined is given then this function returns false.\n */\nexport function ArrayNotContains(values: any[], validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: ARRAY_NOT_CONTAINS,\n constraints: [values],\n validator: {\n validate: (value, args): boolean => arrayNotContains(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property should not contain $constraint1 values',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArrayNotEmpty = exports.arrayNotEmpty = exports.ARRAY_NOT_EMPTY = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.ARRAY_NOT_EMPTY = 'arrayNotEmpty';
|
||||
/**
|
||||
* Checks if given array is not empty.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function arrayNotEmpty(array) {
|
||||
return Array.isArray(array) && array.length > 0;
|
||||
}
|
||||
exports.arrayNotEmpty = arrayNotEmpty;
|
||||
/**
|
||||
* Checks if given array is not empty.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function ArrayNotEmpty(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.ARRAY_NOT_EMPTY,
|
||||
validator: {
|
||||
validate: (value, args) => arrayNotEmpty(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property should not be empty', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.ArrayNotEmpty = ArrayNotEmpty;
|
||||
//# sourceMappingURL=ArrayNotEmpty.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ArrayNotEmpty.js","sourceRoot":"","sources":["../../../../src/decorator/array/ArrayNotEmpty.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,eAAe,GAAG,eAAe,CAAC;AAE/C;;;GAGG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC;AAFD,sCAEC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAC,iBAAqC;IACjE,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,uBAAe;QACrB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC;YACxD,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,+BAA+B,EAAE,iBAAiB,CAAC;SAC5G;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,sCAWC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const ARRAY_NOT_EMPTY = 'arrayNotEmpty';\n\n/**\n * Checks if given array is not empty.\n * If null or undefined is given then this function returns false.\n */\nexport function arrayNotEmpty(array: unknown): boolean {\n return Array.isArray(array) && array.length > 0;\n}\n\n/**\n * Checks if given array is not empty.\n * If null or undefined is given then this function returns false.\n */\nexport function ArrayNotEmpty(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: ARRAY_NOT_EMPTY,\n validator: {\n validate: (value, args): boolean => arrayNotEmpty(value),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property should not be empty', validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArrayUnique = exports.arrayUnique = exports.ARRAY_UNIQUE = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.ARRAY_UNIQUE = 'arrayUnique';
|
||||
/**
|
||||
* Checks if all array's values are unique. Comparison for objects is reference-based.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function arrayUnique(array, identifier) {
|
||||
if (!Array.isArray(array))
|
||||
return false;
|
||||
if (identifier) {
|
||||
array = array.map(o => (o != null ? identifier(o) : o));
|
||||
}
|
||||
const uniqueItems = array.filter((a, b, c) => c.indexOf(a) === b);
|
||||
return array.length === uniqueItems.length;
|
||||
}
|
||||
exports.arrayUnique = arrayUnique;
|
||||
/**
|
||||
* Checks if all array's values are unique. Comparison for objects is reference-based.
|
||||
* If null or undefined is given then this function returns false.
|
||||
*/
|
||||
function ArrayUnique(identifierOrOptions, validationOptions) {
|
||||
const identifier = typeof identifierOrOptions === 'function' ? identifierOrOptions : undefined;
|
||||
const options = typeof identifierOrOptions !== 'function' ? identifierOrOptions : validationOptions;
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.ARRAY_UNIQUE,
|
||||
validator: {
|
||||
validate: (value, args) => arrayUnique(value, identifier),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + "All $property's elements must be unique", options),
|
||||
},
|
||||
}, options);
|
||||
}
|
||||
exports.ArrayUnique = ArrayUnique;
|
||||
//# sourceMappingURL=ArrayUnique.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ArrayUnique.js","sourceRoot":"","sources":["../../../../src/decorator/array/ArrayUnique.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,YAAY,GAAG,aAAa,CAAC;AAG1C;;;GAGG;AACH,SAAgB,WAAW,CAAC,KAAgB,EAAE,UAAkC;IAC9E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAExC,IAAI,UAAU,EAAE,CAAC;QACf,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAClE,OAAO,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC;AAC7C,CAAC;AATD,kCASC;AAED;;;GAGG;AACH,SAAgB,WAAW,CACzB,mBAAkE,EAClE,iBAAqC;IAErC,MAAM,UAAU,GAAG,OAAO,mBAAmB,KAAK,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/F,MAAM,OAAO,GAAG,OAAO,mBAAmB,KAAK,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,iBAAiB,CAAC;IAEpG,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,oBAAY;QAClB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC;YAClE,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,yCAAyC,EAAE,OAAO,CAAC;SAC5G;KACF,EACD,OAAO,CACR,CAAC;AACJ,CAAC;AAjBD,kCAiBC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const ARRAY_UNIQUE = 'arrayUnique';\nexport type ArrayUniqueIdentifier<T = any> = (o: T) => any;\n\n/**\n * Checks if all array's values are unique. Comparison for objects is reference-based.\n * If null or undefined is given then this function returns false.\n */\nexport function arrayUnique(array: unknown[], identifier?: ArrayUniqueIdentifier): boolean {\n if (!Array.isArray(array)) return false;\n\n if (identifier) {\n array = array.map(o => (o != null ? identifier(o) : o));\n }\n\n const uniqueItems = array.filter((a, b, c) => c.indexOf(a) === b);\n return array.length === uniqueItems.length;\n}\n\n/**\n * Checks if all array's values are unique. Comparison for objects is reference-based.\n * If null or undefined is given then this function returns false.\n */\nexport function ArrayUnique<T = any>(\n identifierOrOptions?: ArrayUniqueIdentifier<T> | ValidationOptions,\n validationOptions?: ValidationOptions\n): PropertyDecorator {\n const identifier = typeof identifierOrOptions === 'function' ? identifierOrOptions : undefined;\n const options = typeof identifierOrOptions !== 'function' ? identifierOrOptions : validationOptions;\n\n return ValidateBy(\n {\n name: ARRAY_UNIQUE,\n validator: {\n validate: (value, args): boolean => arrayUnique(value, identifier),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + \"All $property's elements must be unique\", options),\n },\n },\n options\n );\n}\n"]}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Allow = void 0;
|
||||
const ValidationTypes_1 = require("../../validation/ValidationTypes");
|
||||
const ValidationMetadata_1 = require("../../metadata/ValidationMetadata");
|
||||
const MetadataStorage_1 = require("../../metadata/MetadataStorage");
|
||||
/**
|
||||
* If object has both allowed and not allowed properties a validation error will be thrown.
|
||||
*/
|
||||
function Allow(validationOptions) {
|
||||
return function (object, propertyName) {
|
||||
const args = {
|
||||
type: ValidationTypes_1.ValidationTypes.WHITELIST,
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
validationOptions: validationOptions,
|
||||
};
|
||||
(0, MetadataStorage_1.getMetadataStorage)().addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
|
||||
};
|
||||
}
|
||||
exports.Allow = Allow;
|
||||
//# sourceMappingURL=Allow.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Allow.js","sourceRoot":"","sources":["../../../../src/decorator/common/Allow.ts"],"names":[],"mappings":";;;AAEA,sEAAmE;AACnE,0EAAuE;AACvE,oEAAoE;AAEpE;;GAEG;AACH,SAAgB,KAAK,CAAC,iBAAqC;IACzD,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,MAAM,IAAI,GAA2B;YACnC,IAAI,EAAE,iCAAe,CAAC,SAAS;YAC/B,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,iBAAiB,EAAE,iBAAiB;SACrC,CAAC;QACF,IAAA,oCAAkB,GAAE,CAAC,qBAAqB,CAAC,IAAI,uCAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC;AAVD,sBAUC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs';\nimport { ValidationTypes } from '../../validation/ValidationTypes';\nimport { ValidationMetadata } from '../../metadata/ValidationMetadata';\nimport { getMetadataStorage } from '../../metadata/MetadataStorage';\n\n/**\n * If object has both allowed and not allowed properties a validation error will be thrown.\n */\nexport function Allow(validationOptions?: ValidationOptions): PropertyDecorator {\n return function (object: object, propertyName: string): void {\n const args: ValidationMetadataArgs = {\n type: ValidationTypes.WHITELIST,\n target: object.constructor,\n propertyName: propertyName,\n validationOptions: validationOptions,\n };\n getMetadataStorage().addValidationMetadata(new ValidationMetadata(args));\n };\n}\n"]}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Equals = exports.equals = exports.EQUALS = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.EQUALS = 'equals';
|
||||
/**
|
||||
* Checks if value matches ("===") the comparison.
|
||||
*/
|
||||
function equals(value, comparison) {
|
||||
return value === comparison;
|
||||
}
|
||||
exports.equals = equals;
|
||||
/**
|
||||
* Checks if value matches ("===") the comparison.
|
||||
*/
|
||||
function Equals(comparison, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.EQUALS,
|
||||
constraints: [comparison],
|
||||
validator: {
|
||||
validate: (value, args) => equals(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be equal to $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.Equals = Equals;
|
||||
//# sourceMappingURL=Equals.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Equals.js","sourceRoot":"","sources":["../../../../src/decorator/common/Equals.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,MAAM,GAAG,QAAQ,CAAC;AAE/B;;GAEG;AACH,SAAgB,MAAM,CAAC,KAAc,EAAE,UAAmB;IACxD,OAAO,KAAK,KAAK,UAAU,CAAC;AAC9B,CAAC;AAFD,wBAEC;AAED;;GAEG;AACH,SAAgB,MAAM,CAAC,UAAe,EAAE,iBAAqC;IAC3E,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,cAAM;QACZ,WAAW,EAAE,CAAC,UAAU,CAAC;QACzB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACvE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,yCAAyC,EACpE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,wBAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const EQUALS = 'equals';\n\n/**\n * Checks if value matches (\"===\") the comparison.\n */\nexport function equals(value: unknown, comparison: unknown): boolean {\n return value === comparison;\n}\n\n/**\n * Checks if value matches (\"===\") the comparison.\n */\nexport function Equals(comparison: any, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: EQUALS,\n constraints: [comparison],\n validator: {\n validate: (value, args): boolean => equals(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be equal to $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsDefined = exports.isDefined = exports.IS_DEFINED = void 0;
|
||||
const ValidateBy_1 = require("./ValidateBy");
|
||||
const ValidationTypes_1 = require("../../validation/ValidationTypes");
|
||||
// isDefined is (yet) a special case
|
||||
exports.IS_DEFINED = ValidationTypes_1.ValidationTypes.IS_DEFINED;
|
||||
/**
|
||||
* Checks if value is defined (!== undefined, !== null).
|
||||
*/
|
||||
function isDefined(value) {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
exports.isDefined = isDefined;
|
||||
/**
|
||||
* Checks if value is defined (!== undefined, !== null).
|
||||
*/
|
||||
function IsDefined(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_DEFINED,
|
||||
validator: {
|
||||
validate: (value) => isDefined(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property should not be null or undefined', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsDefined = IsDefined;
|
||||
//# sourceMappingURL=IsDefined.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsDefined.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsDefined.ts"],"names":[],"mappings":";;;AACA,6CAAwD;AACxD,sEAAmE;AAEnE,oCAAoC;AACvB,QAAA,UAAU,GAAG,iCAAe,CAAC,UAAU,CAAC;AAErD;;GAEG;AACH,SAAgB,SAAS,CAAI,KAA2B;IACtD,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AAC/C,CAAC;AAFD,8BAEC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,iBAAqC;IAC7D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,kBAAU;QAChB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAW,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC;YAC9C,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,2CAA2C,EACtE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,8BAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from './ValidateBy';\nimport { ValidationTypes } from '../../validation/ValidationTypes';\n\n// isDefined is (yet) a special case\nexport const IS_DEFINED = ValidationTypes.IS_DEFINED;\n\n/**\n * Checks if value is defined (!== undefined, !== null).\n */\nexport function isDefined<T>(value: T | undefined | null): value is T {\n return value !== undefined && value !== null;\n}\n\n/**\n * Checks if value is defined (!== undefined, !== null).\n */\nexport function IsDefined(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_DEFINED,\n validator: {\n validate: (value): boolean => isDefined(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property should not be null or undefined',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsEmpty = exports.isEmpty = exports.IS_EMPTY = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.IS_EMPTY = 'isEmpty';
|
||||
/**
|
||||
* Checks if given value is empty (=== '', === null, === undefined).
|
||||
*/
|
||||
function isEmpty(value) {
|
||||
return value === '' || value === null || value === undefined;
|
||||
}
|
||||
exports.isEmpty = isEmpty;
|
||||
/**
|
||||
* Checks if given value is empty (=== '', === null, === undefined).
|
||||
*/
|
||||
function IsEmpty(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_EMPTY,
|
||||
validator: {
|
||||
validate: (value, args) => isEmpty(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be empty', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsEmpty = IsEmpty;
|
||||
//# sourceMappingURL=IsEmpty.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsEmpty.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsEmpty.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,QAAQ,GAAG,SAAS,CAAC;AAElC;;GAEG;AACH,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/D,CAAC;AAFD,0BAEC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,iBAAqC;IAC3D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,gBAAQ;QACd,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;YAClD,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,yBAAyB,EAAE,iBAAiB,CAAC;SACtG;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,0BAWC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const IS_EMPTY = 'isEmpty';\n\n/**\n * Checks if given value is empty (=== '', === null, === undefined).\n */\nexport function isEmpty(value: unknown): boolean {\n return value === '' || value === null || value === undefined;\n}\n\n/**\n * Checks if given value is empty (=== '', === null, === undefined).\n */\nexport function IsEmpty(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_EMPTY,\n validator: {\n validate: (value, args): boolean => isEmpty(value),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be empty', validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsIn = exports.isIn = exports.IS_IN = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.IS_IN = 'isIn';
|
||||
/**
|
||||
* Checks if given value is in a array of allowed values.
|
||||
*/
|
||||
function isIn(value, possibleValues) {
|
||||
return Array.isArray(possibleValues) && possibleValues.some(possibleValue => possibleValue === value);
|
||||
}
|
||||
exports.isIn = isIn;
|
||||
/**
|
||||
* Checks if given value is in a array of allowed values.
|
||||
*/
|
||||
function IsIn(values, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_IN,
|
||||
constraints: [values],
|
||||
validator: {
|
||||
validate: (value, args) => isIn(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be one of the following values: $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsIn = IsIn;
|
||||
//# sourceMappingURL=IsIn.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsIn.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsIn.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,KAAK,GAAG,MAAM,CAAC;AAE5B;;GAEG;AACH,SAAgB,IAAI,CAAC,KAAc,EAAE,cAAkC;IACrE,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,aAAa,KAAK,KAAK,CAAC,CAAC;AACxG,CAAC;AAFD,oBAEC;AAED;;GAEG;AACH,SAAgB,IAAI,CAAC,MAAsB,EAAE,iBAAqC;IAChF,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,aAAK;QACX,WAAW,EAAE,CAAC,MAAM,CAAC;QACrB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACrE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,6DAA6D,EACxF,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,oBAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const IS_IN = 'isIn';\n\n/**\n * Checks if given value is in a array of allowed values.\n */\nexport function isIn(value: unknown, possibleValues: readonly unknown[]): boolean {\n return Array.isArray(possibleValues) && possibleValues.some(possibleValue => possibleValue === value);\n}\n\n/**\n * Checks if given value is in a array of allowed values.\n */\nexport function IsIn(values: readonly any[], validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_IN,\n constraints: [values],\n validator: {\n validate: (value, args): boolean => isIn(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be one of the following values: $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsLatLong = exports.isLatLong = exports.IS_LATLONG = void 0;
|
||||
const ValidateBy_1 = require("./ValidateBy");
|
||||
const isLatLong_1 = __importDefault(require("validator/lib/isLatLong"));
|
||||
exports.IS_LATLONG = 'isLatLong';
|
||||
/**
|
||||
* Checks if a value is string in format a "latitude,longitude".
|
||||
*/
|
||||
function isLatLong(value) {
|
||||
return typeof value === 'string' && (0, isLatLong_1.default)(value);
|
||||
}
|
||||
exports.isLatLong = isLatLong;
|
||||
/**
|
||||
* Checks if a value is string in format a "latitude,longitude".
|
||||
*/
|
||||
function IsLatLong(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_LATLONG,
|
||||
validator: {
|
||||
validate: (value, args) => isLatLong(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a latitude,longitude string', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsLatLong = IsLatLong;
|
||||
//# sourceMappingURL=IsLatLong.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsLatLong.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsLatLong.ts"],"names":[],"mappings":";;;;;;AACA,6CAAwD;AACxD,wEAAyD;AAE5C,QAAA,UAAU,GAAG,WAAW,CAAC;AAEtC;;GAEG;AACH,SAAgB,SAAS,CAAC,KAAa;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,mBAAkB,EAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAFD,8BAEC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,iBAAqC;IAC7D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,kBAAU;QAChB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC;YACpD,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,+CAA+C,EAC1E,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,8BAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from './ValidateBy';\nimport isLatLongValidator from 'validator/lib/isLatLong';\n\nexport const IS_LATLONG = 'isLatLong';\n\n/**\n * Checks if a value is string in format a \"latitude,longitude\".\n */\nexport function isLatLong(value: string): boolean {\n return typeof value === 'string' && isLatLongValidator(value);\n}\n\n/**\n * Checks if a value is string in format a \"latitude,longitude\".\n */\nexport function IsLatLong(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_LATLONG,\n validator: {\n validate: (value, args): boolean => isLatLong(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be a latitude,longitude string',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsLatitude = exports.isLatitude = exports.IS_LATITUDE = void 0;
|
||||
const ValidateBy_1 = require("./ValidateBy");
|
||||
const IsLatLong_1 = require("./IsLatLong");
|
||||
exports.IS_LATITUDE = 'isLatitude';
|
||||
/**
|
||||
* Checks if a given value is a latitude.
|
||||
*/
|
||||
function isLatitude(value) {
|
||||
return (typeof value === 'number' || typeof value === 'string') && (0, IsLatLong_1.isLatLong)(`${value},0`);
|
||||
}
|
||||
exports.isLatitude = isLatitude;
|
||||
/**
|
||||
* Checks if a given value is a latitude.
|
||||
*/
|
||||
function IsLatitude(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_LATITUDE,
|
||||
validator: {
|
||||
validate: (value, args) => isLatitude(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a latitude string or number', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsLatitude = IsLatitude;
|
||||
//# sourceMappingURL=IsLatitude.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsLatitude.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsLatitude.ts"],"names":[],"mappings":";;;AACA,6CAAwD;AACxD,2CAAwC;AAE3B,QAAA,WAAW,GAAG,YAAY,CAAC;AAExC;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAa;IACtC,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,IAAI,IAAA,qBAAS,EAAC,GAAG,KAAK,IAAI,CAAC,CAAC;AAC7F,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,iBAAqC;IAC9D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,mBAAW;QACjB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;YACrD,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,+CAA+C,EAC1E,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,gCAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from './ValidateBy';\nimport { isLatLong } from './IsLatLong';\n\nexport const IS_LATITUDE = 'isLatitude';\n\n/**\n * Checks if a given value is a latitude.\n */\nexport function isLatitude(value: string): boolean {\n return (typeof value === 'number' || typeof value === 'string') && isLatLong(`${value},0`);\n}\n\n/**\n * Checks if a given value is a latitude.\n */\nexport function IsLatitude(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_LATITUDE,\n validator: {\n validate: (value, args): boolean => isLatitude(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be a latitude string or number',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsLongitude = exports.isLongitude = exports.IS_LONGITUDE = void 0;
|
||||
const ValidateBy_1 = require("./ValidateBy");
|
||||
const IsLatLong_1 = require("./IsLatLong");
|
||||
exports.IS_LONGITUDE = 'isLongitude';
|
||||
/**
|
||||
* Checks if a given value is a longitude.
|
||||
*/
|
||||
function isLongitude(value) {
|
||||
return (typeof value === 'number' || typeof value === 'string') && (0, IsLatLong_1.isLatLong)(`0,${value}`);
|
||||
}
|
||||
exports.isLongitude = isLongitude;
|
||||
/**
|
||||
* Checks if a given value is a longitude.
|
||||
*/
|
||||
function IsLongitude(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_LONGITUDE,
|
||||
validator: {
|
||||
validate: (value, args) => isLongitude(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a longitude string or number', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsLongitude = IsLongitude;
|
||||
//# sourceMappingURL=IsLongitude.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsLongitude.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsLongitude.ts"],"names":[],"mappings":";;;AACA,6CAAwD;AACxD,2CAAwC;AAE3B,QAAA,YAAY,GAAG,aAAa,CAAC;AAE1C;;GAEG;AACH,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,IAAI,IAAA,qBAAS,EAAC,KAAK,KAAK,EAAE,CAAC,CAAC;AAC7F,CAAC;AAFD,kCAEC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,iBAAqC;IAC/D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,oBAAY;QAClB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;YACtD,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,gDAAgD,EAC3E,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,kCAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from './ValidateBy';\nimport { isLatLong } from './IsLatLong';\n\nexport const IS_LONGITUDE = 'isLongitude';\n\n/**\n * Checks if a given value is a longitude.\n */\nexport function isLongitude(value: string): boolean {\n return (typeof value === 'number' || typeof value === 'string') && isLatLong(`0,${value}`);\n}\n\n/**\n * Checks if a given value is a longitude.\n */\nexport function IsLongitude(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_LONGITUDE,\n validator: {\n validate: (value, args): boolean => isLongitude(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be a longitude string or number',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsNotEmpty = exports.isNotEmpty = exports.IS_NOT_EMPTY = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.IS_NOT_EMPTY = 'isNotEmpty';
|
||||
/**
|
||||
* Checks if given value is not empty (!== '', !== null, !== undefined).
|
||||
*/
|
||||
function isNotEmpty(value) {
|
||||
return value !== '' && value !== null && value !== undefined;
|
||||
}
|
||||
exports.isNotEmpty = isNotEmpty;
|
||||
/**
|
||||
* Checks if given value is not empty (!== '', !== null, !== undefined).
|
||||
*/
|
||||
function IsNotEmpty(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_NOT_EMPTY,
|
||||
validator: {
|
||||
validate: (value, args) => isNotEmpty(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property should not be empty', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsNotEmpty = IsNotEmpty;
|
||||
//# sourceMappingURL=IsNotEmpty.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsNotEmpty.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsNotEmpty.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,YAAY,GAAG,YAAY,CAAC;AAEzC;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/D,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,iBAAqC;IAC9D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,oBAAY;QAClB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;YACrD,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,+BAA+B,EAAE,iBAAiB,CAAC;SAC5G;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,gCAWC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const IS_NOT_EMPTY = 'isNotEmpty';\n\n/**\n * Checks if given value is not empty (!== '', !== null, !== undefined).\n */\nexport function isNotEmpty(value: unknown): boolean {\n return value !== '' && value !== null && value !== undefined;\n}\n\n/**\n * Checks if given value is not empty (!== '', !== null, !== undefined).\n */\nexport function IsNotEmpty(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_NOT_EMPTY,\n validator: {\n validate: (value, args): boolean => isNotEmpty(value),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property should not be empty', validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsNotIn = exports.isNotIn = exports.IS_NOT_IN = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.IS_NOT_IN = 'isNotIn';
|
||||
/**
|
||||
* Checks if given value not in a array of allowed values.
|
||||
*/
|
||||
function isNotIn(value, possibleValues) {
|
||||
return !Array.isArray(possibleValues) || !possibleValues.some(possibleValue => possibleValue === value);
|
||||
}
|
||||
exports.isNotIn = isNotIn;
|
||||
/**
|
||||
* Checks if given value not in a array of allowed values.
|
||||
*/
|
||||
function IsNotIn(values, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_NOT_IN,
|
||||
constraints: [values],
|
||||
validator: {
|
||||
validate: (value, args) => isNotIn(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property should not be one of the following values: $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsNotIn = IsNotIn;
|
||||
//# sourceMappingURL=IsNotIn.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsNotIn.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsNotIn.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,SAAS,GAAG,SAAS,CAAC;AAEnC;;GAEG;AACH,SAAgB,OAAO,CAAC,KAAc,EAAE,cAAkC;IACxE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,aAAa,KAAK,KAAK,CAAC,CAAC;AAC1G,CAAC;AAFD,0BAEC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,MAAsB,EAAE,iBAAqC;IACnF,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,iBAAS;QACf,WAAW,EAAE,CAAC,MAAM,CAAC;QACrB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACxE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,mEAAmE,EAC9F,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,0BAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const IS_NOT_IN = 'isNotIn';\n\n/**\n * Checks if given value not in a array of allowed values.\n */\nexport function isNotIn(value: unknown, possibleValues: readonly unknown[]): boolean {\n return !Array.isArray(possibleValues) || !possibleValues.some(possibleValue => possibleValue === value);\n}\n\n/**\n * Checks if given value not in a array of allowed values.\n */\nexport function IsNotIn(values: readonly any[], validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_NOT_IN,\n constraints: [values],\n validator: {\n validate: (value, args): boolean => isNotIn(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property should not be one of the following values: $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsOptional = exports.IS_OPTIONAL = void 0;
|
||||
const ValidationTypes_1 = require("../../validation/ValidationTypes");
|
||||
const ValidationMetadata_1 = require("../../metadata/ValidationMetadata");
|
||||
const MetadataStorage_1 = require("../../metadata/MetadataStorage");
|
||||
exports.IS_OPTIONAL = 'isOptional';
|
||||
/**
|
||||
* Checks if value is missing and if so, ignores all validators.
|
||||
*/
|
||||
function IsOptional(validationOptions) {
|
||||
return function (object, propertyName) {
|
||||
const args = {
|
||||
type: ValidationTypes_1.ValidationTypes.CONDITIONAL_VALIDATION,
|
||||
name: exports.IS_OPTIONAL,
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
constraints: [
|
||||
(object, value) => {
|
||||
return object[propertyName] !== null && object[propertyName] !== undefined;
|
||||
},
|
||||
],
|
||||
validationOptions: validationOptions,
|
||||
};
|
||||
(0, MetadataStorage_1.getMetadataStorage)().addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
|
||||
};
|
||||
}
|
||||
exports.IsOptional = IsOptional;
|
||||
//# sourceMappingURL=IsOptional.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsOptional.js","sourceRoot":"","sources":["../../../../src/decorator/common/IsOptional.ts"],"names":[],"mappings":";;;AAEA,sEAAmE;AACnE,0EAAuE;AACvE,oEAAoE;AAEvD,QAAA,WAAW,GAAG,YAAY,CAAC;AAExC;;GAEG;AACH,SAAgB,UAAU,CAAC,iBAAqC;IAC9D,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,MAAM,IAAI,GAA2B;YACnC,IAAI,EAAE,iCAAe,CAAC,sBAAsB;YAC5C,IAAI,EAAE,mBAAW;YACjB,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,WAAW,EAAE;gBACX,CAAC,MAAW,EAAE,KAAU,EAAW,EAAE;oBACnC,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,SAAS,CAAC;gBAC7E,CAAC;aACF;YACD,iBAAiB,EAAE,iBAAiB;SACrC,CAAC;QACF,IAAA,oCAAkB,GAAE,CAAC,qBAAqB,CAAC,IAAI,uCAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC;AAhBD,gCAgBC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs';\nimport { ValidationTypes } from '../../validation/ValidationTypes';\nimport { ValidationMetadata } from '../../metadata/ValidationMetadata';\nimport { getMetadataStorage } from '../../metadata/MetadataStorage';\n\nexport const IS_OPTIONAL = 'isOptional';\n\n/**\n * Checks if value is missing and if so, ignores all validators.\n */\nexport function IsOptional(validationOptions?: ValidationOptions): PropertyDecorator {\n return function (object: object, propertyName: string): void {\n const args: ValidationMetadataArgs = {\n type: ValidationTypes.CONDITIONAL_VALIDATION,\n name: IS_OPTIONAL,\n target: object.constructor,\n propertyName: propertyName,\n constraints: [\n (object: any, value: any): boolean => {\n return object[propertyName] !== null && object[propertyName] !== undefined;\n },\n ],\n validationOptions: validationOptions,\n };\n getMetadataStorage().addValidationMetadata(new ValidationMetadata(args));\n };\n}\n"]}
|
||||
Generated
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NotEquals = exports.notEquals = exports.NOT_EQUALS = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.NOT_EQUALS = 'notEquals';
|
||||
/**
|
||||
* Checks if value does not match ("!==") the comparison.
|
||||
*/
|
||||
function notEquals(value, comparison) {
|
||||
return value !== comparison;
|
||||
}
|
||||
exports.notEquals = notEquals;
|
||||
/**
|
||||
* Checks if value does not match ("!==") the comparison.
|
||||
*/
|
||||
function NotEquals(comparison, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.NOT_EQUALS,
|
||||
constraints: [comparison],
|
||||
validator: {
|
||||
validate: (value, args) => notEquals(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property should not be equal to $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.NotEquals = NotEquals;
|
||||
//# sourceMappingURL=NotEquals.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"NotEquals.js","sourceRoot":"","sources":["../../../../src/decorator/common/NotEquals.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,UAAU,GAAG,WAAW,CAAC;AAEtC;;GAEG;AACH,SAAgB,SAAS,CAAC,KAAc,EAAE,UAAmB;IAC3D,OAAO,KAAK,KAAK,UAAU,CAAC;AAC9B,CAAC;AAFD,8BAEC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,UAAe,EAAE,iBAAqC;IAC9E,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,kBAAU;QAChB,WAAW,EAAE,CAAC,UAAU,CAAC;QACzB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YAC1E,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,+CAA+C,EAC1E,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,8BAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const NOT_EQUALS = 'notEquals';\n\n/**\n * Checks if value does not match (\"!==\") the comparison.\n */\nexport function notEquals(value: unknown, comparison: unknown): boolean {\n return value !== comparison;\n}\n\n/**\n * Checks if value does not match (\"!==\") the comparison.\n */\nexport function NotEquals(comparison: any, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: NOT_EQUALS,\n constraints: [comparison],\n validator: {\n validate: (value, args): boolean => notEquals(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property should not be equal to $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Validate = exports.ValidatorConstraint = void 0;
|
||||
const ValidationMetadata_1 = require("../../metadata/ValidationMetadata");
|
||||
const MetadataStorage_1 = require("../../metadata/MetadataStorage");
|
||||
const ValidationTypes_1 = require("../../validation/ValidationTypes");
|
||||
const ConstraintMetadata_1 = require("../../metadata/ConstraintMetadata");
|
||||
/**
|
||||
* Registers custom validator class.
|
||||
*/
|
||||
function ValidatorConstraint(options) {
|
||||
return function (target) {
|
||||
const isAsync = options && options.async;
|
||||
let name = options && options.name ? options.name : '';
|
||||
if (!name) {
|
||||
name = target.name;
|
||||
if (!name)
|
||||
// generate name if it was not given
|
||||
name = name.replace(/\.?([A-Z]+)/g, (x, y) => '_' + y.toLowerCase()).replace(/^_/, '');
|
||||
}
|
||||
const metadata = new ConstraintMetadata_1.ConstraintMetadata(target, name, isAsync);
|
||||
(0, MetadataStorage_1.getMetadataStorage)().addConstraintMetadata(metadata);
|
||||
};
|
||||
}
|
||||
exports.ValidatorConstraint = ValidatorConstraint;
|
||||
function Validate(constraintClass, constraintsOrValidationOptions, maybeValidationOptions) {
|
||||
return function (object, propertyName) {
|
||||
const args = {
|
||||
type: ValidationTypes_1.ValidationTypes.CUSTOM_VALIDATION,
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
constraintCls: constraintClass,
|
||||
constraints: Array.isArray(constraintsOrValidationOptions) ? constraintsOrValidationOptions : undefined,
|
||||
validationOptions: !Array.isArray(constraintsOrValidationOptions)
|
||||
? constraintsOrValidationOptions
|
||||
: maybeValidationOptions,
|
||||
};
|
||||
(0, MetadataStorage_1.getMetadataStorage)().addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
|
||||
};
|
||||
}
|
||||
exports.Validate = Validate;
|
||||
//# sourceMappingURL=Validate.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Validate.js","sourceRoot":"","sources":["../../../../src/decorator/common/Validate.ts"],"names":[],"mappings":";;;AAEA,0EAAuE;AACvE,oEAAoE;AACpE,sEAAmE;AACnE,0EAAuE;AAEvE;;GAEG;AACH,SAAgB,mBAAmB,CAAC,OAA4C;IAC9E,OAAO,UAAU,MAAgB;QAC/B,MAAM,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC;QACzC,IAAI,IAAI,GAAG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAI,MAAc,CAAC,IAAI,CAAC;YAC5B,IAAI,CAAC,IAAI;gBACP,oCAAoC;gBACpC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAI,CAAY,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACvG,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,uCAAkB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/D,IAAA,oCAAkB,GAAE,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC;AAbD,kDAaC;AAYD,SAAgB,QAAQ,CACtB,eAAyB,EACzB,8BAA0D,EAC1D,sBAA0C;IAE1C,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,MAAM,IAAI,GAA2B;YACnC,IAAI,EAAE,iCAAe,CAAC,iBAAiB;YACvC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,aAAa,EAAE,eAAe;YAC9B,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAAC,CAAC,SAAS;YACvG,iBAAiB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,8BAA8B,CAAC;gBAC/D,CAAC,CAAC,8BAA8B;gBAChC,CAAC,CAAC,sBAAsB;SAC3B,CAAC;QACF,IAAA,oCAAkB,GAAE,CAAC,qBAAqB,CAAC,IAAI,uCAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC;AAlBD,4BAkBC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs';\nimport { ValidationMetadata } from '../../metadata/ValidationMetadata';\nimport { getMetadataStorage } from '../../metadata/MetadataStorage';\nimport { ValidationTypes } from '../../validation/ValidationTypes';\nimport { ConstraintMetadata } from '../../metadata/ConstraintMetadata';\n\n/**\n * Registers custom validator class.\n */\nexport function ValidatorConstraint(options?: { name?: string; async?: boolean }) {\n return function (target: Function): void {\n const isAsync = options && options.async;\n let name = options && options.name ? options.name : '';\n if (!name) {\n name = (target as any).name;\n if (!name)\n // generate name if it was not given\n name = name.replace(/\\.?([A-Z]+)/g, (x, y) => '_' + (y as string).toLowerCase()).replace(/^_/, '');\n }\n const metadata = new ConstraintMetadata(target, name, isAsync);\n getMetadataStorage().addConstraintMetadata(metadata);\n };\n}\n\n/**\n * Performs validation based on the given custom validation class.\n * Validation class must be decorated with ValidatorConstraint decorator.\n */\nexport function Validate(constraintClass: Function, validationOptions?: ValidationOptions): PropertyDecorator;\nexport function Validate(\n constraintClass: Function,\n constraints?: any[],\n validationOptions?: ValidationOptions\n): PropertyDecorator;\nexport function Validate(\n constraintClass: Function,\n constraintsOrValidationOptions?: any[] | ValidationOptions,\n maybeValidationOptions?: ValidationOptions\n): PropertyDecorator {\n return function (object: object, propertyName: string): void {\n const args: ValidationMetadataArgs = {\n type: ValidationTypes.CUSTOM_VALIDATION,\n target: object.constructor,\n propertyName: propertyName,\n constraintCls: constraintClass,\n constraints: Array.isArray(constraintsOrValidationOptions) ? constraintsOrValidationOptions : undefined,\n validationOptions: !Array.isArray(constraintsOrValidationOptions)\n ? constraintsOrValidationOptions\n : maybeValidationOptions,\n };\n getMetadataStorage().addValidationMetadata(new ValidationMetadata(args));\n };\n}\n"]}
|
||||
Generated
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ValidateBy = exports.buildMessage = void 0;
|
||||
const register_decorator_1 = require("../../register-decorator");
|
||||
function buildMessage(impl, validationOptions) {
|
||||
return (validationArguments) => {
|
||||
const eachPrefix = validationOptions && validationOptions.each ? 'each value in ' : '';
|
||||
return impl(eachPrefix, validationArguments);
|
||||
};
|
||||
}
|
||||
exports.buildMessage = buildMessage;
|
||||
function ValidateBy(options, validationOptions) {
|
||||
return function (object, propertyName) {
|
||||
(0, register_decorator_1.registerDecorator)({
|
||||
name: options.name,
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
constraints: options.constraints,
|
||||
validator: options.validator,
|
||||
});
|
||||
};
|
||||
}
|
||||
exports.ValidateBy = ValidateBy;
|
||||
//# sourceMappingURL=ValidateBy.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ValidateBy.js","sourceRoot":"","sources":["../../../../src/decorator/common/ValidateBy.ts"],"names":[],"mappings":";;;AACA,iEAA6D;AAW7D,SAAgB,YAAY,CAC1B,IAAgE,EAChE,iBAAqC;IAErC,OAAO,CAAC,mBAAyC,EAAU,EAAE;QAC3D,MAAM,UAAU,GAAG,iBAAiB,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;QACvF,OAAO,IAAI,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC;AARD,oCAQC;AAED,SAAgB,UAAU,CAAC,OAA0B,EAAE,iBAAqC;IAC1F,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,IAAA,sCAAiB,EAAC;YAChB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,OAAO,EAAE,iBAAiB;YAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAXD,gCAWC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { registerDecorator } from '../../register-decorator';\nimport { ValidationArguments } from '../../validation/ValidationArguments';\nimport { ValidatorConstraintInterface } from '../../validation/ValidatorConstraintInterface';\n\nexport interface ValidateByOptions {\n name: string;\n constraints?: any[];\n validator: ValidatorConstraintInterface | Function;\n async?: boolean;\n}\n\nexport function buildMessage(\n impl: (eachPrefix: string, args?: ValidationArguments) => string,\n validationOptions?: ValidationOptions\n): (validationArguments?: ValidationArguments) => string {\n return (validationArguments?: ValidationArguments): string => {\n const eachPrefix = validationOptions && validationOptions.each ? 'each value in ' : '';\n return impl(eachPrefix, validationArguments);\n };\n}\n\nexport function ValidateBy(options: ValidateByOptions, validationOptions?: ValidationOptions): PropertyDecorator {\n return function (object: object, propertyName: string): void {\n registerDecorator({\n name: options.name,\n target: object.constructor,\n propertyName: propertyName,\n options: validationOptions,\n constraints: options.constraints,\n validator: options.validator,\n });\n };\n}\n"]}
|
||||
Generated
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ValidateIf = void 0;
|
||||
const ValidationTypes_1 = require("../../validation/ValidationTypes");
|
||||
const ValidationMetadata_1 = require("../../metadata/ValidationMetadata");
|
||||
const MetadataStorage_1 = require("../../metadata/MetadataStorage");
|
||||
/**
|
||||
* Ignores the other validators on a property when the provided condition function returns false.
|
||||
*/
|
||||
function ValidateIf(condition, validationOptions) {
|
||||
return function (object, propertyName) {
|
||||
const args = {
|
||||
type: ValidationTypes_1.ValidationTypes.CONDITIONAL_VALIDATION,
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
constraints: [condition],
|
||||
validationOptions: validationOptions,
|
||||
};
|
||||
(0, MetadataStorage_1.getMetadataStorage)().addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
|
||||
};
|
||||
}
|
||||
exports.ValidateIf = ValidateIf;
|
||||
//# sourceMappingURL=ValidateIf.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ValidateIf.js","sourceRoot":"","sources":["../../../../src/decorator/common/ValidateIf.ts"],"names":[],"mappings":";;;AAEA,sEAAmE;AACnE,0EAAuE;AACvE,oEAAoE;AAEpE;;GAEG;AACH,SAAgB,UAAU,CACxB,SAA+C,EAC/C,iBAAqC;IAErC,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,MAAM,IAAI,GAA2B;YACnC,IAAI,EAAE,iCAAe,CAAC,sBAAsB;YAC5C,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,WAAW,EAAE,CAAC,SAAS,CAAC;YACxB,iBAAiB,EAAE,iBAAiB;SACrC,CAAC;QACF,IAAA,oCAAkB,GAAE,CAAC,qBAAqB,CAAC,IAAI,uCAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC;AAdD,gCAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs';\nimport { ValidationTypes } from '../../validation/ValidationTypes';\nimport { ValidationMetadata } from '../../metadata/ValidationMetadata';\nimport { getMetadataStorage } from '../../metadata/MetadataStorage';\n\n/**\n * Ignores the other validators on a property when the provided condition function returns false.\n */\nexport function ValidateIf(\n condition: (object: any, value: any) => boolean,\n validationOptions?: ValidationOptions\n): PropertyDecorator {\n return function (object: object, propertyName: string): void {\n const args: ValidationMetadataArgs = {\n type: ValidationTypes.CONDITIONAL_VALIDATION,\n target: object.constructor,\n propertyName: propertyName,\n constraints: [condition],\n validationOptions: validationOptions,\n };\n getMetadataStorage().addValidationMetadata(new ValidationMetadata(args));\n };\n}\n"]}
|
||||
Generated
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ValidateNested = void 0;
|
||||
const ValidationTypes_1 = require("../../validation/ValidationTypes");
|
||||
const ValidationMetadata_1 = require("../../metadata/ValidationMetadata");
|
||||
const MetadataStorage_1 = require("../../metadata/MetadataStorage");
|
||||
/**
|
||||
* Objects / object arrays marked with this decorator will also be validated.
|
||||
*/
|
||||
function ValidateNested(validationOptions) {
|
||||
const opts = { ...validationOptions };
|
||||
const eachPrefix = opts.each ? 'each value in ' : '';
|
||||
opts.message = opts.message || eachPrefix + 'nested property $property must be either object or array';
|
||||
return function (object, propertyName) {
|
||||
const args = {
|
||||
type: ValidationTypes_1.ValidationTypes.NESTED_VALIDATION,
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
validationOptions: opts,
|
||||
};
|
||||
(0, MetadataStorage_1.getMetadataStorage)().addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
|
||||
};
|
||||
}
|
||||
exports.ValidateNested = ValidateNested;
|
||||
//# sourceMappingURL=ValidateNested.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ValidateNested.js","sourceRoot":"","sources":["../../../../src/decorator/common/ValidateNested.ts"],"names":[],"mappings":";;;AAEA,sEAAmE;AACnE,0EAAuE;AACvE,oEAAoE;AAEpE;;GAEG;AACH,SAAgB,cAAc,CAAC,iBAAqC;IAClE,MAAM,IAAI,GAAsB,EAAE,GAAG,iBAAiB,EAAE,CAAC;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,UAAU,GAAG,0DAA0D,CAAC;IAEvG,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,MAAM,IAAI,GAA2B;YACnC,IAAI,EAAE,iCAAe,CAAC,iBAAiB;YACvC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,iBAAiB,EAAE,IAAI;SACxB,CAAC;QACF,IAAA,oCAAkB,GAAE,CAAC,qBAAqB,CAAC,IAAI,uCAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC;AAdD,wCAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs';\nimport { ValidationTypes } from '../../validation/ValidationTypes';\nimport { ValidationMetadata } from '../../metadata/ValidationMetadata';\nimport { getMetadataStorage } from '../../metadata/MetadataStorage';\n\n/**\n * Objects / object arrays marked with this decorator will also be validated.\n */\nexport function ValidateNested(validationOptions?: ValidationOptions): PropertyDecorator {\n const opts: ValidationOptions = { ...validationOptions };\n const eachPrefix = opts.each ? 'each value in ' : '';\n opts.message = opts.message || eachPrefix + 'nested property $property must be either object or array';\n\n return function (object: object, propertyName: string): void {\n const args: ValidationMetadataArgs = {\n type: ValidationTypes.NESTED_VALIDATION,\n target: object.constructor,\n propertyName: propertyName,\n validationOptions: opts,\n };\n getMetadataStorage().addValidationMetadata(new ValidationMetadata(args));\n };\n}\n"]}
|
||||
Generated
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ValidatePromise = void 0;
|
||||
const ValidationTypes_1 = require("../../validation/ValidationTypes");
|
||||
const ValidationMetadata_1 = require("../../metadata/ValidationMetadata");
|
||||
const MetadataStorage_1 = require("../../metadata/MetadataStorage");
|
||||
/**
|
||||
* Resolve promise before validation
|
||||
*/
|
||||
function ValidatePromise(validationOptions) {
|
||||
return function (object, propertyName) {
|
||||
const args = {
|
||||
type: ValidationTypes_1.ValidationTypes.PROMISE_VALIDATION,
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
validationOptions: validationOptions,
|
||||
};
|
||||
(0, MetadataStorage_1.getMetadataStorage)().addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
|
||||
};
|
||||
}
|
||||
exports.ValidatePromise = ValidatePromise;
|
||||
//# sourceMappingURL=ValidatePromise.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ValidatePromise.js","sourceRoot":"","sources":["../../../../src/decorator/common/ValidatePromise.ts"],"names":[],"mappings":";;;AAEA,sEAAmE;AACnE,0EAAuE;AACvE,oEAAoE;AAEpE;;GAEG;AACH,SAAgB,eAAe,CAAC,iBAAqC;IACnE,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,MAAM,IAAI,GAA2B;YACnC,IAAI,EAAE,iCAAe,CAAC,kBAAkB;YACxC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,iBAAiB,EAAE,iBAAiB;SACrC,CAAC;QACF,IAAA,oCAAkB,GAAE,CAAC,qBAAqB,CAAC,IAAI,uCAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC;AAVD,0CAUC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs';\nimport { ValidationTypes } from '../../validation/ValidationTypes';\nimport { ValidationMetadata } from '../../metadata/ValidationMetadata';\nimport { getMetadataStorage } from '../../metadata/MetadataStorage';\n\n/**\n * Resolve promise before validation\n */\nexport function ValidatePromise(validationOptions?: ValidationOptions): PropertyDecorator {\n return function (object: object, propertyName: string): void {\n const args: ValidationMetadataArgs = {\n type: ValidationTypes.PROMISE_VALIDATION,\n target: object.constructor,\n propertyName: propertyName,\n validationOptions: validationOptions,\n };\n getMetadataStorage().addValidationMetadata(new ValidationMetadata(args));\n };\n}\n"]}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MaxDate = exports.maxDate = exports.MAX_DATE = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.MAX_DATE = 'maxDate';
|
||||
/**
|
||||
* Checks if the value is a date that's before the specified date.
|
||||
*/
|
||||
function maxDate(date, maxDate) {
|
||||
return date instanceof Date && date.getTime() <= (maxDate instanceof Date ? maxDate : maxDate()).getTime();
|
||||
}
|
||||
exports.maxDate = maxDate;
|
||||
/**
|
||||
* Checks if the value is a date that's before the specified date.
|
||||
*/
|
||||
function MaxDate(date, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.MAX_DATE,
|
||||
constraints: [date],
|
||||
validator: {
|
||||
validate: (value, args) => maxDate(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => 'maximal allowed date for ' + eachPrefix + '$property is $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.MaxDate = MaxDate;
|
||||
//# sourceMappingURL=MaxDate.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MaxDate.js","sourceRoot":"","sources":["../../../../src/decorator/date/MaxDate.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,QAAQ,GAAG,SAAS,CAAC;AAElC;;GAEG;AACH,SAAgB,OAAO,CAAC,IAAa,EAAE,OAA4B;IACjE,OAAO,IAAI,YAAY,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,YAAY,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAC7G,CAAC;AAFD,0BAEC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,IAAyB,EAAE,iBAAqC;IACtF,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,gBAAQ;QACd,WAAW,EAAE,CAAC,IAAI,CAAC;QACnB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACxE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,2BAA2B,GAAG,UAAU,GAAG,2BAA2B,EACpF,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,0BAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const MAX_DATE = 'maxDate';\n\n/**\n * Checks if the value is a date that's before the specified date.\n */\nexport function maxDate(date: unknown, maxDate: Date | (() => Date)): boolean {\n return date instanceof Date && date.getTime() <= (maxDate instanceof Date ? maxDate : maxDate()).getTime();\n}\n\n/**\n * Checks if the value is a date that's before the specified date.\n */\nexport function MaxDate(date: Date | (() => Date), validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: MAX_DATE,\n constraints: [date],\n validator: {\n validate: (value, args): boolean => maxDate(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => 'maximal allowed date for ' + eachPrefix + '$property is $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MinDate = exports.minDate = exports.MIN_DATE = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.MIN_DATE = 'minDate';
|
||||
/**
|
||||
* Checks if the value is a date that's after the specified date.
|
||||
*/
|
||||
function minDate(date, minDate) {
|
||||
return date instanceof Date && date.getTime() >= (minDate instanceof Date ? minDate : minDate()).getTime();
|
||||
}
|
||||
exports.minDate = minDate;
|
||||
/**
|
||||
* Checks if the value is a date that's after the specified date.
|
||||
*/
|
||||
function MinDate(date, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.MIN_DATE,
|
||||
constraints: [date],
|
||||
validator: {
|
||||
validate: (value, args) => minDate(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => 'minimal allowed date for ' + eachPrefix + '$property is $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.MinDate = MinDate;
|
||||
//# sourceMappingURL=MinDate.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MinDate.js","sourceRoot":"","sources":["../../../../src/decorator/date/MinDate.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,QAAQ,GAAG,SAAS,CAAC;AAElC;;GAEG;AACH,SAAgB,OAAO,CAAC,IAAa,EAAE,OAA4B;IACjE,OAAO,IAAI,YAAY,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,YAAY,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAC7G,CAAC;AAFD,0BAEC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,IAAyB,EAAE,iBAAqC;IACtF,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,gBAAQ;QACd,WAAW,EAAE,CAAC,IAAI,CAAC;QACnB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACxE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,2BAA2B,GAAG,UAAU,GAAG,2BAA2B,EACpF,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,0BAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const MIN_DATE = 'minDate';\n\n/**\n * Checks if the value is a date that's after the specified date.\n */\nexport function minDate(date: unknown, minDate: Date | (() => Date)): boolean {\n return date instanceof Date && date.getTime() >= (minDate instanceof Date ? minDate : minDate()).getTime();\n}\n\n/**\n * Checks if the value is a date that's after the specified date.\n */\nexport function MinDate(date: Date | (() => Date), validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: MIN_DATE,\n constraints: [date],\n validator: {\n validate: (value, args): boolean => minDate(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => 'minimal allowed date for ' + eachPrefix + '$property is $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
"use strict";
|
||||
// -------------------------------------------------------------------------
|
||||
// System
|
||||
// -------------------------------------------------------------------------
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// -------------------------------------------------------------------------
|
||||
// Common checkers
|
||||
// -------------------------------------------------------------------------
|
||||
__exportStar(require("./common/Allow"), exports);
|
||||
__exportStar(require("./common/IsDefined"), exports);
|
||||
__exportStar(require("./common/IsOptional"), exports);
|
||||
__exportStar(require("./common/Validate"), exports);
|
||||
__exportStar(require("./common/ValidateBy"), exports);
|
||||
__exportStar(require("./common/ValidateIf"), exports);
|
||||
__exportStar(require("./common/ValidateNested"), exports);
|
||||
__exportStar(require("./common/ValidatePromise"), exports);
|
||||
__exportStar(require("./common/IsLatLong"), exports);
|
||||
__exportStar(require("./common/IsLatitude"), exports);
|
||||
__exportStar(require("./common/IsLongitude"), exports);
|
||||
__exportStar(require("./common/Equals"), exports);
|
||||
__exportStar(require("./common/NotEquals"), exports);
|
||||
__exportStar(require("./common/IsEmpty"), exports);
|
||||
__exportStar(require("./common/IsNotEmpty"), exports);
|
||||
__exportStar(require("./common/IsIn"), exports);
|
||||
__exportStar(require("./common/IsNotIn"), exports);
|
||||
// -------------------------------------------------------------------------
|
||||
// Number checkers
|
||||
// -------------------------------------------------------------------------
|
||||
__exportStar(require("./number/IsDivisibleBy"), exports);
|
||||
__exportStar(require("./number/IsPositive"), exports);
|
||||
__exportStar(require("./number/IsNegative"), exports);
|
||||
__exportStar(require("./number/Max"), exports);
|
||||
__exportStar(require("./number/Min"), exports);
|
||||
// -------------------------------------------------------------------------
|
||||
// Date checkers
|
||||
// -------------------------------------------------------------------------
|
||||
__exportStar(require("./date/MinDate"), exports);
|
||||
__exportStar(require("./date/MaxDate"), exports);
|
||||
// -------------------------------------------------------------------------
|
||||
// String checkers
|
||||
// -------------------------------------------------------------------------
|
||||
__exportStar(require("./string/Contains"), exports);
|
||||
__exportStar(require("./string/NotContains"), exports);
|
||||
__exportStar(require("./string/IsAlpha"), exports);
|
||||
__exportStar(require("./string/IsAlphanumeric"), exports);
|
||||
__exportStar(require("./string/IsDecimal"), exports);
|
||||
__exportStar(require("./string/IsAscii"), exports);
|
||||
__exportStar(require("./string/IsBase64"), exports);
|
||||
__exportStar(require("./string/IsByteLength"), exports);
|
||||
__exportStar(require("./string/IsCreditCard"), exports);
|
||||
__exportStar(require("./string/IsCurrency"), exports);
|
||||
__exportStar(require("./string/IsEmail"), exports);
|
||||
__exportStar(require("./string/IsFQDN"), exports);
|
||||
__exportStar(require("./string/IsFullWidth"), exports);
|
||||
__exportStar(require("./string/IsHalfWidth"), exports);
|
||||
__exportStar(require("./string/IsVariableWidth"), exports);
|
||||
__exportStar(require("./string/IsHexColor"), exports);
|
||||
__exportStar(require("./string/IsHexadecimal"), exports);
|
||||
__exportStar(require("./string/IsMacAddress"), exports);
|
||||
__exportStar(require("./string/IsIP"), exports);
|
||||
__exportStar(require("./string/IsPort"), exports);
|
||||
__exportStar(require("./string/IsISBN"), exports);
|
||||
__exportStar(require("./string/IsISIN"), exports);
|
||||
__exportStar(require("./string/IsISO8601"), exports);
|
||||
__exportStar(require("./string/IsJSON"), exports);
|
||||
__exportStar(require("./string/IsJWT"), exports);
|
||||
__exportStar(require("./string/IsLowercase"), exports);
|
||||
__exportStar(require("./string/IsMobilePhone"), exports);
|
||||
__exportStar(require("./string/IsISO31661Alpha2"), exports);
|
||||
__exportStar(require("./string/IsISO31661Alpha3"), exports);
|
||||
__exportStar(require("./string/IsMongoId"), exports);
|
||||
__exportStar(require("./string/IsMultibyte"), exports);
|
||||
__exportStar(require("./string/IsSurrogatePair"), exports);
|
||||
__exportStar(require("./string/IsUrl"), exports);
|
||||
__exportStar(require("./string/IsUUID"), exports);
|
||||
__exportStar(require("./string/IsFirebasePushId"), exports);
|
||||
__exportStar(require("./string/IsUppercase"), exports);
|
||||
__exportStar(require("./string/Length"), exports);
|
||||
__exportStar(require("./string/MaxLength"), exports);
|
||||
__exportStar(require("./string/MinLength"), exports);
|
||||
__exportStar(require("./string/Matches"), exports);
|
||||
__exportStar(require("./string/IsPhoneNumber"), exports);
|
||||
__exportStar(require("./string/IsMilitaryTime"), exports);
|
||||
__exportStar(require("./string/IsHash"), exports);
|
||||
__exportStar(require("./string/IsISSN"), exports);
|
||||
__exportStar(require("./string/IsDateString"), exports);
|
||||
__exportStar(require("./string/IsBooleanString"), exports);
|
||||
__exportStar(require("./string/IsNumberString"), exports);
|
||||
__exportStar(require("./string/IsBase32"), exports);
|
||||
__exportStar(require("./string/IsBIC"), exports);
|
||||
__exportStar(require("./string/IsBtcAddress"), exports);
|
||||
__exportStar(require("./string/IsDataURI"), exports);
|
||||
__exportStar(require("./string/IsEAN"), exports);
|
||||
__exportStar(require("./string/IsEthereumAddress"), exports);
|
||||
__exportStar(require("./string/IsHSL"), exports);
|
||||
__exportStar(require("./string/IsIBAN"), exports);
|
||||
__exportStar(require("./string/IsIdentityCard"), exports);
|
||||
__exportStar(require("./string/IsISRC"), exports);
|
||||
__exportStar(require("./string/IsLocale"), exports);
|
||||
__exportStar(require("./string/IsMagnetURI"), exports);
|
||||
__exportStar(require("./string/IsMimeType"), exports);
|
||||
__exportStar(require("./string/IsOctal"), exports);
|
||||
__exportStar(require("./string/IsPassportNumber"), exports);
|
||||
__exportStar(require("./string/IsPostalCode"), exports);
|
||||
__exportStar(require("./string/IsRFC3339"), exports);
|
||||
__exportStar(require("./string/IsRgbColor"), exports);
|
||||
__exportStar(require("./string/IsSemVer"), exports);
|
||||
__exportStar(require("./string/IsStrongPassword"), exports);
|
||||
__exportStar(require("./string/IsTimeZone"), exports);
|
||||
__exportStar(require("./string/IsBase58"), exports);
|
||||
__exportStar(require("./string/is-tax-id"), exports);
|
||||
__exportStar(require("./string/is-iso4217-currency-code"), exports);
|
||||
// -------------------------------------------------------------------------
|
||||
// Type checkers
|
||||
// -------------------------------------------------------------------------
|
||||
__exportStar(require("./typechecker/IsBoolean"), exports);
|
||||
__exportStar(require("./typechecker/IsDate"), exports);
|
||||
__exportStar(require("./typechecker/IsNumber"), exports);
|
||||
__exportStar(require("./typechecker/IsEnum"), exports);
|
||||
__exportStar(require("./typechecker/IsInt"), exports);
|
||||
__exportStar(require("./typechecker/IsString"), exports);
|
||||
__exportStar(require("./typechecker/IsArray"), exports);
|
||||
__exportStar(require("./typechecker/IsObject"), exports);
|
||||
// -------------------------------------------------------------------------
|
||||
// Array checkers
|
||||
// -------------------------------------------------------------------------
|
||||
__exportStar(require("./array/ArrayContains"), exports);
|
||||
__exportStar(require("./array/ArrayNotContains"), exports);
|
||||
__exportStar(require("./array/ArrayNotEmpty"), exports);
|
||||
__exportStar(require("./array/ArrayMinSize"), exports);
|
||||
__exportStar(require("./array/ArrayMaxSize"), exports);
|
||||
__exportStar(require("./array/ArrayUnique"), exports);
|
||||
// -------------------------------------------------------------------------
|
||||
// Object checkers
|
||||
// -------------------------------------------------------------------------
|
||||
__exportStar(require("./object/IsNotEmptyObject"), exports);
|
||||
__exportStar(require("./object/IsInstance"), exports);
|
||||
//# sourceMappingURL=decorators.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsDivisibleBy = exports.isDivisibleBy = exports.IS_DIVISIBLE_BY = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isDivisibleBy_1 = __importDefault(require("validator/lib/isDivisibleBy"));
|
||||
exports.IS_DIVISIBLE_BY = 'isDivisibleBy';
|
||||
/**
|
||||
* Checks if value is a number that's divisible by another.
|
||||
*/
|
||||
function isDivisibleBy(value, num) {
|
||||
return typeof value === 'number' && typeof num === 'number' && (0, isDivisibleBy_1.default)(String(value), num);
|
||||
}
|
||||
exports.isDivisibleBy = isDivisibleBy;
|
||||
/**
|
||||
* Checks if value is a number that's divisible by another.
|
||||
*/
|
||||
function IsDivisibleBy(num, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_DIVISIBLE_BY,
|
||||
constraints: [num],
|
||||
validator: {
|
||||
validate: (value, args) => isDivisibleBy(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be divisible by $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsDivisibleBy = IsDivisibleBy;
|
||||
//# sourceMappingURL=IsDivisibleBy.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsDivisibleBy.js","sourceRoot":"","sources":["../../../../src/decorator/number/IsDivisibleBy.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,gFAAiE;AAEpD,QAAA,eAAe,GAAG,eAAe,CAAC;AAE/C;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAc,EAAE,GAAW;IACvD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,IAAA,uBAAsB,EAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5G,CAAC;AAFD,sCAEC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,GAAW,EAAE,iBAAqC;IAC9E,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,uBAAe;QACrB,WAAW,EAAE,CAAC,GAAG,CAAC;QAClB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YAC9E,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,6CAA6C,EACxE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,sCAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isDivisibleByValidator from 'validator/lib/isDivisibleBy';\n\nexport const IS_DIVISIBLE_BY = 'isDivisibleBy';\n\n/**\n * Checks if value is a number that's divisible by another.\n */\nexport function isDivisibleBy(value: unknown, num: number): boolean {\n return typeof value === 'number' && typeof num === 'number' && isDivisibleByValidator(String(value), num);\n}\n\n/**\n * Checks if value is a number that's divisible by another.\n */\nexport function IsDivisibleBy(num: number, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_DIVISIBLE_BY,\n constraints: [num],\n validator: {\n validate: (value, args): boolean => isDivisibleBy(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be divisible by $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsNegative = exports.isNegative = exports.IS_NEGATIVE = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.IS_NEGATIVE = 'isNegative';
|
||||
/**
|
||||
* Checks if the value is a negative number smaller than zero.
|
||||
*/
|
||||
function isNegative(value) {
|
||||
return typeof value === 'number' && value < 0;
|
||||
}
|
||||
exports.isNegative = isNegative;
|
||||
/**
|
||||
* Checks if the value is a negative number smaller than zero.
|
||||
*/
|
||||
function IsNegative(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_NEGATIVE,
|
||||
validator: {
|
||||
validate: (value, args) => isNegative(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a negative number', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsNegative = IsNegative;
|
||||
//# sourceMappingURL=IsNegative.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsNegative.js","sourceRoot":"","sources":["../../../../src/decorator/number/IsNegative.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,WAAW,GAAG,YAAY,CAAC;AAExC;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,CAAC,CAAC;AAChD,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,iBAAqC;IAC9D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,mBAAW;QACjB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;YACrD,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,qCAAqC,EAChE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,gCAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const IS_NEGATIVE = 'isNegative';\n\n/**\n * Checks if the value is a negative number smaller than zero.\n */\nexport function isNegative(value: unknown): boolean {\n return typeof value === 'number' && value < 0;\n}\n\n/**\n * Checks if the value is a negative number smaller than zero.\n */\nexport function IsNegative(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_NEGATIVE,\n validator: {\n validate: (value, args): boolean => isNegative(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be a negative number',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsPositive = exports.isPositive = exports.IS_POSITIVE = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.IS_POSITIVE = 'isPositive';
|
||||
/**
|
||||
* Checks if the value is a positive number greater than zero.
|
||||
*/
|
||||
function isPositive(value) {
|
||||
return typeof value === 'number' && value > 0;
|
||||
}
|
||||
exports.isPositive = isPositive;
|
||||
/**
|
||||
* Checks if the value is a positive number greater than zero.
|
||||
*/
|
||||
function IsPositive(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_POSITIVE,
|
||||
validator: {
|
||||
validate: (value, args) => isPositive(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a positive number', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsPositive = IsPositive;
|
||||
//# sourceMappingURL=IsPositive.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsPositive.js","sourceRoot":"","sources":["../../../../src/decorator/number/IsPositive.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,WAAW,GAAG,YAAY,CAAC;AAExC;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,CAAC,CAAC;AAChD,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,iBAAqC;IAC9D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,mBAAW;QACjB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;YACrD,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,qCAAqC,EAChE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,gCAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const IS_POSITIVE = 'isPositive';\n\n/**\n * Checks if the value is a positive number greater than zero.\n */\nexport function isPositive(value: unknown): boolean {\n return typeof value === 'number' && value > 0;\n}\n\n/**\n * Checks if the value is a positive number greater than zero.\n */\nexport function IsPositive(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_POSITIVE,\n validator: {\n validate: (value, args): boolean => isPositive(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be a positive number',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Max = exports.max = exports.MAX = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.MAX = 'max';
|
||||
/**
|
||||
* Checks if the first number is less than or equal to the second.
|
||||
*/
|
||||
function max(num, max) {
|
||||
return typeof num === 'number' && typeof max === 'number' && num <= max;
|
||||
}
|
||||
exports.max = max;
|
||||
/**
|
||||
* Checks if the value is less than or equal to the allowed maximum value.
|
||||
*/
|
||||
function Max(maxValue, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.MAX,
|
||||
constraints: [maxValue],
|
||||
validator: {
|
||||
validate: (value, args) => max(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must not be greater than $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.Max = Max;
|
||||
//# sourceMappingURL=Max.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Max.js","sourceRoot":"","sources":["../../../../src/decorator/number/Max.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,GAAG,GAAG,KAAK,CAAC;AAEzB;;GAEG;AACH,SAAgB,GAAG,CAAC,GAAY,EAAE,GAAW;IAC3C,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAI,GAAG,CAAC;AAC1E,CAAC;AAFD,kBAEC;AAED;;GAEG;AACH,SAAgB,GAAG,CAAC,QAAgB,EAAE,iBAAqC;IACzE,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,WAAG;QACT,WAAW,EAAE,CAAC,QAAQ,CAAC;QACvB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACpE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,iDAAiD,EAC5E,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,kBAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const MAX = 'max';\n\n/**\n * Checks if the first number is less than or equal to the second.\n */\nexport function max(num: unknown, max: number): boolean {\n return typeof num === 'number' && typeof max === 'number' && num <= max;\n}\n\n/**\n * Checks if the value is less than or equal to the allowed maximum value.\n */\nexport function Max(maxValue: number, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: MAX,\n constraints: [maxValue],\n validator: {\n validate: (value, args): boolean => max(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must not be greater than $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Min = exports.min = exports.MIN = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.MIN = 'min';
|
||||
/**
|
||||
* Checks if the first number is greater than or equal to the second.
|
||||
*/
|
||||
function min(num, min) {
|
||||
return typeof num === 'number' && typeof min === 'number' && num >= min;
|
||||
}
|
||||
exports.min = min;
|
||||
/**
|
||||
* Checks if the value is greater than or equal to the allowed minimum value.
|
||||
*/
|
||||
function Min(minValue, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.MIN,
|
||||
constraints: [minValue],
|
||||
validator: {
|
||||
validate: (value, args) => min(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must not be less than $constraint1', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.Min = Min;
|
||||
//# sourceMappingURL=Min.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Min.js","sourceRoot":"","sources":["../../../../src/decorator/number/Min.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,GAAG,GAAG,KAAK,CAAC;AAEzB;;GAEG;AACH,SAAgB,GAAG,CAAC,GAAY,EAAE,GAAW;IAC3C,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAI,GAAG,CAAC;AAC1E,CAAC;AAFD,kBAEC;AAED;;GAEG;AACH,SAAgB,GAAG,CAAC,QAAgB,EAAE,iBAAqC;IACzE,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,WAAG;QACT,WAAW,EAAE,CAAC,QAAQ,CAAC;QACvB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACpE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,8CAA8C,EACzE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,kBAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const MIN = 'min';\n\n/**\n * Checks if the first number is greater than or equal to the second.\n */\nexport function min(num: unknown, min: number): boolean {\n return typeof num === 'number' && typeof min === 'number' && num >= min;\n}\n\n/**\n * Checks if the value is greater than or equal to the allowed minimum value.\n */\nexport function Min(minValue: number, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: MIN,\n constraints: [minValue],\n validator: {\n validate: (value, args): boolean => min(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must not be less than $constraint1',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsInstance = exports.isInstance = exports.IS_INSTANCE = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
exports.IS_INSTANCE = 'isInstance';
|
||||
/**
|
||||
* Checks if the value is an instance of the specified object.
|
||||
*/
|
||||
function isInstance(object, targetTypeConstructor) {
|
||||
return (targetTypeConstructor && typeof targetTypeConstructor === 'function' && object instanceof targetTypeConstructor);
|
||||
}
|
||||
exports.isInstance = isInstance;
|
||||
/**
|
||||
* Checks if the value is an instance of the specified object.
|
||||
*/
|
||||
function IsInstance(targetType, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_INSTANCE,
|
||||
constraints: [targetType],
|
||||
validator: {
|
||||
validate: (value, args) => isInstance(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)((eachPrefix, args) => {
|
||||
if (args === null || args === void 0 ? void 0 : args.constraints[0]) {
|
||||
return eachPrefix + `$property must be an instance of ${args === null || args === void 0 ? void 0 : args.constraints[0].name}`;
|
||||
}
|
||||
else {
|
||||
return eachPrefix + `${exports.IS_INSTANCE} decorator expects and object as value, but got falsy value.`;
|
||||
}
|
||||
}, validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsInstance = IsInstance;
|
||||
//# sourceMappingURL=IsInstance.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsInstance.js","sourceRoot":"","sources":["../../../../src/decorator/object/IsInstance.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAEnD,QAAA,WAAW,GAAG,YAAY,CAAC;AAExC;;GAEG;AACH,SAAgB,UAAU,CAAC,MAAe,EAAE,qBAAkD;IAC5F,OAAO,CACL,qBAAqB,IAAI,OAAO,qBAAqB,KAAK,UAAU,IAAI,MAAM,YAAY,qBAAqB,CAChH,CAAC;AACJ,CAAC;AAJD,gCAIC;AAED;;GAEG;AACH,SAAgB,UAAU,CACxB,UAAuC,EACvC,iBAAqC;IAErC,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,mBAAW;QACjB,WAAW,EAAE,CAAC,UAAU,CAAC;QACzB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YAC3E,cAAc,EAAE,IAAA,yBAAY,EAAC,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE;gBAChD,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;oBACzB,OAAO,UAAU,GAAG,oCAAoC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,EAAE,IAAc,EAAE,CAAC;gBAChG,CAAC;qBAAM,CAAC;oBACN,OAAO,UAAU,GAAG,GAAG,mBAAW,8DAA8D,CAAC;gBACnG,CAAC;YACH,CAAC,EAAE,iBAAiB,CAAC;SACtB;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AArBD,gCAqBC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\n\nexport const IS_INSTANCE = 'isInstance';\n\n/**\n * Checks if the value is an instance of the specified object.\n */\nexport function isInstance(object: unknown, targetTypeConstructor: new (...args: any[]) => any): boolean {\n return (\n targetTypeConstructor && typeof targetTypeConstructor === 'function' && object instanceof targetTypeConstructor\n );\n}\n\n/**\n * Checks if the value is an instance of the specified object.\n */\nexport function IsInstance(\n targetType: new (...args: any[]) => any,\n validationOptions?: ValidationOptions\n): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_INSTANCE,\n constraints: [targetType],\n validator: {\n validate: (value, args): boolean => isInstance(value, args?.constraints[0]),\n defaultMessage: buildMessage((eachPrefix, args) => {\n if (args?.constraints[0]) {\n return eachPrefix + `$property must be an instance of ${args?.constraints[0].name as string}`;\n } else {\n return eachPrefix + `${IS_INSTANCE} decorator expects and object as value, but got falsy value.`;\n }\n }, validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsNotEmptyObject = exports.isNotEmptyObject = exports.IS_NOT_EMPTY_OBJECT = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const IsObject_1 = require("../typechecker/IsObject");
|
||||
exports.IS_NOT_EMPTY_OBJECT = 'isNotEmptyObject';
|
||||
/**
|
||||
* Checks if the value is valid Object & not empty.
|
||||
* Returns false if the value is not an object or an empty valid object.
|
||||
*/
|
||||
function isNotEmptyObject(value, options) {
|
||||
if (!(0, IsObject_1.isObject)(value)) {
|
||||
return false;
|
||||
}
|
||||
if ((options === null || options === void 0 ? void 0 : options.nullable) === false) {
|
||||
return !Object.values(value).every(propertyValue => propertyValue === null || propertyValue === undefined);
|
||||
}
|
||||
for (const key in value) {
|
||||
if (value.hasOwnProperty(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isNotEmptyObject = isNotEmptyObject;
|
||||
/**
|
||||
* Checks if the value is valid Object & not empty.
|
||||
* Returns false if the value is not an object or an empty valid object.
|
||||
*/
|
||||
function IsNotEmptyObject(options, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_NOT_EMPTY_OBJECT,
|
||||
constraints: [options],
|
||||
validator: {
|
||||
validate: (value, args) => isNotEmptyObject(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a non-empty object', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsNotEmptyObject = IsNotEmptyObject;
|
||||
//# sourceMappingURL=IsNotEmptyObject.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsNotEmptyObject.js","sourceRoot":"","sources":["../../../../src/decorator/object/IsNotEmptyObject.ts"],"names":[],"mappings":";;;AACA,qDAAgE;AAChE,sDAAmD;AAEtC,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AAEtD;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,KAAc,EAAE,OAAgC;IAC/E,IAAI,CAAC,IAAA,mBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,MAAK,KAAK,EAAE,CAAC;QAChC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC,aAAa,KAAK,IAAI,IAAI,aAAa,KAAK,SAAS,CAAC,CAAC;IAC7G,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAhBD,4CAgBC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAC9B,OAAgC,EAChC,iBAAqC;IAErC,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,2BAAmB;QACzB,WAAW,EAAE,CAAC,OAAO,CAAC;QACtB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACjF,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,sCAAsC,EACjE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAlBD,4CAkBC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport { isObject } from '../typechecker/IsObject';\n\nexport const IS_NOT_EMPTY_OBJECT = 'isNotEmptyObject';\n\n/**\n * Checks if the value is valid Object & not empty.\n * Returns false if the value is not an object or an empty valid object.\n */\nexport function isNotEmptyObject(value: unknown, options?: { nullable?: boolean }): boolean {\n if (!isObject(value)) {\n return false;\n }\n\n if (options?.nullable === false) {\n return !Object.values(value).every(propertyValue => propertyValue === null || propertyValue === undefined);\n }\n\n for (const key in value) {\n if (value.hasOwnProperty(key)) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Checks if the value is valid Object & not empty.\n * Returns false if the value is not an object or an empty valid object.\n */\nexport function IsNotEmptyObject(\n options?: { nullable?: boolean },\n validationOptions?: ValidationOptions\n): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_NOT_EMPTY_OBJECT,\n constraints: [options],\n validator: {\n validate: (value, args): boolean => isNotEmptyObject(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be a non-empty object',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Contains = exports.contains = exports.CONTAINS = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const contains_1 = __importDefault(require("validator/lib/contains"));
|
||||
exports.CONTAINS = 'contains';
|
||||
/**
|
||||
* Checks if the string contains the seed.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function contains(value, seed) {
|
||||
return typeof value === 'string' && (0, contains_1.default)(value, seed);
|
||||
}
|
||||
exports.contains = contains;
|
||||
/**
|
||||
* Checks if the string contains the seed.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function Contains(seed, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.CONTAINS,
|
||||
constraints: [seed],
|
||||
validator: {
|
||||
validate: (value, args) => contains(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must contain a $constraint1 string', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.Contains = Contains;
|
||||
//# sourceMappingURL=Contains.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Contains.js","sourceRoot":"","sources":["../../../../src/decorator/string/Contains.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,sEAAuD;AAE1C,QAAA,QAAQ,GAAG,UAAU,CAAC;AAEnC;;;GAGG;AACH,SAAgB,QAAQ,CAAC,KAAc,EAAE,IAAY;IACnD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,kBAAiB,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACrE,CAAC;AAFD,4BAEC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,IAAY,EAAE,iBAAqC;IAC1E,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,gBAAQ;QACd,WAAW,EAAE,CAAC,IAAI,CAAC;QACnB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACzE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,8CAA8C,EACzE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,4BAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport containsValidator from 'validator/lib/contains';\n\nexport const CONTAINS = 'contains';\n\n/**\n * Checks if the string contains the seed.\n * If given value is not a string, then it returns false.\n */\nexport function contains(value: unknown, seed: string): boolean {\n return typeof value === 'string' && containsValidator(value, seed);\n}\n\n/**\n * Checks if the string contains the seed.\n * If given value is not a string, then it returns false.\n */\nexport function Contains(seed: string, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: CONTAINS,\n constraints: [seed],\n validator: {\n validate: (value, args): boolean => contains(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must contain a $constraint1 string',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsAlpha = exports.isAlpha = exports.IS_ALPHA = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isAlpha_1 = __importDefault(require("validator/lib/isAlpha"));
|
||||
exports.IS_ALPHA = 'isAlpha';
|
||||
/**
|
||||
* Checks if the string contains only letters (a-zA-Z).
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isAlpha(value, locale) {
|
||||
return typeof value === 'string' && (0, isAlpha_1.default)(value, locale);
|
||||
}
|
||||
exports.isAlpha = isAlpha;
|
||||
/**
|
||||
* Checks if the string contains only letters (a-zA-Z).
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsAlpha(locale, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_ALPHA,
|
||||
constraints: [locale],
|
||||
validator: {
|
||||
validate: (value, args) => isAlpha(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must contain only letters (a-zA-Z)', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsAlpha = IsAlpha;
|
||||
//# sourceMappingURL=IsAlpha.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsAlpha.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsAlpha.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,oEAAqD;AAGxC,QAAA,QAAQ,GAAG,SAAS,CAAC;AAElC;;;GAGG;AACH,SAAgB,OAAO,CAAC,KAAc,EAAE,MAAgC;IACtE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,iBAAgB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACtE,CAAC;AAFD,0BAEC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,MAAgC,EAAE,iBAAqC;IAC7F,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,gBAAQ;QACd,WAAW,EAAE,CAAC,MAAM,CAAC;QACrB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACxE,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,8CAA8C,EACzE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,0BAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isAlphaValidator from 'validator/lib/isAlpha';\nimport * as ValidatorJS from 'validator';\n\nexport const IS_ALPHA = 'isAlpha';\n\n/**\n * Checks if the string contains only letters (a-zA-Z).\n * If given value is not a string, then it returns false.\n */\nexport function isAlpha(value: unknown, locale?: ValidatorJS.AlphaLocale): boolean {\n return typeof value === 'string' && isAlphaValidator(value, locale);\n}\n\n/**\n * Checks if the string contains only letters (a-zA-Z).\n * If given value is not a string, then it returns false.\n */\nexport function IsAlpha(locale?: ValidatorJS.AlphaLocale, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_ALPHA,\n constraints: [locale],\n validator: {\n validate: (value, args): boolean => isAlpha(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must contain only letters (a-zA-Z)',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsAlphanumeric = exports.isAlphanumeric = exports.IS_ALPHANUMERIC = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isAlphanumeric_1 = __importDefault(require("validator/lib/isAlphanumeric"));
|
||||
exports.IS_ALPHANUMERIC = 'isAlphanumeric';
|
||||
/**
|
||||
* Checks if the string contains only letters and numbers.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isAlphanumeric(value, locale) {
|
||||
return typeof value === 'string' && (0, isAlphanumeric_1.default)(value, locale);
|
||||
}
|
||||
exports.isAlphanumeric = isAlphanumeric;
|
||||
/**
|
||||
* Checks if the string contains only letters and numbers.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsAlphanumeric(locale, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_ALPHANUMERIC,
|
||||
constraints: [locale],
|
||||
validator: {
|
||||
validate: (value, args) => isAlphanumeric(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must contain only letters and numbers', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsAlphanumeric = IsAlphanumeric;
|
||||
//# sourceMappingURL=IsAlphanumeric.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsAlphanumeric.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsAlphanumeric.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,kFAAmE;AAGtD,QAAA,eAAe,GAAG,gBAAgB,CAAC;AAEhD;;;GAGG;AACH,SAAgB,cAAc,CAAC,KAAc,EAAE,MAAuC;IACpF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,wBAAuB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC7E,CAAC;AAFD,wCAEC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAC5B,MAAuC,EACvC,iBAAqC;IAErC,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,uBAAe;QACrB,WAAW,EAAE,CAAC,MAAM,CAAC;QACrB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YAC/E,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,iDAAiD,EAC5E,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAlBD,wCAkBC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isAlphanumericValidator from 'validator/lib/isAlphanumeric';\nimport * as ValidatorJS from 'validator';\n\nexport const IS_ALPHANUMERIC = 'isAlphanumeric';\n\n/**\n * Checks if the string contains only letters and numbers.\n * If given value is not a string, then it returns false.\n */\nexport function isAlphanumeric(value: unknown, locale?: ValidatorJS.AlphanumericLocale): boolean {\n return typeof value === 'string' && isAlphanumericValidator(value, locale);\n}\n\n/**\n * Checks if the string contains only letters and numbers.\n * If given value is not a string, then it returns false.\n */\nexport function IsAlphanumeric(\n locale?: ValidatorJS.AlphanumericLocale,\n validationOptions?: ValidationOptions\n): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_ALPHANUMERIC,\n constraints: [locale],\n validator: {\n validate: (value, args): boolean => isAlphanumeric(value, args?.constraints[0]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must contain only letters and numbers',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsAscii = exports.isAscii = exports.IS_ASCII = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isAscii_1 = __importDefault(require("validator/lib/isAscii"));
|
||||
exports.IS_ASCII = 'isAscii';
|
||||
/**
|
||||
* Checks if the string contains ASCII chars only.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isAscii(value) {
|
||||
return typeof value === 'string' && (0, isAscii_1.default)(value);
|
||||
}
|
||||
exports.isAscii = isAscii;
|
||||
/**
|
||||
* Checks if the string contains ASCII chars only.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsAscii(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_ASCII,
|
||||
validator: {
|
||||
validate: (value, args) => isAscii(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must contain only ASCII characters', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsAscii = IsAscii;
|
||||
//# sourceMappingURL=IsAscii.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsAscii.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsAscii.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,oEAAqD;AAExC,QAAA,QAAQ,GAAG,SAAS,CAAC;AAElC;;;GAGG;AACH,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,iBAAgB,EAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAFD,0BAEC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,iBAAqC;IAC3D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,gBAAQ;QACd,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;YAClD,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,8CAA8C,EACzE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,0BAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isAsciiValidator from 'validator/lib/isAscii';\n\nexport const IS_ASCII = 'isAscii';\n\n/**\n * Checks if the string contains ASCII chars only.\n * If given value is not a string, then it returns false.\n */\nexport function isAscii(value: unknown): boolean {\n return typeof value === 'string' && isAsciiValidator(value);\n}\n\n/**\n * Checks if the string contains ASCII chars only.\n * If given value is not a string, then it returns false.\n */\nexport function IsAscii(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_ASCII,\n validator: {\n validate: (value, args): boolean => isAscii(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must contain only ASCII characters',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsBIC = exports.isBIC = exports.IS_BIC = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isBIC_1 = __importDefault(require("validator/lib/isBIC"));
|
||||
exports.IS_BIC = 'isBIC';
|
||||
/**
|
||||
* Check if a string is a BIC (Bank Identification Code) or SWIFT code.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isBIC(value) {
|
||||
return typeof value === 'string' && (0, isBIC_1.default)(value);
|
||||
}
|
||||
exports.isBIC = isBIC;
|
||||
/**
|
||||
* Check if a string is a BIC (Bank Identification Code) or SWIFT code.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsBIC(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_BIC,
|
||||
validator: {
|
||||
validate: (value, args) => isBIC(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a BIC or SWIFT code', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsBIC = IsBIC;
|
||||
//# sourceMappingURL=IsBIC.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsBIC.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsBIC.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,gEAAiD;AAEpC,QAAA,MAAM,GAAG,OAAO,CAAC;AAE9B;;;GAGG;AACH,SAAgB,KAAK,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,eAAc,EAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAFD,sBAEC;AAED;;;GAGG;AACH,SAAgB,KAAK,CAAC,iBAAqC;IACzD,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,cAAM;QACZ,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;YAChD,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,uCAAuC,EAClE,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,sBAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isBICValidator from 'validator/lib/isBIC';\n\nexport const IS_BIC = 'isBIC';\n\n/**\n * Check if a string is a BIC (Bank Identification Code) or SWIFT code.\n * If given value is not a string, then it returns false.\n */\nexport function isBIC(value: unknown): boolean {\n return typeof value === 'string' && isBICValidator(value);\n}\n\n/**\n * Check if a string is a BIC (Bank Identification Code) or SWIFT code.\n * If given value is not a string, then it returns false.\n */\nexport function IsBIC(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_BIC,\n validator: {\n validate: (value, args): boolean => isBIC(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be a BIC or SWIFT code',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsBase32 = exports.isBase32 = exports.IS_BASE32 = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isBase32_1 = __importDefault(require("validator/lib/isBase32"));
|
||||
exports.IS_BASE32 = 'isBase32';
|
||||
/**
|
||||
* Checks if a string is base32 encoded.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isBase32(value) {
|
||||
return typeof value === 'string' && (0, isBase32_1.default)(value);
|
||||
}
|
||||
exports.isBase32 = isBase32;
|
||||
/**
|
||||
* Check if a string is base32 encoded.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsBase32(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_BASE32,
|
||||
validator: {
|
||||
validate: (value, args) => isBase32(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be base32 encoded', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsBase32 = IsBase32;
|
||||
//# sourceMappingURL=IsBase32.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsBase32.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsBase32.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,sEAAuD;AAE1C,QAAA,SAAS,GAAG,UAAU,CAAC;AAEpC;;;GAGG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,kBAAiB,EAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAFD,4BAEC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,iBAAqC;IAC5D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,iBAAS;QACf,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;YACnD,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,kCAAkC,EAAE,iBAAiB,CAAC;SAC/G;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,4BAWC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isBase32Validator from 'validator/lib/isBase32';\n\nexport const IS_BASE32 = 'isBase32';\n\n/**\n * Checks if a string is base32 encoded.\n * If given value is not a string, then it returns false.\n */\nexport function isBase32(value: unknown): boolean {\n return typeof value === 'string' && isBase32Validator(value);\n}\n\n/**\n * Check if a string is base32 encoded.\n * If given value is not a string, then it returns false.\n */\nexport function IsBase32(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_BASE32,\n validator: {\n validate: (value, args): boolean => isBase32(value),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be base32 encoded', validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsBase58 = exports.isBase58 = exports.IS_BASE58 = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isBase58_1 = __importDefault(require("validator/lib/isBase58"));
|
||||
exports.IS_BASE58 = 'isBase58';
|
||||
/**
|
||||
* Checks if a string is base58 encoded.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isBase58(value) {
|
||||
return typeof value === 'string' && (0, isBase58_1.default)(value);
|
||||
}
|
||||
exports.isBase58 = isBase58;
|
||||
/**
|
||||
* Checks if a string is base58 encoded.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsBase58(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_BASE58,
|
||||
validator: {
|
||||
validate: (value, args) => isBase58(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be base58 encoded', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsBase58 = IsBase58;
|
||||
//# sourceMappingURL=IsBase58.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsBase58.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsBase58.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,sEAAuD;AAE1C,QAAA,SAAS,GAAG,UAAU,CAAC;AAEpC;;;GAGG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,kBAAiB,EAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAFD,4BAEC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,iBAAqC;IAC5D,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,iBAAS;QACf,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;YACnD,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,kCAAkC,EAAE,iBAAiB,CAAC;SAC/G;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,4BAWC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isBase58Validator from 'validator/lib/isBase58';\n\nexport const IS_BASE58 = 'isBase58';\n\n/**\n * Checks if a string is base58 encoded.\n * If given value is not a string, then it returns false.\n */\nexport function isBase58(value: unknown): boolean {\n return typeof value === 'string' && isBase58Validator(value);\n}\n\n/**\n * Checks if a string is base58 encoded.\n * If given value is not a string, then it returns false.\n */\nexport function IsBase58(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_BASE58,\n validator: {\n validate: (value, args): boolean => isBase58(value),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be base58 encoded', validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsBase64 = exports.isBase64 = exports.IS_BASE64 = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isBase64_1 = __importDefault(require("validator/lib/isBase64"));
|
||||
exports.IS_BASE64 = 'isBase64';
|
||||
/**
|
||||
* Checks if a string is base64 encoded.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isBase64(value, options) {
|
||||
return typeof value === 'string' && (0, isBase64_1.default)(value, options);
|
||||
}
|
||||
exports.isBase64 = isBase64;
|
||||
/**
|
||||
* Checks if a string is base64 encoded.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsBase64(options, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_BASE64,
|
||||
constraints: [options],
|
||||
validator: {
|
||||
validate: (value, args) => isBase64(value, args === null || args === void 0 ? void 0 : args.constraints[0]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be base64 encoded', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsBase64 = IsBase64;
|
||||
//# sourceMappingURL=IsBase64.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsBase64.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsBase64.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,sEAAuD;AAG1C,QAAA,SAAS,GAAG,UAAU,CAAC;AAEpC;;;GAGG;AACH,SAAgB,QAAQ,CAAC,KAAc,EAAE,OAAqC;IAC5E,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,kBAAiB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAFD,4BAEC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CACtB,OAAqC,EACrC,iBAAqC;IAErC,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,iBAAS;QACf,WAAW,EAAE,CAAC,OAAO,CAAC;QACtB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACzE,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,kCAAkC,EAAE,iBAAiB,CAAC;SAC/G;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,4BAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isBase64Validator from 'validator/lib/isBase64';\nimport * as ValidatorJS from 'validator';\n\nexport const IS_BASE64 = 'isBase64';\n\n/**\n * Checks if a string is base64 encoded.\n * If given value is not a string, then it returns false.\n */\nexport function isBase64(value: unknown, options?: ValidatorJS.IsBase64Options): boolean {\n return typeof value === 'string' && isBase64Validator(value, options);\n}\n\n/**\n * Checks if a string is base64 encoded.\n * If given value is not a string, then it returns false.\n */\nexport function IsBase64(\n options?: ValidatorJS.IsBase64Options,\n validationOptions?: ValidationOptions\n): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_BASE64,\n constraints: [options],\n validator: {\n validate: (value, args): boolean => isBase64(value, args?.constraints[0]),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be base64 encoded', validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsBooleanString = exports.isBooleanString = exports.IS_BOOLEAN_STRING = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isBoolean_1 = __importDefault(require("validator/lib/isBoolean"));
|
||||
exports.IS_BOOLEAN_STRING = 'isBooleanString';
|
||||
/**
|
||||
* Checks if a string is a boolean.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isBooleanString(value) {
|
||||
return typeof value === 'string' && (0, isBoolean_1.default)(value);
|
||||
}
|
||||
exports.isBooleanString = isBooleanString;
|
||||
/**
|
||||
* Checks if a string is a boolean.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsBooleanString(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_BOOLEAN_STRING,
|
||||
validator: {
|
||||
validate: (value, args) => isBooleanString(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a boolean string', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsBooleanString = IsBooleanString;
|
||||
//# sourceMappingURL=IsBooleanString.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsBooleanString.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsBooleanString.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,wEAAyD;AAE5C,QAAA,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD;;;GAGG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,mBAAkB,EAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAFD,0CAEC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,iBAAqC;IACnE,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,yBAAiB;QACvB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC;YAC1D,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,oCAAoC,EAC/D,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAdD,0CAcC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isBooleanValidator from 'validator/lib/isBoolean';\n\nexport const IS_BOOLEAN_STRING = 'isBooleanString';\n\n/**\n * Checks if a string is a boolean.\n * If given value is not a string, then it returns false.\n */\nexport function isBooleanString(value: unknown): boolean {\n return typeof value === 'string' && isBooleanValidator(value);\n}\n\n/**\n * Checks if a string is a boolean.\n * If given value is not a string, then it returns false.\n */\nexport function IsBooleanString(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_BOOLEAN_STRING,\n validator: {\n validate: (value, args): boolean => isBooleanString(value),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + '$property must be a boolean string',\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsBtcAddress = exports.isBtcAddress = exports.IS_BTC_ADDRESS = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isBtcAddress_1 = __importDefault(require("validator/lib/isBtcAddress"));
|
||||
exports.IS_BTC_ADDRESS = 'isBtcAddress';
|
||||
/**
|
||||
* Check if the string is a valid BTC address.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isBtcAddress(value) {
|
||||
return typeof value === 'string' && (0, isBtcAddress_1.default)(value);
|
||||
}
|
||||
exports.isBtcAddress = isBtcAddress;
|
||||
/**
|
||||
* Check if the string is a valid BTC address.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsBtcAddress(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_BTC_ADDRESS,
|
||||
validator: {
|
||||
validate: (value, args) => isBtcAddress(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a BTC address', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsBtcAddress = IsBtcAddress;
|
||||
//# sourceMappingURL=IsBtcAddress.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsBtcAddress.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsBtcAddress.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,8EAA+D;AAElD,QAAA,cAAc,GAAG,cAAc,CAAC;AAE7C;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,sBAAqB,EAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,iBAAqC;IAChE,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,sBAAc;QACpB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC;YACvD,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,iCAAiC,EAAE,iBAAiB,CAAC;SAC9G;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,oCAWC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isBtcAddressValidator from 'validator/lib/isBtcAddress';\n\nexport const IS_BTC_ADDRESS = 'isBtcAddress';\n\n/**\n * Check if the string is a valid BTC address.\n * If given value is not a string, then it returns false.\n */\nexport function isBtcAddress(value: unknown): boolean {\n return typeof value === 'string' && isBtcAddressValidator(value);\n}\n\n/**\n * Check if the string is a valid BTC address.\n * If given value is not a string, then it returns false.\n */\nexport function IsBtcAddress(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_BTC_ADDRESS,\n validator: {\n validate: (value, args): boolean => isBtcAddress(value),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a BTC address', validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsByteLength = exports.isByteLength = exports.IS_BYTE_LENGTH = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isByteLength_1 = __importDefault(require("validator/lib/isByteLength"));
|
||||
exports.IS_BYTE_LENGTH = 'isByteLength';
|
||||
/**
|
||||
* Checks if the string's length (in bytes) falls in a range.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isByteLength(value, min, max) {
|
||||
return typeof value === 'string' && (0, isByteLength_1.default)(value, { min, max });
|
||||
}
|
||||
exports.isByteLength = isByteLength;
|
||||
/**
|
||||
* Checks if the string's length (in bytes) falls in a range.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsByteLength(min, max, validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_BYTE_LENGTH,
|
||||
constraints: [min, max],
|
||||
validator: {
|
||||
validate: (value, args) => isByteLength(value, args === null || args === void 0 ? void 0 : args.constraints[0], args === null || args === void 0 ? void 0 : args.constraints[1]),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + "$property's byte length must fall into ($constraint1, $constraint2) range", validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsByteLength = IsByteLength;
|
||||
//# sourceMappingURL=IsByteLength.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsByteLength.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsByteLength.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,8EAA+D;AAElD,QAAA,cAAc,GAAG,cAAc,CAAC;AAE7C;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAc,EAAE,GAAW,EAAE,GAAY;IACpE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,sBAAqB,EAAC,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;AACjF,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,GAAY,EAAE,iBAAqC;IAC3F,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,sBAAc;QACpB,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;QACvB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YACnG,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,2EAA2E,EACtG,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,oCAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isByteLengthValidator from 'validator/lib/isByteLength';\n\nexport const IS_BYTE_LENGTH = 'isByteLength';\n\n/**\n * Checks if the string's length (in bytes) falls in a range.\n * If given value is not a string, then it returns false.\n */\nexport function isByteLength(value: unknown, min: number, max?: number): boolean {\n return typeof value === 'string' && isByteLengthValidator(value, { min, max });\n}\n\n/**\n * Checks if the string's length (in bytes) falls in a range.\n * If given value is not a string, then it returns false.\n */\nexport function IsByteLength(min: number, max?: number, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_BYTE_LENGTH,\n constraints: [min, max],\n validator: {\n validate: (value, args): boolean => isByteLength(value, args?.constraints[0], args?.constraints[1]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + \"$property's byte length must fall into ($constraint1, $constraint2) range\",\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Generated
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsCreditCard = exports.isCreditCard = exports.IS_CREDIT_CARD = void 0;
|
||||
const ValidateBy_1 = require("../common/ValidateBy");
|
||||
const isCreditCard_1 = __importDefault(require("validator/lib/isCreditCard"));
|
||||
exports.IS_CREDIT_CARD = 'isCreditCard';
|
||||
/**
|
||||
* Checks if the string is a credit card.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function isCreditCard(value) {
|
||||
return typeof value === 'string' && (0, isCreditCard_1.default)(value);
|
||||
}
|
||||
exports.isCreditCard = isCreditCard;
|
||||
/**
|
||||
* Checks if the string is a credit card.
|
||||
* If given value is not a string, then it returns false.
|
||||
*/
|
||||
function IsCreditCard(validationOptions) {
|
||||
return (0, ValidateBy_1.ValidateBy)({
|
||||
name: exports.IS_CREDIT_CARD,
|
||||
validator: {
|
||||
validate: (value, args) => isCreditCard(value),
|
||||
defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a credit card', validationOptions),
|
||||
},
|
||||
}, validationOptions);
|
||||
}
|
||||
exports.IsCreditCard = IsCreditCard;
|
||||
//# sourceMappingURL=IsCreditCard.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"IsCreditCard.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsCreditCard.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,8EAA+D;AAElD,QAAA,cAAc,GAAG,cAAc,CAAC;AAE7C;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,sBAAqB,EAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,iBAAqC;IAChE,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,sBAAc;QACpB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC;YACvD,cAAc,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,iCAAiC,EAAE,iBAAiB,CAAC;SAC9G;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,oCAWC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isCreditCardValidator from 'validator/lib/isCreditCard';\n\nexport const IS_CREDIT_CARD = 'isCreditCard';\n\n/**\n * Checks if the string is a credit card.\n * If given value is not a string, then it returns false.\n */\nexport function isCreditCard(value: unknown): boolean {\n return typeof value === 'string' && isCreditCardValidator(value);\n}\n\n/**\n * Checks if the string is a credit card.\n * If given value is not a string, then it returns false.\n */\nexport function IsCreditCard(validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_CREDIT_CARD,\n validator: {\n validate: (value, args): boolean => isCreditCard(value),\n defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a credit card', validationOptions),\n },\n },\n validationOptions\n );\n}\n"]}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user