From 9cb8fd0b3f1475f0d8fa487d49cd4a4ac582be23 Mon Sep 17 00:00:00 2001 From: Bartolomeu Date: Fri, 22 Jul 2022 20:59:29 +0000 Subject: [PATCH] Changed error messages --- package-lock.json | 2 +- package.json | 2 +- src/schemas/array/array-schema.spec.ts | 4 ++-- src/schemas/array/array-schema.ts | 2 +- src/schemas/base/base-schema.spec.ts | 4 ++-- src/schemas/base/base-schema.ts | 6 +++--- src/schemas/boolean/boolean-schema.ts | 2 +- src/schemas/date/date-schema.spec.ts | 2 +- src/schemas/date/date-schema.ts | 4 ++-- src/schemas/equals/equals-schema.spec.ts | 2 +- src/schemas/equals/equals-schema.ts | 2 +- src/schemas/number/number-schema.spec.ts | 2 +- src/schemas/number/number-schema.ts | 2 +- src/schemas/object/object-of-schema.spec.ts | 4 ++-- src/schemas/object/object-schema.spec.ts | 6 +++--- src/schemas/object/object-schema.union.spec.ts | 4 ++-- src/schemas/object/object-type-filter.ts | 2 +- src/schemas/or/or-schema.spec.ts | 6 ++++++ src/schemas/string/string-schema.spec.ts | 2 +- src/schemas/string/string-schema.ts | 2 +- 20 files changed, 34 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2b62b78..2fed3bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "not-me", - "version": "5.2.1", + "version": "5.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9108d0d..244f317 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "not-me", - "version": "5.2.1", + "version": "5.3.0", "description": "Easy and type-safe validation", "main": "lib/index.js", "types": "lib/types.d.ts", diff --git a/src/schemas/array/array-schema.spec.ts b/src/schemas/array/array-schema.spec.ts index 8679bdd..3fe70e2 100644 --- a/src/schemas/array/array-schema.spec.ts +++ b/src/schemas/array/array-schema.spec.ts @@ -29,7 +29,7 @@ describe("Array Schema", () => { it("Should fail when input is not an array", () => { expect(schema.validate(4)).toEqual({ errors: true, - messagesTree: ["Input must be an array"], + messagesTree: ["Must be an array"], }); }); @@ -38,7 +38,7 @@ describe("Array Schema", () => { errors: true, messagesTree: [ { - 2: [{ someProp: ["Input must be one of the allowed values"] }], + 2: [{ someProp: ["Must be one of the allowed values"] }], }, ], }); diff --git a/src/schemas/array/array-schema.ts b/src/schemas/array/array-schema.ts index b294eba..31e4895 100644 --- a/src/schemas/array/array-schema.ts +++ b/src/schemas/array/array-schema.ts @@ -31,7 +31,7 @@ class ArraySchemaImpl< message || DefaultErrorMessagesManager.getDefaultMessages().array ?.notAnArray || - "Input must be an array", + "Must be an array", ], }; } diff --git a/src/schemas/base/base-schema.spec.ts b/src/schemas/base/base-schema.spec.ts index 6979404..68311b1 100644 --- a/src/schemas/base/base-schema.spec.ts +++ b/src/schemas/base/base-schema.spec.ts @@ -89,14 +89,14 @@ describe("Base Schema", () => { expect(undefinedRes).toEqual({ errors: true, - messagesTree: ["Input is required"], + messagesTree: ["Required"], }); const nullRes = schema.validate(null); expect(nullRes).toEqual({ errors: true, - messagesTree: ["Input is required"], + messagesTree: ["Required"], }); }); diff --git a/src/schemas/base/base-schema.ts b/src/schemas/base/base-schema.ts index 5f9618a..c151b25 100644 --- a/src/schemas/base/base-schema.ts +++ b/src/schemas/base/base-schema.ts @@ -259,7 +259,7 @@ export abstract class BaseSchema< message || DefaultErrorMessagesManager.getDefaultMessages().base ?.cannotBeUndefined || - "Input must be defined", + "Cannot be undefined", }); } @@ -269,7 +269,7 @@ export abstract class BaseSchema< message: message || DefaultErrorMessagesManager.getDefaultMessages().base?.cannotBeNull || - "Input cannot be null", + "Cannot be null", }); } @@ -279,7 +279,7 @@ export abstract class BaseSchema< message: message || DefaultErrorMessagesManager.getDefaultMessages().base?.isRequired || - "Input is required", + "Required", }); } diff --git a/src/schemas/boolean/boolean-schema.ts b/src/schemas/boolean/boolean-schema.ts index 47fcabd..25b4e74 100644 --- a/src/schemas/boolean/boolean-schema.ts +++ b/src/schemas/boolean/boolean-schema.ts @@ -21,7 +21,7 @@ class BooleanSchemaImpl< message || DefaultErrorMessagesManager.getDefaultMessages().boolean ?.notABoolean || - "Input must be a true or false", + "Must be a boolean", ]; return { diff --git a/src/schemas/date/date-schema.spec.ts b/src/schemas/date/date-schema.spec.ts index 48f8484..18754b9 100644 --- a/src/schemas/date/date-schema.spec.ts +++ b/src/schemas/date/date-schema.spec.ts @@ -7,7 +7,7 @@ describe("Date Schema", () => { expect(schema.validate("abc")).toEqual({ errors: true, - messagesTree: ["Input is not a valid date"], + messagesTree: ["Invalid date"], }); }); diff --git a/src/schemas/date/date-schema.ts b/src/schemas/date/date-schema.ts index cd38b4d..d2b5f7b 100644 --- a/src/schemas/date/date-schema.ts +++ b/src/schemas/date/date-schema.ts @@ -11,13 +11,13 @@ class DateSchemaImpl<_Output = Date | undefined | null> extends BaseSchema< const notADateMessages = [ message || DefaultErrorMessagesManager.getDefaultMessages().date?.notADate || - "Input must be a date", + "Must be a date", ]; const invalidDateMessages = [ message || DefaultErrorMessagesManager.getDefaultMessages().date?.invalidDate || - "Input is not a valid date", + "Invalid date", ]; if (input instanceof Date) { diff --git a/src/schemas/equals/equals-schema.spec.ts b/src/schemas/equals/equals-schema.spec.ts index 6dd405e..f4ef161 100644 --- a/src/schemas/equals/equals-schema.spec.ts +++ b/src/schemas/equals/equals-schema.spec.ts @@ -23,7 +23,7 @@ describe("Equals Schema", () => { expect(result).toEqual({ errors: true, - messagesTree: ["Input must be one of the allowed values"], + messagesTree: ["Must be one of the allowed values"], }); }); }); diff --git a/src/schemas/equals/equals-schema.ts b/src/schemas/equals/equals-schema.ts index de7e569..7ec9608 100644 --- a/src/schemas/equals/equals-schema.ts +++ b/src/schemas/equals/equals-schema.ts @@ -19,7 +19,7 @@ class EqualsSchemaImpl< message || DefaultErrorMessagesManager.getDefaultMessages().equals ?.notEqual || - "Input must be one of the allowed values", + "Must be one of the allowed values", ], }; } diff --git a/src/schemas/number/number-schema.spec.ts b/src/schemas/number/number-schema.spec.ts index 6bb5f72..044e278 100644 --- a/src/schemas/number/number-schema.spec.ts +++ b/src/schemas/number/number-schema.spec.ts @@ -7,7 +7,7 @@ describe("Number Schema", () => { expect(schema.validate("abc")).toEqual({ errors: true, - messagesTree: ["Input must be a number"], + messagesTree: ["Must be a number"], }); }); diff --git a/src/schemas/number/number-schema.ts b/src/schemas/number/number-schema.ts index a27a79a..b9803c0 100644 --- a/src/schemas/number/number-schema.ts +++ b/src/schemas/number/number-schema.ts @@ -11,7 +11,7 @@ class NumberSchemaImpl<_Output = number | undefined | null> extends BaseSchema< const typeErrorMessage = [ message || DefaultErrorMessagesManager.getDefaultMessages().number?.notANumber || - "Input must be a number", + "Must be a number", ]; if (typeof input === "number" || typeof input === "string") { diff --git a/src/schemas/object/object-of-schema.spec.ts b/src/schemas/object/object-of-schema.spec.ts index d8f78e8..942c7ad 100644 --- a/src/schemas/object/object-of-schema.spec.ts +++ b/src/schemas/object/object-of-schema.spec.ts @@ -26,7 +26,7 @@ describe("Object Of Schema", () => { errors: true, messagesTree: [ { - b: ["Input must be one of the allowed values"], + b: ["Must be one of the allowed values"], }, ], }); @@ -38,7 +38,7 @@ describe("Object Of Schema", () => { expect(result).toEqual({ errors: true, - messagesTree: ["Input must be an object"], + messagesTree: ["Must be an object"], }); }); diff --git a/src/schemas/object/object-schema.spec.ts b/src/schemas/object/object-schema.spec.ts index 058ca01..72df5fa 100644 --- a/src/schemas/object/object-schema.spec.ts +++ b/src/schemas/object/object-schema.spec.ts @@ -25,7 +25,7 @@ describe("Object Schema", () => { errors: true, messagesTree: [ { - a: ["Input must be an object"], + a: ["Must be an object"], }, ], }); @@ -40,7 +40,7 @@ describe("Object Schema", () => { expect(result).toEqual({ errors: true, - messagesTree: [{ a: ["Input is required"] }], + messagesTree: [{ a: ["Required"] }], }); }); @@ -53,7 +53,7 @@ describe("Object Schema", () => { expect(result).toEqual({ errors: true, - messagesTree: [{ a: ["Input must be a string"] }], + messagesTree: [{ a: ["Must be a string"] }], }); }); diff --git a/src/schemas/object/object-schema.union.spec.ts b/src/schemas/object/object-schema.union.spec.ts index d7a7ae8..d11650e 100644 --- a/src/schemas/object/object-schema.union.spec.ts +++ b/src/schemas/object/object-schema.union.spec.ts @@ -83,7 +83,7 @@ describe("Object Schema - Union", () => { errors: true, messagesTree: [ { - d: ["Input is required"], + d: ["Required"], }, ], }); @@ -98,7 +98,7 @@ describe("Object Schema - Union", () => { errors: true, messagesTree: [ { - d: ["Input must be one of the allowed values"], + d: ["Must be one of the allowed values"], }, ], }); diff --git a/src/schemas/object/object-type-filter.ts b/src/schemas/object/object-type-filter.ts index f9fcb6e..79ff082 100644 --- a/src/schemas/object/object-type-filter.ts +++ b/src/schemas/object/object-type-filter.ts @@ -19,7 +19,7 @@ export function objectTypeFilter( message || DefaultErrorMessagesManager.getDefaultMessages().object ?.notAnObject || - "Input must be an object", + "Must be an object", ], }; } diff --git a/src/schemas/or/or-schema.spec.ts b/src/schemas/or/or-schema.spec.ts index cef6f08..0663ef8 100644 --- a/src/schemas/or/or-schema.spec.ts +++ b/src/schemas/or/or-schema.spec.ts @@ -43,4 +43,10 @@ describe("Or Schema", () => { messagesTree: expect.any(Array) as unknown, }); }); + + it("Should throw when schemas are not provided on declaration", () => { + expect(() => { + or([] as unknown as [Schema]).required(); + }).toThrow("No schemas provided"); + }); }); diff --git a/src/schemas/string/string-schema.spec.ts b/src/schemas/string/string-schema.spec.ts index beba56e..06df739 100644 --- a/src/schemas/string/string-schema.spec.ts +++ b/src/schemas/string/string-schema.spec.ts @@ -7,7 +7,7 @@ describe("String Schema", () => { expect(schema.validate({})).toEqual({ errors: true, - messagesTree: ["Input must be a string"], + messagesTree: ["Must be a string"], }); }); }); diff --git a/src/schemas/string/string-schema.ts b/src/schemas/string/string-schema.ts index 2f00496..bd729f9 100644 --- a/src/schemas/string/string-schema.ts +++ b/src/schemas/string/string-schema.ts @@ -16,7 +16,7 @@ abstract class StringSchemaImpl< message || DefaultErrorMessagesManager.getDefaultMessages().string ?.notAString || - "Input must be a string", + "Must be a string", ]; return {