@prismicio/types-internal 4.0.0-pr.6.7b0b0be → 4.0.0-pr.6.bbcafda

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 (138) hide show
  1. package/dist/content/codec/link.js +8 -8
  2. package/dist/content/codec/link.js.map +1 -1
  3. package/dist/content/codec/richText.js +2 -2
  4. package/dist/content/codec/richText.js.map +1 -1
  5. package/dist/content/document.d.ts +2 -3019
  6. package/dist/content/document.d.ts.map +1 -1
  7. package/dist/content/field.d.ts +1 -30
  8. package/dist/content/field.d.ts.map +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/richText.d.ts +109 -0
  29. package/dist/content/legacy/richText.d.ts.map +1 -0
  30. package/dist/content/legacy/richText.js +3 -3
  31. package/dist/content/legacy/richText.js.map +1 -1
  32. package/dist/content/legacy/separator.d.ts +1 -0
  33. package/dist/content/legacy/slice.js.map +1 -1
  34. package/dist/content/legacy/table.d.ts +1 -0
  35. package/dist/content/link.d.ts +74 -99
  36. package/dist/content/link.d.ts.map +1 -1
  37. package/dist/content/link.js +2 -2
  38. package/dist/content/link.js.map +1 -1
  39. package/dist/content/nestable.d.ts +13 -749
  40. package/dist/content/nestable.d.ts.map +1 -1
  41. package/dist/content/nestable.js.map +1 -1
  42. package/dist/content/repeatable.d.ts +3 -98
  43. package/dist/content/repeatable.d.ts.map +1 -1
  44. package/dist/content/richText.d.ts +81 -131
  45. package/dist/content/richText.d.ts.map +1 -1
  46. package/dist/content/richText.js +5 -4
  47. package/dist/content/richText.js.map +1 -1
  48. package/dist/content/slice.d.ts +6 -4509
  49. package/dist/content/slice.d.ts.map +1 -1
  50. package/dist/content/slice.js.map +1 -1
  51. package/dist/content/slices.d.ts +8 -6765
  52. package/dist/content/slices.d.ts.map +1 -1
  53. package/dist/content/table.d.ts +2 -134
  54. package/dist/content/table.d.ts.map +1 -1
  55. package/dist/content/widget.d.ts +5 -3020
  56. package/dist/content/widget.d.ts.map +1 -1
  57. package/dist/content/widget.js.map +1 -1
  58. package/dist/helpers/customTypeModel.d.ts +1 -1
  59. package/dist/helpers/documentContent.d.ts +3 -9
  60. package/dist/helpers/documentContent.d.ts.map +1 -1
  61. package/dist/helpers/documentContent.js +3 -3
  62. package/dist/helpers/documentContent.js.map +1 -1
  63. package/dist/helpers/traverseContent.d.ts +10 -11
  64. package/dist/helpers/traverseContent.d.ts.map +1 -1
  65. package/dist/helpers/traverseContent.js.map +1 -1
  66. package/dist/helpers/traverseContentWithModel.d.ts +10 -11
  67. package/dist/helpers/traverseContentWithModel.d.ts.map +1 -1
  68. package/dist/helpers/traverseContentWithModel.js.map +1 -1
  69. package/dist/index.d.ts +25 -25
  70. package/dist/io-ts.d.ts +3380 -70926
  71. package/dist/io-ts.d.ts.map +1 -1
  72. package/dist/io-ts.js +125 -122
  73. package/dist/io-ts.js.map +1 -1
  74. package/dist/model/customType.d.ts +3 -3329
  75. package/dist/model/customType.d.ts.map +1 -1
  76. package/dist/model/group.d.ts +391 -392
  77. package/dist/model/group.d.ts.map +1 -1
  78. package/dist/model/group.js.map +1 -1
  79. package/dist/model/image.d.ts +4 -4
  80. package/dist/model/image.js.map +1 -1
  81. package/dist/model/link.d.ts +18 -18
  82. package/dist/model/link.d.ts.map +1 -1
  83. package/dist/model/link.js +7 -7
  84. package/dist/model/link.js.map +1 -1
  85. package/dist/model/nestable.d.ts +17 -178
  86. package/dist/model/nestable.d.ts.map +1 -1
  87. package/dist/model/nestable.js.map +1 -1
  88. package/dist/model/richText.d.ts +3 -7
  89. package/dist/model/richText.d.ts.map +1 -1
  90. package/dist/model/richText.js.map +1 -1
  91. package/dist/model/section.d.ts +3 -3329
  92. package/dist/model/section.d.ts.map +1 -1
  93. package/dist/model/select.d.ts +1 -1
  94. package/dist/model/select.js +1 -1
  95. package/dist/model/select.js.map +1 -1
  96. package/dist/model/slice.d.ts +861 -3800
  97. package/dist/model/slice.d.ts.map +1 -1
  98. package/dist/model/slice.js +7 -2
  99. package/dist/model/slice.js.map +1 -1
  100. package/dist/model/slices.d.ts +3 -2195
  101. package/dist/model/slices.d.ts.map +1 -1
  102. package/dist/model/widget.d.ts +6 -3331
  103. package/dist/model/widget.d.ts.map +1 -1
  104. package/dist/model/widget.js.map +1 -1
  105. package/dist/zod4.d.ts +1345 -34797
  106. package/dist/zod4.d.ts.map +1 -1
  107. package/dist/zod4.js +125 -122
  108. package/dist/zod4.js.map +1 -1
  109. package/package.json +3 -2
  110. package/src/content/codec/link.ts +8 -8
  111. package/src/content/codec/richText.ts +10 -6
  112. package/src/content/field.ts +9 -2
  113. package/src/content/group.ts +5 -2
  114. package/src/content/legacy/group.ts +10 -4
  115. package/src/content/legacy/link.ts +32 -9
  116. package/src/content/legacy/nestable.ts +26 -2
  117. package/src/content/legacy/richText.ts +40 -7
  118. package/src/content/legacy/slice.ts +2 -2
  119. package/src/content/legacy/widget.ts +6 -2
  120. package/src/content/link.ts +32 -9
  121. package/src/content/nestable.ts +40 -2
  122. package/src/content/richText.ts +31 -9
  123. package/src/content/slice.ts +2 -2
  124. package/src/content/widget.ts +6 -2
  125. package/src/helpers/documentContent.ts +12 -15
  126. package/src/helpers/traverseContent.ts +12 -19
  127. package/src/helpers/traverseContentWithModel.ts +10 -16
  128. package/src/index.ts +3 -2
  129. package/src/io-ts.ts +166 -140
  130. package/src/model/group.ts +4 -1
  131. package/src/model/image.ts +1 -1
  132. package/src/model/link.ts +39 -45
  133. package/src/model/nestable.ts +33 -1
  134. package/src/model/richText.ts +2 -2
  135. package/src/model/select.ts +2 -2
  136. package/src/model/slice.ts +36 -9
  137. package/src/model/widget.ts +8 -4
  138. package/src/zod4.ts +166 -140
