- typsafe vanilla_error_reporter.ts
Some checks failed
CI Pipeline / japa-tests (push) Failing after 59s

- updated Dockerfole for using node 20
- remove validator_old.ts
- npm updates
This commit is contained in:
Kaimbacher 2024-05-21 14:41:10 +02:00
parent ec17d79cf2
commit 770e791613
9 changed files with 204 additions and 381 deletions

View file

@ -17,7 +17,7 @@ export interface MessagesBagContract {
* given validation failure.
*/
export class MessagesBag implements MessagesBagContract {
messages;
messages: Message;
wildCardCallback;
constructor(messages: string[]) {
this.messages = messages;
@ -66,13 +66,16 @@ export class MessagesBag implements MessagesBagContract {
/**
* Shape of the error message collected by the SimpleErrorReporter
*/
// type SimpleError = {
// message: string;
// field: string;
// rule: string;
// index?: number;
// meta?: Record<string, any>;
// };
type SimpleError = {
message: string;
field: string;
rule: string;
index?: number;
meta?: Record<string, any>;
};
export interface Message {
[key: string]: any;
}
/**
* Simple error reporter collects error messages as an array of object.
* Each object has following properties.
@ -84,7 +87,7 @@ export class MessagesBag implements MessagesBagContract {
* - args?: Record<string, any>
*/
export class VanillaErrorReporter implements ErrorReporterContract {
private messages;
// private messages;
// private bail;
/**
* Boolean to know one or more errors have been reported
@ -94,7 +97,7 @@ export class VanillaErrorReporter implements ErrorReporterContract {
* Collection of errors
*/
// errors: SimpleError[] = [];
errors = {};
errors: Message = {};
/**
* Report an error.
*/
@ -117,7 +120,12 @@ export class VanillaErrorReporter implements ErrorReporterContract {
// }
// this.errors.push(error);
this.hasErrors = true;
const error = {
// if (this.errors[field.getFieldPath()]) {
// this.errors[field.getFieldPath()]?.push(message);
// } else {
// this.errors[field.getFieldPath()] = [message];
// }
const error: SimpleError = {
message,
rule,
field: field.getFieldPath(),