@diia-inhouse/validators 1.28.36 → 2.2.0

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.
Files changed (50) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.js +3 -20
  3. package/dist/interfaces/index.d.ts +3 -0
  4. package/dist/interfaces/rule.d.ts +17 -0
  5. package/dist/interfaces/schema.d.ts +8 -0
  6. package/dist/interfaces/validationSchema.d.ts +90 -0
  7. package/dist/rules/buffer.js +25 -26
  8. package/dist/rules/date.js +44 -40
  9. package/dist/rules/index.js +7 -23
  10. package/dist/rules/internationalPhoneNumber.js +26 -27
  11. package/dist/rules/objectId.js +25 -26
  12. package/dist/rules/phoneNumber.js +30 -32
  13. package/dist/rules/version.js +44 -37
  14. package/dist/schemas/index.d.ts +19 -0
  15. package/dist/schemas/index.js +132 -106
  16. package/dist/validator.d.ts +15 -0
  17. package/dist/validator.js +46 -49
  18. package/package.json +30 -20
  19. package/dist/index.js.map +0 -1
  20. package/dist/interfaces/index.js +0 -20
  21. package/dist/interfaces/index.js.map +0 -1
  22. package/dist/interfaces/rule.js +0 -3
  23. package/dist/interfaces/rule.js.map +0 -1
  24. package/dist/interfaces/schema.js +0 -3
  25. package/dist/interfaces/schema.js.map +0 -1
  26. package/dist/interfaces/validationSchema.js +0 -3
  27. package/dist/interfaces/validationSchema.js.map +0 -1
  28. package/dist/rules/buffer.js.map +0 -1
  29. package/dist/rules/date.js.map +0 -1
  30. package/dist/rules/index.js.map +0 -1
  31. package/dist/rules/internationalPhoneNumber.js.map +0 -1
  32. package/dist/rules/objectId.js.map +0 -1
  33. package/dist/rules/phoneNumber.js.map +0 -1
  34. package/dist/rules/version.js.map +0 -1
  35. package/dist/schemas/index.js.map +0 -1
  36. package/dist/types/index.d.ts +0 -3
  37. package/dist/types/interfaces/index.d.ts +0 -3
  38. package/dist/types/interfaces/rule.d.ts +0 -13
  39. package/dist/types/interfaces/schema.d.ts +0 -5
  40. package/dist/types/interfaces/validationSchema.d.ts +0 -92
  41. package/dist/types/rules/buffer.d.ts +0 -7
  42. package/dist/types/rules/date.d.ts +0 -9
  43. package/dist/types/rules/index.d.ts +0 -6
  44. package/dist/types/rules/internationalPhoneNumber.d.ts +0 -8
  45. package/dist/types/rules/objectId.d.ts +0 -7
  46. package/dist/types/rules/phoneNumber.d.ts +0 -9
  47. package/dist/types/rules/version.d.ts +0 -10
  48. package/dist/types/schemas/index.d.ts +0 -14
  49. package/dist/types/validator.d.ts +0 -11
  50. package/dist/validator.js.map +0 -1
@@ -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
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __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,8 @@
1
+ //#region src/interfaces/schema.d.ts
2
+ interface ParameterValidation {
3
+ regexp: string;
4
+ flags: string[];
5
+ errorMessage: string;
6
+ }
7
+ //#endregion
8
+ export { ParameterValidation };
@@ -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 };
@@ -1,31 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BufferValidationRule = void 0;
4
- class BufferValidationRule {
5
- getName() {
6
- return 'buffer';
7
- }
8
- getMessage() {
9
- return "The '{field}' field must be an Buffer object!";
10
- }
11
- getRule(validator) {
12
- /**
13
- * Signature: function(value, field, parent, errors, context)
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({ type: 'buffer', actual: 'value', messages })}
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
- return {
25
- source,
26
- };
27
- };
28
- }
29
- }
30
- exports.BufferValidationRule = BufferValidationRule;
31
- //# sourceMappingURL=buffer.js.map
25
+ ` };
26
+ };
27
+ }
28
+ };
29
+ //#endregion
30
+ export { BufferValidationRule };
@@ -1,50 +1,54 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateValidationRule = void 0;
4
- class DateValidationRule {
5
- checkPattern;
6
- constructor(checkPattern = /(?:\d{2}\.){2}\d{4}/) {
7
- this.checkPattern = checkPattern;
8
- }
9
- getName() {
10
- return 'customDate';
11
- }
12
- getMessage() {
13
- return "The '{field}' field must be a valid date string format (DD.MM.YYYY)!";
14
- }
15
- getRule(validator) {
16
- /**
17
- * Signature: function(value, field, parent, errors, context)
18
- */
19
- return ({ schema, messages }) => {
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({ type: 'customDate', actual: 'value', messages })}
21
+ ${validator.makeError({
22
+ type: "customDate",
23
+ actual: "value",
24
+ messages
25
+ })}
25
26
  }
26
- `,
27
- ];
28
- if (schema.convert === true) {
29
- sanitized = true;
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({ type: 'customDate', actual: 'origValue', messages })}
36
+ ${validator.makeError({
37
+ type: "customDate",
38
+ actual: "origValue",
39
+ messages
40
+ })}
37
41
  }
38
42
  }
39
43
  `);