@@ -1,15 +1,21 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
+ import type { NestableLegacy } from "./nestable"
3
4
  import { NestableLegacySchema } from "./nestable"
4
5
 
5
6
  export const GroupItemLegacySchema = z.record(z.string(), z.unknown())
6
7
 
7
8
  export type GroupItemLegacy = z.infer<typeof GroupItemLegacySchema>
8
9
 
9
- export const GroupLegacySchema = z.array(z.union([GroupItemLegacySchema, z.null()]))
10
+ export const GroupLegacySchema: z.ZodMiniType<GroupLegacy> = z.array(
11
+ z.union([GroupItemLegacySchema, z.null()]),
12
+ )
10
13
 
11
- export type GroupLegacy = z.infer<typeof GroupLegacySchema>
14
+ export type GroupLegacy = (GroupItemLegacy | null)[]
12
15
 
13
- export const NestableAndGroupLegacySchema = z.union([NestableLegacySchema, GroupLegacySchema])
16
+ export const NestableAndGroupLegacySchema: z.ZodMiniType<NestableAndGroupLegacy> = z.union([
17
+ NestableLegacySchema,
18
+ GroupLegacySchema,
19
+ ])
14
20
 
15
- export type NestableAndGroupLegacy = z.infer<typeof NestableAndGroupLegacySchema>
21
+ 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
@@ -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,7 +81,13 @@ const BasicSpanSchema = z.object({
60
81
  end: z.number(),
61
82
  })
62
83
 
63
- const getSpanSchema = <
84
+ export type Span<TLink extends FilledLinkValueLegacy | FilledLinkValueContent> =
85
+ | HyperlinkSpan<TLink>
86
+ | LabelSpan
87
+ | BasicSpan
88
+
89
+ // oxlint-disable-next-line explicit-module-boundary-types
90
+ export const getSpanSchema = <
64
91
  TLinkSchema extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
