Skip to content

Commit

Permalink
fix(notion-api-zod-schema): rollupSchema allow type number
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlu-zyl committed May 12, 2024
1 parent 93bd3c2 commit 63dff6e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-emus-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alanlu-dev/notion-api-zod-schema": patch
---

fix(notion-api-zod-schema): rollupSchema allow type number
118 changes: 63 additions & 55 deletions packages/notion-api-zod-schema/src/NotionDatabaseSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,63 +195,71 @@ export const NotionDatabaseRelationSchema = NotionDatabaseCellSchema.merge(Notio
export type NotionDatabaseRelationType = z.infer<typeof NotionDatabaseRelationSchema>

// rollup
const rollupFunctionEnum = z.enum([
'average',
'checked',
'count_per_group',
'count',
'count_values',
'date_range',
'earliest_date',
'empty',
'latest_date',
'max',
'median',
'min',
'not_empty',
'percent_checked',
'percent_empty',
'percent_not_empty',
'percent_per_group',
'percent_unchecked',
'range',
'unchecked',
'unique',
'show_original',
'show_unique',
'sum',
])
export const NotionDatabaseRollupSchema = NotionDatabaseCellSchema.extend({
type: z.literal('rollup'),
rollup: z.object({
type: z.literal('array'),
array: z.array(
z
.discriminatedUnion('type', [
NotionTitleSchema,
NotionRichTextSchema,
NotionNumberSchema,
NotionSelectSchema,
NotionMultiSelectSchema,
NotionStatusSchema,
NotionDateSchema,
NotionPeopleSchema,
NotionFilesSchema,
NotionCheckboxSchema,
NotionUrlSchema,
NotionEmailSchema,
NotionPhoneNumberSchema,
NotionCreatedTimeSchema,
NotionCreatedBySchema,
NotionLastEditedTimeSchema,
NotionLastEditedBySchema,
NotionUniqueIdSchema,
NotionFormulaSchema,
NotionRelationSchema,
])
.optional(),
),
function: z.enum([
'average',
'checked',
'count_per_group',
'count',
'count_values',
'date_range',
'earliest_date',
'empty',
'latest_date',
'max',
'median',
'min',
'not_empty',
'percent_checked',
'percent_empty',
'percent_not_empty',
'percent_per_group',
'percent_unchecked',
'range',
'unchecked',
'unique',
'show_original',
'show_unique',
'sum',
]),
}),
rollup: z.discriminatedUnion('type', [
z.object({
type: z.literal('array'),
array: z.array(
z
.discriminatedUnion('type', [
NotionTitleSchema,
NotionRichTextSchema,
NotionNumberSchema,
NotionSelectSchema,
NotionMultiSelectSchema,
NotionStatusSchema,
NotionDateSchema,
NotionPeopleSchema,
NotionFilesSchema,
NotionCheckboxSchema,
NotionUrlSchema,
NotionEmailSchema,
NotionPhoneNumberSchema,
NotionCreatedTimeSchema,
NotionCreatedBySchema,
NotionLastEditedTimeSchema,
NotionLastEditedBySchema,
NotionUniqueIdSchema,
NotionFormulaSchema,
NotionRelationSchema,
])
.optional(),
),
function: rollupFunctionEnum,
}),
z.object({
type: z.literal('number'),
number: z.number(),
function: rollupFunctionEnum,
}),
]),
})
export type NotionDatabaseRollupType = z.infer<typeof NotionDatabaseRollupSchema>

Expand Down

0 comments on commit 63dff6e

Please sign in to comment.