@prismicio/types-internal 1.5.3 → 2.0.0-alpha.1

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 (255) hide show
  1. package/lib/common/WidgetKey.d.ts +3 -0
  2. package/lib/common/WidgetKey.js +8 -0
  3. package/lib/common/index.d.ts +1 -0
  4. package/lib/common/index.js +4 -0
  5. package/lib/content/Document.d.ts +4285 -2573
  6. package/lib/content/Document.js +87 -10
  7. package/lib/content/LegacyContentCtx.d.ts +41 -0
  8. package/lib/content/LegacyContentCtx.js +65 -0
  9. package/lib/content/fields/EmptyContent.d.ts +16 -0
  10. package/lib/content/fields/EmptyContent.js +30 -0
  11. package/lib/content/fields/GroupContent.d.ts +1063 -364
  12. package/lib/content/fields/GroupContent.js +65 -6
  13. package/lib/content/fields/UIDContent.d.ts +10 -1
  14. package/lib/content/fields/UIDContent.js +17 -4
  15. package/lib/content/fields/WidgetContent.d.ts +6820 -0
  16. package/lib/content/fields/WidgetContent.js +57 -0
  17. package/lib/content/fields/index.d.ts +1 -2989
  18. package/lib/content/fields/index.js +1 -18
  19. package/lib/content/fields/nestable/BooleanContent.d.ts +10 -1
  20. package/lib/content/fields/nestable/BooleanContent.js +17 -4
  21. package/lib/content/fields/nestable/EmbedContent.d.ts +56 -5
  22. package/lib/content/fields/nestable/EmbedContent.js +57 -6
  23. package/lib/content/fields/nestable/FieldContent/ColorContent.d.ts +18 -0
  24. package/lib/content/fields/nestable/FieldContent/ColorContent.js +34 -0
  25. package/lib/content/fields/nestable/FieldContent/DateContent.d.ts +18 -0
  26. package/lib/content/fields/nestable/FieldContent/DateContent.js +34 -0
  27. package/lib/content/fields/nestable/FieldContent/NumberContent.d.ts +18 -0
  28. package/lib/content/fields/nestable/FieldContent/NumberContent.js +34 -0
  29. package/lib/content/fields/nestable/FieldContent/RangeContent.d.ts +18 -0
  30. package/lib/content/fields/nestable/FieldContent/RangeContent.js +34 -0
  31. package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +18 -0
  32. package/lib/content/fields/nestable/FieldContent/SelectContent.js +34 -0
  33. package/lib/content/fields/nestable/FieldContent/TextContent.d.ts +18 -0
  34. package/lib/content/fields/nestable/FieldContent/TextContent.js +34 -0
  35. package/lib/content/fields/nestable/FieldContent/TimestampContent.d.ts +18 -0
  36. package/lib/content/fields/nestable/FieldContent/TimestampContent.js +34 -0
  37. package/lib/content/fields/nestable/FieldContent/common.d.ts +1 -0
  38. package/lib/content/fields/nestable/FieldContent/common.js +4 -0
  39. package/lib/content/fields/nestable/FieldContent/index.d.ts +49 -0
  40. package/lib/content/fields/nestable/FieldContent/index.js +38 -0
  41. package/lib/content/fields/nestable/FieldContent.d.ts +7 -1
  42. package/lib/content/fields/nestable/FieldContent.js +19 -4
  43. package/lib/content/fields/nestable/GeoPointContent.d.ts +19 -4
  44. package/lib/content/fields/nestable/GeoPointContent.js +22 -5
  45. package/lib/content/fields/nestable/ImageContent.d.ts +109 -11
  46. package/lib/content/fields/nestable/ImageContent.js +64 -6
  47. package/lib/content/fields/nestable/IntegrationFieldContent.d.ts +10 -1
  48. package/lib/content/fields/nestable/IntegrationFieldContent.js +20 -4
  49. package/lib/content/fields/nestable/LinkContent.d.ts +240 -87
  50. package/lib/content/fields/nestable/LinkContent.js +133 -36
  51. package/lib/content/fields/nestable/NestableContent.d.ts +711 -251
  52. package/lib/content/fields/nestable/NestableContent.js +116 -13
  53. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +594 -0
  54. package/lib/content/fields/nestable/RichTextContent/Blocks.js +151 -0
  55. package/lib/content/fields/nestable/RichTextContent/index.d.ts +489 -0
  56. package/lib/content/fields/nestable/RichTextContent/index.js +27 -0
  57. package/lib/content/fields/nestable/SeparatorContent.d.ts +8 -1
  58. package/lib/content/fields/nestable/SeparatorContent.js +15 -4
  59. package/lib/content/fields/slices/CompositeSliceContent.d.ts +296 -362
  60. package/lib/content/fields/slices/RepeatableContent.d.ts +148 -181
  61. package/lib/content/fields/slices/SharedSliceContent.d.ts +296 -362
  62. package/lib/content/fields/slices/SimpleSliceContent.d.ts +296 -362
  63. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1709 -0
  64. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +81 -0
  65. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +582 -0
  66. package/lib/content/fields/slices/Slice/RepeatableContent.js +18 -0
  67. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +1713 -0
  68. package/lib/content/fields/slices/Slice/SharedSliceContent.js +98 -0
  69. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +1429 -0
  70. package/lib/content/fields/slices/Slice/SimpleSliceContent.js +24 -0
  71. package/lib/content/fields/slices/Slice/index.d.ts +3216 -0
  72. package/lib/content/fields/slices/Slice/index.js +41 -0
  73. package/lib/content/fields/slices/SliceItem.d.ts +3498 -0
  74. package/lib/content/fields/slices/SliceItem.js +61 -0
  75. package/lib/content/fields/slices/SlicesContent.d.ts +4243 -3576
  76. package/lib/content/fields/slices/SlicesContent.js +28 -18
  77. package/lib/content/fields/slices/index.d.ts +4 -3
  78. package/lib/content/fields/slices/index.js +4 -3
  79. package/lib/content/index.d.ts +1 -0
  80. package/lib/content/index.js +1 -0
  81. package/lib/content/utils.d.ts +10 -0
  82. package/lib/content/utils.js +19 -0
  83. package/lib/customtypes/CustomType.d.ts +366 -366
  84. package/lib/customtypes/CustomType.js +4 -7
  85. package/lib/customtypes/Section.d.ts +366 -366
  86. package/lib/customtypes/Section.js +2 -2
  87. package/lib/customtypes/diff/SharedSlice.d.ts +4 -4
  88. package/lib/customtypes/diff/Variation.d.ts +4 -4
  89. package/lib/customtypes/index.d.ts +1 -1
  90. package/lib/customtypes/index.js +2 -2
  91. package/lib/customtypes/widgets/Group.d.ts +1 -0
  92. package/lib/customtypes/widgets/Group.js +6 -5
  93. package/lib/customtypes/widgets/UID.d.ts +1 -0
  94. package/lib/customtypes/widgets/UID.js +3 -2
  95. package/lib/customtypes/widgets/Widget.d.ts +384 -362
  96. package/lib/customtypes/widgets/Widget.js +29 -8
  97. package/lib/customtypes/widgets/index.d.ts +6 -7
  98. package/lib/customtypes/widgets/index.js +6 -11
  99. package/lib/customtypes/widgets/nestable/BooleanField.d.ts +10 -3
  100. package/lib/customtypes/widgets/nestable/BooleanField.js +6 -6
  101. package/lib/customtypes/widgets/nestable/Color.d.ts +8 -3
  102. package/lib/customtypes/widgets/nestable/Color.js +6 -6
  103. package/lib/customtypes/widgets/nestable/Date.d.ts +9 -3
  104. package/lib/customtypes/widgets/nestable/Date.js +6 -6
  105. package/lib/customtypes/widgets/nestable/Embed.d.ts +9 -3
  106. package/lib/customtypes/widgets/nestable/Embed.js +6 -6
  107. package/lib/customtypes/widgets/nestable/GeoPoint.d.ts +7 -3
  108. package/lib/customtypes/widgets/nestable/GeoPoint.js +6 -6
  109. package/lib/customtypes/widgets/nestable/Image.d.ts +25 -3
  110. package/lib/customtypes/widgets/nestable/Image.js +8 -8
  111. package/lib/customtypes/widgets/nestable/IntegrationField.d.ts +9 -3
  112. package/lib/customtypes/widgets/nestable/IntegrationField.js +6 -6
  113. package/lib/customtypes/widgets/nestable/Link.d.ts +14 -2
  114. package/lib/customtypes/widgets/nestable/Link.js +7 -6
  115. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +3 -3
  116. package/lib/customtypes/widgets/nestable/NestableWidget.js +30 -30
  117. package/lib/customtypes/widgets/nestable/Number.d.ts +11 -3
  118. package/lib/customtypes/widgets/nestable/Number.js +6 -6
  119. package/lib/customtypes/widgets/nestable/Range.d.ts +11 -3
  120. package/lib/customtypes/widgets/nestable/Range.js +6 -6
  121. package/lib/customtypes/widgets/nestable/RichText.d.ts +1 -0
  122. package/lib/customtypes/widgets/nestable/RichText.js +3 -3
  123. package/lib/customtypes/widgets/nestable/Select.d.ts +10 -3
  124. package/lib/customtypes/widgets/nestable/Select.js +6 -6
  125. package/lib/customtypes/widgets/nestable/Separator.d.ts +7 -3
  126. package/lib/customtypes/widgets/nestable/Separator.js +6 -6
  127. package/lib/customtypes/widgets/nestable/Text.d.ts +9 -2
  128. package/lib/customtypes/widgets/nestable/Text.js +7 -6
  129. package/lib/customtypes/widgets/nestable/Timestamp.d.ts +9 -3
  130. package/lib/customtypes/widgets/nestable/Timestamp.js +6 -6
  131. package/lib/customtypes/widgets/nestable/index.d.ts +15 -15
  132. package/lib/customtypes/widgets/nestable/index.js +15 -31
  133. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +1 -0
  134. package/lib/customtypes/widgets/slices/CompositeSlice.js +7 -6
  135. package/lib/customtypes/widgets/slices/LegacySlice.js +2 -2
  136. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +1 -0
  137. package/lib/customtypes/widgets/slices/SharedSlice.js +7 -7
  138. package/lib/customtypes/widgets/slices/SharedSliceRef.js +2 -2
  139. package/lib/customtypes/widgets/slices/Slices.d.ts +364 -362
  140. package/lib/customtypes/widgets/slices/Slices.js +8 -8
  141. package/lib/customtypes/widgets/slices/SlicesTypes.d.ts +6 -5
  142. package/lib/customtypes/widgets/slices/SlicesTypes.js +8 -4
  143. package/lib/documents/DocumentData.d.ts +3 -14
  144. package/lib/documents/DocumentData.js +5 -60
  145. package/lib/documents/widgets/nestable/ImageContent.d.ts +1 -1
  146. package/lib/documents/widgets/nestable/ImageContent.js +2 -2
  147. package/lib/utils/Objects.d.ts +1 -0
  148. package/lib/utils/Objects.js +10 -1
  149. package/package.json +1 -1
  150. package/src/common/WidgetKey.ts +13 -0
  151. package/src/common/index.ts +1 -0
  152. package/src/content/Document.ts +129 -16
  153. package/src/content/LegacyContentCtx.ts +57 -0
  154. package/src/content/fields/EmptyContent.ts +45 -0
  155. package/src/content/fields/GroupContent.ts +103 -8
  156. package/src/content/fields/UIDContent.ts +33 -3
  157. package/src/content/fields/WidgetContent.ts +76 -0
  158. package/src/content/fields/index.ts +1 -23
  159. package/src/content/fields/nestable/BooleanContent.ts +32 -3
  160. package/src/content/fields/nestable/EmbedContent.ts +79 -8
  161. package/src/content/fields/nestable/FieldContent/ColorContent.ts +48 -0
  162. package/src/content/fields/nestable/FieldContent/DateContent.ts +48 -0
  163. package/src/content/fields/nestable/FieldContent/NumberContent.ts +48 -0
  164. package/src/content/fields/nestable/FieldContent/RangeContent.ts +48 -0
  165. package/src/content/fields/nestable/FieldContent/SelectContent.ts +48 -0
  166. package/src/content/fields/nestable/FieldContent/TextContent.ts +48 -0
  167. package/src/content/fields/nestable/FieldContent/TimestampContent.ts +48 -0
  168. package/src/content/fields/nestable/FieldContent/common.ts +1 -0
  169. package/src/content/fields/nestable/FieldContent/index.ts +40 -0
  170. package/src/content/fields/nestable/GeoPointContent.ts +38 -7
  171. package/src/content/fields/nestable/ImageContent.ts +91 -11
  172. package/src/content/fields/nestable/IntegrationFieldContent.ts +42 -3
  173. package/src/content/fields/nestable/LinkContent.ts +208 -47
  174. package/src/content/fields/nestable/NestableContent.ts +180 -24
  175. package/src/content/fields/nestable/RichTextContent/Blocks.ts +205 -0
  176. package/src/content/fields/nestable/RichTextContent/index.ts +43 -0
  177. package/src/content/fields/nestable/SeparatorContent.ts +26 -3
  178. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +118 -0
  179. package/src/content/fields/slices/{RepeatableContent.ts → Slice/RepeatableContent.ts} +7 -4
  180. package/src/content/fields/slices/Slice/SharedSliceContent.ts +129 -0
  181. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +30 -0
  182. package/src/content/fields/slices/Slice/index.ts +47 -0
  183. package/src/content/fields/slices/SliceItem.ts +83 -0
  184. package/src/content/fields/slices/SlicesContent.ts +47 -19
  185. package/src/content/fields/slices/index.ts +4 -3
  186. package/src/content/index.ts +1 -0
  187. package/src/content/utils.ts +20 -0
  188. package/src/customtypes/CustomType.ts +4 -10
  189. package/src/customtypes/Section.ts +1 -1
  190. package/src/customtypes/index.ts +1 -1
  191. package/src/customtypes/widgets/Group.ts +4 -4
  192. package/src/customtypes/widgets/UID.ts +3 -2
  193. package/src/customtypes/widgets/Widget.ts +53 -7
  194. package/src/customtypes/widgets/index.ts +6 -7
  195. package/src/customtypes/widgets/nestable/BooleanField.ts +7 -8
  196. package/src/customtypes/widgets/nestable/Color.ts +6 -8
  197. package/src/customtypes/widgets/nestable/Date.ts +7 -8
  198. package/src/customtypes/widgets/nestable/Embed.ts +7 -8
  199. package/src/customtypes/widgets/nestable/GeoPoint.ts +7 -8
  200. package/src/customtypes/widgets/nestable/Image.ts +9 -10
  201. package/src/customtypes/widgets/nestable/IntegrationField.ts +6 -8
  202. package/src/customtypes/widgets/nestable/Link.ts +7 -6
  203. package/src/customtypes/widgets/nestable/NestableWidget.ts +17 -18
  204. package/src/customtypes/widgets/nestable/Number.ts +7 -8
  205. package/src/customtypes/widgets/nestable/Range.ts +7 -8
  206. package/src/customtypes/widgets/nestable/RichText.ts +3 -2
  207. package/src/customtypes/widgets/nestable/Select.ts +7 -8
  208. package/src/customtypes/widgets/nestable/Separator.ts +7 -8
  209. package/src/customtypes/widgets/nestable/Text.ts +7 -6
  210. package/src/customtypes/widgets/nestable/Timestamp.ts +7 -8
  211. package/src/customtypes/widgets/nestable/index.ts +15 -15
  212. package/src/customtypes/widgets/slices/CompositeSlice.ts +5 -4
  213. package/src/customtypes/widgets/slices/LegacySlice.ts +1 -1
  214. package/src/customtypes/widgets/slices/SharedSlice.ts +5 -4
  215. package/src/customtypes/widgets/slices/SharedSliceRef.ts +2 -2
  216. package/src/customtypes/widgets/slices/Slices.ts +7 -6
  217. package/src/customtypes/widgets/slices/SlicesTypes.ts +10 -5
  218. package/src/utils/Objects.ts +12 -0
  219. package/src/content/fields/nestable/FieldContent.ts +0 -25
  220. package/src/content/fields/nestable/RichTextContent.ts +0 -32
  221. package/src/content/fields/slices/CompositeSliceContent.ts +0 -14
  222. package/src/content/fields/slices/SharedSliceContent.ts +0 -14
  223. package/src/content/fields/slices/SimpleSliceContent.ts +0 -7
  224. package/src/customtypes/widgets/WidgetTypes.ts +0 -24
  225. package/src/documents/DocumentData.ts +0 -112
  226. package/src/documents/index.ts +0 -2
  227. package/src/documents/widgets/EmptyContent.ts +0 -8
  228. package/src/documents/widgets/GroupContent.ts +0 -91
  229. package/src/documents/widgets/SimpleWidgetContent.ts +0 -96
  230. package/src/documents/widgets/StaticWidgetContent.ts +0 -46
  231. package/src/documents/widgets/UIDContent.ts +0 -18
  232. package/src/documents/widgets/index.ts +0 -70
  233. package/src/documents/widgets/nestable/BooleanContent.ts +0 -21
  234. package/src/documents/widgets/nestable/EmbedContent.ts +0 -56
  235. package/src/documents/widgets/nestable/FieldContent.ts +0 -53
  236. package/src/documents/widgets/nestable/GeoPointContent.ts +0 -18
  237. package/src/documents/widgets/nestable/ImageContent.ts +0 -51
  238. package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +0 -26
  239. package/src/documents/widgets/nestable/Link/DocumentLink.ts +0 -18
  240. package/src/documents/widgets/nestable/Link/ExternalLink.ts +0 -31
  241. package/src/documents/widgets/nestable/Link/FileLink.ts +0 -30
  242. package/src/documents/widgets/nestable/Link/ImageLink.ts +0 -31
  243. package/src/documents/widgets/nestable/Link/LinkContent.ts +0 -25
  244. package/src/documents/widgets/nestable/Link/index.ts +0 -35
  245. package/src/documents/widgets/nestable/SeparatorContent.ts +0 -13
  246. package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +0 -126
  247. package/src/documents/widgets/nestable/StructuredTextContent/index.ts +0 -25
  248. package/src/documents/widgets/nestable/index.ts +0 -35
  249. package/src/documents/widgets/slices/CompositeSliceContent.ts +0 -77
  250. package/src/documents/widgets/slices/SharedSliceContent.ts +0 -94
  251. package/src/documents/widgets/slices/SimpleSliceContent.ts +0 -4
  252. package/src/documents/widgets/slices/SliceWidgetContent.ts +0 -51
  253. package/src/documents/widgets/slices/SlicesContent.ts +0 -91
  254. package/src/documents/widgets/slices/index.ts +0 -5
  255. package/src/index.ts +0 -3
