@diia-inhouse/validators 2.2.144 → 2.3.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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Rule, RuleValidator } from "./interfaces/rule.js";
2
2
  import { ParameterValidation } from "./interfaces/schema.js";
3
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 "./interfaces/index.js";
4
5
  import { AppValidator } from "./validator.js";
5
6
  import { appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation } from "./schemas/index.js";
6
7
  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,3 +1,3 @@
1
- import { appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation } from "./schemas/index.js";
2
1
  import { AppValidator } from "./validator.js";
2
+ import { appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation } from "./schemas/index.js";
3
3
  export { AppValidator, appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation };
@@ -1,3 +1,4 @@
1
1
  import { Rule, RuleValidator } from "./rule.js";
2
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";
3
+ import { ArrayRule, BooleanRule, CheckerFunctionError, CustomDateRule, DateRule, EmailRule, EnumRule, ListValidationSchema, NumberRule, ObjectIdRule, ObjectRule, RecordRule, RuleType, StringRule, ValidationRule, ValidationSchema, VersionRule } from "./validationSchema.js";
4
+ export { ArrayRule, BooleanRule, CheckerFunctionError, CustomDateRule, DateRule, EmailRule, EnumRule, ListValidationSchema, NumberRule, ObjectIdRule, ObjectRule, ParameterValidation, RecordRule, Rule, RuleType, RuleValidator, StringRule, ValidationRule, ValidationSchema, VersionRule };
@@ -1,17 +1,13 @@
1
1
  import FastestValidator, { MessagesType, ValidationSchema } from "fastest-validator";
