validno 0.4.1 → 0.4.4

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 (75) hide show
  1. package/dist/constants/details.d.ts +3 -2
  2. package/dist/constants/details.d.ts.map +1 -1
  3. package/dist/constants/details.js +2 -1
  4. package/dist/dev.js +9 -56
  5. package/dist/engine/methods/handleNestedKey.js +1 -1
  6. package/dist/engine/methods/validate.d.ts.map +1 -1
  7. package/dist/engine/methods/validate.js +7 -0
  8. package/dist/engine/methods/validateType.js +1 -1
  9. package/dist/tests/cases/corruptedData.test.d.ts +2 -0
  10. package/dist/tests/cases/corruptedData.test.d.ts.map +1 -0
  11. package/dist/tests/cases/corruptedData.test.js +81 -0
  12. package/dist/tests/cases/dataInputIsNotAnObject.test.d.ts +2 -0
  13. package/dist/tests/cases/dataInputIsNotAnObject.test.d.ts.map +1 -0
  14. package/dist/tests/cases/dataInputIsNotAnObject.test.js +24 -0
  15. package/dist/tests/cases/notRequiredNestedKey.test.d.ts +2 -0
  16. package/dist/tests/cases/notRequiredNestedKey.test.d.ts.map +1 -0
  17. package/dist/tests/cases/notRequiredNestedKey.test.js +38 -0
  18. package/dist/tests/cases/secondLevelDeepValidates.test.d.ts +2 -0
  19. package/dist/tests/cases/secondLevelDeepValidates.test.d.ts.map +1 -0
  20. package/dist/tests/cases/secondLevelDeepValidates.test.js +112 -0
  21. package/dist/tests/customMessage.test.d.ts +2 -0
  22. package/dist/tests/customMessage.test.d.ts.map +1 -0
  23. package/dist/tests/customMessage.test.js +102 -0
  24. package/dist/tests/customType.test.d.ts +2 -0
  25. package/dist/tests/customType.test.d.ts.map +1 -0
  26. package/dist/tests/customType.test.js +146 -0
  27. package/dist/tests/joinErrors.test.d.ts +2 -0
  28. package/dist/tests/joinErrors.test.d.ts.map +1 -0
  29. package/dist/tests/joinErrors.test.js +62 -0
  30. package/dist/tests/missing.test.d.ts +2 -0
  31. package/dist/tests/missing.test.d.ts.map +1 -0
  32. package/dist/tests/missing.test.js +224 -0
  33. package/dist/tests/onlyKeys.test.d.ts +2 -0
  34. package/dist/tests/onlyKeys.test.d.ts.map +1 -0
  35. package/dist/tests/onlyKeys.test.js +74 -0
  36. package/dist/tests/types.test.d.ts +2 -0
  37. package/dist/tests/types.test.d.ts.map +1 -0
  38. package/dist/tests/types.test.js +273 -0
  39. package/dist/tests/utils/_errors.test.d.ts +2 -0
  40. package/dist/tests/utils/_errors.test.d.ts.map +1 -0
  41. package/dist/tests/utils/_errors.test.js +47 -0
  42. package/dist/tests/utils/_validations.test.d.ts +2 -0
  43. package/dist/tests/utils/_validations.test.d.ts.map +1 -0
  44. package/dist/tests/utils/_validations.test.js +773 -0
  45. package/dist/utils/helpers.d.ts.map +1 -1
  46. package/package.json +4 -2
  47. package/dist/ValidnoResult.js +0 -102
  48. package/dist/checkType.js +0 -1
  49. package/dist/validate/index.js +0 -1
  50. package/dist/validate/validate.js +0 -151
  51. package/dist/validate.js +0 -151
  52. package/dist/validateEngine/ValidateEngine.js +0 -44
  53. package/dist/validateEngine/index.js +0 -2
  54. package/dist/validateEngine/methods/ValidateEngine.js +0 -139
  55. package/dist/validateEngine/methods/checkRulesForKey.js +0 -15
  56. package/dist/validateEngine/methods/checkValueType.js +0 -134
  57. package/dist/validateEngine/methods/finalizeValidation.js +0 -15
  58. package/dist/validateEngine/methods/finishValidation.js +0 -15
  59. package/dist/validateEngine/methods/handleKey.js +0 -43
  60. package/dist/validateEngine/methods/handleMissingKey.js +0 -19
  61. package/dist/validateEngine/methods/handleMissingKeyValidation.js +0 -9
  62. package/dist/validateEngine/methods/handleNestedKey.js +0 -19
  63. package/dist/validateEngine/methods/validate.js +0 -14
  64. package/dist/validateEngine/methods/validateKey.js +0 -31
  65. package/dist/validateEngine/methods/validateKeyDetails.js +0 -13
  66. package/dist/validateEngine/methods/validateKeyValue.js +0 -13
  67. package/dist/validateEngine/methods/validateNestedKey.js +0 -19
  68. package/dist/validateEngine/methods/validateType.js +0 -134
  69. package/dist/validateEngine/validate.js +0 -14
  70. package/dist/validateRules.js +0 -159
  71. package/dist/validateSchema/ValidateEngine.js +0 -147
  72. package/dist/validateSchema/index.js +0 -6
  73. package/dist/validateSchema/validate.js +0 -151
  74. package/dist/validateSchema.js +0 -6
  75. package/dist/validateType.js +0 -124