@@ -1,16 +1,47 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/function"
1
3
  import * as t from "io-ts"
2
4
 
3
- import {
4
- GeoPointContent as GeoPointNoType,
5
- GeoPointContentType as type,
6
- } from "../../../documents/widgets/nestable/GeoPointContent"
5
+ import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
6
+ import { hasContentType } from "../../utils"
7
+
8
+ export const GeoPointContentType = "GeoPointContent"
9
+
10
+ export const isGeoPointContent = (u: unknown): u is GeoPointContent =>
11
+ hasContentType(u) && u.__TYPE__ === GeoPointContentType
12
+
13
+ const legacyReader = t.strict({
14
+ position: t.strict({
15
+ lat: t.number,
16
+ lng: t.number,
17
+ }),
18
+ })
19
+ type GeoPointLegacy = t.TypeOf<typeof legacyReader>
20
+
21
+ export const GeoPointLegacy = (ctx: LegacyContentCtx) =>
22
+ new t.Type<GeoPointContent, WithTypes<GeoPointLegacy>, unknown>(
23
+ "GeoPointLegacy",
24
+ isGeoPointContent,
25
+ (u) => {
26
+ return pipe(
27
+ legacyReader.decode(u),
28
+ either.map((geo) =>
29
+ GeoPointContent.encode({ ...geo, __TYPE__: GeoPointContentType }),
30
+ ),
31
+ )
32
+ },
33
+
34
+ (geo: GeoPointContent) => ({
35
+ content: { position: geo.position },
36
+ types: { [ctx.keyOfType]: "GeoPoint" },
37
+ }),
38
+ )
7
39
 
