@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Rule, RuleValidator } from "./interfaces/rule.js";
|
|
2
|
+
import { ParameterValidation } from "./interfaces/schema.js";
|
|
3
|
+
import { ArrayRule, BooleanRule, CheckerFunctionError, CustomDateRule, DateRule, EmailRule, EnumRule, ListValidationSchema, NumberRule, ObjectIdRule, ObjectRule, RecordRule, RuleType, StringRule, ValidationRule, ValidationSchema, VersionRule } from "./interfaces/validationSchema.js";
|
|
4
|
+
import { AppValidator } from "./validator.js";
|
|
5
|
+
import { appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation } from "./schemas/index.js";
|
|
6
|
+
export { AppValidator, ArrayRule, BooleanRule, CheckerFunctionError, CustomDateRule, DateRule, EmailRule, EnumRule, ListValidationSchema, NumberRule, ObjectIdRule, ObjectRule, ParameterValidation, RecordRule, Rule, RuleType, RuleValidator, StringRule, ValidationRule, ValidationSchema, VersionRule, appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation };
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./interfaces"), exports);
|
|
18
|
-
__exportStar(require("./validator"), exports);
|
|
19
|
-
__exportStar(require("./schemas"), exports);
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation } from "./schemas/index.js";
|
|
2
|
+
import { AppValidator } from "./validator.js";
|
|
3
|
+
export { AppValidator, appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Rule, RuleValidator } from "./rule.js";
|
|
2
|
+
import { ParameterValidation } from "./schema.js";
|
|
3
|
+
import { ArrayRule, BooleanRule, CheckerFunctionError, CustomDateRule, DateRule, EmailRule, EnumRule, ListValidationSchema, NumberRule, ObjectIdRule, ObjectRule, RecordRule, RuleType, StringRule, ValidationRule, ValidationSchema, VersionRule } from "./validationSchema.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import FastestValidator, { MessagesType, ValidationSchema } from "fastest-validator";
|
|
2
|
+
|
|
3
|
+
//#region src/interfaces/rule.d.ts
|
|
4
|
+
type RuleValidator = (param: {
|
|
5
|
+
messages: MessagesType;
|
|
6
|
+
schema: ValidationSchema;
|
|
7
|
+
}) => {
|
|
8
|
+
source: string;
|
|
9
|
+
sanitized?: boolean;
|
|
10
|
+
};
|
|
11
|
+
interface Rule {
|
|
12
|
+
getName(): string;
|
|
13
|
+
getMessage(): string;
|
|
14
|
+
getRule(validator: FastestValidator): RuleValidator;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Rule, RuleValidator };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Context, ValidationRuleObject } from "fastest-validator";
|
|
2
|
+
import { ObjectId } from "bson";
|
|
3
|
+
|
|
4
|
+
//#region src/interfaces/validationSchema.d.ts
|
|
5
|
+
type RuleType = "any" | "boolean" | "number" | "email" | "object" | "string" | "enum" | "uuid" | "array" | "forbidden" | "function" | "date" | "customDate" | "objectId" | "version" | "phoneNumber" | "internationalPhoneNumber" | "buffer" | "record";
|
|
6
|
+
interface CheckerFunctionError {
|
|
7
|
+
type: string;
|
|
8
|
+
messages: string;
|
|
9
|
+
field?: string;
|
|
10
|
+
}
|
|
11
|
+
interface BasicRule<T extends RuleType> {
|
|
12
|
+
type: T;
|
|
13
|
+
optional?: boolean;
|
|
14
|
+
default?: unknown;
|
|
15
|
+
null?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface Sanitazible {
|
|
18
|
+
convert?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface NumberRule extends BasicRule<"number">, Sanitazible {
|
|
21
|
+
min?: number;
|
|
22
|
+
max?: number;
|
|
23
|
+
equal?: number;
|
|
24
|
+
notEqual?: number;
|
|
25
|
+
integer?: boolean;
|
|
26
|
+
positive?: boolean;
|
|
27
|
+
negative?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface ArrayRule<T = null> extends BasicRule<"array"> {
|
|
30
|
+
items?: ValidationProperty<T>;
|
|
31
|
+
empty?: boolean;
|
|
32
|
+
min?: number;
|
|
33
|
+
max?: number;
|
|
34
|
+
length?: number;
|
|
35
|
+
contains?: any;
|
|
36
|
+
enum?: any[];
|
|
37
|
+
unique?: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface ObjectRule<T = null> extends BasicRule<"object"> {
|
|
40
|
+
props?: ValidationSchema$1<T>;
|
|
41
|
+
strict?: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface RecordRule<K, V> extends BasicRule<"record"> {
|
|
44
|
+
key: EnumRule<K> | StringRule;
|
|
45
|
+
value: ValidationProperty<V> | ValidationProperty<V>[];
|
|
46
|
+
}
|
|
47
|
+
interface StringRule extends BasicRule<"string"> {
|
|
48
|
+
empty?: boolean;
|
|
49
|
+
min?: number;
|
|
50
|
+
max?: number;
|
|
51
|
+
length?: number;
|
|
52
|
+
pattern?: any;
|
|
53
|
+
contains?: any;
|
|
54
|
+
enum?: string[];
|
|
55
|
+
alpha?: boolean;
|
|
56
|
+
numeric?: boolean;
|
|
57
|
+
alphanum?: boolean;
|
|
58
|
+
alphadash?: boolean;
|
|
59
|
+
uppercase?: boolean;
|
|
60
|
+
custom?: (value: string, errors: CheckerFunctionError[], ruleSchema?: ValidationRuleObject, path?: string, parent?: object | null, context?: Context) => string;
|
|
61
|
+
}
|
|
62
|
+
interface EmailRule extends BasicRule<"email"> {
|
|
63
|
+
mode?: string;
|
|
64
|
+
}
|
|
65
|
+
interface VersionRule extends BasicRule<"version">, Sanitazible {
|
|
66
|
+
versions?: string[];
|
|
67
|
+
}
|
|
68
|
+
interface EnumRule<T = any> extends BasicRule<"enum"> {
|
|
69
|
+
values: T[];
|
|
70
|
+
}
|
|
71
|
+
interface DateRule extends BasicRule<"date">, Sanitazible {
|
|
72
|
+
format?: string;
|
|
73
|
+
}
|
|
74
|
+
interface ListValidationSchema {
|
|
75
|
+
skip: NumberRule;
|
|
76
|
+
limit: NumberRule;
|
|
77
|
+
}
|
|
78
|
+
interface CustomDateRule extends BasicRule<"customDate">, Sanitazible {}
|
|
79
|
+
interface ObjectIdRule extends BasicRule<"objectId">, Sanitazible {}
|
|
80
|
+
interface BooleanRule extends BasicRule<"boolean">, Sanitazible {}
|
|
81
|
+
type CommonRule = BasicRule<"any" | "forbidden"> | EnumRule;
|
|
82
|
+
type ComplexRule = StringRule | NumberRule | BooleanRule | ArrayRule | ObjectRule | DateRule | CustomDateRule | EmailRule | EnumRule | ObjectIdRule | RecordRule<string, unknown> | VersionRule;
|
|
83
|
+
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;
|
|
84
|
+
type Rule = string | boolean | ComplexRule | CommonRule | BasicRule<Exclude<RuleType, CommonRule["type"] | ComplexRule["type"]>>;
|
|
85
|
+
type ValidationRule<T = null> = T extends null ? Rule : T extends object ? ObjectRule<T> : T extends ArrayLike<infer U> ? ArrayRule<U> : Rule;
|
|
86
|
+
type ValidationSchema$1<T = null> = T extends null ? {
|
|
87
|
+
[path: string]: ValidationRule | ValidationRule[];
|
|
88
|
+
} : { [path in keyof Required<T>]: ValidationProperty<T[path]> | ValidationProperty<T[path]>[] | CommonRule };
|
|
89
|
+
//#endregion
|
|
90
|
+
export { ArrayRule, BooleanRule, CheckerFunctionError, CustomDateRule, DateRule, EmailRule, EnumRule, ListValidationSchema, NumberRule, ObjectIdRule, ObjectRule, RecordRule, RuleType, StringRule, ValidationRule, ValidationSchema$1 as ValidationSchema, VersionRule };
|
package/dist/rules/buffer.js
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return ({ messages }) => {
|
|
16
|
-
const source = `
|
|
1
|
+
//#region src/rules/buffer.ts
|
|
2
|
+
var BufferValidationRule = class {
|
|
3
|
+
getName() {
|
|
4
|
+
return "buffer";
|
|
5
|
+
}
|
|
6
|
+
getMessage() {
|
|
7
|
+
return "The '{field}' field must be an Buffer object!";
|
|
8
|
+
}
|
|
9
|
+
getRule(validator) {
|
|
10
|
+
/**
|
|
11
|
+
* Signature: function(value, field, parent, errors, context)
|
|
12
|
+
*/
|
|
13
|
+
return ({ messages }) => {
|
|
14
|
+
return { source: `
|
|
17
15
|
if (!value || !(Buffer.isBuffer(value) || value.type === 'Buffer')) {
|
|
18
|
-
${validator.makeError({
|
|
16
|
+
${validator.makeError({
|
|
17
|
+
type: "buffer",
|
|
18
|
+
actual: "value",
|
|
19
|
+
messages
|
|
20
|
+
})}
|
|
19
21
|
return value;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
return value;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
exports.BufferValidationRule = BufferValidationRule;
|
|
31
|
-
//# sourceMappingURL=buffer.js.map
|
|
25
|
+
` };
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { BufferValidationRule };
|
package/dist/rules/date.js
CHANGED
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let sanitized = false;
|
|
21
|
-
const src = [
|
|
22
|
-
`
|
|
1
|
+
//#region src/rules/date.ts
|
|
2
|
+
var DateValidationRule = class {
|
|
3
|
+
checkPattern;
|
|
4
|
+
constructor(checkPattern = /(?:\d{2}\.){2}\d{4}/) {
|
|
5
|
+
this.checkPattern = checkPattern;
|
|
6
|
+
}
|
|
7
|
+
getName() {
|
|
8
|
+
return "customDate";
|
|
9
|
+
}
|
|
10
|
+
getMessage() {
|
|
11
|
+
return "The '{field}' field must be a valid date string format (DD.MM.YYYY)!";
|
|
12
|
+
}
|
|
13
|
+
getRule(validator) {
|
|
14
|
+
/**
|
|
15
|
+
* Signature: function(value, field, parent, errors, context)
|
|
16
|
+
*/
|
|
17
|
+
return ({ schema, messages }) => {
|
|
18
|
+
let sanitized = false;
|
|
19
|
+
const src = [`
|
|
23
20
|
if (typeof value !== 'string' || !${this.checkPattern.toString()}.test(value)) {
|
|
24
|
-
${validator.makeError({
|
|
21
|
+
${validator.makeError({
|
|
22
|
+
type: "customDate",
|
|
23
|
+
actual: "value",
|
|
24
|
+
messages
|
|
25
|
+
})}
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
src.push(`
|
|
27
|
+
`];
|
|
28
|
+
if (schema.convert === true) {
|
|
29
|
+
sanitized = true;
|
|
30
|
+
src.push(`
|
|
31
31
|
var origValue = value;
|
|
32
32
|
if (!(value instanceof Date)) {
|
|
33
33
|
var parts = origValue.split('.');
|
|
34
34
|
value = new Date(Date.UTC(parts[2], parts[1] - 1, parts[0]));
|
|
35
35
|
if (isNaN(value)) {
|
|
36
|
-
${validator.makeError({
|
|
36
|
+
${validator.makeError({
|
|
37
|
+
type: "customDate",
|
|
38
|
+
actual: "origValue",
|
|
39
|
+
messages
|
|
40
|
+
})}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
`);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
}
|
|
45
|
+
src.push("return value;");
|
|
46
|
+
return {
|
|
47
|
+
sanitized,
|
|
48
|
+
source: src.join("\n")
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { DateValidationRule };
|
package/dist/rules/index.js
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./buffer"), exports);
|
|
18
|
-
__exportStar(require("./date"), exports);
|
|
19
|
-
__exportStar(require("./objectId"), exports);
|
|
20
|
-
__exportStar(require("./phoneNumber"), exports);
|
|
21
|
-
__exportStar(require("./version"), exports);
|
|
22
|
-
__exportStar(require("./internationalPhoneNumber"), exports);
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import "./buffer.js";
|
|
2
|
+
import "./date.js";
|
|
3
|
+
import "./objectId.js";
|
|
4
|
+
import "./phoneNumber.js";
|
|
5
|
+
import "./version.js";
|
|
6
|
+
import "./internationalPhoneNumber.js";
|
|
7
|
+
export {};
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return ({ messages }) => {
|
|
17
|
-
const source = `
|
|
1
|
+
//#region src/rules/internationalPhoneNumber.ts
|
|
2
|
+
var InternationalPhoneNumberValidationRule = class {
|
|
3
|
+
checkPattern = /^\+?\d{1,4}?[\s.-]?\(?\d{1,3}?\)?(?:[\s.-]?\d{1,4}){2}[\s.-]?\d{1,9}$/g;
|
|
4
|
+
getName() {
|
|
5
|
+
return "internationalPhoneNumber";
|
|
6
|
+
}
|
|
7
|
+
getMessage() {
|
|
8
|
+
return "The '{field}' field must be a string and valid international phone number!";
|
|
9
|
+
}
|
|
10
|
+
getRule(validator) {
|
|
11
|
+
/**
|
|
12
|
+
* Signature: function(value, field, parent, errors, context)
|
|
13
|
+
*/
|
|
14
|
+
return ({ messages }) => {
|
|
15
|
+
return { source: `
|
|
18
16
|
if (typeof value !== 'string' || !${this.checkPattern.toString()}.test(value)) {
|
|
19
|
-
${validator.makeError({
|
|
17
|
+
${validator.makeError({
|
|
18
|
+
type: "internationalPhoneNumber",
|
|
19
|
+
actual: "value",
|
|
20
|
+
messages
|
|
21
|
+
})}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
return value;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
exports.InternationalPhoneNumberValidationRule = InternationalPhoneNumberValidationRule;
|
|
31
|
-
//# sourceMappingURL=internationalPhoneNumber.js.map
|
|
25
|
+
` };
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { InternationalPhoneNumberValidationRule };
|
package/dist/rules/objectId.js
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObjectIdValidationRule = void 0;
|
|
1
|
+
//#region src/rules/objectId.ts
|
|
4
2
|
const PATTERN = /^[\da-f]{24}$/i;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
var ObjectIdValidationRule = class {
|
|
4
|
+
getName() {
|
|
5
|
+
return "objectId";
|
|
6
|
+
}
|
|
7
|
+
getMessage() {
|
|
8
|
+
return "The '{field}' field must be an objectId string!";
|
|
9
|
+
}
|
|
10
|
+
getRule(validator) {
|
|
11
|
+
/**
|
|
12
|
+
* Signature: function(value, field, parent, errors, context)
|
|
13
|
+
*/
|
|
14
|
+
return ({ messages }) => {
|
|
15
|
+
return { source: `
|
|
18
16
|
if (typeof value !== 'string' || !${PATTERN.toString()}.test(value)) {
|
|
19
|
-
${validator.makeError({
|
|
17
|
+
${validator.makeError({
|
|
18
|
+
type: "objectId",
|
|
19
|
+
actual: "value",
|
|
20
|
+
messages
|
|
21
|
+
})}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
return value;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
exports.ObjectIdValidationRule = ObjectIdValidationRule;
|
|
31
|
-
//# sourceMappingURL=objectId.js.map
|
|
25
|
+
` };
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ObjectIdValidationRule };
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
return ({ messages }) => {
|
|
22
|
-
const source = `
|
|
1
|
+
import { availableMobileCodes } from "../schemas/index.js";
|
|
2
|
+
//#region src/rules/phoneNumber.ts
|
|
3
|
+
var PhoneNumberValidationRule = class {
|
|
4
|
+
checkPattern;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.checkPattern = new RegExp(String.raw`^38(${availableMobileCodes.map((code) => `0${code}`).join("|")})\d{7}$`);
|
|
7
|
+
}
|
|
8
|
+
getName() {
|
|
9
|
+
return "phoneNumber";
|
|
10
|
+
}
|
|
11
|
+
getMessage() {
|
|
12
|
+
return "The '{field}' field must be a string and valid phone number. E.g. 380xxxxxxx!";
|
|
13
|
+
}
|
|
14
|
+
getRule(validator) {
|
|
15
|
+
/**
|
|
16
|
+
* Signature: function(value, field, parent, errors, context)
|
|
17
|
+
*/
|
|
18
|
+
return ({ messages }) => {
|
|
19
|
+
return { source: `
|
|
23
20
|
if (typeof value !== 'string' || !${this.checkPattern.toString()}.test(value)) {
|
|
24
|
-
${validator.makeError({
|
|
21
|
+
${validator.makeError({
|
|
22
|
+
type: "phoneNumber",
|
|
23
|
+
actual: "value",
|
|
24
|
+
messages
|
|
25
|
+
})}
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
return value;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
exports.PhoneNumberValidationRule = PhoneNumberValidationRule;
|
|
36
|
-
//# sourceMappingURL=phoneNumber.js.map
|
|
29
|
+
` };
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { PhoneNumberValidationRule };
|
package/dist/rules/version.js
CHANGED
|
@@ -1,51 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VersionValidationRule = void 0;
|
|
1
|
+
//#region src/rules/version.ts
|
|
4
2
|
const PATTERN = /^v\d+$/;
|
|
5
3
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
`
|
|
4
|
+
* @deprecated
|
|
5
|
+
*/
|
|
6
|
+
var VersionValidationRule = class {
|
|
7
|
+
getName() {
|
|
8
|
+
return "version";
|
|
9
|
+
}
|
|
10
|
+
getMessage() {
|
|
11
|
+
return "The '{field}' field must be a valid version provided. E.g. v1";
|
|
12
|
+
}
|
|
13
|
+
getRule(validator) {
|
|
14
|
+
/**
|
|
15
|
+
* Signature: function(value, field, parent, errors, context)
|
|
16
|
+
*/
|
|
17
|
+
return ({ schema, messages }) => {
|
|
18
|
+
const src = [`
|
|
22
19
|
if (typeof value !== 'string') {
|
|
23
|
-
${validator.makeError({
|
|
20
|
+
${validator.makeError({
|
|
21
|
+
type: "string",
|
|
22
|
+
actual: "value",
|
|
23
|
+
messages
|
|
24
|
+
})}
|
|
24
25
|
return value;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
src.push(`
|
|
27
|
+
`];
|
|
28
|
+
if (Array.isArray(schema.versions) && schema.versions.length > 0) {
|
|
29
|
+
const { versions } = schema;
|
|
30
|
+
src.push(`
|
|
31
31
|
if (!${JSON.stringify(versions)}.includes(value)) {
|
|
32
|
-
${validator.makeError({
|
|
32
|
+
${validator.makeError({
|
|
33
|
+
type: "version",
|
|
34
|
+
expected: `'${versions.join(", ")}'`,
|
|
35
|
+
actual: "value",
|
|
36
|
+
messages
|
|
37
|
+
})}
|
|
33
38
|
return value;
|
|
34
39
|
}
|
|
35
40
|
`);
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
}
|
|
42
|
+
src.push(`
|
|
38
43
|
if (!${PATTERN.toString()}.test(value)) {
|
|
39
|
-
${validator.makeError({
|
|
44
|
+
${validator.makeError({
|
|
45
|
+
type: "version",
|
|
46
|
+
actual: "value",
|
|
47
|
+
messages
|
|
48
|
+
})}
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
return value;
|
|
43
52
|
`);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
exports.VersionValidationRule = VersionValidationRule;
|
|
51
|
-
//# sourceMappingURL=version.js.map
|
|
53
|
+
return { source: src.join("\n") };
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { VersionValidationRule };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ParameterValidation } from "../interfaces/schema.js";
|
|
2
|
+
import { ListValidationSchema, ObjectRule, StringRule } from "../interfaces/validationSchema.js";
|
|
3
|
+
import { AppVersions } from "@diia-inhouse/types";
|
|
4
|
+
|
|
5
|
+
//#region src/schemas/index.d.ts
|
|
6
|
+
declare const availableMobileCodes: string[];
|
|
7
|
+
declare const phoneNumberValidation: ParameterValidation;
|
|
8
|
+
declare const phoneNumberWithoutPlusValidation: ParameterValidation;
|
|
9
|
+
declare const emailValidation: ParameterValidation;
|
|
10
|
+
declare const emailRuValidation: ParameterValidation;
|
|
11
|
+
declare const shortTextValidation: ParameterValidation;
|
|
12
|
+
declare const zipValidation: ParameterValidation;
|
|
13
|
+
/** @deprecated use getListValidationSchema function instead */
|
|
14
|
+
declare const listValidationSchema: ListValidationSchema;
|
|
15
|
+
declare function getListValidationSchema(min?: number, max?: number): ListValidationSchema;
|
|
16
|
+
declare const appVersionsValidationSchema: ObjectRule<AppVersions>;
|
|
17
|
+
declare function getStringDateSchema(format?: string, optional?: boolean): StringRule;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation };
|