@@ -5,7 +5,8 @@ export declare enum ValidationIds {
5
5
  }
6
6
  export declare enum ValidationDetails {
7
7
  OK = "OK",
8
- INVALID_DATE = "Invalid date",
9
- CustomRuleFailed = "Custom rule failed"
8
+ InvalidDate = "Invalid date",
9
+ CustomRuleFailed = "Custom rule failed",
10
+ BadInput = "Validation input must be a plain object"
10
11
  }
11
12
  //# sourceMappingURL=details.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/constants/details.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACrB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,IAAI,SAAS;CAChB;AAED,oBAAY,iBAAiB;IACzB,EAAE,OAAO;IACT,YAAY,iBAAiB;IAC7B,gBAAgB,uBAAuB;CAC1C"}
1
+ {"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/constants/details.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACrB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,IAAI,SAAS;CAChB;AAED,oBAAY,iBAAiB;IACzB,EAAE,OAAO;IACT,WAAW,iBAAiB;IAC5B,gBAAgB,uBAAuB;IACvC,QAAQ,4CAA4C;CACvD"}
@@ -7,6 +7,7 @@ export var ValidationIds;
7
7
  export var ValidationDetails;
8
8
  (function (ValidationDetails) {
9
9
  ValidationDetails["OK"] = "OK";
10
- ValidationDetails["INVALID_DATE"] = "Invalid date";
10
+ ValidationDetails["InvalidDate"] = "Invalid date";
11
11
  ValidationDetails["CustomRuleFailed"] = "Custom rule failed";
12
+ ValidationDetails["BadInput"] = "Validation input must be a plain object";
12
13
  })(ValidationDetails || (ValidationDetails = {}));