8
40
  export const GeoPointContent = t.intersection([
9
- GeoPointNoType,
41
+ legacyReader,
10
42
  t.strict({
11
- __TYPE__: t.literal(type),
43
+ __TYPE__: t.literal(GeoPointContentType),
12
44
  }),
13
45
  ])
14
46
 
15
47
  export type GeoPointContent = t.TypeOf<typeof GeoPointContent>
16
- export const GeoPointContentType = type
@@ -1,20 +1,100 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
1
3
  import * as t from "io-ts"
2
4
 
3
- import {
4
- ImageContent as ImageNoType,
5
- ImageContentType as type,
6
- ImageContentView as view,
7
- } from "../../../documents/widgets/nestable/ImageContent"
5
+ import { withOptionals } from "../../../utils/Objects"
6
+ import { NonEmptyStringOrNull, StringOrNull } from "../../../validators"
7
+ import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
8
+ import { hasContentType } from "../../utils"
9
+
10
+ export const ImageContentType = "ImageContent"
11
+
12
+ export const isImageContent = (u: unknown): u is ImageContent =>
13
+ hasContentType(u) && u.__TYPE__ === ImageContentType
14
+
15
+ const originReader = t.exact(
16
+ t.type({
17
+ id: t.string,
18
+ url: t.string,
19
+ width: t.number,
20
+ height: t.number,
21
+ }),
22
+ )
23
+
24
+ export const ImageContentView = t.exact(
25
+ t.intersection([
26
+ t.type({
27
+ origin: originReader,
28
+ width: t.number,
29
+ height: t.number,
30
+ edit: t.type({
31
+ zoom: t.number,
32
+ crop: t.type({
33
+ x: t.number,
34
+ y: t.number,
35
+ }),
36
+ background: t.string,
37
+ }),
38
+ }),
39
+ t.partial({
40
+ url: t.string,
41
+ credits: NonEmptyStringOrNull,
42
+ alt: NonEmptyStringOrNull,
43
+ provider: StringOrNull,
44
+ }),
45
+ ]),
46
+ )
47
+ export type ImageContentView = t.TypeOf<typeof ImageContentView>
48
+
49
+ const legacyReader = t.intersection([
50
+ ImageContentView,
51
+ t.partial({
52
+ thumbnails: t.record(t.string, ImageContentView),
53
+ }),
54
+ ])
55
+
56
+ type ImageLegacy = t.TypeOf<typeof legacyReader>
57
+
58
+ export const ImageLegacy = (ctx: LegacyContentCtx) =>
59
+ new t.Type<ImageContent, WithTypes<ImageLegacy>, unknown>(
60
+ "ImageLegacy",
61
+ isImageContent,
62
+ (u) => {
63
+ return pipe(
64
+ legacyReader.decode(u),
65
+ either.map((i) =>
66
+ ImageContent.encode({ ...i, __TYPE__: ImageContentType }),
67
+ ),
68
+ )
69
+ },
70
+
71
+ (i: ImageContent) => {
72
+ return {
73
+ content: withOptionals<ImageLegacy>(
74
+ {
75
+ edit: i.edit,
76
+ height: i.height,
77
+ origin: i.origin,
78
+ width: i.width,
79
+ },
80
+ [
81
+ ["alt", i.alt],
82
+ ["credits", i.credits],
83
+ ["provider", i.provider],
84
+ ["thumbnails", i.thumbnails],
85
+ ["url", i.url],
86
+ ],
87
+ ),
88
+ types: { [ctx.keyOfType]: "Image" },
89
+ }
90
+ },
91
+ )
8
92
 
