-
-
Notifications
You must be signed in to change notification settings - Fork 121
Closed
Milestone
Description
Description:
- the
zod
plugin will create a validator like so forBytes
fields:z.union([z.string(), z.instanceof(Uint8Array)])
- i.e., a zod validator that infers toUint8Array
- this is problematic as the schemas are then type-casted to a type that treats
Bytes
as aBuffer
- seeexport const ${this.name}ObjectSchema: SchemaType = ${schema} as SchemaType;`; - this then results in a type-error (see screenshot)
Solution:
- Quick fix:
- Remove
:SchemaType
from the line above - Change
as SchemaType
toas unknown as SchemaType
- Remove
- Elegant fix:
- General background:
- Buffers aren't supported on the frontend, and have to be serialized + deserialized into a Uint8Array or another byte array
Bytes
fields are initially returned as aBuffer
when directly interacting with the prisma client- Therefore, both types technically have some merit
- A clean solution might be something like
z.custom<Buffer | Uint8Array>(data => data instanceof Uint8Array)
- NOTE: I haven't tested the above, but I believe it should work
- The above would let us preserve those types, while not having to have a runtime Buffer object on the frontend
- General background:
Environment (please complete the following information):
- ZenStack version: [e.g., 2.0.0-beta.13]
- Prisma version: [e.g., 5.12.1]
- Database type: [e.g. MySQL]
Eliav2
Metadata
Metadata
Assignees
Labels
No labels