-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete
zod
plugin with proprietary brands (#1730)
Due to #1721, colinhacks/zod#2860 (comment), and #1719 I'm exploring the possibility to alter the behaviour of `.brand()` for storing the `brand` property as a way to distinguish the proprietary schemas in runtime. This can replace the `proprietary()` function with a call of `.brand()`. However, so far it turned out to be breaking because `ZodBranded` does not expose the methods of the wrapped schema, such as `.extend()`, which is used in `accept-raw.ts` endpoint for possible route params. —— After a series of serious considerations I realized that exposing brand to consumers of `express-zod-api` could be a beneficial feature. Runtime brand can be accessed via `._def[Symbol.for("express-zod-api")].brand`
- Loading branch information
Showing
33 changed files
with
290 additions
and
253 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
import { z } from "zod"; | ||
import { proprietary } from "./metadata"; | ||
import { isValidDate } from "./schema-helpers"; | ||
|
||
export const ezDateOutKind = "DateOut"; | ||
export const ezDateOutBrand = Symbol("DateOut"); | ||
|
||
export const dateOut = () => | ||
proprietary( | ||
ezDateOutKind, | ||
z | ||
.date() | ||
.refine(isValidDate) | ||
.transform((date) => date.toISOString()), | ||
); | ||
z | ||
.date() | ||
.refine(isValidDate) | ||
.transform((date) => date.toISOString()) | ||
.brand(ezDateOutBrand); | ||
|
||
export type DateOutSchema = ReturnType<typeof dateOut>; |
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
Oops, something went wrong.