9
93
  export const ImageContent = t.intersection([
10
- ImageNoType,
94
+ legacyReader,
11
95
  t.strict({
12
- __TYPE__: t.literal(type),
96
+ __TYPE__: t.literal(ImageContentType),
13
97
  }),
14
98
  ])
15
99
 
16
100
  export type ImageContent = t.TypeOf<typeof ImageContent>
17
- export const ImageContentType = type
18
-
19
- export const ImageContentView = view
20
- export type ImageContentView = view
@@ -1,11 +1,50 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
1
3
  import * as t from "io-ts"
2
4
 
3
- import { IntegrationFieldsContentType as type } from "../../../documents/widgets/nestable/IntegrationFieldsContent"
5
+ import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
6
+ import { hasContentType } from "../../utils"
7
+
8
+ export const IntegrationFieldContentType = "IntegrationFieldsContent"
9
+
10
+ export const isIntegrationFieldContent = (
11
+ u: unknown,
12
+ ): u is IntegrationFieldContent =>
13
+ hasContentType(u) && u.__TYPE__ === IntegrationFieldContentType
14
+
15
+ type IntegrationFieldLegacy = string
16
+
17
+ export const IntegrationFieldLegacy = (ctx: LegacyContentCtx) =>
18
+ new t.Type<
19
+ IntegrationFieldContent,
20
+ WithTypes<IntegrationFieldLegacy>,
21
+ unknown
22
+ >(
23
+ "IntegrationFieldLegacy",
24
+ isIntegrationFieldContent,
25
+ (u) => {
26
+ return pipe(
27
+ t.string.decode(u),
28
+ either.map((i) =>
29
+ IntegrationFieldContent.encode({
30
+ value: i,
31
+ __TYPE__: IntegrationFieldContentType,
32
+ }),
33
+ ),
34
+ )
35
+ },
36
+
37
+ (i: IntegrationFieldContent) => {
38
+ return {
39
+ content: i.value,
40
+ types: { [ctx.keyOfType]: "IntegrationFields" },
41
+ }
42
+ },
43
+ )
4
44
 
