/
writeInputJsonValue.ts
37 lines (33 loc) · 1.09 KB
/
writeInputJsonValue.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { type ContentWriterOptions } from '../../types';
export const writeInputJsonValue = ({
fileWriter: { writer, writeImport },
dmmf,
getSingleFileContent = false,
}: ContentWriterOptions) => {
const { useMultipleFiles, prismaClientPath } = dmmf.generatorConfig;
if (useMultipleFiles && !getSingleFileContent) {
writeImport('{ z }', 'zod');
writeImport('type { Prisma }', prismaClientPath);
}
writer
.blankLine()
.writeLine(
`export const InputJsonValue: z.ZodType<Prisma.InputJsonValue> = z.union([`,
)
.withIndentationLevel(1, () => {
writer
.writeLine(`z.string(),`)
.writeLine(`z.number(),`)
.writeLine(`z.boolean(),`)
.writeLine(`z.lazy(() => z.array(InputJsonValue.nullable())),`)
.writeLine(`z.lazy(() => z.record(InputJsonValue.nullable())),`);
})
.write(`]);`)
.blankLine()
.writeLine(
`export type InputJsonValueType = z.infer<typeof InputJsonValue>;`,
);
if (useMultipleFiles && !getSingleFileContent) {
writer.blankLine().writeLine(`export default InputJsonValue;`);
}
};