@prismicio/types-internal 4.0.0 → 4.1.0-canary.51f7473

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +5 -5
  2. package/dist/content/boolean.d.ts.map +1 -1
  3. package/dist/content/boolean.js.map +1 -1
  4. package/dist/content/codec/link.js.map +1 -1
  5. package/dist/content/codec/nestable.js +4 -4
  6. package/dist/content/field.d.ts.map +1 -1
  7. package/dist/content/field.js +2 -2
  8. package/dist/content/field.js.map +1 -1
  9. package/dist/content/group.d.ts +1 -2
  10. package/dist/content/group.d.ts.map +1 -1
  11. package/dist/content/group.js +1 -1
  12. package/dist/content/group.js.map +1 -1
  13. package/dist/content/image.d.ts +3 -1
  14. package/dist/content/image.d.ts.map +1 -1
  15. package/dist/content/image.js +3 -3
  16. package/dist/content/image.js.map +1 -1
  17. package/dist/content/legacy/boolean.d.ts +1 -0
  18. package/dist/content/legacy/embed.d.ts +1 -0
  19. package/dist/content/legacy/empty.d.ts +1 -0
  20. package/dist/content/legacy/field.d.ts +1 -0
  21. package/dist/content/legacy/geopoint.d.ts +1 -0
  22. package/dist/content/legacy/image.d.ts +28 -0
  23. package/dist/content/legacy/image.d.ts.map +1 -0
  24. package/dist/content/legacy/image.js +3 -3
  25. package/dist/content/legacy/image.js.map +1 -1
  26. package/dist/content/legacy/integrationField.d.ts +1 -0
  27. package/dist/content/legacy/link.d.ts +14 -14
  28. package/dist/content/legacy/link.js +23 -23
  29. package/dist/content/legacy/link.js.map +1 -1
  30. package/dist/content/legacy/nestable.d.ts +1 -0
  31. package/dist/content/legacy/nestable.js +1 -1
  32. package/dist/content/legacy/repeatable.d.ts +1 -0
  33. package/dist/content/legacy/richText.d.ts +32 -20
  34. package/dist/content/legacy/richText.d.ts.map +1 -1
  35. package/dist/content/legacy/richText.js +7 -7
  36. package/dist/content/legacy/richText.js.map +1 -1
  37. package/dist/content/legacy/separator.d.ts +1 -0
  38. package/dist/content/legacy/table.d.ts +1 -0
  39. package/dist/content/link.d.ts +66 -89
  40. package/dist/content/link.d.ts.map +1 -1
  41. package/dist/content/link.js +30 -27
  42. package/dist/content/link.js.map +1 -1
  43. package/dist/content/nestable.d.ts +3 -3
  44. package/dist/content/nestable.d.ts.map +1 -1
  45. package/dist/content/nestable.js +7 -13
  46. package/dist/content/nestable.js.map +1 -1
  47. package/dist/content/repeatable.d.ts +4 -69
  48. package/dist/content/repeatable.d.ts.map +1 -1
  49. package/dist/content/richText.d.ts +14 -14
  50. package/dist/content/richText.d.ts.map +1 -1
  51. package/dist/content/richText.js +10 -10
  52. package/dist/content/richText.js.map +1 -1
  53. package/dist/content/slice.d.ts +507 -5
  54. package/dist/content/slice.d.ts.map +1 -1
  55. package/dist/content/slice.js +1 -1
  56. package/dist/content/slice.js.map +1 -1
  57. package/dist/content/slices.d.ts +507 -5
  58. package/dist/content/slices.d.ts.map +1 -1
  59. package/dist/content/table.d.ts +5 -2
  60. package/dist/content/table.d.ts.map +1 -1
  61. package/dist/content/widget.js +1 -1
  62. package/dist/content/widget.js.map +1 -1
  63. package/dist/helpers/customTypeModel.d.ts +5 -5
  64. package/dist/helpers/customTypeModel.d.ts.map +1 -1
  65. package/dist/helpers/customTypeModel.js +30 -0
  66. package/dist/helpers/customTypeModel.js.map +1 -1
  67. package/dist/helpers/imageContent.d.ts +33 -0
  68. package/dist/helpers/imageContent.d.ts.map +1 -0
  69. package/dist/helpers/imageContent.js +55 -0
  70. package/dist/helpers/imageContent.js.map +1 -0
  71. package/dist/helpers/traverseContent.d.ts +4 -4
  72. package/dist/helpers/traverseContent.d.ts.map +1 -1
  73. package/dist/helpers/traverseContent.js +5 -3
  74. package/dist/helpers/traverseContent.js.map +1 -1
  75. package/dist/helpers/traverseContentWithModel.d.ts +4 -4
  76. package/dist/helpers/traverseContentWithModel.js +1 -1
  77. package/dist/helpers/withDefaultContent.d.ts +21 -0
  78. package/dist/helpers/withDefaultContent.d.ts.map +1 -0
  79. package/dist/helpers/withDefaultContent.js +120 -0
  80. package/dist/helpers/withDefaultContent.js.map +1 -0
  81. package/dist/index.d.ts +26 -24
  82. package/dist/index.js +6 -1
  83. package/dist/io-ts.d.ts +6777 -3127
  84. package/dist/io-ts.d.ts.map +1 -1
  85. package/dist/io-ts.js +17 -12
  86. package/dist/io-ts.js.map +1 -1
  87. package/dist/model/customType.d.ts +9 -3
  88. package/dist/model/customType.d.ts.map +1 -1
  89. package/dist/model/customType.js +7 -4
  90. package/dist/model/customType.js.map +1 -1
  91. package/dist/model/group.d.ts +2 -2
  92. package/dist/model/group.js +1 -1
  93. package/dist/model/group.js.map +1 -1
  94. package/dist/model/nestable.js +1 -1
  95. package/dist/model/nestable.js.map +1 -1
  96. package/dist/model/richText.d.ts +20 -1
  97. package/dist/model/richText.d.ts.map +1 -1
  98. package/dist/model/richText.js +3 -3
  99. package/dist/model/richText.js.map +1 -1
  100. package/dist/model/slice.d.ts +1259 -651
  101. package/dist/model/slice.d.ts.map +1 -1
  102. package/dist/model/slice.js +9 -9
  103. package/dist/model/slice.js.map +1 -1
  104. package/dist/model/table.js +5 -5
  105. package/dist/model/table.js.map +1 -1
  106. package/dist/model/widget.d.ts +1 -3
  107. package/dist/model/widget.d.ts.map +1 -1
  108. package/dist/model/widget.js +7 -4
  109. package/dist/model/widget.js.map +1 -1
  110. package/dist/zod4.d.ts +3946 -1862
  111. package/dist/zod4.d.ts.map +1 -1
  112. package/dist/zod4.js +17 -12
  113. package/dist/zod4.js.map +1 -1
  114. package/package.json +22 -12
  115. package/src/content/boolean.ts +0 -13
  116. package/src/content/codec/link.ts +12 -12
  117. package/src/content/field.ts +1 -15
  118. package/src/content/group.ts +2 -55
  119. package/src/content/image.ts +3 -91
  120. package/src/content/legacy/image.ts +4 -4
  121. package/src/content/legacy/link.ts +46 -46
  122. package/src/content/legacy/richText.ts +32 -37
  123. package/src/content/link.ts +100 -89
  124. package/src/content/nestable.ts +4 -38
  125. package/src/content/richText.ts +31 -22
  126. package/src/content/slice.ts +1 -1
  127. package/src/content/widget.ts +1 -1
  128. package/src/helpers/customTypeModel.ts +51 -4
  129. package/src/helpers/imageContent.ts +84 -0
  130. package/src/helpers/traverseContent.ts +4 -1
  131. package/src/helpers/withDefaultContent.ts +180 -0
  132. package/src/index.ts +25 -7
  133. package/src/io-ts.ts +22 -10
  134. package/src/model/customType.ts +18 -7
  135. package/src/model/diff/sharedSlice.ts +2 -2
  136. package/src/model/diff/variation.ts +7 -7
  137. package/src/model/group.ts +1 -1
  138. package/src/model/nestable.ts +1 -1
  139. package/src/model/richText.ts +5 -2
  140. package/src/model/slice.ts +20 -23
  141. package/src/model/table.ts +5 -5
  142. package/src/model/widget.ts +14 -14
  143. package/src/zod4.ts +22 -10
  144. package/dist/model/section.d.ts +0 -11
  145. package/dist/model/section.d.ts.map +0 -1
  146. package/dist/model/section.js +0 -10
  147. package/dist/model/section.js.map +0 -1
  148. package/src/content/withDefaultValues.ts +0 -114
  149. package/src/model/section.ts +0 -12
