@prismicio/types-internal 4.0.0-pr.6.eb53f11 → 4.0.0-pr.9.e09af2c

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 (167) 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/document.d.ts +2 -3019
  5. package/dist/content/document.d.ts.map +1 -1
  6. package/dist/content/field.d.ts +1 -30
  7. package/dist/content/field.d.ts.map +1 -1
  8. package/dist/content/field.js +1 -1
  9. package/dist/content/field.js.map +1 -1
  10. package/dist/content/group.d.ts +2 -1
  11. package/dist/content/group.d.ts.map +1 -1
  12. package/dist/content/group.js.map +1 -1
  13. package/dist/content/legacy/boolean.d.ts +1 -0
  14. package/dist/content/legacy/embed.d.ts +1 -0
  15. package/dist/content/legacy/empty.d.ts +1 -0
  16. package/dist/content/legacy/field.d.ts +1 -0
  17. package/dist/content/legacy/geopoint.d.ts +1 -0
  18. package/dist/content/legacy/group.d.ts +9 -0
  19. package/dist/content/legacy/group.d.ts.map +1 -0
  20. package/dist/content/legacy/group.js.map +1 -1
  21. package/dist/content/legacy/integrationField.d.ts +1 -0
  22. package/dist/content/legacy/link.d.ts +41 -0
  23. package/dist/content/legacy/link.d.ts.map +1 -0
  24. package/dist/content/legacy/link.js.map +1 -1
  25. package/dist/content/legacy/nestable.d.ts +1 -0
  26. package/dist/content/legacy/nestable.js.map +1 -1
  27. package/dist/content/legacy/repeatable.d.ts +1 -0
  28. package/dist/content/legacy/repeatable.js +2 -8
  29. package/dist/content/legacy/repeatable.js.map +1 -1
  30. package/dist/content/legacy/richText.d.ts +109 -0
  31. package/dist/content/legacy/richText.d.ts.map +1 -0
  32. package/dist/content/legacy/richText.js.map +1 -1
  33. package/dist/content/legacy/separator.d.ts +1 -0
  34. package/dist/content/legacy/slice.js +2 -3
  35. package/dist/content/legacy/slice.js.map +1 -1
  36. package/dist/content/legacy/table.d.ts +1 -0
  37. package/dist/content/link.d.ts +74 -99
  38. package/dist/content/link.d.ts.map +1 -1
  39. package/dist/content/link.js +2 -2
  40. package/dist/content/link.js.map +1 -1
  41. package/dist/content/nestable.d.ts +13 -749
  42. package/dist/content/nestable.d.ts.map +1 -1
  43. package/dist/content/nestable.js +1 -0
  44. package/dist/content/nestable.js.map +1 -1
  45. package/dist/content/repeatable.d.ts +3 -98
  46. package/dist/content/repeatable.d.ts.map +1 -1
  47. package/dist/content/richText.d.ts +20 -248
  48. package/dist/content/richText.d.ts.map +1 -1
  49. package/dist/content/richText.js.map +1 -1
  50. package/dist/content/slice.d.ts +6 -4509
  51. package/dist/content/slice.d.ts.map +1 -1
  52. package/dist/content/slice.js.map +1 -1
  53. package/dist/content/slices.d.ts +8 -6765
  54. package/dist/content/slices.d.ts.map +1 -1
  55. package/dist/content/table.d.ts +2 -134
  56. package/dist/content/table.d.ts.map +1 -1
  57. package/dist/content/widget.d.ts +5 -3020
  58. package/dist/content/widget.d.ts.map +1 -1
  59. package/dist/content/widget.js.map +1 -1
  60. package/dist/helpers/contentPath.js +1 -1
  61. package/dist/helpers/customTypeModel.d.ts +3 -2
  62. package/dist/helpers/customTypeModel.d.ts.map +1 -1
  63. package/dist/helpers/customTypeModel.js +31 -1
  64. package/dist/helpers/customTypeModel.js.map +1 -1
  65. package/dist/helpers/documentContent.d.ts +3 -2
  66. package/dist/helpers/documentContent.d.ts.map +1 -1
  67. package/dist/helpers/documentContent.js +14 -1
  68. package/dist/helpers/documentContent.js.map +1 -1
  69. package/dist/helpers/sliceContent.d.ts +12 -0
  70. package/dist/helpers/sliceContent.d.ts.map +1 -0
  71. package/dist/helpers/sliceContent.js +60 -0
  72. package/dist/helpers/sliceContent.js.map +1 -0
  73. package/dist/helpers/traverseContent.d.ts +15 -16
  74. package/dist/helpers/traverseContent.d.ts.map +1 -1
  75. package/dist/helpers/traverseContent.js +53 -19
  76. package/dist/helpers/traverseContent.js.map +1 -1
  77. package/dist/helpers/traverseContentWithModel.d.ts +14 -15
  78. package/dist/helpers/traverseContentWithModel.d.ts.map +1 -1
  79. package/dist/helpers/traverseContentWithModel.js +61 -35
  80. package/dist/helpers/traverseContentWithModel.js.map +1 -1
  81. package/dist/helpers/withDefaultContent.d.ts +17 -0
  82. package/dist/helpers/withDefaultContent.d.ts.map +1 -0
  83. package/dist/helpers/withDefaultContent.js +113 -0
  84. package/dist/helpers/withDefaultContent.js.map +1 -0
  85. package/dist/index.d.ts +16 -14
  86. package/dist/index.js +4 -1
  87. package/dist/io-ts.d.ts +3629 -70848
  88. package/dist/io-ts.d.ts.map +1 -1
  89. package/dist/io-ts.js +126 -124
  90. package/dist/io-ts.js.map +1 -1
  91. package/dist/model/customType.d.ts +3 -3329
  92. package/dist/model/customType.d.ts.map +1 -1
  93. package/dist/model/group.d.ts +375 -376
  94. package/dist/model/group.d.ts.map +1 -1
  95. package/dist/model/group.js.map +1 -1
  96. package/dist/model/image.d.ts +4 -4
  97. package/dist/model/image.js.map +1 -1
  98. package/dist/model/link.d.ts +2 -2
  99. package/dist/model/link.js.map +1 -1
  100. package/dist/model/nestable.d.ts +17 -178
  101. package/dist/model/nestable.d.ts.map +1 -1
  102. package/dist/model/nestable.js +3 -3
  103. package/dist/model/nestable.js.map +1 -1
  104. package/dist/model/richText.d.ts +3 -7
  105. package/dist/model/richText.d.ts.map +1 -1
  106. package/dist/model/richText.js +4 -3
  107. package/dist/model/richText.js.map +1 -1
  108. package/dist/model/section.d.ts +3 -3329
  109. package/dist/model/section.d.ts.map +1 -1
  110. package/dist/model/select.d.ts +1 -1
  111. package/dist/model/select.js +1 -1
  112. package/dist/model/select.js.map +1 -1
  113. package/dist/model/slice.d.ts +1360 -3691
  114. package/dist/model/slice.d.ts.map +1 -1
  115. package/dist/model/slice.js +10 -5
  116. package/dist/model/slice.js.map +1 -1
  117. package/dist/model/slices.d.ts +3 -2195
  118. package/dist/model/slices.d.ts.map +1 -1
  119. package/dist/model/table.d.ts +2 -1
  120. package/dist/model/table.d.ts.map +1 -1
  121. package/dist/model/table.js +9 -7
  122. package/dist/model/table.js.map +1 -1
  123. package/dist/model/widget.d.ts +7 -3334
  124. package/dist/model/widget.d.ts.map +1 -1
  125. package/dist/model/widget.js +5 -2
  126. package/dist/model/widget.js.map +1 -1
  127. package/dist/zod4.d.ts +1796 -34837
  128. package/dist/zod4.d.ts.map +1 -1
  129. package/dist/zod4.js +126 -124
  130. package/dist/zod4.js.map +1 -1
  131. package/package.json +3 -2
  132. package/src/content/boolean.ts +0 -13
  133. package/src/content/field.ts +9 -16
  134. package/src/content/group.ts +6 -56
  135. package/src/content/legacy/group.ts +12 -4
  136. package/src/content/legacy/link.ts +32 -9
  137. package/src/content/legacy/nestable.ts +26 -2
  138. package/src/content/legacy/repeatable.ts +3 -16
  139. package/src/content/legacy/richText.ts +37 -5
  140. package/src/content/legacy/slice.ts +8 -7
  141. package/src/content/legacy/widget.ts +6 -2
  142. package/src/content/link.ts +32 -9
  143. package/src/content/nestable.ts +43 -22
  144. package/src/content/richText.ts +19 -7
  145. package/src/content/slice.ts +2 -2
  146. package/src/content/widget.ts +6 -2
  147. package/src/helpers/customTypeModel.ts +44 -0
  148. package/src/helpers/documentContent.ts +32 -1
  149. package/src/helpers/sliceContent.ts +86 -0
  150. package/src/helpers/traverseContent.ts +96 -32
  151. package/src/helpers/traverseContentWithModel.ts +73 -48
  152. package/src/helpers/withDefaultContent.ts +173 -0
  153. package/src/index.ts +6 -1
  154. package/src/io-ts.ts +166 -144
  155. package/src/model/diff/sharedSlice.ts +2 -2
  156. package/src/model/diff/variation.ts +7 -7
  157. package/src/model/group.ts +4 -1
  158. package/src/model/image.ts +1 -1
  159. package/src/model/link.ts +1 -1
  160. package/src/model/nestable.ts +33 -1
  161. package/src/model/richText.ts +2 -2
  162. package/src/model/select.ts +2 -2
  163. package/src/model/slice.ts +38 -13
  164. package/src/model/table.ts +11 -2
  165. package/src/model/widget.ts +14 -6
  166. package/src/zod4.ts +166 -144
  167. package/src/content/withDefaultValues.ts +0 -114
