73 lines
1.4 KiB
TypeScript
73 lines
1.4 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
|
|
|
import {
|
|
linkRefsUnionSchema,
|
|
linkUnionSchema,
|
|
transformPageLink,
|
|
transformPageLinkRef,
|
|
} from "./pageLinks"
|
|
|
|
const titleSchema = z.object({
|
|
title: nullableStringValidator,
|
|
})
|
|
|
|
export const linkConnectionSchema = z
|
|
.object({
|
|
linkConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: linkUnionSchema,
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
.transform((data) => {
|
|
if (data.linkConnection.edges.length) {
|
|
const linkNode = data.linkConnection.edges[0].node
|
|
if (linkNode) {
|
|
const link = transformPageLink(linkNode)
|
|
if (link) {
|
|
return {
|
|
link,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
link: null,
|
|
}
|
|
})
|
|
|
|
export const linkAndTitleSchema = z.intersection(
|
|
linkConnectionSchema,
|
|
titleSchema
|
|
)
|
|
|
|
export const linkConnectionRefs = z
|
|
.object({
|
|
linkConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: linkRefsUnionSchema,
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
.transform((data) => {
|
|
if (data.linkConnection.edges.length) {
|
|
const linkNode = data.linkConnection.edges[0].node
|
|
if (linkNode) {
|
|
const link = transformPageLinkRef(linkNode)
|
|
if (link) {
|
|
return {
|
|
link,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return { link: null }
|
|
})
|