-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete zod
plugin with proprietary brands
#1730
Conversation
At the moment, despite the beauty of it, I'm thinking that it's not needed to be a part of consumer's API, so it can be kept as an internal method for a while. At least until I come up with something better for |
UPDATE on raw / extending shape issue: |
037147d
to
5453ff9
Compare
I realized that this can actually be a feature for those who may need it as much as I am. |
78a517b
to
4730811
Compare
zod
plugin with proprietary brands
…or('express-zod-api')] - if needed (compromise for keeping it simpler).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I'm kinda proud of it
![image](https://github.com/RobinTail/express-zod-api/assets/13189514/f090c11f-4d73-409a-8546-5c586adb0afc) Pebbles LaDime (Dime) Doe was a black transgender woman. https://edition.cnn.com/2024/02/25/us/dime-doe-trial-south-carolina-federal-hate-crime/index.html https://www.nbcnews.com/feature/nbc-out/south-carolina-death-marks-14th-black-transgender-woman-killed-u-n1040971 https://www.justice.gov/opa/pr/south-carolina-man-found-guilty-hate-crime-killing-transgender-woman-because-her-gender Transgender women suffer too frequently from transphobic violence and cruelty, being the less protected social group. I'd like to raise an awareness of this problem. Humans should be creators — not killers. But most importantly, I want every transgender girl to have an opportunity to create applications quickly and, in general, learn to write code easily in order to receive job offers and leave dangerously transphobic territories for more favorable and civilized ones, and live happily there. Protect transgender women. ------------------------------ This version is focused on making `express-zod-api` a complete `zod` plugin. In this regard `withMeta` is removed in favor of the recommended approach on extending `zod` functionality, which opens up opportunities for new features and simplifies the consumer experience. Another improvement has been made for parsers: they are now applied selectively depending on the type of expected request. - #1693 - #1705 - #1707 - Theoretically #1631 - In advance #1708 - #1726 - #1736 - #1741 - #1745 - #1762 - #1756 - #1766 - #1730 - #1747 - #1748 - #1755 - #1760 - Not included, but comes later: #1750⚠️ don't squash it, to avoid conflicts with #1750
…#1750) Based on #1470 and thanks to #1730 This will be a feature in v19. I'd like to keep changes of 19.0.0 smaller, making it easier to migrate. Thus, I'm going to separate breaking changes from features and release this as 19.1.0. This will be the interface: ```ts import { z } from "zod"; import { Documentation, Integration } from "express-zod-api"; const myBrand = Symbol("MamaToldMeImSpecial"); // I highly recommend using symbols for this purpose const myBrandedSchema = z.string().brand(myBrand); new Documentation({ /* config, routing, title, version */ brandHandling: { [myBrand]: ( schema: typeof myBrandedSchema, // you should assign type yourself { next, path, method, isResponse }, // handle a nested schema using next() ) => { const defaultResult = next(schema.unwrap()); // { type: string } return { summary: "Special type of data" }; }, }, }); import ts from "typescript"; const { factory: f } = ts; new Integration({ /* routing */ brandHandling: { [myBrand]: ( schema: typeof myBrandedSchema, // you should assign type yourself { next, isResponse, serializer }, // handle a nested schema using next() ) => f.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword), }, }); ```
Due to #1721, colinhacks/zod#2860 (comment), and #1719 I'm exploring the possibility to alter the behaviour of
.brand()
for storing thebrand
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 inaccept-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