@@ -1,15 +1,23 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
+ import type { NestableLegacy } from "./nestable"
3
4
  import { NestableLegacySchema } from "./nestable"
4
5
 
6
+ // Keep item values raw here: array-shaped legacy payloads are ambiguous until
7
+ // `codec/group.ts` resolves the field model and picks the right decoder.
5
8
  export const GroupItemLegacySchema = z.record(z.string(), z.unknown())
6
9
 
7
10
  export type GroupItemLegacy = z.infer<typeof GroupItemLegacySchema>
8
11
 
9
- export const GroupLegacySchema = z.array(z.union([GroupItemLegacySchema, z.null()]))
12
+ export const GroupLegacySchema: z.ZodMiniType<GroupLegacy> = z.array(
13
+ z.union([GroupItemLegacySchema, z.null()]),
14
+ )
10
15
 
11
- export type GroupLegacy = z.infer<typeof GroupLegacySchema>
16
+ export type GroupLegacy = (GroupItemLegacy | null)[]
12
17
 
13
- export const NestableAndGroupLegacySchema = z.union([NestableLegacySchema, GroupLegacySchema])
18
+ export const NestableAndGroupLegacySchema: z.ZodMiniType<NestableAndGroupLegacy> = z.union([
19
+ NestableLegacySchema,
20
+ GroupLegacySchema,
21
+ ])
14
22
 
