I have a parser
stringParser
that would take a string (of a specific format, in my case query-like k1=v1&k2=v2
) and with transform
(OR preprocess
, which is a lot less desirable because of the bug https://github.com/colinhacks/zod/issues/1460) and make a Record<string,string>
out of it.
I have a recordParser
that would parse this record's k1/k2
keys and v1/v2
values according to my schema where the keys and values are statically set (like interface Parsed {k1: BrandedValue1, k2: BrandedValue2}
). But basically the recordParser
is a vanilla z.object(...)
parser.
How do I compose these two?
stringParser.and(recordParser)
sounds strange to me (although I could be wrong) cause it doesn't define a "pipeline" semantically but rather "the value should be both of" (which a string is clearly not a Record for recordParser).
Calling recordParser
inside transform
of stringParser
looks undesirable as well because of bad composition.
What's the best way / lesser evil to achieve such a composition?