@diia-inhouse/validators 1.28.36 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -20
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/rule.d.ts +17 -0
- package/dist/interfaces/schema.d.ts +8 -0
- package/dist/interfaces/validationSchema.d.ts +90 -0
- package/dist/rules/buffer.js +25 -26
- package/dist/rules/date.js +44 -40
- package/dist/rules/index.js +7 -23
- package/dist/rules/internationalPhoneNumber.js +26 -27
- package/dist/rules/objectId.js +25 -26
- package/dist/rules/phoneNumber.js +30 -32
- package/dist/rules/version.js +44 -37
- package/dist/schemas/index.d.ts +19 -0
- package/dist/schemas/index.js +132 -106
- package/dist/validator.d.ts +15 -0
- package/dist/validator.js +46 -49
- package/package.json +30 -20
- package/dist/index.js.map +0 -1
- package/dist/interfaces/index.js +0 -20
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/rule.js +0 -3
- package/dist/interfaces/rule.js.map +0 -1
- package/dist/interfaces/schema.js +0 -3
- package/dist/interfaces/schema.js.map +0 -1
- package/dist/interfaces/validationSchema.js +0 -3
- package/dist/interfaces/validationSchema.js.map +0 -1
- package/dist/rules/buffer.js.map +0 -1
- package/dist/rules/date.js.map +0 -1
- package/dist/rules/index.js.map +0 -1
- package/dist/rules/internationalPhoneNumber.js.map +0 -1
- package/dist/rules/objectId.js.map +0 -1
- package/dist/rules/phoneNumber.js.map +0 -1
- package/dist/rules/version.js.map +0 -1
- package/dist/schemas/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/interfaces/index.d.ts +0 -3
- package/dist/types/interfaces/rule.d.ts +0 -13
- package/dist/types/interfaces/schema.d.ts +0 -5
- package/dist/types/interfaces/validationSchema.d.ts +0 -92
- package/dist/types/rules/buffer.d.ts +0 -7
- package/dist/types/rules/date.d.ts +0 -9
- package/dist/types/rules/index.d.ts +0 -6
- package/dist/types/rules/internationalPhoneNumber.d.ts +0 -8
- package/dist/types/rules/objectId.d.ts +0 -7
- package/dist/types/rules/phoneNumber.d.ts +0 -9
- package/dist/types/rules/version.d.ts +0 -10
- package/dist/types/schemas/index.d.ts +0 -14
- package/dist/types/validator.d.ts +0 -11
- package/dist/validator.js.map +0 -1
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { ObjectId } from 'bson';
|
|
2
|
-
import { Context, ValidationRuleObject } from 'fastest-validator';
|
|
3
|
-
export type RuleType = 'any' | 'boolean' | 'number' | 'email' | 'object' | 'string' | 'enum' | 'uuid' | 'array' | 'forbidden' | 'function' | 'date' | 'customDate' | 'objectId' | 'version' | 'phoneNumber' | 'internationalPhoneNumber' | 'buffer' | 'record';
|
|
4
|
-
export interface CheckerFunctionError {
|
|
5
|
-
type: string;
|
|
6
|
-
messages: string;
|
|
7
|
-
field?: string;
|
|
8
|
-
}
|
|
9
|
-
interface BasicRule<T extends RuleType> {
|
|
10
|
-
type: T;
|
|
11
|
-
optional?: boolean;
|
|
12
|
-
default?: unknown;
|
|
13
|
-
null?: boolean;
|
|
14
|
-
}
|
|
15
|
-
interface Sanitazible {
|
|
16
|
-
convert?: boolean;
|
|
17
|
-
}
|
|
18
|
-
export interface NumberRule extends BasicRule<'number'>, Sanitazible {
|
|
19
|
-
min?: number;
|
|
20
|
-
max?: number;
|
|
21
|
-
equal?: number;
|
|
22
|
-
notEqual?: number;
|
|
23
|
-
integer?: boolean;
|
|
24
|
-
positive?: boolean;
|
|
25
|
-
negative?: boolean;
|
|
26
|
-
}
|
|
27
|
-
export interface ArrayRule<T = null> extends BasicRule<'array'> {
|
|
28
|
-
items?: ValidationProperty<T>;
|
|
29
|
-
empty?: boolean;
|
|
30
|
-
min?: number;
|
|
31
|
-
max?: number;
|
|
32
|
-
length?: number;
|
|
33
|
-
contains?: any;
|
|
34
|
-
enum?: any[];
|
|
35
|
-
unique?: boolean;
|
|
36
|
-
}
|
|
37
|
-
export interface ObjectRule<T = null> extends BasicRule<'object'> {
|
|
38
|
-
props?: ValidationSchema<T>;
|
|
39
|
-
strict?: boolean;
|
|
40
|
-
}
|
|
41
|
-
export interface RecordRule<K, V> extends BasicRule<'record'> {
|
|
42
|
-
key: EnumRule<K> | StringRule;
|
|
43
|
-
value: ValidationProperty<V> | ValidationProperty<V>[];
|
|
44
|
-
}
|
|
45
|
-
export interface StringRule extends BasicRule<'string'> {
|
|
46
|
-
empty?: boolean;
|
|
47
|
-
min?: number;
|
|
48
|
-
max?: number;
|
|
49
|
-
length?: number;
|
|
50
|
-
pattern?: any;
|
|
51
|
-
contains?: any;
|
|
52
|
-
enum?: string[];
|
|
53
|
-
alpha?: boolean;
|
|
54
|
-
numeric?: boolean;
|
|
55
|
-
alphanum?: boolean;
|
|
56
|
-
alphadash?: boolean;
|
|
57
|
-
uppercase?: boolean;
|
|
58
|
-
custom?: (value: string, errors: CheckerFunctionError[], ruleSchema?: ValidationRuleObject, path?: string, parent?: object | null, context?: Context) => string;
|
|
59
|
-
}
|
|
60
|
-
export interface EmailRule extends BasicRule<'email'> {
|
|
61
|
-
mode?: string;
|
|
62
|
-
}
|
|
63
|
-
export interface VersionRule extends BasicRule<'version'>, Sanitazible {
|
|
64
|
-
versions?: string[];
|
|
65
|
-
}
|
|
66
|
-
export interface EnumRule<T = any> extends BasicRule<'enum'> {
|
|
67
|
-
values: T[];
|
|
68
|
-
}
|
|
69
|
-
export interface DateRule extends BasicRule<'date'>, Sanitazible {
|
|
70
|
-
format?: string;
|
|
71
|
-
}
|
|
72
|
-
export interface ListValidationSchema {
|
|
73
|
-
skip: NumberRule;
|
|
74
|
-
limit: NumberRule;
|
|
75
|
-
}
|
|
76
|
-
export interface CustomDateRule extends BasicRule<'customDate'>, Sanitazible {
|
|
77
|
-
}
|
|
78
|
-
export interface ObjectIdRule extends BasicRule<'objectId'>, Sanitazible {
|
|
79
|
-
}
|
|
80
|
-
export interface BooleanRule extends BasicRule<'boolean'>, Sanitazible {
|
|
81
|
-
}
|
|
82
|
-
type CommonRule = BasicRule<'any' | 'forbidden'> | EnumRule;
|
|
83
|
-
type ComplexRule = StringRule | NumberRule | BooleanRule | ArrayRule | ObjectRule | DateRule | CustomDateRule | EmailRule | EnumRule | ObjectIdRule | RecordRule<string, unknown> | VersionRule;
|
|
84
|
-
type ValidationProperty<T = null> = T extends null ? ValidationRule : T extends string ? StringRule | EmailRule | VersionRule | BasicRule<'uuid' | 'phoneNumber' | 'internationalPhoneNumber'> : T extends number ? NumberRule : T extends boolean ? BooleanRule : T extends Date ? DateRule | CustomDateRule | StringRule : T extends Buffer ? BasicRule<'buffer'> : T extends ObjectId ? ObjectIdRule | StringRule : T extends ArrayLike<infer U> ? ArrayRule<U> : T extends object ? ObjectRule<T> | RecordRule<keyof T, Required<T>[keyof T]> : ValidationRule;
|
|
85
|
-
type Rule = string | boolean | ComplexRule | CommonRule | BasicRule<Exclude<RuleType, CommonRule['type'] | ComplexRule['type']>>;
|
|
86
|
-
export type ValidationRule<T = null> = T extends null ? Rule : T extends object ? ObjectRule<T> : T extends ArrayLike<infer U> ? ArrayRule<U> : Rule;
|
|
87
|
-
export type ValidationSchema<T = null> = T extends null ? {
|
|
88
|
-
[path: string]: ValidationRule | ValidationRule[];
|
|
89
|
-
} : {
|
|
90
|
-
[path in keyof Required<T>]: ValidationProperty<T[path]> | ValidationProperty<T[path]>[] | CommonRule;
|
|
91
|
-
};
|
|
92
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Fastest from 'fastest-validator';
|
|
2
|
-
import { Rule, RuleValidator } from '../interfaces/rule';
|
|
3
|
-
export declare class DateValidationRule implements Rule {
|
|
4
|
-
private readonly checkPattern;
|
|
5
|
-
constructor(checkPattern?: RegExp);
|
|
6
|
-
getName(): string;
|
|
7
|
-
getMessage(): string;
|
|
8
|
-
getRule(validator: Fastest): RuleValidator;
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import Fastest from 'fastest-validator';
|
|
2
|
-
import { Rule, RuleValidator } from '../interfaces/rule';
|
|
3
|
-
export declare class InternationalPhoneNumberValidationRule implements Rule {
|
|
4
|
-
private checkPattern;
|
|
5
|
-
getName(): string;
|
|
6
|
-
getMessage(): string;
|
|
7
|
-
getRule(validator: Fastest): RuleValidator;
|
|
8
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Fastest from 'fastest-validator';
|
|
2
|
-
import { Rule, RuleValidator } from '../interfaces/rule';
|
|
3
|
-
export declare class PhoneNumberValidationRule implements Rule {
|
|
4
|
-
private checkPattern;
|
|
5
|
-
constructor();
|
|
6
|
-
getName(): string;
|
|
7
|
-
getMessage(): string;
|
|
8
|
-
getRule(validator: Fastest): RuleValidator;
|
|
9
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import Fastest from 'fastest-validator';
|
|
2
|
-
import { Rule, RuleValidator } from '../interfaces/rule';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated
|
|
5
|
-
*/
|
|
6
|
-
export declare class VersionValidationRule implements Rule {
|
|
7
|
-
getName(): string;
|
|
8
|
-
getMessage(): string;
|
|
9
|
-
getRule(validator: Fastest): RuleValidator;
|
|
10
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AppVersions } from '@diia-inhouse/types';
|
|
2
|
-
import { ListValidationSchema, ObjectRule, ParameterValidation, StringRule } from '../interfaces';
|
|
3
|
-
export declare const availableMobileCodes: string[];
|
|
4
|
-
export declare const phoneNumberValidation: ParameterValidation;
|
|
5
|
-
export declare const phoneNumberWithoutPlusValidation: ParameterValidation;
|
|
6
|
-
export declare const emailValidation: ParameterValidation;
|
|
7
|
-
export declare const emailRuValidation: ParameterValidation;
|
|
8
|
-
export declare const shortTextValidation: ParameterValidation;
|
|
9
|
-
export declare const zipValidation: ParameterValidation;
|
|
10
|
-
/** @deprecated use getListValidationSchema function instead */
|
|
11
|
-
export declare const listValidationSchema: ListValidationSchema;
|
|
12
|
-
export declare function getListValidationSchema(min?: number, max?: number): ListValidationSchema;
|
|
13
|
-
export declare const appVersionsValidationSchema: ObjectRule<AppVersions>;
|
|
14
|
-
export declare function getStringDateSchema(format?: string, optional?: boolean): StringRule;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ValidationSchema } from 'fastest-validator';
|
|
2
|
-
import { ErrorType } from '@diia-inhouse/errors';
|
|
3
|
-
export declare class AppValidator {
|
|
4
|
-
private readonly validator;
|
|
5
|
-
private customRules;
|
|
6
|
-
constructor();
|
|
7
|
-
compile(schema: ValidationSchema): (params: unknown) => boolean;
|
|
8
|
-
validate(params: unknown, schema: ValidationSchema, errorType?: ErrorType): boolean;
|
|
9
|
-
private getCustomValidatorsMessages;
|
|
10
|
-
private addCustomValidationRules;
|
|
11
|
-
}
|
package/dist/validator.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAsE;AAEtE,iDAAkG;AAGlG,mCAA4I;AAC5I,+EAAyF;AAEzF,MAAa,YAAY;IACJ,SAAS,CAAkB;IAEpC,WAAW,CAAQ;IAE3B;QACI,IAAI,CAAC,WAAW,GAAG;YACf,IAAI,4BAAoB,EAAE;YAC1B,IAAI,0BAAkB,EAAE;YACxB,IAAI,8BAAsB,EAAE;YAC5B,IAAI,iCAAyB,EAAE;YAC/B,IAAI,iEAAsC,EAAE;YAC5C,IAAI,6BAAqB,EAAE;SAC9B,CAAA;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,2BAAgB,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,2BAA2B,EAAE,EAAE,2BAA2B,EAAE,IAAI,EAAE,CAAC,CAAA;QAE1H,IAAI,CAAC,wBAAwB,EAAE,CAAA;IACnC,CAAC;IAED,OAAO,CAAC,MAAwB;QAC5B,OAAO,CAAC,MAAe,EAAW,EAAE,CAAC,IAAI,C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