5
45
  export const IntegrationFieldContent = t.strict({
6
- __TYPE__: t.literal(type),
46
+ __TYPE__: t.literal(IntegrationFieldContentType),
7
47
  value: t.string,
8
48
  })
9
49
 
10
50
  export type IntegrationFieldContent = t.TypeOf<typeof IntegrationFieldContent>
11
- export const IntegrationFieldsContentType = type
@@ -1,80 +1,241 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
1
3
  import * as t from "io-ts"
2
4
  import { withFallback } from "io-ts-types"
3
5
 
4
- import {
5
- DocumentLink,
6
- DocumentLinkType as dlType,
7
- } from "../../../documents/widgets/nestable/Link/DocumentLink"
8
- import {
9
- ExternalLink,
10
- ExternalLinkType as elType,
11
- } from "../../../documents/widgets/nestable/Link/ExternalLink"
12
- import {
13
- FileLink,
14
- FileLinkType as flType,
15
- } from "../../../documents/widgets/nestable/Link/FileLink"
16
- import {
17
- ImageLink,
18
- ImageLinkType as ilType,
19
- } from "../../../documents/widgets/nestable/Link/ImageLink"
20
- import { LinkContentType as lcType } from "../../../documents/widgets/nestable/Link/LinkContent"
6
+ import { NonEmptyString, StringOrNull } from "../../../validators"
7
+ import { nullable } from "../../../validators/function"
8
+ import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
9
+ import { hasContentType } from "../../utils"
10
+
11
+ export const ImageLinkType = "ImageLink"
12
+
13
+ const imageLinkLegacyCodec = t.exact(
14
+ t.intersection([
15
+ t.type({
16
+ id: t.string,
17
+ url: t.string,
18
+ height: t.string,
19
+ width: t.string,
20
+ size: t.string,
21
+ name: t.string,
22
+ kind: t.string,
23
+ }),
24
+ t.partial({
25
+ date: StringOrNull,
26
+ }),
27
+ ]),
28
+ )
29
+ type ImageLinkLegacy = t.TypeOf<typeof imageLinkLegacyCodec>
30
+ const ImageLinkLegacy = new t.Type<ImageLinkContent, ImageLinkLegacy, unknown>(
31
+ "ImageLink",
32
+ (u): u is ImageLinkContent =>
33
+ hasContentType(u) && u.__TYPE__ === ImageLinkType,
34
+ (image) => {
35
+ return pipe(
36
+ imageLinkLegacyCodec.decode(image),
37
+ either.map((parsedImage) => {
38
+ return ImageLinkContent.encode({
39
+ ...parsedImage,
40
+ __TYPE__: ImageLinkType,
41
+ })
42
+ }),
43
+ )
44
+ },
45
+ (image: ImageLinkContent): ImageLinkLegacy => {
46
+ return imageLinkLegacyCodec.encode(image)
47
+ },
48
+ )
21
49
 
