import { type } from "arktype"; export enum HeadingBlockLevel { L1 = 1, L2 = 2, L3 = 3, L4 = 4, L5 = 5, L6 = 6, } export const fileAttributeSchema = type({ "alternativeText?": "string | null", "caption?": "string | null", "createdAt": "string", "documentId": "string", "ext": "string", "formats?": "Record | null", "hash": "string", "height?": "number | null", "mime": "string", "name": "string", "previewUrl?": "string | null", "provider": "string", "provider_metadata?": "unknown", "size": "number", "updatedAt": "string", "url": "string", "width?": "number | null", }); export type FileAttribute = typeof fileAttributeSchema.infer; export const imageAttributeSchema = fileAttributeSchema.narrow( (o): o is Omit & { width: number; height: number } => !!o.width && !!o.height, ); export type ImageAttribute = typeof imageAttributeSchema.infer; const blocksAttributeScope = type .scope({ codeBlockNode: { "children": "defaultInlineNode[]", "language?": "string", "type": "'code'", }, defaultInlineNode: "textInlineNode | linkInlineNode", headingBlockNode: { children: "defaultInlineNode[]", level: "1 | 2 | 3 | 4 | 5 | 6", type: "'heading'", }, imageBlockNode: { children: type({ text: "string", type: "'text'", }).array(), image: fileAttributeSchema.omit("documentId"), type: "'image'", }, linkInlineNode: { children: "textInlineNode[]", type: "'link'", url: "string", }, listBlockNode: { children: "(listItemInlineNode | listBlockNode)[]", format: "'ordered' | 'unordered'", type: "'list'", }, listItemInlineNode: { children: "defaultInlineNode[]", type: "'list-item'", }, node: "rootNode | nonTextInlineNode", nonTextInlineNode: "linkInlineNode | listItemInlineNode", paragraphBlockNode: { children: "defaultInlineNode[]", type: "'paragraph'", }, quoteBlockNode: { children: "defaultInlineNode[]", type: "'quote'", }, rootNode: "paragraphBlockNode | quoteBlockNode | codeBlockNode | headingBlockNode | listBlockNode | imageBlockNode", textInlineNode: { "bold?": "boolean", "code?": "boolean", "italic?": "boolean", "strikethrough?": "boolean", "text": "string", "type": "'text'", "underline?": "boolean", }, }) .export(); export const defaultInlineNodeSchema = blocksAttributeScope.defaultInlineNode; export type DefaultInlineNode = typeof defaultInlineNodeSchema.infer; export const nodeSchema = blocksAttributeScope.node; export type Node = typeof nodeSchema.infer; export const strapiItemSchema = type({ "[string]": "unknown", "documentId": "string", "publishedAt": "string.date.parse | null", "updatedAt": "string.date.parse", }); export type StrapiItem = typeof strapiItemSchema.infer; export const strapiCollectionResponseSchema = type({ data: strapiItemSchema.array(), meta: { pagination: { page: "number", pageCount: "number", pageSize: "number", total: "number", }, }, }); export const strapiItemResponseSchema = type({ data: strapiItemSchema, });