Open FlorianWendelborn opened 2 years ago
Yep, seems like an oversight, should be a quick addition. I'll look into it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@stale this issue is still relevant
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@stale don’t
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@stale don't
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@stale don't
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@stale don’t
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
A simply workaround:
z.preprocess(
async (value) => {
// ...
},
z.promise(someSchema), // Wrap your own schema with a promise schema.
);
I’m trying to parse some minecraft NBT data with zod. However, in order to do this, one key of the object (
item_bytes
) first needs to be converted from the binary NBT format to a JSON-like structure.The best way to implement this in my opinion would be to use zod’s
z.preprocess()
. Unfortunately, the library I’m usingprismarine-nbt
only exposesparse
as anasync
function.As far as I can tell, async preprocessing is not supported right now. I think it would be great if it’s allowed as it would really simplify parsing with
async
libraries.I’d suggest either
z.preprocess(async () => { /* ... */ }, z.any())
orz.preprocessAsync(async () => { /* ... */ }, z.any())
as I think either would be reasonable from an API standpoint.