From 383b8fe1f8461a7bbd728c917e68967c47d362d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Frison?= Date: Mon, 14 Oct 2024 21:22:54 +0200 Subject: [PATCH] feat: create Zod's `default` function for entity's booleans (#1773) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Théo Frison Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com> --- packages/schema/src/plugins/zod/utils/schema-gen.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/schema/src/plugins/zod/utils/schema-gen.ts b/packages/schema/src/plugins/zod/utils/schema-gen.ts index 6d96087d0..ee46390ff 100644 --- a/packages/schema/src/plugins/zod/utils/schema-gen.ts +++ b/packages/schema/src/plugins/zod/utils/schema-gen.ts @@ -20,6 +20,7 @@ import { isInvocationExpr, isNumberLiteral, isStringLiteral, + isBooleanLiteral } from '@zenstackhq/sdk/ast'; import { upperCaseFirst } from 'upper-case-first'; import { name } from '..'; @@ -282,6 +283,8 @@ export function getFieldSchemaDefault(field: DataModelField) { return JSON.stringify(arg.value.value); } else if (isNumberLiteral(arg.value)) { return arg.value.value; + } else if (isBooleanLiteral(arg.value)) { + return arg.value.value; } else if ( isInvocationExpr(arg.value) && isFromStdlib(arg.value.function.ref!) &&