15
- export type NestableAndGroupLegacy = z.infer<typeof NestableAndGroupLegacySchema>
23
+ export type NestableAndGroupLegacy = NestableLegacy | GroupLegacy
@@ -109,16 +109,24 @@ export const AnyLinkLegacySchema = z.strictObject({
109
109
 
110
110
  // All
111
111
 
112
- export const FilledLinkValueLegacySchema = z.union([
112
+ export const FilledLinkValueLegacySchema: z.ZodMiniType<FilledLinkValueLegacy> = z.union([
113
113
  FilledImageLinkValueLegacySchema,
114
114
  FilledFileLinkValueLegacySchema,
115
115
  FilledDocumentLinkValueLegacySchema,
116
116
  FilledExternalLinkValueLegacySchema,
117
117
  ])
118
118
 
119
- export type FilledLinkValueLegacy = z.infer<typeof FilledLinkValueLegacySchema>
120
-
121
- const EmptyLinkValueLegacySchema = z.union([
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([
122
130
  EmptyImageLinkValueLegacySchema,
123
131
  EmptyFileLinkValueLegacySchema,
124
132
  EmptyMediaLinkValueLegacySchema,
@@ -127,11 +135,26 @@ const EmptyLinkValueLegacySchema = z.union([
127
135
  AnyLinkLegacySchema,
128
136
  ])
129
137
 
130
- export type EmptyLinkValueLegacy = z.infer<typeof EmptyLinkValueLegacySchema>
131
-
132
- const LinkValueLegacySchema = z.union([FilledLinkValueLegacySchema, EmptyLinkValueLegacySchema])
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>
143
+ type AnyLinkLegacy = z.infer<typeof AnyLinkLegacySchema>
144
+ export type EmptyLinkValueLegacy =
145
+ | EmptyImageLinkValueLegacy
146
+ | EmptyFileLinkValueLegacy
147
+ | EmptyMediaLinkValueLegacy
148
+ | EmptyDocumentLinkValueLegacy
149
+ | EmptyExternalLinkValueLegacy
150
+ | AnyLinkLegacy
151
+
152
+ const LinkValueLegacySchema: z.ZodMiniType<LinkValueLegacy> = z.union([
153
+ FilledLinkValueLegacySchema,
154
+ EmptyLinkValueLegacySchema,
155
+ ])
133
156
 
134
- export type LinkValueLegacy = z.infer<typeof LinkValueLegacySchema>
157
+ export type LinkValueLegacy = FilledLinkValueLegacy | EmptyLinkValueLegacy
135
158
 
136
159
  // We cannot use z.extend here because we're working with unions.
137
160
  // z.intersection wouldn't work also for the same reason.
@@ -157,7 +180,7 @@ export const LinkLegacySchema = z.pipe(
157
180
  key: z.optional(z.string()),
158
181
  text: z.optional(z.string()),
159
182
  variant: z.optional(z.string()),
160
- value: LinkValueLegacySchema,
183
+ value: LinkValueLegacySchema as z.ZodMiniType<LinkValueLegacy, Record<string, unknown>>,
161
184
  }),
162
185
  ),
163
186
  z.transform(({ key, text, variant, value }) => ({
@@ -1,19 +1,31 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
+ import type { BooleanLegacy } from "./boolean"
3
4
  import { BooleanLegacySchema } from "./boolean"
5
+ import type { EmbedLegacy } from "./embed"
4
6
  import { EmbedLegacyLooseSchema } from "./embed"
7
+ import type { EmptyLegacy } from "./empty"
5
8
  import { EmptyLegacySchema } from "./empty"
9
+ import type { StringLegacy } from "./field"
6
10
  import { StringLegacySchema } from "./field"
11
+ import type { GeoPointLegacy } from "./geopoint"
7
12
  import { GeoPointLegacySchema } from "./geopoint"
13
+ import type { ImageLegacy } from "./image"
8
14
  import { ImageLegacySchema } from "./image"
15
+ import type { IntegrationFieldLegacy } from "./integrationField"
9
16
  import { IntegrationFieldLegacySchema } from "./integrationField"
17
+ import type { LinkLegacy } from "./link"
10
18
  import { LinkLegacySchema } from "./link"
19
+ import type { RepeatableLegacy } from "./repeatable"
11
20
  import { RepeatableLegacySchema } from "./repeatable"
21
+ import type { RichTextLegacy } from "./richText"
12
22
  import { RichTextLegacySchema } from "./richText"
23
+ import type { SeparatorLegacy } from "./separator"
13
24
  import { SeparatorLegacySchema } from "./separator"
25
+ import type { TableLegacy } from "./table"
14
26
  import { TableLegacySchema } from "./table"
15
27
 
16
- export const NestableLegacySchema = z.union([
28
+ export const NestableLegacySchema: z.ZodMiniType<NestableLegacy> = z.union([
17
29
  EmptyLegacySchema,
18
30
  BooleanLegacySchema,
19
31
  EmbedLegacyLooseSchema,
@@ -28,4 +40,16 @@ export const NestableLegacySchema = z.union([
28
40
  TableLegacySchema,
29
41
  ])
30
42
 
31
- export type NestableLegacy = z.infer<typeof NestableLegacySchema>
43
+ export type NestableLegacy =
44
+ | EmptyLegacy
45
+ | BooleanLegacy
46
+ | EmbedLegacy
47
+ | StringLegacy
48
+ | GeoPointLegacy
49
+ | ImageLegacy
50
+ | IntegrationFieldLegacy
51
+ | LinkLegacy
52
+ | RepeatableLegacy
53
+ | RichTextLegacy
54
+ | SeparatorLegacy
55
+ | TableLegacy
@@ -1,20 +1,7 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
- import { LinkLegacySchema } from "./link"
4
-
5
- const RepeatableLinkLegacySchema = z.pipe(
6
- z.array(z.unknown()),
7
- z.transform((value) =>
8
- value.flatMap((item) => {
9
- try {
10
- return [LinkLegacySchema.parse(item)]
11
- } catch {
12
- return []
13
- }
14
- }),
15
- ),
16
- )
17
-
18
- export const RepeatableLegacySchema = RepeatableLinkLegacySchema
3
+ // Keep the legacy schema non-lossy; item-level link decoding lives in
4
+ // `codec/repeatable.ts`, where the field model is available.
5
+ export const RepeatableLegacySchema = z.array(z.unknown())
19
6
 
20
7
  export type RepeatableLegacy = z.infer<typeof RepeatableLegacySchema>
@@ -4,10 +4,11 @@ import { z } from "zod/mini"
4
4
  // avoid runtime circular dependencies!
5
5
  import type { EmbedContentSchema } from "../embed"
6
6
  import type { ImageViewContentSchema } from "../image"
7
- import type { FilledLinkValueContentSchema } from "../link"
7
+ import type { FilledLinkValueContent, FilledLinkValueContentSchema } from "../link"
8
8
  import { EmbedLegacyLooseSchema } from "./embed"
9
9
  import { ImageViewLegacySchema } from "./image"
10
10
  import { FilledLinkValueLegacySchema } from "./link"
11
+ import type { FilledLinkValueLegacy } from "./link"
11
12
 
12
13
  export const RichTextNodeType = {
13
14
  paragraph: "paragraph",
@@ -28,6 +29,13 @@ export const RichTextNodeType = {
28
29
  } as const
29
30
 
30
31
  // Spans
32
+ type HyperlinkSpan<TData extends FilledLinkValueLegacy | FilledLinkValueContent> = {
33
+ type: typeof RichTextNodeType.hyperlink
34
+ start: number
35
+ end: number
36
+ data: TData
37
+ }
38
+
31
39
  const getHyperlinkSpanSchema = <
32
40
  TData extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
33
41
  >(
@@ -40,7 +48,14 @@ const getHyperlinkSpanSchema = <
40
48
  data,
41
49
  })
42
50
 
43
- const LabelSpanSchema = z.object({
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({
44
59
  type: z.literal("label"),
45
60
  start: z.number(),
46
61
  end: z.number(),
@@ -50,7 +65,13 @@ const LabelSpanSchema = z.object({
50
65
  ),
51
66
  })
52
67
 
53
- const BasicSpanSchema = z.object({
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({
54
75
  type: z.union([
55
76
  z.literal(RichTextNodeType.strong),
56
77
  z.literal(RichTextNodeType.em),
@@ -60,6 +81,11 @@ const BasicSpanSchema = z.object({
60
81
  end: z.number(),
61
82
  })
62
83
 
84
+ export type Span<TLink extends FilledLinkValueLegacy | FilledLinkValueContent> =
85
+ | HyperlinkSpan<TLink>
86
+ | LabelSpan
87
+ | BasicSpan
88
+
63
89
  // oxlint-disable-next-line explicit-module-boundary-types
64
90
  export const getSpanSchema = <
65
91
  TLinkSchema extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
@@ -114,6 +140,8 @@ export const getTextBlockSchema = <
114
140
 
115
141
  const TextBlockLegacySchema = getTextBlockSchema(FilledLinkValueLegacySchema)
116
142
 
143
+ type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
144
+
117
145
  // Image block
118
146
 
119
147
  // oxlint-disable-next-line explicit-module-boundary-types
@@ -136,6 +164,8 @@ const ImageBlockLegacySchema = getImageBlockSchema(
136
164
  FilledLinkValueLegacySchema,
137
165
  )
138
166
 
167
+ type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>
168
+
139
169
  // Embed block
140
170
  // oxlint-disable-next-line explicit-module-boundary-types
141
171
  export const getEmbedBlockSchema = <
@@ -152,14 +182,16 @@ export const getEmbedBlockSchema = <
152
182
 
153
183
  const EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)
154
184
 
185
+ type EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>
186
+
155
187
  // Blocks
156
- export const RichTextLegacyBlockSchema = z.union([
188
+ export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.union([
157
189
  TextBlockLegacySchema,
158
190
  ImageBlockLegacySchema,
159
191
  EmbedBlockLegacySchema,
160
192
  ])
161
193
 
162
- export type RichTextLegacyBlock = z.infer<typeof RichTextLegacyBlockSchema>
194
+ export type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy
163
195
 
164
196
  export const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema)
165
197
 
@@ -1,7 +1,6 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
3
  import { GroupItemLegacySchema, NestableAndGroupLegacySchema } from "./group"
4
- import { NestableLegacySchema } from "./nestable"
5
4
 
6
5
  // Legacy (before 2020)
7
6
  export const LegacySliceLegacySchema = NestableAndGroupLegacySchema
@@ -9,29 +8,31 @@ export const LegacySliceLegacySchema = NestableAndGroupLegacySchema
9
8
  export type LegacySliceLegacy = z.infer<typeof LegacySliceLegacySchema>
10
9
 
11
10
  // Composite (2020 to 2021)
11
+ // Keep non-repeat values raw here: array-shaped legacy payloads are ambiguous until
12
+ // `codec/slice.ts` resolves the field model and picks the right decoder.
12
13
  export const CompositeSliceLegacySchema = z.object({
13
- "non-repeat": z.optional(z.record(z.string(), NestableLegacySchema)),
14
+ "non-repeat": z.optional(z.record(z.string(), z.unknown())),
14
15
  repeat: z.optional(z.array(GroupItemLegacySchema)),
15
16
  })
16
17
 
17
18
  export type CompositeSliceLegacy = z.infer<typeof CompositeSliceLegacySchema>
18
19
 
19
20
  // Shared (2021 to present)
21
+ // Keep primary values raw here: array-shaped legacy payloads are ambiguous until
22
+ // `codec/slice.ts` resolves the field model and picks the right decoder.
20
23
  export const SharedSliceLegacySchema = z.object({
21
24
  variation: z.string(),
22
- primary: z.transform(
23
- (value) => z.record(z.string(), NestableAndGroupLegacySchema).safeParse(value).data || {},
24
- ),
25
+ primary: z.transform((value) => z.record(z.string(), z.unknown()).safeParse(value).data || {}),
25
26
  items: z.transform((value) => z.array(GroupItemLegacySchema).safeParse(value).data || []),
26
27
  })
27
28
 
28
29
  export type SharedSliceLegacy = z.infer<typeof SharedSliceLegacySchema>
29
30
 
30
31
  // All
31
- export const SliceLegacySchema = z.union([
32
+ export const SliceLegacySchema: z.ZodMiniType<SliceLegacy> = z.union([
32
33
  LegacySliceLegacySchema,
33
34
  CompositeSliceLegacySchema,
34
35
  SharedSliceLegacySchema,
35
36
  ])
36
37
 
37
- export type SliceLegacy = z.infer<typeof SliceLegacySchema>
38
+ export type SliceLegacy = LegacySliceLegacy | CompositeSliceLegacy | SharedSliceLegacy
@@ -1,15 +1,19 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
+ import type { GroupLegacy } from "./group"
3
4
  import { GroupLegacySchema } from "./group"
5
+ import type { NestableLegacy } from "./nestable"
4
6
  import { NestableLegacySchema } from "./nestable"
7
+ import type { SlicesLegacy } from "./slices"
5
8
  import { SlicesLegacySchema } from "./slices"
9
+ import type { UIDLegacy } from "./uid"
6
10
  import { UIDLegacySchema } from "./uid"
7
11
 
8
- export const WidgetLegacySchema = z.union([
12
+ export const WidgetLegacySchema: z.ZodMiniType<WidgetLegacy> = z.union([
9
13
  UIDLegacySchema,
10
14
  GroupLegacySchema,
11
15
  SlicesLegacySchema,
12
16
  NestableLegacySchema,
13
17
  ])
14
18
 
15
- export type WidgetLegacy = z.infer<typeof WidgetLegacySchema>
19
+ export type WidgetLegacy = UIDLegacy | GroupLegacy | SlicesLegacy | NestableLegacy
@@ -63,7 +63,7 @@ const AnyLinkValueContentSchema = z.extend(AnyLinkLegacySchema, {
63
63
  // All
64
64
 
65
65
  // Used by content/richText
66
- export const FilledLinkValueContentSchema = z.union([
66
+ export const FilledLinkValueContentSchema: z.ZodMiniType<FilledLinkValueContent> = z.union([
67
67
  FilledImageLinkValueContentSchema,
68
68
  FilledFileLinkValueContentSchema,
69
69
  FilledDocumentLinkValueContentSchema,
@@ -71,9 +71,17 @@ export const FilledLinkValueContentSchema = z.union([
71
71
  ])
72
72
 
73
73
  // Used by content/legacy/link
74
- export type FilledLinkValueContent = z.infer<typeof FilledLinkValueContentSchema>
75
-
76
- const EmptyLinkValueContentSchema = z.union([
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([
77
85
  EmptyImageLinkValueContentSchema,
78
86
  EmptyFileLinkValueContentSchema,
79
87
  EmptyMediaLinkValueContentSchema,
@@ -83,12 +91,27 @@ const EmptyLinkValueContentSchema = z.union([
83
91
  ])
84
92
 
85
93
  // Used by content/codec/link
86
- export type EmptyLinkValueContent = z.infer<typeof EmptyLinkValueContentSchema>
87
-
88
- const LinkValueContentSchema = z.union([FilledLinkValueContentSchema, EmptyLinkValueContentSchema])
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,
111
+ ])
89
112
 
90
113
  // Used by content/codec/link
91
- export type LinkValueContent = z.infer<typeof LinkValueContentSchema>
114
+ export type LinkValueContent = FilledLinkValueContent | EmptyLinkValueContent
92
115
 
93
116
  // Content
94
117
  export const LinkContentType = "LinkContent" as const
@@ -117,7 +140,7 @@ export const LinkContentSchema = z.object({
117
140
  z.object({
118
141
  text: z.optional(z.string()),
119
142
  variant: z.optional(z.string()),
120
- value: z.union([FilledLinkValueContentSchema, EmptyLinkValueContentSchema]),
143
+ value: LinkValueContentSchema as z.ZodMiniType<LinkValueContent, Record<string, unknown>>,
121
144
  }),
122
145
  ),
123
146
  z.transform(({ text, variant, value }) => ({
@@ -1,30 +1,48 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
- import type { NestableModel } from "../model/nestable"
4
- import { BooleanContentDefaultValue, BooleanContentSchema, BooleanContentType } from "./boolean"
3
+ import type { BooleanContent } from "./boolean"
4
+ import { BooleanContentSchema, BooleanContentType } from "./boolean"
5
+ import type { EmbedContent } from "./embed"
5
6
  import { EmbedContentSchema, EmbedContentType } from "./embed"
7
+ import type { EmptyContent } from "./empty"
6
8
  import { EmptyContentSchema, EmptyContentType } from "./empty"
9
+ import type {
10
+ ColorContent,
11
+ DateContent,
12
+ NumberContent,
13
+ RangeContent,
14
+ SelectContent,
15
+ TextContent,
16
+ TimestampContent,
17
+ } from "./field"
7
18
  import {
8
19
  ColorContentSchema,
9
20
  DateContentSchema,
10
21
  FieldContentType,
11
22
  NumberContentSchema,
12
23
  RangeContentSchema,
13
- SelectContentDefaultValue,
14
24
  SelectContentSchema,
15
25
  TextContentSchema,
16
26
  TimestampContentSchema,
17
27
  } from "./field"
28
+ import type { GeoPointContent } from "./geopoint"
18
29
  import { GeoPointContentSchema, GeoPointContentType } from "./geopoint"
30
+ import type { ImageContent } from "./image"
19
31
  import { ImageContentSchema, ImageContentType } from "./image"
32
+ import type { IntegrationFieldContent } from "./integrationField"
20
33
  import { IntegrationFieldContentSchema, IntegrationFieldContentType } from "./integrationField"
34
+ import type { LinkContent } from "./link"
21
35
  import { LinkContentSchema, LinkContentType } from "./link"
36
+ import type { RepeatableContent } from "./repeatable"
22
37
  import { RepeatableContentSchema, RepeatableContentType } from "./repeatable"
38
+ import type { RichTextContent } from "./richText"
23
39
  import { RichTextContentSchema, RichTextContentType } from "./richText"
40
+ import type { SeparatorContent } from "./separator"
24
41
  import { SeparatorContentSchema, SeparatorContentType } from "./separator"
42
+ import type { TableContent } from "./table"
25
43
  import { TableContentSchema, TableContentType } from "./table"
26
44
 
27
- export const NestableContentSchema = z.union([
45
+ export const NestableContentSchema: z.ZodMiniType<NestableContent> = z.union([
28
46
  EmptyContentSchema,
29
47
  BooleanContentSchema,
30
48
  ColorContentSchema,
@@ -45,7 +63,25 @@ export const NestableContentSchema = z.union([
45
63
  TimestampContentSchema,
46
64
  ])
47
65
 
48
- export type NestableContent = z.infer<typeof NestableContentSchema>
66
+ export type NestableContent =
67
+ | EmptyContent
68
+ | BooleanContent
69
+ | ColorContent
70
+ | DateContent
71
+ | EmbedContent
72
+ | GeoPointContent
73
+ | ImageContent
74
+ | IntegrationFieldContent
75
+ | LinkContent
76
+ | NumberContent
77
+ | RangeContent
78
+ | RepeatableContent
79
+ | RichTextContent
80
+ | SelectContent
81
+ | SeparatorContent
82
+ | TableContent
83
+ | TextContent
84
+ | TimestampContent
49
85
 
50
86
  const NestableContentTypes = [
51
87
  EmptyContentType,
@@ -62,25 +98,10 @@ const NestableContentTypes = [
62
98
  TableContentType,
63
99
  ]
64
100
  type NestableContentType = (typeof NestableContentTypes)[number]
101
+
102
+ /** @internal */
65
103
  export function isNestableContent(content: {
66
104
  __TYPE__: string
67
105
  }): content is { __TYPE__: NestableContentType } {
68
106
  return (NestableContentTypes as string[]).includes(content.__TYPE__)
69
107
  }
70
-
71
- /**
72
- * Returns the default value for a nestable widget based on its configuration.
73
- * Currently only Boolean and Select fields have default values.
74
- */
75
- export const NestableContentDefaultValue = (
76
- widgetDef: NestableModel,
77
- ): NestableContent | undefined => {
78
- switch (widgetDef.type) {
79
- case "Boolean":
80
- return BooleanContentDefaultValue(widgetDef)
81
- case "Select":
82
- return SelectContentDefaultValue(widgetDef)
83
- default:
84
- return undefined
85
- }
86
- }
@@ -8,35 +8,47 @@ import {
8
8
  getSpanSchema,
9
9
  getTextBlockSchema,
10
10
  } from "./legacy/richText"
11
+ import type { Span } from "./legacy/richText"
12
+ import type { FilledLinkValueContent } from "./link"
11
13
  import { FilledLinkValueContentSchema } from "./link"
12
14
 
13
15
  // Spans
14
- export const RichTextContentSpanSchema = getSpanSchema(FilledLinkValueContentSchema)
16
+ export type RichTextContentSpan = Span<FilledLinkValueContent>
15
17
 
16
- export type RichTextContentSpan = z.infer<typeof RichTextContentSpanSchema>
18
+ export const RichTextContentSpanSchema: z.ZodMiniType<RichTextContentSpan> = getSpanSchema(
19
+ FilledLinkValueContentSchema,
20
+ )
17
21
 
18
22
  // Blocks
19
23
  const TextBlockValueSchema = getTextBlockSchema(FilledLinkValueContentSchema)
24
+ type TextBlockValue = z.infer<typeof TextBlockValueSchema>
25
+
20
26
  const ImageBlockValueSchema = getImageBlockSchema(
21
27
  ImageViewContentSchema,
22
28
  FilledLinkValueContentSchema,
23
29
  )
30
+ type ImageBlockValue = z.infer<typeof ImageBlockValueSchema>
31
+
24
32
  const EmbedBlockValueSchema = getEmbedBlockSchema(EmbedContentSchema)
33
+ type EmbedBlockValue = z.infer<typeof EmbedBlockValueSchema>
25
34
 
26
- export const RichTextContentBlockSchema = z.union([
35
+ export const RichTextContentBlockSchema: z.ZodMiniType<RichTextContentBlock> = z.union([
27
36
  TextBlockValueSchema,
28
37
  ImageBlockValueSchema,
29
38
  EmbedBlockValueSchema,
30
39
  ])
31
40
 
32
41
  // Used by content/codec/richText
33
- export type RichTextContentBlock = z.infer<typeof RichTextContentBlockSchema>
42
+ export type RichTextContentBlock = TextBlockValue | ImageBlockValue | EmbedBlockValue
34
43
 
35
44
  export const RichTextContentType = "StructuredTextContent" as const
36
45
 
37
- export const RichTextContentSchema = z.object({
46
+ export type RichTextContent = {
47
+ __TYPE__: typeof RichTextContentType
48
+ value: RichTextContentBlock[]
49
+ }
50
+
51
+ export const RichTextContentSchema: z.ZodMiniType<RichTextContent> = z.object({
38
52
  __TYPE__: z.literal(RichTextContentType),
39
53
  value: z.array(RichTextContentBlockSchema),
40
54
  })
41
-
42
- export type RichTextContent = z.infer<typeof RichTextContentSchema>
@@ -32,10 +32,10 @@ export const SharedSliceContentSchema = z.object({
32
32
  export type SharedSliceContent = z.infer<typeof SharedSliceContentSchema>
33
33
 
34
34
  // All
35
- export const SliceContentSchema = z.union([
35
+ export const SliceContentSchema: z.ZodMiniType<SliceContent> = z.union([
36
36
  LegacySliceContentSchema,
37
37
  CompositeSliceContentSchema,
38
38
  SharedSliceContentSchema,
39
39
  ])
40
40
 
41
- export type SliceContent = z.infer<typeof SliceContentSchema>
41
+ export type SliceContent = LegacySliceContent | CompositeSliceContent | SharedSliceContent
@@ -1,17 +1,21 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
+ import type { GroupContent } from "./group"
3
4
  import { GroupContentSchema } from "./group"
5
+ import type { NestableContent } from "./nestable"
4
6
  import { NestableContentSchema } from "./nestable"
7
+ import type { SlicesContent } from "./slices"
5
8
  import { SlicesContentSchema } from "./slices"
9
+ import type { UIDContent } from "./uid"
6
10
  import { UIDContentSchema } from "./uid"
7
11
 
8
- export const WidgetContentSchema = z.union([
12
+ export const WidgetContentSchema: z.ZodMiniType<WidgetContent> = z.union([
9
13
  GroupContentSchema,
10
14
  NestableContentSchema,
11
15
  UIDContentSchema,
12
16
  SlicesContentSchema,
13
17
  ])
14
18
 
15
- export type WidgetContent = z.infer<typeof WidgetContentSchema>
19
+ export type WidgetContent = GroupContent | NestableContent | UIDContent | SlicesContent
16
20
 
17
21
  export type ContentType = WidgetContent["__TYPE__"]
@@ -67,3 +67,47 @@ export function collectSharedSlices(
67
67
 
68
68
  return sharedSlices
69
69
  }
70
+
71
+ export function filterMissingSharedSlices<
72
+ TCustomType extends StaticCustomTypeModel | CustomTypeModel,
73
+ >(
74
+ customType: TCustomType,
75
+ sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,
76
+ ): TCustomType {
77
+ const json: TCustomType["json"] = {}
78
+
79
+ const sharedSlicesMap =
80
+ sharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))
81
+
82
+ for (const [tabKey, tab] of Object.entries(customType.json)) {
83
+ const tabJSON: typeof tab = {}
84
+ for (const [key, widget] of Object.entries(tab)) {
85
+ switch (widget.type) {
86
+ case "Slices":
87
+ case "Choice":
88
+ const choices: Required<typeof widget>["config"]["choices"] = {}
89
+ for (const [id, model] of Object.entries(widget.config?.choices || {})) {
90
+ if (model.type === "SharedSlice") {
91
+ if (sharedSlicesMap.get(id)) {
92
+ choices[id] = model
93
+ }
94
+ } else {
95
+ choices[id] = model
96
+ }
97
+ }
98
+
99
+ tabJSON[key] = {
100
+ ...widget,
101
+ config: { ...widget.config, choices },
102
+ }
103
+ break
104
+ default:
105
+ tabJSON[key] = widget
106
+ }
107
+ }
108
+
109
+ json[tabKey] = tabJSON
110
+ }
111
+
112
+ return { ...customType, json }
113
+ }