diff options
Diffstat (limited to 'src/deps/strapi/schema.ts')
| -rw-r--r-- | src/deps/strapi/schema.ts | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/deps/strapi/schema.ts b/src/deps/strapi/schema.ts new file mode 100644 index 0000000..6161680 --- /dev/null +++ b/src/deps/strapi/schema.ts | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | import { type } from "arktype"; | ||
| 2 | |||
| 3 | export enum HeadingBlockLevel { | ||
| 4 | L1 = 1, | ||
| 5 | L2 = 2, | ||
| 6 | L3 = 3, | ||
| 7 | L4 = 4, | ||
| 8 | L5 = 5, | ||
| 9 | L6 = 6, | ||
| 10 | } | ||
| 11 | |||
| 12 | export const fileAttributeSchema = type({ | ||
| 13 | "alternativeText?": "string | null", | ||
| 14 | "caption?": "string | null", | ||
| 15 | "createdAt": "string", | ||
| 16 | "documentId": "string", | ||
| 17 | "ext": "string", | ||
| 18 | "formats?": "Record<string, unknown> | null", | ||
| 19 | "hash": "string", | ||
| 20 | "height?": "number | null", | ||
| 21 | "mime": "string", | ||
| 22 | "name": "string", | ||
| 23 | "previewUrl?": "string | null", | ||
| 24 | "provider": "string", | ||
| 25 | "provider_metadata?": "unknown", | ||
| 26 | "size": "number", | ||
| 27 | "updatedAt": "string", | ||
| 28 | "url": "string", | ||
| 29 | "width?": "number | null", | ||
| 30 | }); | ||
| 31 | |||
| 32 | export type FileAttribute = typeof fileAttributeSchema.infer; | ||
| 33 | |||
| 34 | export const imageAttributeSchema = fileAttributeSchema.narrow( | ||
| 35 | (o): o is Omit<typeof o, "width" | "height"> & { width: number; height: number } => | ||
| 36 | !!o.width && !!o.height, | ||
| 37 | ); | ||
| 38 | |||
| 39 | export type ImageAttribute = typeof imageAttributeSchema.infer; | ||
| 40 | |||
| 41 | const blocksAttributeScope = type | ||
| 42 | .scope({ | ||
| 43 | codeBlockNode: { | ||
| 44 | "children": "defaultInlineNode[]", | ||
| 45 | "language?": "string", | ||
| 46 | "type": "'code'", | ||
| 47 | }, | ||
| 48 | |||
| 49 | defaultInlineNode: "textInlineNode | linkInlineNode", | ||
| 50 | |||
| 51 | headingBlockNode: { | ||
| 52 | children: "defaultInlineNode[]", | ||
| 53 | level: "1 | 2 | 3 | 4 | 5 | 6", | ||
| 54 | type: "'heading'", | ||
| 55 | }, | ||
| 56 | |||
| 57 | imageBlockNode: { | ||
| 58 | children: type({ | ||
| 59 | text: "string", | ||
| 60 | type: "'text'", | ||
| 61 | }).array(), | ||
| 62 | image: fileAttributeSchema.omit("documentId"), | ||
| 63 | type: "'image'", | ||
| 64 | }, | ||
| 65 | |||
| 66 | linkInlineNode: { | ||
| 67 | children: "textInlineNode[]", | ||
| 68 | type: "'link'", | ||
| 69 | url: "string", | ||
| 70 | }, | ||
| 71 | |||
| 72 | listBlockNode: { | ||
| 73 | children: "(listItemInlineNode | listBlockNode)[]", | ||
| 74 | format: "'ordered' | 'unordered'", | ||
| 75 | type: "'list'", | ||
| 76 | }, | ||
| 77 | |||
| 78 | listItemInlineNode: { | ||
| 79 | children: "defaultInlineNode[]", | ||
| 80 | type: "'list-item'", | ||
| 81 | }, | ||
| 82 | |||
| 83 | node: "rootNode | nonTextInlineNode", | ||
| 84 | |||
| 85 | nonTextInlineNode: "linkInlineNode | listItemInlineNode", | ||
| 86 | |||
| 87 | paragraphBlockNode: { | ||
| 88 | children: "defaultInlineNode[]", | ||
| 89 | type: "'paragraph'", | ||
| 90 | }, | ||
| 91 | |||
| 92 | quoteBlockNode: { | ||
| 93 | children: "defaultInlineNode[]", | ||
| 94 | type: "'quote'", | ||
| 95 | }, | ||
| 96 | |||
| 97 | rootNode: | ||
| 98 | "paragraphBlockNode | quoteBlockNode | codeBlockNode | headingBlockNode | listBlockNode | imageBlockNode", | ||
| 99 | |||
| 100 | textInlineNode: { | ||
| 101 | "bold?": "boolean", | ||
| 102 | "code?": "boolean", | ||
| 103 | "italic?": "boolean", | ||
| 104 | "strikethrough?": "boolean", | ||
| 105 | "text": "string", | ||
| 106 | "type": "'text'", | ||
| 107 | "underline?": "boolean", | ||
| 108 | }, | ||
| 109 | }) | ||
| 110 | .export(); | ||
| 111 | |||
| 112 | export const defaultInlineNodeSchema = blocksAttributeScope.defaultInlineNode; | ||
| 113 | |||
| 114 | export type DefaultInlineNode = typeof defaultInlineNodeSchema.infer; | ||
| 115 | |||
| 116 | export const nodeSchema = blocksAttributeScope.node; | ||
| 117 | |||
| 118 | export type Node = typeof nodeSchema.infer; | ||
| 119 | |||
| 120 | export const strapiItemSchema = type({ | ||
| 121 | "[string]": "unknown", | ||
| 122 | "documentId": "string", | ||
| 123 | "publishedAt": "string.date.parse | null", | ||
| 124 | "updatedAt": "string.date.parse", | ||
| 125 | }); | ||
| 126 | |||
| 127 | export type StrapiItem = typeof strapiItemSchema.infer; | ||
| 128 | |||
| 129 | export const strapiCollectionResponseSchema = type({ | ||
| 130 | data: strapiItemSchema.array(), | ||
| 131 | meta: { | ||
| 132 | pagination: { | ||
| 133 | page: "number", | ||
| 134 | pageCount: "number", | ||
| 135 | pageSize: "number", | ||
| 136 | total: "number", | ||
| 137 | }, | ||
| 138 | }, | ||
| 139 | }); | ||
| 140 | |||
| 141 | export const strapiItemResponseSchema = type({ | ||
| 142 | data: strapiItemSchema, | ||
| 143 | }); | ||