package/dist/dev.js CHANGED
@@ -1,57 +1,10 @@
1
- import Schema from './index.js';
2
- const configSchema = new Schema({
3
- api: {
4
- port: {
5
- type: Number,
6
- required: true,
7
- rules: { min: 1000, max: 9999 }
8
- },
9
- cors: {
10
- enabled: { type: Boolean, required: true },
11
- origins: {
12
- type: Array,
13
- eachType: String,
14
- required: false
15
- }
16
- },
17
- rateLimit: {
18
- enabled: { type: Boolean, required: true },
19
- maxRequests: {
20
- type: Number,
21
- required: false,
22
- rules: { min: 1, max: 10000 }
23
- },
24
- windowMs: {
25
- type: Number,
26
- required: false,
27
- rules: { min: 1000, max: 86400000 }
28
- }
29
- }
30
- }
31
- });
32
- const exampleConfigFile = {
33
- "app": {
34
- "name": "MyApp",
35
- "version": "1.0.0",
36
- "environment": "development"
37
- },
38
- "database": {
39
- "host": "localhost",
40
- "port": 5432,
41
- "name": "myappdb",
42
- "ssl": false
43
- },
44
- "api": {
45
- "port": 3000,
46
- "cors": {
47
- "enabled": true,
48
- "origins": ["http://localhost:3000"]
49
- },
50
- "rateLimit": {
51
- "enabled": true,
52
- "maxRequests": 1000,
53
- "windowMs": 60000
54
- }
55
- },
1
+ import { Schema } from "./Schema.js";
2
+ const test = () => {
3
+ console.log('--- Custom Test ---');
4
+ const schema = new Schema({
5
+ anyKey: { type: String }
6
+ });
7
+ const result = schema.validate({ anyKey: null });
8
+ console.log(result);
56
9
  };
57
- const res = configSchema.validate(exampleConfigFile);
10
+ test();
@@ -5,7 +5,7 @@ function handleNestedKey(input) {
5
5
  for (const itemKey of nestedKeys) {
6
6
  const deepParams = {
7
7
  key: itemKey,
8
- data: data[key],
8
+ data: data ? data[key] : undefined,
9
9
  reqs: reqs[itemKey],
10
10
  nestedKey: `${nestedKey}.${itemKey}`
11
11
  };
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/engine/methods/validate.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAC/C,OAAO,cAAwC,MAAM,sBAAsB,CAAA;AAE3E,iBAAS,QAAQ,CACb,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,GAAG,EACT,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GACnC,aAAa,CAaf;AAED,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/engine/methods/validate.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAC/C,OAAO,cAAwC,MAAM,sBAAsB,CAAA;AAG3E,iBAAS,QAAQ,CACb,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,GAAG,EACT,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GACnC,aAAa,CAmBf;AAED,eAAe,QAAQ,CAAC"}
@@ -1,5 +1,12 @@
1
1
  import _helpers from "../../utils/helpers.js";
2
+ import ValidnoResult from "../ValidnoResult.js";
3
+ import { ValidationDetails } from "../../constants/details.js";
2
4
  function validate(data, validationKeys) {
5
+ if (typeof data !== "object" || data === null || Array.isArray(data)) {
6
+ const result = new ValidnoResult();
7
+ result.setFailed("", ValidationDetails.BadInput);
8
+ return result.finish();
9
+ }
3
10
  const hasKeysToCheck = _helpers.areKeysLimited(validationKeys);
4
11
  const schemaKeys = Object.entries(this.definition);
5
12
  for (const [key, reqs] of schemaKeys) {
@@ -69,7 +69,7 @@ const handleTypeValidation = (key, value, requirements, keyName = key) => {
69
69
  const isDate = isNotNull && value.constructor === Date;
70
70
  const isValid = isDate && !isNaN(value.getTime());
71
71
  const isValidDate = isDate && isValid;
72
- result.push(_validateType.getResult(keyName, isValidDate, getDetails(isValidDate, ValidationDetails.INVALID_DATE)));
72
+ result.push(_validateType.getResult(keyName, isValidDate, getDetails(isValidDate, ValidationDetails.InvalidDate)));
73
73
  break;
74
74
  }
75
75
  case Boolean: {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=corruptedData.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"corruptedData.test.d.ts","sourceRoot":"","sources":["../../../src/tests/cases/corruptedData.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,81 @@
1
+ import { describe, expect, test } from '@jest/globals';
2
+ import { Schema } from '../../Schema';
3
+ const AccessScopes = {
4
+ Public: 'public',
5
+ Project: 'workspace',
6
+ User: 'user'
7
+ };
8
+ const collectionSettingsSchema = new Schema({
9
+ auth: { type: null },
10
+ scope: {
11
+ type: String,
12
+ rules: {
13
+ enum: Object.values(AccessScopes)
14
+ },
15
+ },
16
+ methods: {
17
+ get: {
18
+ isActive: { type: Boolean },
19
+ scope: {
20
+ type: String,
21
+ rules: { enum: Object.values(AccessScopes) },
22
+ required: false
23
+ }
24
+ },
25
+ getAll: {
26
+ isActive: { type: Boolean },
27
+ scope: {
28
+ type: String,
29
+ rules: {
30
+ enum: Object.values(AccessScopes)
31
+ },
32
+ required: false
33
+ },
34
+ sort: { default: { type: String } },
35
+ filter: { fields: { type: Array, eachType: String } },
36
+ search: { fields: { type: Array, eachType: String } }
37
+ },
38
+ create: {
39
+ isActive: { type: Boolean },
40
+ scope: {
41
+ type: String,
42
+ rules: { enum: Object.values(AccessScopes) },
43
+ required: false
44
+ }
45
+ },
46
+ update: {
47
+ isActive: { type: Boolean },
48
+ scope: {
49
+ type: String,
50
+ rules: { enum: Object.values(AccessScopes) },
51
+ required: false
52
+ },
53
+ allowedFields: { type: Array, eachType: String }
54
+ },
55
+ delete: {
56
+ isActive: { type: Boolean },
57
+ scope: {
58
+ type: String,
59
+ rules: { enum: Object.values(AccessScopes) },
60
+ required: false
61
+ }
62
+ },
63
+ distinct: {
64
+ isActive: { type: Boolean },
65
+ scope: {
66
+ type: String,
67
+ rules: { enum: Object.values(AccessScopes) },
68
+ required: false
69
+ },
70
+ fields: { type: Array, eachType: String }
71
+ }
72
+ }
73
+ });
74
+ const settingsData = { test: 1 };
75
+ describe('Corrupted data in nested keys', () => {
76
+ test('Corrupted data in nested keys should not pass the validation', () => {
77
+ const result = collectionSettingsSchema.validate(settingsData);
78
+ expect(result.ok).toBe(false);
79
+ expect(result.errors.length).toBeGreaterThan(1);
80
+ });
81
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dataInputIsNotAnObject.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataInputIsNotAnObject.test.d.ts","sourceRoot":"","sources":["../../../src/tests/cases/dataInputIsNotAnObject.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { describe, expect, test } from '@jest/globals';
2
+ import { Schema } from '../../Schema';
3
+ describe('Data input is not an object → returns failed validation result', () => {
4
+ const schema = new Schema({
5
+ name: {
6
+ type: String
7
+ }
8
+ });
9
+ test('null input fails validation but not throws', () => {
10
+ const result = schema.validate(null);
11
+ expect(result).toBeDefined();
12
+ expect(result.ok).toBe(false);
13
+ });
14
+ test('array input fails validation but not throws', () => {
15
+ const result = schema.validate([]);
16
+ expect(result).toBeDefined();
17
+ expect(result.ok).toBe(false);
18
+ });
19
+ test('undefined input fails validation but not throws', () => {
20
+ const result = schema.validate(undefined);
21
+ expect(result).toBeDefined();
22
+ expect(result.ok).toBe(false);
23
+ });
24
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=notRequiredNestedKey.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notRequiredNestedKey.test.d.ts","sourceRoot":"","sources":["../../../src/tests/cases/notRequiredNestedKey.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ import { describe, expect, test } from '@jest/globals';
2
+ import { Schema } from '../../Schema';
3
+ describe('Not required nested key', () => {
4
+ test('[1] Nested key that is not required should pass the validation', () => {
5
+ const schema = new Schema({
6
+ query: { type: Object },
7
+ data: { type: Object },
8
+ params: {
9
+ upsert: { type: Boolean, required: false },
10
+ }
11
+ });
12
+ const data = {
13
+ query: {},
14
+ data: {}
15
+ };
16
+ const result = schema.validate(data);
17
+ expect(result.ok).toBe(true);
18
+ expect(result.missed).toEqual([]);
19
+ });
20
+ test('[2] Nested key that is required should not pass the validation', () => {
21
+ const schema = new Schema({
22
+ query: { type: Object },
23
+ data: { type: Object },
24
+ params: {
25
+ upsert: { type: Boolean, required: true },
26
+ }
27
+ });
28
+ const data = {
29
+ query: {},
30
+ data: {}
31
+ };
32
+ const result = schema.validate(data);
33
+ expect(result.ok).toBe(false);
34
+ expect(result.missed).toEqual(['params.upsert']);
35
+ expect(result.failed).toEqual(['params.upsert', 'params']);
36
+ expect(result.passed).toEqual(['query', 'data']);
37
+ });
38
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=secondLevelDeepValidates.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secondLevelDeepValidates.test.d.ts","sourceRoot":"","sources":["../../../src/tests/cases/secondLevelDeepValidates.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,112 @@
1
+ import { describe, expect, test } from '@jest/globals';
2
+ import { Schema } from '../../Schema';
3
+ const configSchema = new Schema({
4
+ app: {
5
+ name: {
6
+ type: String,
7
+ required: true,
8
+ rules: { lengthMin: 1, lengthMax: 50 }
9
+ },
10
+ version: {
11
+ type: String,
12
+ required: true,
13
+ rules: {
14
+ regex: /^\d+\.\d+\.\d+$/
15
+ }
16
+ },
17
+ environment: {
18
+ type: String,
19
+ required: true,
20
+ rules: {
21
+ enum: ['development', 'testing', 'staging', 'production']
22
+ }
23
+ }
24
+ },
25
+ database: {
26
+ host: {
27
+ type: String,
28
+ required: true,
29
+ rules: { lengthMin: 1 }
30
+ },
31
+ port: {
32
+ type: Number,
33
+ required: true,
34
+ rules: { min: 1, max: 65535 }
35
+ },
36
+ name: {
37
+ type: String,
38
+ required: true,
39
+ rules: { lengthMin: 1, lengthMax: 64 }
40
+ },
41
+ ssl: {
42
+ type: Boolean,
43
+ required: false
44
+ }
45
+ },
46
+ api: {
47
+ port: {
48
+ type: Number,
49
+ required: true,
50
+ rules: { min: 1000, max: 9999 }
51
+ },
52
+ cors: {
53
+ enabled: { type: Boolean, required: true },
54
+ origins: {
55
+ type: Array,
56
+ eachType: String,
57
+ required: false
58
+ }
59
+ },
60
+ rateLimit: {
61
+ enabled: { type: Boolean, required: true },
62
+ maxRequests: {
63
+ type: Number,
64
+ required: false,
65
+ rules: { min: 1, max: 10000 }
66
+ },
67
+ windowMs: {
68
+ type: Number,
69
+ required: false,
70
+ rules: { min: 1000, max: 86400000 }
71
+ }
72
+ }
73
+ }
74
+ });
75
+ const exampleConfigFile = {
76
+ "app": {
77
+ "name": "MyApp",
78
+ "version": "1.0.0",
79
+ "environment": "development"
80
+ },
81
+ "database": {
82
+ "host": "localhost",
83
+ "port": 5432,
84
+ "name": "myappdb",
85
+ "ssl": false
86
+ },
87
+ "api": {
88
+ "port": 3000,
89
+ "cors": {
90
+ "enabled": true,
91
+ "origins": ["http://localhost:3000"]
92
+ },
93
+ "rateLimit": {
94
+ "enabled": true,
95
+ "maxRequests": 1000,
96
+ "windowMs": 60000
97
+ }
98
+ },
99
+ };
100
+ describe('Second level deep validates as expected', () => {
101
+ test('should validate the api key', () => {
102
+ const res = configSchema.validate(exampleConfigFile);
103
+ expect(res.ok).toBe(true);
104
+ expect(res.failed).toEqual([]);
105
+ expect(res.missed).toEqual([]);
106
+ });
107
+ test('api key shouldn\'t validate with wrong port type', () => {
108
+ const res2 = configSchema.validate(Object.assign(Object.assign({}, exampleConfigFile), { api: Object.assign(Object.assign({}, exampleConfigFile.api), { port: '99999' }) }));
109
+ expect(res2.ok).toBe(false);
110
+ expect(res2.failed).toContain('api');
111
+ });
112
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=customMessage.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customMessage.test.d.ts","sourceRoot":"","sources":["../../src/tests/customMessage.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,102 @@
1
+ import { describe, expect, test } from '@jest/globals';
2
+ import { Schema } from '../Schema';
3
+ describe('Тестирование кастомного сообщения об ошибке', () => {
4
+ test('Кастомные сообщения корректно отображаются в результате валидации', () => {
5
+ const wrongTypeKey = 'wrongType';
6
+ const missingKey = 'missingKey';
7
+ const wrongRule1 = 'wrongRule1';
8
+ const wrongRule2 = 'wrongRule2';
9
+ const wrongRule3 = 'wrongRule3';
10
+ const allKeys = [
11
+ wrongTypeKey,
12
+ missingKey,
13
+ wrongRule1,
14
+ wrongRule2,
15
+ wrongRule3
16
+ ];
17
+ const getCustomMsg = (key, variation = '') => key + ' custom' + variation;
18
+ const schema = new Schema({
19
+ [wrongTypeKey]: {
20
+ type: Number,
21
+ required: true,
22
+ title: 'Не по типу',
23
+ customMessage: (input) => {
24
+ return getCustomMsg(wrongTypeKey);
25
+ }
26
+ },
27
+ [missingKey]: {
28
+ type: Date,
29
+ required: true,
30
+ title: 'Отсутствующий',
31
+ customMessage: (input) => {
32
+ return getCustomMsg(missingKey);
33
+ }
34
+ },
35
+ [wrongRule1]: {
36
+ type: String,
37
+ required: true,
38
+ title: 'Wrong Rule #1',
39
+ rules: {
40
+ is: 'xxx'
41
+ },
42
+ customMessage: (input) => {
43
+ return getCustomMsg(wrongRule1);
44
+ }
45
+ },
46
+ [wrongRule2]: {
47
+ type: String,
48
+ required: true,
49
+ title: 'Wrong Rule #2',
50
+ rules: {
51
+ lengthMin: 999
52
+ },
53
+ customMessage: (input) => {
54
+ return getCustomMsg(wrongRule2);
55
+ }
56
+ },
57
+ [wrongRule3]: {
58
+ type: String,
59
+ required: true,
60
+ title: 'Wrong Rule #3',
61
+ rules: {
62
+ lengthMax: 1
63
+ },
64
+ customMessage: (input) => {
65
+ const { keyword, value, key, title, reqs, schema, rules } = input;
66
+ if (keyword === 'lengthMax') {
67
+ return getCustomMsg(wrongRule3);
68
+ }
69
+ return wrongRule3 + ' should reach here';
70
+ }
71
+ },
72
+ });
73
+ const obj = {
74
+ [wrongTypeKey]: 'abc',
75
+ [wrongRule1]: 'def',
76
+ [wrongRule2]: 'ghi',
77
+ [wrongRule3]: 'jkl'
78
+ };
79
+ const result = schema.validate(obj);
80
+ expect(result).toEqual({
81
+ ok: false,
82
+ missed: [missingKey],
83
+ failed: [...allKeys],
84
+ passed: [],
85
+ errors: allKeys.map(el => getCustomMsg(el)),
86
+ byKeys: {
87
+ wrongType: false,
88
+ missingKey: false,
89
+ wrongRule1: false,
90
+ wrongRule2: false,
91
+ wrongRule3: false
92
+ },
93
+ errorsByKeys: {
94
+ wrongType: [getCustomMsg(allKeys[0])],
95
+ missingKey: [getCustomMsg(allKeys[1])],
96
+ wrongRule1: [getCustomMsg(allKeys[2])],
97
+ wrongRule2: [getCustomMsg(allKeys[3])],
98
+ wrongRule3: [getCustomMsg(allKeys[4])],
99
+ }
100
+ });
101
+ });
102
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=customType.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customType.test.d.ts","sourceRoot":"","sources":["../../src/tests/customType.test.ts"],"names":[],"mappings":""}