22
50
  export const ImageLinkContent = t.intersection([
23
51
  t.strict({
24
- __TYPE__: t.literal(ilType),
52
+ __TYPE__: t.literal(ImageLinkType),
25
53
  }),
26
- ImageLink,
54
+ imageLinkLegacyCodec,
27
55
  ])
28
56
  export type ImageLinkContent = t.TypeOf<typeof ImageLinkContent>
29
- export const ImageLinkType = ilType
30
57
 
31
- export const FileLinkContent = t.intersection([
32
- FileLink,
33
- t.exact(
58
+ export const FileLinkType = "FileLink"
59
+
60
+ const fileLinkLegacyCodec = t.exact(
61
+ t.intersection([
34
62
  t.type({
35
- __TYPE__: t.literal(flType),
63
+ id: t.string,
64
+ url: t.string,
65
+ name: t.string,
66
+ kind: t.string,
67
+ }),
68
+ t.partial({
69
+ date: nullable(t.string),
36
70
  size: withFallback(t.string, "0"),
37
71
  }),
72
+ ]),
73
+ )
74
+ type FileLinkLegacy = t.TypeOf<typeof fileLinkLegacyCodec>
75
+ const FileLinkLegacy = new t.Type<FileLinkContent, FileLinkLegacy>(
76
+ "FileLink",
77
+ (u): u is FileLinkContent => hasContentType(u) && u.__TYPE__ === FileLinkType,
78
+ (file) => {
79
+ return pipe(
80
+ fileLinkLegacyCodec.decode(file),
81
+ either.map((parsedFile) => {
82
+ return FileLinkContent.encode({
83
+ ...parsedFile,
84
+ __TYPE__: FileLinkType,
85
+ })
86
+ }),
87
+ )
88
+ },
89
+ (file: FileLinkContent): FileLinkLegacy => {
90
+ return fileLinkLegacyCodec.encode(file)
91
+ },
92
+ )
93
+
94
+ export const FileLinkContent = t.intersection([
95
+ fileLinkLegacyCodec,
96
+ t.exact(
97
+ t.intersection([
98
+ t.type({
99
+ __TYPE__: t.literal(FileLinkType),
100
+ }),
101
+ t.partial({
102
+ size: withFallback(t.string, "0"),
103
+ }),
104
+ ]),
38
105
  ),
39
106
  ])
40
107
  export type FileLinkContent = t.TypeOf<typeof FileLinkContent>
41
- export const FileLinkType = flType
42
108
 
109
+ export const DocumentLinkType = "DocumentLink"
110
+
111
+ const documentLinkLegacyCodec = t.strict({ id: NonEmptyString })
112
+ type DocumentLinkLegacy = t.TypeOf<typeof documentLinkLegacyCodec>
113
+ const DocumentLinkLegacy = new t.Type<DocumentLinkContent, DocumentLinkLegacy>(
114
+ "DocumentLink",
115
+ (u): u is DocumentLinkContent =>
116
+ hasContentType(u) && u.__TYPE__ === DocumentLinkType,
117
+ (file) => {
118
+ return pipe(
119
+ documentLinkLegacyCodec.decode(file),
120
+ either.map((parsedDoc) => {
121
+ return DocumentLinkContent.encode({
122
+ ...parsedDoc,
123
+ __TYPE__: DocumentLinkType,
124
+ })
125
+ }),
126
+ )
127
+ },
128
+ (doc: DocumentLinkContent): DocumentLinkLegacy => {
129
+ return documentLinkLegacyCodec.encode(doc)
130
+ },
131
+ )
43
132
  export const DocumentLinkContent = t.intersection([
44
133
  t.strict({
45
- __TYPE__: t.literal(dlType),
134
+ __TYPE__: t.literal(DocumentLinkType),
46
135
  }),
47
- DocumentLink,
136
+ documentLinkLegacyCodec,
48
137
  ])
49
138
  export type DocumentLinkContent = t.TypeOf<typeof DocumentLinkContent>
50
- export const DocumentLinkType = dlType
139
+
140
+ export const ExternalLinkType = "ExternalLink"
141
+
142
+ const externalLinkLegacyCodec = t.exact(
143
+ t.intersection([
144
+ t.type({
145
+ url: t.string,
146
+ }),
147
+ t.partial({
148
+ kind: t.literal("web"),
149
+ target: StringOrNull,
150
+ preview: nullable(
151
+ t.partial({
152
+ title: t.string,
153
+ }),
154
+ ),
155
+ }),
156
+ ]),
157
+ )
158
+
159
+ type ExternalLinkLegacy = t.TypeOf<typeof externalLinkLegacyCodec>
160
+ const ExternalLinkLegacy = new t.Type<ExternalLinkContent, ExternalLinkLegacy>(
161
+ "ExternalLink",
162
+ (u): u is ExternalLinkContent =>
163
+ hasContentType(u) && u.__TYPE__ === ExternalLinkType,
164
+ (file) => {
165
+ return pipe(
166
+ externalLinkLegacyCodec.decode(file),
167
+ either.map((parsedLink) => {
168
+ return ExternalLinkContent.encode({
169
+ ...parsedLink,
170
+ __TYPE__: ExternalLinkType,
171
+ })
172
+ }),
173
+ )
174
+ },
175
+ (link: ExternalLinkContent): ExternalLinkLegacy => {
176
+ return externalLinkLegacyCodec.encode(link)
177
+ },
178
+ )
51
179
 
52
180
  export const ExternalLinkContent = t.intersection([
53
181
  t.strict({
54
- __TYPE__: t.literal(elType),
182
+ __TYPE__: t.literal(ExternalLinkType),
55
183
  }),
56
- ExternalLink,
184
+ externalLinkLegacyCodec,
57
185
  ])
58
186
  export type ExternalLinkContent = t.TypeOf<typeof ExternalLinkContent>
59
- export const ExternalLinkType = elType
60
187
 
188
+ export const LinkContentType = "LinkContent"
189
+
190
+ export const isLinkContent = (u: unknown): u is LinkContent =>
191
+ hasContentType(u) && u.__TYPE__ === LinkContentType
192
+
193
+ export const LinkLegacy = t.union([
194
+ ImageLinkLegacy,
195
+ FileLinkLegacy,
196
+ DocumentLinkLegacy,
197
+ ExternalLinkLegacy,
198
+ ])
199
+
200
+ type LinkLegacy = t.OutputOf<typeof LinkLegacy>
201
+
202
+ export const LinkContentLegacy = (ctx: LegacyContentCtx) =>
203
+ new t.Type<LinkContent, WithTypes<LinkLegacy>, unknown>(
204
+ "LinkLegacy",
205
+ isLinkContent,
206
+ (u) => {
207
+ return pipe(
208
+ LinkLegacy.decode(u),
209
+ either.map((link) =>
210
+ LinkContent.encode({
211
+ value: link,
212
+ __TYPE__: LinkContentType,
213
+ }),
214
+ ),
215
+ )
216
+ },
217
+
218
+ (link: LinkContent): WithTypes<LinkLegacy> => {
219
+ return {
220
+ content: LinkLegacy.encode(link.value),
221
+ types: { [ctx.keyOfType]: "Link" },
222
+ }
223
+ },
224
+ )
225
+
226
+ export const Link = t.union([
227
+ ImageLinkContent,
228
+ FileLinkContent,
229
+ DocumentLinkContent,
230
+ ExternalLinkContent,
231
+ ])
61
232
  export const LinkContent = t.strict({
62
- __TYPE__: t.literal(lcType),
63
- value: t.union([
64
- ImageLinkContent,
65
- FileLinkContent,
66
- DocumentLinkContent,
67
- ExternalLinkContent,
68
- ]),
233
+ __TYPE__: t.literal(LinkContentType),
234
+ value: Link,
69
235
  })
70
236
 
71
237
  export type LinkContent = t.TypeOf<typeof LinkContent>
72
- export const LinkContentType = lcType
73
-
74
- export const LinksTypes = {
75
- DocumentLink: DocumentLinkType,
76
- FileLink: FileLinkType,
77
- ExternalLink: ExternalLinkType,
78
- ImageLink: ImageLinkType,
79
- LinkContent: LinkContentType,
80
- } as const
238
+
239
+ export type LinksTypes =
240
+ | LinkContent["__TYPE__"]
241
+ | LinkContent["value"]["__TYPE__"]