From 2d9da9c1508baa5693d6afde2d3e800b9cffc999 Mon Sep 17 00:00:00 2001 From: Alan Lu Date: Sat, 4 May 2024 01:38:51 +0800 Subject: [PATCH] fix(notion-api-zod-schema): formula schema --- .changeset/fast-pants-play.md | 5 +++++ .../src/NotionDatabaseSchema.ts | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 .changeset/fast-pants-play.md diff --git a/.changeset/fast-pants-play.md b/.changeset/fast-pants-play.md new file mode 100644 index 0000000..33f9e5d --- /dev/null +++ b/.changeset/fast-pants-play.md @@ -0,0 +1,5 @@ +--- +"@alanlu-dev/notion-api-zod-schema": patch +--- + +fix(notion-api-zod-schema): formula schema diff --git a/packages/notion-api-zod-schema/src/NotionDatabaseSchema.ts b/packages/notion-api-zod-schema/src/NotionDatabaseSchema.ts index 8fdb09e..8ede79f 100644 --- a/packages/notion-api-zod-schema/src/NotionDatabaseSchema.ts +++ b/packages/notion-api-zod-schema/src/NotionDatabaseSchema.ts @@ -166,10 +166,21 @@ export type NotionButtonType = z.infer // formula export const NotionFormulaSchema = z.object({ type: z.literal('formula'), - formula: z.object({ - type: z.literal('string'), - string: z.string().nullable(), - }), + formula: z.discriminatedUnion('type', [ + z.object({ + type: z.literal('string'), + string: z.string().nullable(), + }), + z.object({ + type: z.literal('number'), + number: z.number().nullable(), + }), + z.object({ + type: z.literal('boolean'), + boolean: z.boolean().nullable(), + }), + NotionDateSchema, + ]), }) export type NotionFormulaType = z.infer