65
92
  >(
66
93
  linkSchema: TLinkSchema,
@@ -113,6 +140,8 @@ export const getTextBlockSchema = <
113
140
 
114
141
  const TextBlockLegacySchema = getTextBlockSchema(FilledLinkValueLegacySchema)
115
142
 
143
+ type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
144
+
116
145
  // Image block
117
146
 
118
147
  // oxlint-disable-next-line explicit-module-boundary-types
@@ -135,6 +164,8 @@ const ImageBlockLegacySchema = getImageBlockSchema(
135
164
  FilledLinkValueLegacySchema,
136
165
  )
137
166
 
167
+ type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>
168
+
138
169
  // Embed block
139
170
  // oxlint-disable-next-line explicit-module-boundary-types
140
171
  export const getEmbedBlockSchema = <
@@ -151,15 +182,17 @@ export const getEmbedBlockSchema = <
151
182
 
152
183
  const EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)
153
184
 
185
+ type EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>
186
+
154
187
  // Blocks
155
- export const BlockLegacySchema = z.union([
188
+ export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.union([
156
189
  TextBlockLegacySchema,
157
190
  ImageBlockLegacySchema,
158
191
  EmbedBlockLegacySchema,
159
192
  ])
160
193
 
161
- export type BlockLegacy = z.infer<typeof BlockLegacySchema>
194
+ export type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy
162
195
 
163
- export const RichTextLegacySchema = z.array(BlockLegacySchema)
196
+ export const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema)
164
197
 
165
198
  export type RichTextLegacy = z.infer<typeof RichTextLegacySchema>
@@ -28,10 +28,10 @@ export const SharedSliceLegacySchema = z.object({
28
28
  export type SharedSliceLegacy = z.infer<typeof SharedSliceLegacySchema>
29
29
 
30
30
  // All
31
- export const SliceLegacySchema = z.union([
31
+ export const SliceLegacySchema: z.ZodMiniType<SliceLegacy> = z.union([
32
32
  LegacySliceLegacySchema,
33
33
  CompositeSliceLegacySchema,
34
34
  SharedSliceLegacySchema,
35
35
  ])
36
36
 
37
- export type SliceLegacy = z.infer<typeof SliceLegacySchema>
37
+ 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,9 +1,21 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
3
  import type { NestableModel } from "../model/nestable"
4
+ import type { BooleanContent } from "./boolean"
4
5
  import { BooleanContentDefaultValue, BooleanContentSchema, BooleanContentType } from "./boolean"
6
+ import type { EmbedContent } from "./embed"
5
7
  import { EmbedContentSchema, EmbedContentType } from "./embed"
8
+ import type { EmptyContent } from "./empty"
6
9
  import { EmptyContentSchema, EmptyContentType } from "./empty"
10
+ import type {
11
+ ColorContent,
12
+ DateContent,
13
+ NumberContent,
14
+ RangeContent,
15
+ SelectContent,
16
+ TextContent,
17
+ TimestampContent,
18
+ } from "./field"
7
19
  import {
8
20
  ColorContentSchema,
9
21
  DateContentSchema,
@@ -15,16 +27,24 @@ import {
15
27
  TextContentSchema,
16
28
  TimestampContentSchema,
17
29
  } from "./field"
30
+ import type { GeoPointContent } from "./geopoint"
18
31
  import { GeoPointContentSchema, GeoPointContentType } from "./geopoint"
32
+ import type { ImageContent } from "./image"
19
33
  import { ImageContentSchema, ImageContentType } from "./image"
34
+ import type { IntegrationFieldContent } from "./integrationField"
20
35
  import { IntegrationFieldContentSchema, IntegrationFieldContentType } from "./integrationField"
36
+ import type { LinkContent } from "./link"
21
37
  import { LinkContentSchema, LinkContentType } from "./link"
38
+ import type { RepeatableContent } from "./repeatable"
22
39
  import { RepeatableContentSchema, RepeatableContentType } from "./repeatable"
40
+ import type { RichTextContent } from "./richText"
23
41
  import { RichTextContentSchema, RichTextContentType } from "./richText"
42
+ import type { SeparatorContent } from "./separator"
24
43
  import { SeparatorContentSchema, SeparatorContentType } from "./separator"
44
+ import type { TableContent } from "./table"
25
45
  import { TableContentSchema, TableContentType } from "./table"
26
46
 
27
- export const NestableContentSchema = z.union([
47
+ export const NestableContentSchema: z.ZodMiniType<NestableContent> = z.union([
28
48
  EmptyContentSchema,
29
49
  BooleanContentSchema,
30
50
  ColorContentSchema,
@@ -45,7 +65,25 @@ export const NestableContentSchema = z.union([
45
65
  TimestampContentSchema,
46
66
  ])
47
67
 
48
- export type NestableContent = z.infer<typeof NestableContentSchema>
68
+ export type NestableContent =
69
+ | EmptyContent
70
+ | BooleanContent
71
+ | ColorContent
72
+ | DateContent
73
+ | EmbedContent
74
+ | GeoPointContent
75
+ | ImageContent
76
+ | IntegrationFieldContent
77
+ | LinkContent
78
+ | NumberContent
79
+ | RangeContent
80
+ | RepeatableContent
81
+ | RichTextContent
82
+ | SelectContent
83
+ | SeparatorContent
84
+ | TableContent
85
+ | TextContent
86
+ | TimestampContent
49
87
 
50
88
  const NestableContentTypes = [
51
89
  EmptyContentType,
@@ -2,31 +2,53 @@ import { z } from "zod/mini"
2
2
 
3
3
  import { EmbedContentSchema } from "./embed"
4
4
  import { ImageViewContentSchema } from "./image"
5
- import { getEmbedBlockSchema, getImageBlockSchema, getTextBlockSchema } from "./legacy/richText"
5
+ import {
6
+ getEmbedBlockSchema,
7
+ getImageBlockSchema,
8
+ getSpanSchema,
9
+ getTextBlockSchema,
10
+ } from "./legacy/richText"
11
+ import type { Span } from "./legacy/richText"
12
+ import type { FilledLinkValueContent } from "./link"
6
13
  import { FilledLinkValueContentSchema } from "./link"
7
14
 
15
+ // Spans
16
+ export type RichTextContentSpan = Span<FilledLinkValueContent>
17
+
18
+ export const RichTextContentSpanSchema: z.ZodMiniType<RichTextContentSpan> = getSpanSchema(
19
+ FilledLinkValueContentSchema,
20
+ )
21
+
22
+ // Blocks
8
23
  const TextBlockValueSchema = getTextBlockSchema(FilledLinkValueContentSchema)
24
+ type TextBlockValue = z.infer<typeof TextBlockValueSchema>
25
+
9
26
  const ImageBlockValueSchema = getImageBlockSchema(
10
27
  ImageViewContentSchema,
11
28
  FilledLinkValueContentSchema,
12
29
  )
30
+ type ImageBlockValue = z.infer<typeof ImageBlockValueSchema>
31
+
13
32
  const EmbedBlockValueSchema = getEmbedBlockSchema(EmbedContentSchema)
33
+ type EmbedBlockValue = z.infer<typeof EmbedBlockValueSchema>
14
34
 
15
- // Blocks
16
- const BlockValueSchema = z.union([
35
+ export const RichTextContentBlockSchema: z.ZodMiniType<RichTextContentBlock> = z.union([
17
36
  TextBlockValueSchema,
18
37
  ImageBlockValueSchema,
19
38
  EmbedBlockValueSchema,
20
39
  ])
21
40
 
22
- // Used by content/richText
23
- export type BlockValue = z.infer<typeof BlockValueSchema>
41
+ // Used by content/codec/richText
42
+ export type RichTextContentBlock = TextBlockValue | ImageBlockValue | EmbedBlockValue
24
43
 
25
44
  export const RichTextContentType = "StructuredTextContent" as const
26
45
 
27
- 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({
28
52
  __TYPE__: z.literal(RichTextContentType),
29
- value: z.array(BlockValueSchema),
53
+ value: z.array(RichTextContentBlockSchema),
30
54
  })
31
-
32
- 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__"]
@@ -13,27 +13,24 @@ import { traverseDocumentContent } from "./traverseContent"
13
13
 
14
14
  export function collectWidgets<TWidgetContent extends WidgetContent>(
15
15
  document: DocumentContent,
16
- test: (args: {
17
- path: contentPath.Path
18
- key: string
19
- apiID: string
20
- content: WidgetContent
21
- }) => args is {
22
- path: contentPath.Path
23
- key: string
24
- apiID: string
25
- content: TWidgetContent
26
- },
16
+ test: (
17
+ content: WidgetContent,
18
+ args: {
19
+ path: contentPath.Path
20
+ key: string
21
+ apiID: string
22
+ },
23
+ ) => content is TWidgetContent,
27
24
  ): Record<string, TWidgetContent> {
28
25
  const collected: Record<string, TWidgetContent> = {}
29
26
 
30
27
  traverseDocumentContent(document, {
31
- transformWidget: (args) => {
32
- if (test(args)) {
33
- collected[contentPath.serialize(args.path)] = args.content
28
+ transformWidget: ({ content, ...args }) => {
29
+ if (test(content, args)) {
30
+ collected[contentPath.serialize(args.path)] = content
34
31
  }
35
32
 
36
- return args.content
33
+ return content
37
34
  },
38
35
  })
39
36
 
@@ -24,7 +24,8 @@ import type { NestableModel } from "../model/nestable"
24
24
  import type {
25
25
  CompositeSliceModel,
26
26
  LegacySliceModel,
27
- SharedSliceVariationModel,
27
+ SharedSliceVariationContentModel,
28
+ SliceContentModel,
28
29
  } from "../model/slice"
29
30
  import type { StaticSlicesModel } from "../model/slices"
30
31
  import { TableCellModel } from "../model/table"
@@ -81,10 +82,8 @@ export function traverseSlicesContent(
81
82
  content: SlicesContent,
82
83
  config: TraverseSlicesContentConfig,
83
84
  ): SlicesContent | undefined {
84
- const {
85
- transformWidget = (args) => args.content,
86
- transformSlice = (args) => args.content
87
- } = config
85
+ const { transformWidget = (args) => args.content, transformSlice = (args) => args.content } =
86
+ config
88
87
 
89
88
  const traversed: SlicesContent["value"] = []
90
89
  for (const sliceItemContent of content.value) {
@@ -92,7 +91,7 @@ export function traverseSlicesContent(
92
91
 
93
92
  let traversedSliceItemContent: SliceItemContent | undefined
94
93
  if (sliceItemContent.widget.__TYPE__ === SharedSliceContentType) {
95
- let model: SharedSliceVariationModel | undefined
94
+ let model: SharedSliceVariationContentModel | undefined
96
95
  if (sliceModel?.type === "SharedSlice") {
97
96
  const variationID = sliceItemContent.widget.variation
98
97
  const variationModel = sliceModel.variations.find(
@@ -154,7 +153,7 @@ export function traverseSlicesContent(
154
153
  }
155
154
 
156
155
  type TraverseSharedSliceContentConfig = {
157
- model?: SharedSliceVariationModel
156
+ model?: SharedSliceVariationContentModel
158
157
  transformWidget?: TraverseWidgetContentFunction
159
158
  transformSlice?: TraverseSliceContentFunction
160
159
  }
@@ -166,10 +165,8 @@ export function traverseSharedSliceContent(
166
165
  content: SharedSliceItemContent,
167
166
  config: TraverseSharedSliceContentConfig,
168
167
  ): SharedSliceItemContent | undefined {
169
- const {
170
- transformWidget = (args) => args.content,
171
- transformSlice = (args) => args.content
172
- } = config
168
+ const { transformWidget = (args) => args.content, transformSlice = (args) => args.content } =
169
+ config
173
170
 
174
171
  const traversedPrimary: SharedSliceContent["primary"] = {}
175
172
  for (const [key, fieldContent] of Object.entries(content.widget.primary)) {
@@ -222,10 +219,8 @@ export function traverseCompositeSliceContent(
222
219
  content: CompositeSliceItemContent,
223
220
  config: TraverseCompositeSliceContentConfig,
224
221
  ): CompositeSliceItemContent | undefined {
225
- const {
226
- transformWidget = (args) => args.content,
227
- transformSlice = (args) => args.content
228
- } = config
222
+ const { transformWidget = (args) => args.content, transformSlice = (args) => args.content } =
223
+ config
229
224
 
230
225
  const traversedPrimary: CompositeSliceContent["nonRepeat"] = {}
231
226
  for (const [key, fieldContent] of Object.entries(content.widget.nonRepeat)) {
@@ -278,7 +273,7 @@ export function traverseLegacySliceContent(
278
273
  const {
279
274
  model,
280
275
  transformWidget = (args) => args.content,
281
- transformSlice = (args) => args.content
276
+ transformSlice = (args) => args.content,
282
277
  } = config
283
278
 
284
279
  const traversedContent = traverseWidgetContent(path, key, apiID, content.widget, {
@@ -471,7 +466,7 @@ export type TraverseSliceContentFunction = <TContent extends SliceItemContent>(a
471
466
  key: string
472
467
  apiID: string
473
468
  content: TContent
474
- model?: SliceModel
469
+ model?: SliceContentModel
475
470
  }) => TContent | undefined
476
471
 
477
472
  export type TraverseWidgetContentFunction<
@@ -485,8 +480,6 @@ export type TraverseWidgetContentFunction<
485
480
  }) => (TContentTransformMode extends "preserve" ? TContent : WidgetContent) | undefined
486
481
 
487
482
  // Internals
488
- type SliceModel = SharedSliceVariationModel | CompositeSliceModel | LegacySliceModel
489
-
490
483
  type TraverseWidgetContentConfig = {
491
484
  model?: StaticWidgetModel
492
485
  transformWidget?: TraverseWidgetContentFunction