2
-
3
- //#region src/interfaces/rule.d.ts
4
- type RuleValidator = (param: {
2
+ export type RuleValidator = (param: {
5
3
  messages: MessagesType;
6
4
  schema: ValidationSchema;
7
5
  }) => {
8
6
  source: string;
9
7
  sanitized?: boolean;
10
8
  };
11
- interface Rule {
9
+ export interface Rule {
12
10
  getName(): string;
13
11
  getMessage(): string;
14
12
  getRule(validator: FastestValidator): RuleValidator;
15
- }
16
- //#endregion
17
- export { Rule, RuleValidator };
13
+ }
@@ -1,8 +1,5 @@
1
- //#region src/interfaces/schema.d.ts
2
- interface ParameterValidation {
1
+ export interface ParameterValidation {
3
2
  regexp: string;
4
3
  flags: string[];
5
4
  errorMessage: string;
6
- }
7
- //#endregion
8
- export { ParameterValidation };
5
+ }
@@ -1,9 +1,7 @@
1
- import { Context, ValidationRuleObject } from "fastest-validator";
2
1
  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 {
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 {
7
5
  type: string;
8
6
  messages: string;
9
7
  field?: string;
@@ -17,7 +15,7 @@ interface BasicRule<T extends RuleType> {
17
15
  interface Sanitazible {
18
16
  convert?: boolean;
19
17
  }
20
- interface NumberRule extends BasicRule<"number">, Sanitazible {
18
+ export interface NumberRule extends BasicRule<"number">, Sanitazible {
21
19
  min?: number;
22
20
  max?: number;
23
21
  equal?: number;
@@ -26,7 +24,7 @@ interface NumberRule extends BasicRule<"number">, Sanitazible {
26
24
  positive?: boolean;
27
25
  negative?: boolean;
28
26
  }
29
- interface ArrayRule<T = null> extends BasicRule<"array"> {
27
+ export interface ArrayRule<T = null> extends BasicRule<"array"> {
30
28
  items?: ValidationProperty<T>;
31
29
  empty?: boolean;
32
30
  min?: number;
@@ -36,15 +34,15 @@ interface ArrayRule<T = null> extends BasicRule<"array"> {
36
34
  enum?: any[];
37
35
  unique?: boolean;
38
36
  }
39
- interface ObjectRule<T = null> extends BasicRule<"object"> {
40
- props?: ValidationSchema$1<T>;
37
+ export interface ObjectRule<T = null> extends BasicRule<"object"> {
38
+ props?: ValidationSchema<T>;
41
39
  strict?: boolean;
42
40
  }
43
- interface RecordRule<K, V> extends BasicRule<"record"> {
41
+ export interface RecordRule<K, V> extends BasicRule<"record"> {
44
42
  key: EnumRule<K> | StringRule;
45
43
  value: ValidationProperty<V> | ValidationProperty<V>[];
46
44
  }
47
- interface StringRule extends BasicRule<"string"> {
45
+ export interface StringRule extends BasicRule<"string"> {
48
46
  empty?: boolean;
49
47
  min?: number;
50
48
  max?: number;
@@ -59,32 +57,31 @@ interface StringRule extends BasicRule<"string"> {
59
57
  uppercase?: boolean;
60
58
  custom?: (value: string, errors: CheckerFunctionError[], ruleSchema?: ValidationRuleObject, path?: string, parent?: object | null, context?: Context) => string;
61
59
  }
62
- interface EmailRule extends BasicRule<"email"> {
60
+ export interface EmailRule extends BasicRule<"email"> {
63
61
  mode?: string;
64
62
  }
65
- interface VersionRule extends BasicRule<"version">, Sanitazible {
63
+ export interface VersionRule extends BasicRule<"version">, Sanitazible {
66
64
  versions?: string[];
67
65
  }
68
- interface EnumRule<T = any> extends BasicRule<"enum"> {
66
+ export interface EnumRule<T = any> extends BasicRule<"enum"> {
69
67
  values: T[];
70
68
  }
71
- interface DateRule extends BasicRule<"date">, Sanitazible {
69
+ export interface DateRule extends BasicRule<"date">, Sanitazible {
72
70
  format?: string;
73
71
  }
74
- interface ListValidationSchema {
72
+ export interface ListValidationSchema {
75
73
  skip: NumberRule;
76
74
  limit: NumberRule;
77
75
  }
78
- interface CustomDateRule extends BasicRule<"customDate">, Sanitazible {}
79
- interface ObjectIdRule extends BasicRule<"objectId">, Sanitazible {}
80
- interface BooleanRule extends BasicRule<"boolean">, Sanitazible {}
76
+ export interface CustomDateRule extends BasicRule<"customDate">, Sanitazible {}
77
+ export interface ObjectIdRule extends BasicRule<"objectId">, Sanitazible {}
78
+ export interface BooleanRule extends BasicRule<"boolean">, Sanitazible {}
81
79
  type CommonRule = BasicRule<"any" | "forbidden"> | EnumRule;
82
80
  type ComplexRule = StringRule | NumberRule | BooleanRule | ArrayRule | ObjectRule | DateRule | CustomDateRule | EmailRule | EnumRule | ObjectIdRule | RecordRule<string, unknown> | VersionRule;
83
81
  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
82
  type Rule = string | boolean | ComplexRule | CommonRule | BasicRule<Exclude<RuleType, CommonRule["type"] | ComplexRule["type"]>>;
85
- type ValidationRule<T = null> = T extends null ? Rule : T extends ArrayLike<infer U> ? ArrayRule<U> : T extends object ? ObjectRule<T> : Rule;
86
- type ValidationSchema$1<T = null> = T extends null ? {
83
+ export type ValidationRule<T = null> = T extends null ? Rule : T extends ArrayLike<infer U> ? ArrayRule<U> : T extends object ? ObjectRule<T> : Rule;
84
+ export type ValidationSchema<T = null> = T extends null ? {
87
85
  [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 };
86
+ } : { [path in keyof Required<T>]: ValidationProperty<T[path]> | ValidationProperty<T[path]>[] | CommonRule; };
87
+ export {};
@@ -1,4 +1,4 @@
1
- //#region src/rules/buffer.ts
1
+ // src/rules/buffer.ts
2
2
  var BufferValidationRule = class {
3
3
  getName() {
4
4
  return "buffer";
@@ -26,5 +26,4 @@ var BufferValidationRule = class {
26
26
  };
27
27
  }
28
28
  };
29
- //#endregion
30
29
  export { BufferValidationRule };
@@ -1,4 +1,4 @@
1
- //#region src/rules/date.ts
1
+ // src/rules/date.ts
2
2
  var DateValidationRule = class {
3
3
  checkPattern;
4
4
  constructor(checkPattern = /(?:\d{2}\.){2}\d{4}/) {
@@ -50,5 +50,4 @@ var DateValidationRule = class {
50
50
  };
51
51
  }
52
52
  };
53
- //#endregion
54
53
  export { DateValidationRule };
@@ -1,7 +1,7 @@
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
+ import { BufferValidationRule } from "./buffer.js";
2
+ import { DateValidationRule } from "./date.js";
3
+ import { ObjectIdValidationRule } from "./objectId.js";
4
+ import { PhoneNumberValidationRule } from "./phoneNumber.js";
5
+ import { VersionValidationRule } from "./version.js";
6
+ import { InternationalPhoneNumberValidationRule } from "./internationalPhoneNumber.js";
7
+ export { BufferValidationRule, DateValidationRule, InternationalPhoneNumberValidationRule, ObjectIdValidationRule, PhoneNumberValidationRule, VersionValidationRule };
@@ -1,4 +1,4 @@
1
- //#region src/rules/internationalPhoneNumber.ts
1
+ // src/rules/internationalPhoneNumber.ts
2
2
  var InternationalPhoneNumberValidationRule = class {
3
3
  checkPattern = /^\+?\d{1,4}?[\s.-]?\(?\d{1,3}?\)?(?:[\s.-]?\d{1,4}){2}[\s.-]?\d{1,9}$/g;
4
4
  getName() {
@@ -26,5 +26,4 @@ var InternationalPhoneNumberValidationRule = class {
26
26
  };
27
27
  }
28
28
  };
29
- //#endregion
30
29
  export { InternationalPhoneNumberValidationRule };
@@ -1,4 +1,4 @@
1
- //#region src/rules/objectId.ts
1
+ // src/rules/objectId.ts
2
2
  const PATTERN = /^[\da-f]{24}$/i;
3
3
  var ObjectIdValidationRule = class {
4
4
  getName() {
@@ -26,5 +26,4 @@ var ObjectIdValidationRule = class {
26
26
  };
27
27
  }
28
28
  };
29
- //#endregion
30
29
  export { ObjectIdValidationRule };
@@ -1,5 +1,5 @@
1
1
  import { availableMobileCodes } from "../schemas/index.js";
2
- //#region src/rules/phoneNumber.ts
2
+ // src/rules/phoneNumber.ts
3
3
  var PhoneNumberValidationRule = class {
4
4
  checkPattern;
5
5
  constructor() {
@@ -30,5 +30,4 @@ var PhoneNumberValidationRule = class {
30
30
  };
31
31
  }
32
32
  };
33
- //#endregion
34
33
  export { PhoneNumberValidationRule };
@@ -1,4 +1,4 @@
1
- //#region src/rules/version.ts
1
+ // src/rules/version.ts
2
2
  const PATTERN = /^v\d+$/;
3
3
  /**
4
4
  * @deprecated
@@ -54,5 +54,4 @@ var VersionValidationRule = class {
54
54
  };
55
55
  }
56
56
  };
57
- //#endregion
58
57
  export { VersionValidationRule };
@@ -1,19 +1,16 @@
1
1
  import { ParameterValidation } from "../interfaces/schema.js";
2
2
  import { ListValidationSchema, ObjectRule, StringRule } from "../interfaces/validationSchema.js";
3
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;
4
+ import "../interfaces/index.js";
5
+ export declare const availableMobileCodes: string[];
6
+ export declare const phoneNumberValidation: ParameterValidation;
7
+ export declare const phoneNumberWithoutPlusValidation: ParameterValidation;
8
+ export declare const emailValidation: ParameterValidation;
9
+ export declare const emailRuValidation: ParameterValidation;
10
+ export declare const shortTextValidation: ParameterValidation;
11
+ export declare const zipValidation: ParameterValidation;
13
12
  /** @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 };
13
+ export declare const listValidationSchema: ListValidationSchema;
14
+ export declare function getListValidationSchema(min?: number, max?: number): ListValidationSchema;
15
+ export declare const appVersionsValidationSchema: ObjectRule<AppVersions>;
16
+ export declare function getStringDateSchema(format?: string, optional?: boolean): StringRule;
@@ -1,7 +1,7 @@
1
1
  import fromPairs from "lodash.frompairs";
2
2
  import { DateTime } from "luxon";
3
3
  import { PlatformType } from "@diia-inhouse/types";
4
- //#region src/schemas/index.ts
4
+ // src/schemas/index.ts
5
5
  const availableMobileCodes = [
6
6
  "39",
7
7
  "50",
@@ -142,5 +142,4 @@ function getStringDateSchema(format = `yyyy-MM-dd'T'HH:mm:ss.SSS'Z'`, optional =
142
142
  optional
143
143
  };
144
144
  }
145
- //#endregion
146
145
  export { appVersionsValidationSchema, availableMobileCodes, emailRuValidation, emailValidation, getListValidationSchema, getStringDateSchema, listValidationSchema, phoneNumberValidation, phoneNumberWithoutPlusValidation, shortTextValidation, zipValidation };
@@ -1,8 +1,6 @@
1
1
  import { ValidationSchema } from "fastest-validator";
2
2
  import { ErrorType } from "@diia-inhouse/errors";
3
-
4
- //#region src/validator.d.ts
5
- declare class AppValidator {
3
+ export declare class AppValidator {
6
4
  private readonly validator;
7
5
  private customRules;
8
6
  constructor();
@@ -10,6 +8,4 @@ declare class AppValidator {
10
8
  validate(params: unknown, schema: ValidationSchema, errorType?: ErrorType): boolean;
11
9
  private getCustomValidatorsMessages;
12
10
  private addCustomValidationRules;
13
- }
14
- //#endregion
15
- export { AppValidator };
11
+ }
package/dist/validator.js CHANGED
@@ -3,11 +3,11 @@ import { DateValidationRule } from "./rules/date.js";
3
3
  import { ObjectIdValidationRule } from "./rules/objectId.js";
4
4
  import { PhoneNumberValidationRule } from "./rules/phoneNumber.js";
5
5
  import { VersionValidationRule } from "./rules/version.js";
6
- import { InternationalPhoneNumberValidationRule } from "./rules/internationalPhoneNumber.js";
7
- import "./rules/index.js";
8
6
  import FastestValidator from "fastest-validator";
9
7
  import { ErrorCode, ValidationError } from "@diia-inhouse/errors";
10
- //#region src/validator.ts
8
+ import "./rules/index.js";
9
+ import { InternationalPhoneNumberValidationRule } from "./rules/internationalPhoneNumber.js";
10
+ // src/validator.ts
11
11
  var AppValidator = class {
12
12
  validator;
13
13
  customRules;
@@ -43,5 +43,4 @@ var AppValidator = class {
43
43
  for (const rule of this.customRules) this.validator.add(rule.getName(), rule.getRule(this.validator));
44
44
  }
45
45
  };
46
- //#endregion
47
46
  export { AppValidator };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/validators",
3
- "version": "2.2.144",
3
+ "version": "2.3.0",
4
4
  "description": "Data validators package",
5
5
  "license": "SEE LICENCE IN LICENCE.md",
6
6
  "author": "diia-team",
@@ -30,32 +30,28 @@
30
30
  "test:watch": "vitest watch"
31
31
  },
32
32
  "dependencies": {
33
- "bson": "7.2.0",
33
+ "bson": "7.3.4",
34
34
  "fastest-validator": "1.19.1",
35
35
  "lodash.frompairs": "4.0.1",
36
36
  "luxon": "3.7.2"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@diia-inhouse/configs": "7.4.0",
40
- "@diia-inhouse/errors": "2.3.48",
40
+ "@diia-inhouse/errors": "2.3.49",
41
41
  "@diia-inhouse/oxc-config": "6.2.1",
42
- "@diia-inhouse/test": "8.4.14",
43
42
  "@diia-inhouse/types": "14.13.3",
44
43
  "@types/lodash.frompairs": "4.0.9",
45
- "@types/luxon": "3.7.1",
46
- "@types/node": "25.6.2",
47
- "@vitest/coverage-v8": "4.1.11",
48
- "@vitest/ui": "4.1.11",
49
- "lockfile-lint": "5.0.0",
50
- "oxfmt": "0.72.0",
51
- "oxlint": "1.87.0",
52
- "oxlint-tsgolint": "7.0.2003",
53
- "rimraf": "6.1.3",
54
- "semantic-release": "25.0.3",
55
- "tsdown": "0.22.0",
44
+ "@types/luxon": "3.7.6",
45
+ "@types/node": "26.6.6",
46
+ "@vitest/coverage-v8": "5.1.1",
47
+ "oxfmt": "0.79.0",
48
+ "oxlint": "1.94.0",
49
+ "oxlint-tsgolint": "7.0.2008",
50
+ "rimraf": "6.1.4",
51
+ "semantic-release": "25.0.9",
52
+ "tsdown": "0.23.7",
56
53
  "typescript": "5.9.3",
57
- "vite-tsconfig-paths": "6.1.1",
58
- "vitest": "4.1.11"
54
+ "vitest": "5.1.1"
59
55
  },
60
56
  "peerDependencies": {
61
57
  "@diia-inhouse/errors": ">=2.0.0",