@@ -21,7 +21,7 @@ export const LinkType = {
21
21
  } as const
22
22
 
23
23
  // Image
24
- export const FilledImageLinkValueLegacySchema = z.strictObject({
24
+ export const FilledImageLinkLegacyValueSchema = z.object({
25
25
  // `kind` was normalized to the literal (legacy behavior)
26
26
  kind: z.pipe(
27
27
  z.string(),
@@ -36,12 +36,12 @@ export const FilledImageLinkValueLegacySchema = z.strictObject({
36
36
  date: z.nullish(z.string()),
37
37
  })
38
38
 
39
- export const EmptyImageLinkValueLegacySchema = z.strictObject({
39
+ export const EmptyImageLinkLegacyValueSchema = z.strictObject({
40
40
  kind: z.literal(LinkKind.Image),
41
41
  })
42
42
 
43
43
  // File
44
- export const FilledFileLinkValueLegacySchema = z.strictObject({
44
+ export const FilledFileLinkLegacyValueSchema = z.object({
45
45
  // `kind` was normalized to the literal (legacy behavior)
46
46
  kind: z.pipe(
47
47
  z.string(),
@@ -54,7 +54,7 @@ export const FilledFileLinkValueLegacySchema = z.strictObject({
54
54
  date: z.nullish(z.string()),
55
55
  })
56
56
 
57
- export const EmptyFileLinkValueLegacySchema = z.strictObject({
57
+ export const EmptyFileLinkLegacyValueSchema = z.strictObject({
58
58
  kind: z.literal(LinkKind.File),
59
59
  })
60
60
 
@@ -62,12 +62,12 @@ export const EmptyFileLinkValueLegacySchema = z.strictObject({
62
62
 
63
63
  // Media link only represent the empty state as they turn into
64
64
  // file or image links when they filled.
65
- export const EmptyMediaLinkValueLegacySchema = z.strictObject({
65
+ export const EmptyMediaLinkLegacyValueSchema = z.strictObject({
66
66
  kind: z.literal(LinkKind.Media),
67
67
  })
68
68
 
69
69
  // Document
70
- export const FilledDocumentLinkValueLegacySchema = z.strictObject({
70
+ export const FilledDocumentLinkLegacyValueSchema = z.object({
71
71
  // `kind` is not part of the filled schema... (legacy behavior)
72
72
  // We transform it to the literal for consistency.
73
73
  kind: z.pipe(
@@ -77,12 +77,12 @@ export const FilledDocumentLinkValueLegacySchema = z.strictObject({
77
77
  id: NonEmptyStringSchema,
78
78
  })
79
79
 
80
- export const EmptyDocumentLinkValueLegacySchema = z.strictObject({
80
+ export const EmptyDocumentLinkLegacyValueSchema = z.strictObject({
81
81
  kind: z.literal(LinkKind.Document),
82
82
  })
83
83
 
84
84
  // External
85
- export const FilledExternalLinkValueLegacySchema = z.strictObject({
85
+ export const FilledExternalLinkLegacyValueSchema = z.object({
86
86
  // It's odd that `kind` is optional here... (legacy behavior)
87
87
  // We transform it to the literal for consistency.
88
88
  kind: z.pipe(
@@ -98,7 +98,7 @@ export const FilledExternalLinkValueLegacySchema = z.strictObject({
98
98
  ),
99
99
  })
100
100
 
101
- export const EmptyExternalLinkValueLegacySchema = z.strictObject({
101
+ export const EmptyExternalLinkLegacyValueSchema = z.strictObject({
102
102
  kind: z.literal(LinkKind.External),
103
103
  })
104
104
 
@@ -109,52 +109,52 @@ export const AnyLinkLegacySchema = z.strictObject({
109
109
 
110
110
  // All
111
111
 
112
- export const FilledLinkValueLegacySchema: z.ZodMiniType<FilledLinkValueLegacy> = z.union([
113
- FilledImageLinkValueLegacySchema,
114
- FilledFileLinkValueLegacySchema,
115
- FilledDocumentLinkValueLegacySchema,
116
- FilledExternalLinkValueLegacySchema,
112
+ export const FilledLinkLegacyValueSchema: z.ZodMiniType<FilledLinkLegacyValue> = z.union([
113
+ FilledImageLinkLegacyValueSchema,
114
+ FilledFileLinkLegacyValueSchema,
115
+ FilledDocumentLinkLegacyValueSchema,
116
+ FilledExternalLinkLegacyValueSchema,
117
117
  ])
118
118
 
119
- type FilledImageLinkValueLegacy = z.infer<typeof FilledImageLinkValueLegacySchema>
120
- type FilledFileLinkValueLegacy = z.infer<typeof FilledFileLinkValueLegacySchema>
121
- type FilledDocumentLinkValueLegacy = z.infer<typeof FilledDocumentLinkValueLegacySchema>
122
- type FilledExternalLinkValueLegacy = z.infer<typeof FilledExternalLinkValueLegacySchema>
123
- export type FilledLinkValueLegacy =
124
- | FilledImageLinkValueLegacy
125
- | FilledFileLinkValueLegacy
126
- | FilledDocumentLinkValueLegacy
127
- | FilledExternalLinkValueLegacy
128
-
129
- const EmptyLinkValueLegacySchema: z.ZodMiniType<EmptyLinkValueLegacy> = z.union([
130
- EmptyImageLinkValueLegacySchema,
131
- EmptyFileLinkValueLegacySchema,
132
- EmptyMediaLinkValueLegacySchema,
133
- EmptyDocumentLinkValueLegacySchema,
134
- EmptyExternalLinkValueLegacySchema,
119
+ type FilledImageLinkLegacyValue = z.infer<typeof FilledImageLinkLegacyValueSchema>
120
+ type FilledFileLinkLegacyValue = z.infer<typeof FilledFileLinkLegacyValueSchema>
121
+ type FilledDocumentLinkLegacyValue = z.infer<typeof FilledDocumentLinkLegacyValueSchema>
122
+ type FilledExternalLinkLegacyValue = z.infer<typeof FilledExternalLinkLegacyValueSchema>
123
+ export type FilledLinkLegacyValue =
124
+ | FilledImageLinkLegacyValue
125
+ | FilledFileLinkLegacyValue
126
+ | FilledDocumentLinkLegacyValue
127
+ | FilledExternalLinkLegacyValue
128
+
129
+ const EmptyLinkLegacyValueSchema: z.ZodMiniType<EmptyLinkLegacyValue> = z.union([
130
+ EmptyImageLinkLegacyValueSchema,
131
+ EmptyFileLinkLegacyValueSchema,
132
+ EmptyMediaLinkLegacyValueSchema,
133
+ EmptyDocumentLinkLegacyValueSchema,
134
+ EmptyExternalLinkLegacyValueSchema,
135
135
  AnyLinkLegacySchema,
136
136
  ])
137
137
 
138
- type EmptyImageLinkValueLegacy = z.infer<typeof EmptyImageLinkValueLegacySchema>
139
- type EmptyFileLinkValueLegacy = z.infer<typeof EmptyFileLinkValueLegacySchema>
140
- type EmptyMediaLinkValueLegacy = z.infer<typeof EmptyMediaLinkValueLegacySchema>
141
- type EmptyDocumentLinkValueLegacy = z.infer<typeof EmptyDocumentLinkValueLegacySchema>
142
- type EmptyExternalLinkValueLegacy = z.infer<typeof EmptyExternalLinkValueLegacySchema>
138
+ type EmptyImageLinkLegacyValue = z.infer<typeof EmptyImageLinkLegacyValueSchema>
139
+ type EmptyFileLinkLegacyValue = z.infer<typeof EmptyFileLinkLegacyValueSchema>
140
+ type EmptyMediaLinkLegacyValue = z.infer<typeof EmptyMediaLinkLegacyValueSchema>
141
+ type EmptyDocumentLinkLegacyValue = z.infer<typeof EmptyDocumentLinkLegacyValueSchema>
142
+ type EmptyExternalLinkLegacyValue = z.infer<typeof EmptyExternalLinkLegacyValueSchema>
143
143
  type AnyLinkLegacy = z.infer<typeof AnyLinkLegacySchema>
144
- export type EmptyLinkValueLegacy =
145
- | EmptyImageLinkValueLegacy
146
- | EmptyFileLinkValueLegacy
147
- | EmptyMediaLinkValueLegacy
148
- | EmptyDocumentLinkValueLegacy
149
- | EmptyExternalLinkValueLegacy
144
+ export type EmptyLinkLegacyValue =
145
+ | EmptyImageLinkLegacyValue
146
+ | EmptyFileLinkLegacyValue
147
+ | EmptyMediaLinkLegacyValue
148
+ | EmptyDocumentLinkLegacyValue
149
+ | EmptyExternalLinkLegacyValue
150
150
  | AnyLinkLegacy
151
151
 
152
- const LinkValueLegacySchema: z.ZodMiniType<LinkValueLegacy> = z.union([
153
- FilledLinkValueLegacySchema,
154
- EmptyLinkValueLegacySchema,
152
+ const LinkLegacyValueSchema: z.ZodMiniType<LinkLegacyValue> = z.union([
153
+ FilledLinkLegacyValueSchema,
154
+ EmptyLinkLegacyValueSchema,
155
155
  ])
156
156
 
157
- export type LinkValueLegacy = FilledLinkValueLegacy | EmptyLinkValueLegacy
157
+ export type LinkLegacyValue = FilledLinkLegacyValue | EmptyLinkLegacyValue
158
158
 
159
159
  // We cannot use z.extend here because we're working with unions.
160
160
  // z.intersection wouldn't work also for the same reason.
@@ -180,7 +180,7 @@ export const LinkLegacySchema = z.pipe(
180
180
  key: z.optional(z.string()),
181
181
  text: z.optional(z.string()),
182
182
  variant: z.optional(z.string()),
183
- value: LinkValueLegacySchema as z.ZodMiniType<LinkValueLegacy, Record<string, unknown>>,
183
+ value: LinkLegacyValueSchema as z.ZodMiniType<LinkLegacyValue, Record<string, unknown>>,
184
184
  }),
185
185
  ),
186
186
  z.transform(({ key, text, variant, value }) => ({
@@ -3,21 +3,21 @@ import { z } from "zod/mini"
3
3
  // It's important to only import the types here to
4
4
  // avoid runtime circular dependencies!
5
5
  import type { EmbedContentSchema } from "../embed"
6
- import type { ImageViewContentSchema } from "../image"
7
- import type { FilledLinkValueContent, FilledLinkValueContentSchema } from "../link"
6
+ import type { ImageContentViewSchema } from "../image"
7
+ import type { FilledLinkContentValue, FilledLinkContentValueSchema } from "../link"
8
8
  import { EmbedLegacyLooseSchema } from "./embed"
9
- import { ImageViewLegacySchema } from "./image"
10
- import { FilledLinkValueLegacySchema } from "./link"
11
- import type { FilledLinkValueLegacy } from "./link"
9
+ import { ImageLegacyViewSchema } from "./image"
10
+ import { FilledLinkLegacyValueSchema } from "./link"
11
+ import type { FilledLinkLegacyValue } from "./link"
12
12
 
13
13
  export const RichTextNodeType = {
14
- paragraph: "paragraph",
15
14
  heading1: "heading1",
16
15
  heading2: "heading2",
17
16
  heading3: "heading3",
18
17
  heading4: "heading4",
19
18
  heading5: "heading5",
20
19
  heading6: "heading6",
20
+ paragraph: "paragraph",
21
21
  preformatted: "preformatted",
22
22
  oListItem: "o-list-item",
23
23
  listItem: "list-item",
@@ -28,8 +28,10 @@ export const RichTextNodeType = {
28
28
  em: "em",
29
29
  } as const
30
30
 
31
+ export type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType]
32
+
31
33
  // Spans
32
- type HyperlinkSpan<TData extends FilledLinkValueLegacy | FilledLinkValueContent> = {
34
+ type HyperlinkSpan<TData extends FilledLinkLegacyValue | FilledLinkContentValue> = {
33
35
  type: typeof RichTextNodeType.hyperlink
34
36
  start: number
35
37
  end: number
@@ -37,7 +39,7 @@ type HyperlinkSpan<TData extends FilledLinkValueLegacy | FilledLinkValueContent>
37
39
  }
38
40
 
39
41
  const getHyperlinkSpanSchema = <
40
- TData extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
42
+ TData extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
41
43
  >(
42
44
  data: TData,
43
45
  ) =>
@@ -48,14 +50,7 @@ const getHyperlinkSpanSchema = <
48
50
  data,
49
51
  })
50
52
 
51
- type LabelSpan = {
52
- type: "label"
53
- start: number
54
- end: number
55
- data: string
56
- }
57
-
58
- const LabelSpanSchema: z.ZodMiniType<LabelSpan> = z.object({
53
+ const LabelSpanSchema = z.object({
59
54
  type: z.literal("label"),
60
55
  start: z.number(),
61
56
  end: z.number(),
@@ -64,14 +59,9 @@ const LabelSpanSchema: z.ZodMiniType<LabelSpan> = z.object({
64
59
  z.transform((value) => (typeof value === "string" && value.length > 0 ? value : "")),
65
60
  ),
66
61
  })
62
+ type LabelSpan = z.infer<typeof LabelSpanSchema>
67
63
 
68
- type BasicSpan = {
69
- type: typeof RichTextNodeType.strong | typeof RichTextNodeType.em | "list-item"
70
- start: number
71
- end: number
72
- }
73
-
74
- const BasicSpanSchema: z.ZodMiniType<BasicSpan> = z.object({
64
+ const BasicSpanSchema = z.object({
75
65
  type: z.union([
76
66
  z.literal(RichTextNodeType.strong),
77
67
  z.literal(RichTextNodeType.em),
@@ -80,18 +70,24 @@ const BasicSpanSchema: z.ZodMiniType<BasicSpan> = z.object({
80
70
  start: z.number(),
81
71
  end: z.number(),
82
72
  })
73
+ type BasicSpan = z.infer<typeof BasicSpanSchema>
83
74
 
84
- export type Span<TLink extends FilledLinkValueLegacy | FilledLinkValueContent> =
75
+ export type Span<TLink extends FilledLinkLegacyValue | FilledLinkContentValue> =
85
76
  | HyperlinkSpan<TLink>
86
77
  | LabelSpan
87
78
  | BasicSpan
88
79
 
89
80
  // oxlint-disable-next-line explicit-module-boundary-types
90
81
  export const getSpanSchema = <
91
- TLinkSchema extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
82
+ TLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
92
83
  >(
93
84
  linkSchema: TLinkSchema,
94
- ) => z.union([getHyperlinkSpanSchema(linkSchema), LabelSpanSchema, BasicSpanSchema])
85
+ ) =>
86
+ z.discriminatedUnion("type", [
87
+ getHyperlinkSpanSchema(linkSchema),
88
+ LabelSpanSchema,
89
+ BasicSpanSchema,
90
+ ])
95
91
 
96
92
  // Text blocks
97
93
  const TextBlockTypeSchema = z.union([
@@ -109,7 +105,7 @@ const TextBlockTypeSchema = z.union([
109
105
 
110
106
  // oxlint-disable-next-line explicit-module-boundary-types
111
107
  export const getTextBlockSchema = <
112
- TLinkSchema extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
108
+ TLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
113
109
  >(
114
110
  linkSchema: TLinkSchema,
115
111
  ) =>
@@ -138,7 +134,7 @@ export const getTextBlockSchema = <
138
134
  direction: z.optional(z.string()),
139
135
  })
140
136
 
141
- const TextBlockLegacySchema = getTextBlockSchema(FilledLinkValueLegacySchema)
137
+ const TextBlockLegacySchema = getTextBlockSchema(FilledLinkLegacyValueSchema)
142
138
 
143
139
  type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
144
140
 
@@ -146,8 +142,8 @@ type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
146
142
 
147
143
  // oxlint-disable-next-line explicit-module-boundary-types
148
144
  export const getImageBlockSchema = <
149
- TData extends typeof ImageViewLegacySchema | typeof ImageViewContentSchema,
150
- TLinkTo extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
145
+ TData extends typeof ImageLegacyViewSchema | typeof ImageContentViewSchema,
146
+ TLinkTo extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
151
147
  >(
152
148
  data: TData,
153
149
  linkTo: TLinkTo,
@@ -160,8 +156,8 @@ export const getImageBlockSchema = <
160
156
  })
161
157
 
162
158
  const ImageBlockLegacySchema = getImageBlockSchema(
163
- ImageViewLegacySchema,
164
- FilledLinkValueLegacySchema,
159
+ ImageLegacyViewSchema,
160
+ FilledLinkLegacyValueSchema,
165
161
  )
166
162
 
167
163
  type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>
@@ -185,11 +181,10 @@ const EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)
185
181
  type EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>
186
182
 
187
183
  // Blocks
188
- export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.union([
189
- TextBlockLegacySchema,
190
- ImageBlockLegacySchema,
191
- EmbedBlockLegacySchema,
192
- ])
184
+ export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.discriminatedUnion(
185
+ "type",
186
+ [TextBlockLegacySchema, ImageBlockLegacySchema, EmbedBlockLegacySchema],
187
+ )
193
188
 
194
189
  export type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy
195
190
 
@@ -1,154 +1,165 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
3
  import {
4
- EmptyDocumentLinkValueLegacySchema,
5
- EmptyImageLinkValueLegacySchema,
6
- FilledDocumentLinkValueLegacySchema,
7
- FilledFileLinkValueLegacySchema,
8
- FilledImageLinkValueLegacySchema,
9
- EmptyMediaLinkValueLegacySchema,
10
- FilledExternalLinkValueLegacySchema,
11
- EmptyExternalLinkValueLegacySchema,
4
+ EmptyDocumentLinkLegacyValueSchema,
5
+ EmptyImageLinkLegacyValueSchema,
6
+ FilledDocumentLinkLegacyValueSchema,
7
+ FilledFileLinkLegacyValueSchema,
8
+ FilledImageLinkLegacyValueSchema,
9
+ EmptyMediaLinkLegacyValueSchema,
10
+ FilledExternalLinkLegacyValueSchema,
11
+ EmptyExternalLinkLegacyValueSchema,
12
12
  AnyLinkLegacySchema,
13
13
  LinkType,
14
- EmptyFileLinkValueLegacySchema,
14
+ EmptyFileLinkLegacyValueSchema,
15
15
  } from "./legacy/link"
16
16
 
17
17
  // Image
18
- const FilledImageLinkValueContentSchema = z.extend(FilledImageLinkValueLegacySchema, {
18
+ const FilledImageLinkContentValueSchema = z.extend(FilledImageLinkLegacyValueSchema, {
19
19
  __TYPE__: z.literal(LinkType.Image),
20
20
  })
21
21
 
22
- const EmptyImageLinkValueContentSchema = z.extend(EmptyImageLinkValueLegacySchema, {
22
+ const EmptyImageLinkContentValueSchema = z.extend(EmptyImageLinkLegacyValueSchema, {
23
23
  __TYPE__: z.literal(LinkType.Image),
24
24
  })
25
25
 
26
26
  // File
27
- const FilledFileLinkValueContentSchema = z.extend(FilledFileLinkValueLegacySchema, {
27
+ const FilledFileLinkContentValueSchema = z.extend(FilledFileLinkLegacyValueSchema, {
28
28
  __TYPE__: z.literal(LinkType.File),
29
29
  })
30
30
 
31
- const EmptyFileLinkValueContentSchema = z.extend(EmptyFileLinkValueLegacySchema, {
31
+ const EmptyFileLinkContentValueSchema = z.extend(EmptyFileLinkLegacyValueSchema, {
32
32
  __TYPE__: z.literal(LinkType.File),
33
33
  })
34
34
 
35
35
  // Media
36
- const EmptyMediaLinkValueContentSchema = z.extend(EmptyMediaLinkValueLegacySchema, {
36
+ const EmptyMediaLinkContentValueSchema = z.extend(EmptyMediaLinkLegacyValueSchema, {
37
37
  __TYPE__: z.literal(LinkType.Media),
38
38
  })
39
39
 
40
40
  // Document
41
- const FilledDocumentLinkValueContentSchema = z.extend(FilledDocumentLinkValueLegacySchema, {
41
+ const FilledDocumentLinkContentValueSchema = z.extend(FilledDocumentLinkLegacyValueSchema, {
42
42
  __TYPE__: z.literal(LinkType.Document),
43
43
  })
44
44
 
45
- const EmptyDocumentLinkValueContentSchema = z.extend(EmptyDocumentLinkValueLegacySchema, {
45
+ const EmptyDocumentLinkContentValueSchema = z.extend(EmptyDocumentLinkLegacyValueSchema, {
46
46
  __TYPE__: z.literal(LinkType.Document),
47
47
  })
48
48
 
49
49
  // External
50
- const FilledExternalLinkValueContentSchema = z.extend(FilledExternalLinkValueLegacySchema, {
50
+ const FilledExternalLinkContentValueSchema = z.extend(FilledExternalLinkLegacyValueSchema, {
51
51
  __TYPE__: z.literal(LinkType.External),
52
52
  })
53
53
 
54
- const EmptyExternalLinkValueContentSchema = z.extend(EmptyExternalLinkValueLegacySchema, {
54
+ const EmptyExternalLinkContentValueSchema = z.extend(EmptyExternalLinkLegacyValueSchema, {
55
55
  __TYPE__: z.literal(LinkType.External),
56
56
  })
57
57
 
58
58
  // Any
59
- const AnyLinkValueContentSchema = z.extend(AnyLinkLegacySchema, {
59
+ const AnyLinkContentValueSchema = z.extend(AnyLinkLegacySchema, {
60
60
  __TYPE__: z.literal(LinkType.Any),
61
61
  })
62
62
 
63
63
  // All
64
64
 
65
65
  // Used by content/richText
66
- export const FilledLinkValueContentSchema: z.ZodMiniType<FilledLinkValueContent> = z.union([
67
- FilledImageLinkValueContentSchema,
68
- FilledFileLinkValueContentSchema,
69
- FilledDocumentLinkValueContentSchema,
70
- FilledExternalLinkValueContentSchema,
66
+ export const FilledLinkContentValueSchema: z.ZodMiniType<FilledLinkContentValue> = z.union([
67
+ FilledImageLinkContentValueSchema,
68
+ FilledFileLinkContentValueSchema,
69
+ FilledDocumentLinkContentValueSchema,
70
+ FilledExternalLinkContentValueSchema,
71
71
  ])
72
72
 
73
73
  // Used by content/legacy/link
74
- type FilledImageLinkValueContent = z.infer<typeof FilledImageLinkValueContentSchema>
75
- type FilledFileLinkValueContent = z.infer<typeof FilledFileLinkValueContentSchema>
76
- type FilledDocumentLinkValueContent = z.infer<typeof FilledDocumentLinkValueContentSchema>
77
- type FilledExternalLinkValueContent = z.infer<typeof FilledExternalLinkValueContentSchema>
78
- export type FilledLinkValueContent =
79
- | FilledImageLinkValueContent
80
- | FilledFileLinkValueContent
81
- | FilledDocumentLinkValueContent
82
- | FilledExternalLinkValueContent
83
-
84
- const EmptyLinkValueContentSchema: z.ZodMiniType<EmptyLinkValueContent> = z.union([
85
- EmptyImageLinkValueContentSchema,
86
- EmptyFileLinkValueContentSchema,
87
- EmptyMediaLinkValueContentSchema,
88
- EmptyDocumentLinkValueContentSchema,
89
- EmptyExternalLinkValueContentSchema,
90
- AnyLinkValueContentSchema,
74
+ type FilledImageLinkContentValue = z.infer<typeof FilledImageLinkContentValueSchema>
75
+ type FilledFileLinkContentValue = z.infer<typeof FilledFileLinkContentValueSchema>
76
+ type FilledDocumentLinkContentValue = z.infer<typeof FilledDocumentLinkContentValueSchema>
77
+ type FilledExternalLinkContentValue = z.infer<typeof FilledExternalLinkContentValueSchema>
78
+ export type FilledLinkContentValue =
79
+ | FilledImageLinkContentValue
80
+ | FilledFileLinkContentValue
81
+ | FilledDocumentLinkContentValue
82
+ | FilledExternalLinkContentValue
83
+
84
+ const EmptyLinkContentValueSchema: z.ZodMiniType<EmptyLinkContentValue> = z.union([
85
+ EmptyImageLinkContentValueSchema,
86
+ EmptyFileLinkContentValueSchema,
87
+ EmptyMediaLinkContentValueSchema,
88
+ EmptyDocumentLinkContentValueSchema,
89
+ EmptyExternalLinkContentValueSchema,
90
+ AnyLinkContentValueSchema,
91
91
  ])
92
92
 
93
93
  // Used by content/codec/link
94
- type EmptyImageLinkValueContent = z.infer<typeof EmptyImageLinkValueContentSchema>
95
- type EmptyFileLinkValueContent = z.infer<typeof EmptyFileLinkValueContentSchema>
96
- type EmptyMediaLinkValueContent = z.infer<typeof EmptyMediaLinkValueContentSchema>
97
- type EmptyDocumentLinkValueContent = z.infer<typeof EmptyDocumentLinkValueContentSchema>
98
- type EmptyExternalLinkValueContent = z.infer<typeof EmptyExternalLinkValueContentSchema>
99
- type AnyLinkValueContent = z.infer<typeof AnyLinkValueContentSchema>
100
- export type EmptyLinkValueContent =
101
- | EmptyImageLinkValueContent
102
- | EmptyFileLinkValueContent
103
- | EmptyMediaLinkValueContent
104
- | EmptyDocumentLinkValueContent
105
- | EmptyExternalLinkValueContent
106
- | AnyLinkValueContent
107
-
108
- const LinkValueContentSchema: z.ZodMiniType<LinkValueContent> = z.union([
109
- FilledLinkValueContentSchema,
110
- EmptyLinkValueContentSchema,
94
+ type EmptyImageLinkContentValue = z.infer<typeof EmptyImageLinkContentValueSchema>
95
+ type EmptyFileLinkContentValue = z.infer<typeof EmptyFileLinkContentValueSchema>
96
+ type EmptyMediaLinkContentValue = z.infer<typeof EmptyMediaLinkContentValueSchema>
97
+ type EmptyDocumentLinkContentValue = z.infer<typeof EmptyDocumentLinkContentValueSchema>
98
+ type EmptyExternalLinkContentValue = z.infer<typeof EmptyExternalLinkContentValueSchema>
99
+ type AnyLinkContentValue = z.infer<typeof AnyLinkContentValueSchema>
100
+ export type EmptyLinkContentValue =
101
+ | EmptyImageLinkContentValue
102
+ | EmptyFileLinkContentValue
103
+ | EmptyMediaLinkContentValue
104
+ | EmptyDocumentLinkContentValue
105
+ | EmptyExternalLinkContentValue
106
+ | AnyLinkContentValue
107
+
108
+ const LinkContentValueSchema: z.ZodMiniType<LinkContentValue> = z.union([
109
+ FilledLinkContentValueSchema,
110
+ EmptyLinkContentValueSchema,
111
111
  ])
112
112
 
113
113
  // Used by content/codec/link
114
- export type LinkValueContent = FilledLinkValueContent | EmptyLinkValueContent
114
+ export type LinkContentValue = FilledLinkContentValue | EmptyLinkContentValue
115
115
 
116
116
  // Content
117
117
  export const LinkContentType = "LinkContent" as const
118
118
 
119
- export const LinkContentSchema = z.object({
120
- __TYPE__: z.literal(LinkContentType),
121
- key: z.transform((value) => z.uuidv4().safeParse(value).data || crypto.randomUUID()),
122
- // We cannot use z.extend here because we're working with unions.
123
- // z.intersection wouldn't work also for the same reason.
124
- value: z.pipe(
125
- z.pipe(
119
+ const getLinkContentSchema = <TValue extends LinkContentValue>(value: z.ZodMiniType<TValue>) =>
120
+ z.object({
121
+ __TYPE__: z.literal(LinkContentType),
122
+ key: z.transform((value) => z.uuidv4().safeParse(value).data || crypto.randomUUID()),
123
+ // We cannot use z.extend here because we're working with unions.
124
+ // z.intersection wouldn't work also for the same reason.
125
+ value: z.pipe(
126
126
  z.pipe(
127
- z.record(z.string(), z.unknown()),
128
- z.transform(
129
- ({
130
- text,
131
- variant,
132
- ...value
133
- }): {
134
- text?: unknown
135
- variant?: unknown
136
- value: Record<string, unknown>
137
- } => ({ text, variant, value }),
127
+ z.pipe(
128
+ z.record(z.string(), z.unknown()),
129
+ z.transform(
130
+ ({
131
+ text,
132
+ variant,
133
+ ...value
134
+ }): {
135
+ text?: unknown
136
+ variant?: unknown
137
+ value: Record<string, unknown>
138
+ } => ({ text, variant, value }),
139
+ ),
138
140
  ),
141
+ z.object({
142
+ text: z.optional(z.string()),
143
+ variant: z.optional(z.string()),
144
+ value: value as z.ZodMiniType<TValue, Record<string, unknown>>,
145
+ }),
139
146
  ),
140
- z.object({
141
- text: z.optional(z.string()),
142
- variant: z.optional(z.string()),
143
- value: LinkValueContentSchema as z.ZodMiniType<LinkValueContent, Record<string, unknown>>,
144
- }),
147
+ z.transform(({ text, variant, value }) => ({
148
+ ...(text ? { text } : {}),
149
+ ...(variant ? { variant } : {}),
150
+ ...value,
151
+ })),
145
152
  ),
146
- z.transform(({ text, variant, value }) => ({
147
- ...(text ? { text } : {}),
148
- ...(variant ? { variant } : {}),
149
- ...value,
150
- })),
151
- ),
152
- })
153
+ })
154
+
155
+ export const FilledLinkContentSchema = getLinkContentSchema(FilledLinkContentValueSchema)
156
+
157
+ export type FilledLinkContent = z.infer<typeof FilledLinkContentSchema>
158
+
159
+ export const EmptyLinkContentSchema = getLinkContentSchema(EmptyLinkContentValueSchema)
160
+
161
+ export type EmptyLinkContent = z.infer<typeof EmptyLinkContentSchema>
162
+
163
+ export const LinkContentSchema = getLinkContentSchema(LinkContentValueSchema)
153
164
 
154
165
  export type LinkContent = z.infer<typeof LinkContentSchema>
@@ -1,8 +1,7 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
- import type { NestableModel } from "../model/nestable"
4
3
  import type { BooleanContent } from "./boolean"
5
- import { BooleanContentDefaultValue, BooleanContentSchema, BooleanContentType } from "./boolean"
4
+ import { BooleanContentSchema, BooleanContentType } from "./boolean"
6
5
  import type { EmbedContent } from "./embed"
7
6
  import { EmbedContentSchema, EmbedContentType } from "./embed"
8
7
  import type { EmptyContent } from "./empty"
@@ -16,17 +15,7 @@ import type {
16
15
  TextContent,
17
16
  TimestampContent,
18
17
  } from "./field"
19
- import {
20
- ColorContentSchema,
21
- DateContentSchema,
22
- FieldContentType,
23
- NumberContentSchema,
24
- RangeContentSchema,
25
- SelectContentDefaultValue,
26
- SelectContentSchema,
27
- TextContentSchema,
28
- TimestampContentSchema,
29
- } from "./field"
18
+ import { FieldContentType, FieldContentSchema } from "./field"
30
19
  import type { GeoPointContent } from "./geopoint"
31
20
  import { GeoPointContentSchema, GeoPointContentType } from "./geopoint"
32
21
  import type { ImageContent } from "./image"
@@ -44,25 +33,19 @@ import { SeparatorContentSchema, SeparatorContentType } from "./separator"
44
33
  import type { TableContent } from "./table"
45
34
  import { TableContentSchema, TableContentType } from "./table"
46
35
 
47
- export const NestableContentSchema: z.ZodMiniType<NestableContent> = z.union([
36
+ export const NestableContentSchema = z.discriminatedUnion("__TYPE__", [
48
37
  EmptyContentSchema,
49
38
  BooleanContentSchema,
50
- ColorContentSchema,
51
- DateContentSchema,
52
39
  EmbedContentSchema,
53
40
  GeoPointContentSchema,
54
41
  ImageContentSchema,
55
42
  IntegrationFieldContentSchema,
56
43
  LinkContentSchema,
57
- NumberContentSchema,
58
- RangeContentSchema,
59
44
  RepeatableContentSchema,
60
45
  RichTextContentSchema,
61
- SelectContentSchema,
62
46
  SeparatorContentSchema,
63
47
  TableContentSchema,
64
- TextContentSchema,
65
- TimestampContentSchema,
48
+ FieldContentSchema,
66
49
  ])
67
50
 
68
51
  export type NestableContent =
@@ -107,20 +90,3 @@ export function isNestableContent(content: {
107
90
  }): content is { __TYPE__: NestableContentType } {
108
91
  return (NestableContentTypes as string[]).includes(content.__TYPE__)
109
92
  }
110
-
111
- /**
112
- * Returns the default value for a nestable widget based on its configuration.
113
- * Currently only Boolean and Select fields have default values.
114
- */
115
- export const NestableContentDefaultValue = (
116
- widgetDef: NestableModel,
117
- ): NestableContent | undefined => {
118
- switch (widgetDef.type) {
119
- case "Boolean":
120
- return BooleanContentDefaultValue(widgetDef)
121
- case "Select":
122
- return SelectContentDefaultValue(widgetDef)
123
- default:
124
- return undefined
125
- }
126
- }