40
- }
41
- src.push('return value;');
42
- return {
43
- sanitized,
44
- source: src.join('\n'),
45
- };
46
- };
47
- }
48
- }
49
- exports.DateValidationRule = DateValidationRule;
50
- //# sourceMappingURL=date.js.map
44
+ }
45
+ src.push("return value;");
46
+ return {
47
+ sanitized,
48
+ source: src.join("\n")
49
+ };
50
+ };
51
+ }
52
+ };
53
+ //#endregion
54
+ export { DateValidationRule };
@@ -1,23 +1,7 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InternationalPhoneNumberValidationRule = void 0;
4
- class InternationalPhoneNumberValidationRule {
5
- checkPattern = /^\+?\d{1,4}?[\s.-]?\(?\d{1,3}?\)?(?:[\s.-]?\d{1,4}){2}[\s.-]?\d{1,9}$/g;
6
- getName() {
7
- return 'internationalPhoneNumber';
8
- }
9
- getMessage() {
10
- return "The '{field}' field must be a string and valid international phone number!";
11
- }
12
- getRule(validator) {
13
- /**
14
- * Signature: function(value, field, parent, errors, context)
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({ type: 'internationalPhoneNumber', actual: 'value', messages })}
17
+ ${validator.makeError({
18
+ type: "internationalPhoneNumber",
19
+ actual: "value",
20
+ messages
21
+ })}
20
22
  }
21
23
 
22
24
  return value;
23
- `;
24
- return {
25
- source,
26
- };
27
- };
28
- }
29
- }
30
- exports.InternationalPhoneNumberValidationRule = InternationalPhoneNumberValidationRule;
31
- //# sourceMappingURL=internationalPhoneNumber.js.map
25
+ ` };
26
+ };
27
+ }
28
+ };
29
+ //#endregion
30
+ export { InternationalPhoneNumberValidationRule };
@@ -1,31 +1,30 @@
1
- "use strict";
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
- class ObjectIdValidationRule {
6
- getName() {
7
- return 'objectId';
8
- }
9
- getMessage() {
10
- return "The '{field}' field must be an objectId string!";
11
- }
12
- getRule(validator) {
13
- /**
14
- * Signature: function(value, field, parent, errors, context)
15
- */
16
- return ({ messages }) => {
17
- const source = `
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({ type: 'objectId', actual: 'value', messages })}
17
+ ${validator.makeError({
18
+ type: "objectId",
19
+ actual: "value",
20
+ messages
21
+ })}
20
22
  }
21
23
 
22
24
  return value;
23
- `;
24
- return {
25
- source,
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PhoneNumberValidationRule = void 0;
4
- const schemas_1 = require("../schemas");
5
- class PhoneNumberValidationRule {
6
- checkPattern;
7
- constructor() {
8
- // eslint-disable-next-line security/detect-non-literal-regexp
9
- this.checkPattern = new RegExp(String.raw `^38(${schemas_1.availableMobileCodes.map((code) => `0${code}`).join('|')})\d{7}$`); // nosemgrep: eslint.detect-non-literal-regexp
10
- }
11
- getName() {
12
- return 'phoneNumber';
13
- }
14
- getMessage() {
15
- return "The '{field}' field must be a string and valid phone number. E.g. 380xxxxxxx!";
16
- }
17
- getRule(validator) {
18
- /**
19
- * Signature: function(value, field, parent, errors, context)
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({ type: 'phoneNumber', actual: 'value', messages })}
21
+ ${validator.makeError({
22
+ type: "phoneNumber",
23
+ actual: "value",
24
+ messages
25
+ })}
25
26
  }
26
27
 
27
28
  return value;
28
- `;
29
- return {
30
- source,
31
- };
32
- };
33
- }
34
- }
35
- exports.PhoneNumberValidationRule = PhoneNumberValidationRule;
36
- //# sourceMappingURL=phoneNumber.js.map
29
+ ` };
30
+ };
31
+ }
32
+ };
33
+ //#endregion
34
+ export { PhoneNumberValidationRule };
@@ -1,51 +1,58 @@
1
- "use strict";
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
- * @deprecated
7
- */
8
- class VersionValidationRule {
9
- getName() {
10
- return 'version';
11
- }
12
- getMessage() {
13
- return "The '{field}' field must be a valid version provided. E.g. v1";
14
- }
15
- getRule(validator) {
16
- /**
17
- * Signature: function(value, field, parent, errors, context)
18
- */
19
- return ({ schema, messages }) => {
20
- const src = [
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({ type: 'string', actual: 'value', messages })}
20
+ ${validator.makeError({
21
+ type: "string",
22
+ actual: "value",
23
+ messages
24
+ })}
24
25
  return value;
25
26
  }
26
- `,
27
- ];
28
- if (Array.isArray(schema.versions) && schema.versions.length > 0) {
29
- const { versions } = schema;
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({ type: 'version', expected: `'${versions.join(', ')}'`, actual: 'value', messages })}
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
- src.push(`
41
+ }
42
+ src.push(`
38
43
  if (!${PATTERN.toString()}.test(value)) {
39
- ${validator.makeError({ type: 'version', actual: 'value', messages })}
44
+ ${validator.makeError({
45
+ type: "version",
46
+ actual: "value",
47
+ messages
48
+ })}
40
49
  }
41
50
 
42
51
  return value;
43
52
  `);
44
- return {
45
- source: src.join('\n'),
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 };