-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schema): support zod schema for runtime validation (#39)
- Loading branch information
1 parent
646be9e
commit b6c4000
Showing
9 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// only importing types > dev dep | ||
import type { ZodError, ZodIssue } from 'zod'; | ||
|
||
export class HelpfulZodValidationError extends Error { | ||
public details: ZodIssue[]; | ||
|
||
public props: any; | ||
|
||
public domainObject: string; | ||
|
||
constructor({ | ||
error, | ||
props, | ||
domainObject, | ||
}: { | ||
error: ZodError; | ||
props: any; | ||
domainObject: string; | ||
}) { | ||
const message = ` | ||
Errors were found while validating properties for domain object ${domainObject}.: | ||
${JSON.stringify(error.errors, null, 2)} | ||
Props Provided: | ||
${JSON.stringify(props, null, 2)} | ||
`.trim(); | ||
super(message); | ||
|
||
this.details = error.errors; | ||
this.props = props; | ||
this.domainObject = domainObject; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters