@prismicio/types-internal 1.5.2 → 2.0.0-alpha.0

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 (254) 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 +6 -7
  88. package/lib/customtypes/diff/Variation.d.ts +10 -7
  89. package/lib/customtypes/widgets/Group.d.ts +1 -0
  90. package/lib/customtypes/widgets/Group.js +6 -5
  91. package/lib/customtypes/widgets/UID.d.ts +1 -0
  92. package/lib/customtypes/widgets/UID.js +3 -2
  93. package/lib/customtypes/widgets/Widget.d.ts +384 -362
  94. package/lib/customtypes/widgets/Widget.js +29 -8
  95. package/lib/customtypes/widgets/index.d.ts +6 -7
  96. package/lib/customtypes/widgets/index.js +6 -11
  97. package/lib/customtypes/widgets/nestable/BooleanField.d.ts +10 -3
  98. package/lib/customtypes/widgets/nestable/BooleanField.js +6 -6
  99. package/lib/customtypes/widgets/nestable/Color.d.ts +8 -3
  100. package/lib/customtypes/widgets/nestable/Color.js +6 -6
  101. package/lib/customtypes/widgets/nestable/Date.d.ts +9 -3
  102. package/lib/customtypes/widgets/nestable/Date.js +6 -6
  103. package/lib/customtypes/widgets/nestable/Embed.d.ts +9 -3
  104. package/lib/customtypes/widgets/nestable/Embed.js +6 -6
  105. package/lib/customtypes/widgets/nestable/GeoPoint.d.ts +7 -3
  106. package/lib/customtypes/widgets/nestable/GeoPoint.js +6 -6
  107. package/lib/customtypes/widgets/nestable/Image.d.ts +25 -3
  108. package/lib/customtypes/widgets/nestable/Image.js +8 -8
  109. package/lib/customtypes/widgets/nestable/IntegrationField.d.ts +9 -3
  110. package/lib/customtypes/widgets/nestable/IntegrationField.js +6 -6
  111. package/lib/customtypes/widgets/nestable/Link.d.ts +14 -2
  112. package/lib/customtypes/widgets/nestable/Link.js +7 -6
  113. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +3 -3
  114. package/lib/customtypes/widgets/nestable/NestableWidget.js +30 -30
  115. package/lib/customtypes/widgets/nestable/Number.d.ts +11 -3
  116. package/lib/customtypes/widgets/nestable/Number.js +6 -6
  117. package/lib/customtypes/widgets/nestable/Range.d.ts +11 -3
  118. package/lib/customtypes/widgets/nestable/Range.js +6 -6
  119. package/lib/customtypes/widgets/nestable/RichText.d.ts +1 -0
  120. package/lib/customtypes/widgets/nestable/RichText.js +3 -3
  121. package/lib/customtypes/widgets/nestable/Select.d.ts +10 -3
  122. package/lib/customtypes/widgets/nestable/Select.js +6 -6
  123. package/lib/customtypes/widgets/nestable/Separator.d.ts +7 -3
  124. package/lib/customtypes/widgets/nestable/Separator.js +6 -6
  125. package/lib/customtypes/widgets/nestable/Text.d.ts +9 -2
  126. package/lib/customtypes/widgets/nestable/Text.js +7 -6
  127. package/lib/customtypes/widgets/nestable/Timestamp.d.ts +9 -3
  128. package/lib/customtypes/widgets/nestable/Timestamp.js +6 -6
  129. package/lib/customtypes/widgets/nestable/index.d.ts +15 -15
  130. package/lib/customtypes/widgets/nestable/index.js +15 -31
  131. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +1 -0
  132. package/lib/customtypes/widgets/slices/CompositeSlice.js +7 -6
  133. package/lib/customtypes/widgets/slices/LegacySlice.js +2 -2
  134. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +1 -0
  135. package/lib/customtypes/widgets/slices/SharedSlice.js +7 -7
  136. package/lib/customtypes/widgets/slices/SharedSliceRef.js +2 -2
  137. package/lib/customtypes/widgets/slices/Slices.d.ts +364 -362
  138. package/lib/customtypes/widgets/slices/Slices.js +8 -8
  139. package/lib/customtypes/widgets/slices/SlicesTypes.d.ts +6 -5
  140. package/lib/customtypes/widgets/slices/SlicesTypes.js +8 -4
  141. package/lib/documents/DocumentData.d.ts +3 -14
  142. package/lib/documents/DocumentData.js +5 -60
  143. package/lib/documents/widgets/nestable/ImageContent.d.ts +1 -1
  144. package/lib/documents/widgets/nestable/ImageContent.js +2 -2
  145. package/lib/utils/Objects.d.ts +1 -0
  146. package/lib/utils/Objects.js +10 -1
  147. package/package.json +1 -1
  148. package/src/common/WidgetKey.ts +13 -0
  149. package/src/common/index.ts +1 -0
  150. package/src/content/Document.ts +129 -16
  151. package/src/content/LegacyContentCtx.ts +57 -0
  152. package/src/content/fields/EmptyContent.ts +45 -0
  153. package/src/content/fields/GroupContent.ts +103 -8
  154. package/src/content/fields/UIDContent.ts +33 -3
  155. package/src/content/fields/WidgetContent.ts +76 -0
  156. package/src/content/fields/index.ts +1 -23
  157. package/src/content/fields/nestable/BooleanContent.ts +32 -3
  158. package/src/content/fields/nestable/EmbedContent.ts +79 -8
  159. package/src/content/fields/nestable/FieldContent/ColorContent.ts +48 -0
  160. package/src/content/fields/nestable/FieldContent/DateContent.ts +48 -0
  161. package/src/content/fields/nestable/FieldContent/NumberContent.ts +48 -0
  162. package/src/content/fields/nestable/FieldContent/RangeContent.ts +48 -0
  163. package/src/content/fields/nestable/FieldContent/SelectContent.ts +48 -0
  164. package/src/content/fields/nestable/FieldContent/TextContent.ts +48 -0
  165. package/src/content/fields/nestable/FieldContent/TimestampContent.ts +48 -0
  166. package/src/content/fields/nestable/FieldContent/common.ts +1 -0
  167. package/src/content/fields/nestable/FieldContent/index.ts +40 -0
  168. package/src/content/fields/nestable/GeoPointContent.ts +38 -7
  169. package/src/content/fields/nestable/ImageContent.ts +91 -11
  170. package/src/content/fields/nestable/IntegrationFieldContent.ts +42 -3
  171. package/src/content/fields/nestable/LinkContent.ts +208 -47
  172. package/src/content/fields/nestable/NestableContent.ts +180 -24
  173. package/src/content/fields/nestable/RichTextContent/Blocks.ts +205 -0
  174. package/src/content/fields/nestable/RichTextContent/index.ts +43 -0
  175. package/src/content/fields/nestable/SeparatorContent.ts +26 -3
  176. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +118 -0
  177. package/src/content/fields/slices/{RepeatableContent.ts → Slice/RepeatableContent.ts} +7 -4
  178. package/src/content/fields/slices/Slice/SharedSliceContent.ts +129 -0
  179. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +30 -0
  180. package/src/content/fields/slices/Slice/index.ts +47 -0
  181. package/src/content/fields/slices/SliceItem.ts +83 -0
  182. package/src/content/fields/slices/SlicesContent.ts +47 -19
  183. package/src/content/fields/slices/index.ts +4 -3
  184. package/src/content/index.ts +1 -0
  185. package/src/content/utils.ts +20 -0
  186. package/src/customtypes/CustomType.ts +4 -10
  187. package/src/customtypes/Section.ts +1 -1
  188. package/src/customtypes/diff/SharedSlice.ts +2 -2
  189. package/src/customtypes/diff/Variation.ts +8 -2
  190. package/src/customtypes/widgets/Group.ts +4 -4
  191. package/src/customtypes/widgets/UID.ts +3 -2
  192. package/src/customtypes/widgets/Widget.ts +53 -7
  193. package/src/customtypes/widgets/index.ts +6 -7
  194. package/src/customtypes/widgets/nestable/BooleanField.ts +7 -8
  195. package/src/customtypes/widgets/nestable/Color.ts +6 -8
  196. package/src/customtypes/widgets/nestable/Date.ts +7 -8
  197. package/src/customtypes/widgets/nestable/Embed.ts +7 -8
  198. package/src/customtypes/widgets/nestable/GeoPoint.ts +7 -8
  199. package/src/customtypes/widgets/nestable/Image.ts +9 -10
  200. package/src/customtypes/widgets/nestable/IntegrationField.ts +6 -8
  201. package/src/customtypes/widgets/nestable/Link.ts +7 -6
  202. package/src/customtypes/widgets/nestable/NestableWidget.ts +17 -18
  203. package/src/customtypes/widgets/nestable/Number.ts +7 -8
  204. package/src/customtypes/widgets/nestable/Range.ts +7 -8
  205. package/src/customtypes/widgets/nestable/RichText.ts +3 -2
  206. package/src/customtypes/widgets/nestable/Select.ts +7 -8
  207. package/src/customtypes/widgets/nestable/Separator.ts +7 -8
  208. package/src/customtypes/widgets/nestable/Text.ts +7 -6
  209. package/src/customtypes/widgets/nestable/Timestamp.ts +7 -8
  210. package/src/customtypes/widgets/nestable/index.ts +15 -15
  211. package/src/customtypes/widgets/slices/CompositeSlice.ts +5 -4
  212. package/src/customtypes/widgets/slices/LegacySlice.ts +1 -1
  213. package/src/customtypes/widgets/slices/SharedSlice.ts +5 -4
  214. package/src/customtypes/widgets/slices/SharedSliceRef.ts +2 -2
  215. package/src/customtypes/widgets/slices/Slices.ts +7 -6
  216. package/src/customtypes/widgets/slices/SlicesTypes.ts +10 -5
  217. package/src/utils/Objects.ts +12 -0
  218. package/src/content/fields/nestable/FieldContent.ts +0 -25
  219. package/src/content/fields/nestable/RichTextContent.ts +0 -32
  220. package/src/content/fields/slices/CompositeSliceContent.ts +0 -14
  221. package/src/content/fields/slices/SharedSliceContent.ts +0 -14
  222. package/src/content/fields/slices/SimpleSliceContent.ts +0 -7
  223. package/src/customtypes/widgets/WidgetTypes.ts +0 -24
  224. package/src/documents/DocumentData.ts +0 -112
  225. package/src/documents/index.ts +0 -2
  226. package/src/documents/widgets/EmptyContent.ts +0 -8
  227. package/src/documents/widgets/GroupContent.ts +0 -91
  228. package/src/documents/widgets/SimpleWidgetContent.ts +0 -96
  229. package/src/documents/widgets/StaticWidgetContent.ts +0 -46
  230. package/src/documents/widgets/UIDContent.ts +0 -18
  231. package/src/documents/widgets/index.ts +0 -70
  232. package/src/documents/widgets/nestable/BooleanContent.ts +0 -21
  233. package/src/documents/widgets/nestable/EmbedContent.ts +0 -56
  234. package/src/documents/widgets/nestable/FieldContent.ts +0 -53
  235. package/src/documents/widgets/nestable/GeoPointContent.ts +0 -18
  236. package/src/documents/widgets/nestable/ImageContent.ts +0 -51
  237. package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +0 -26
  238. package/src/documents/widgets/nestable/Link/DocumentLink.ts +0 -18
  239. package/src/documents/widgets/nestable/Link/ExternalLink.ts +0 -31
  240. package/src/documents/widgets/nestable/Link/FileLink.ts +0 -30
  241. package/src/documents/widgets/nestable/Link/ImageLink.ts +0 -31
  242. package/src/documents/widgets/nestable/Link/LinkContent.ts +0 -25
  243. package/src/documents/widgets/nestable/Link/index.ts +0 -35
  244. package/src/documents/widgets/nestable/SeparatorContent.ts +0 -13
  245. package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +0 -126
  246. package/src/documents/widgets/nestable/StructuredTextContent/index.ts +0 -25
  247. package/src/documents/widgets/nestable/index.ts +0 -35
  248. package/src/documents/widgets/slices/CompositeSliceContent.ts +0 -77
  249. package/src/documents/widgets/slices/SharedSliceContent.ts +0 -94
  250. package/src/documents/widgets/slices/SimpleSliceContent.ts +0 -4
  251. package/src/documents/widgets/slices/SliceWidgetContent.ts +0 -51
  252. package/src/documents/widgets/slices/SlicesContent.ts +0 -91
  253. package/src/documents/widgets/slices/index.ts +0 -5
  254. package/src/index.ts +0 -3
@@ -1,11 +1,41 @@
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 { UIDContentType as type } from "../../documents/widgets/UIDContent"
5
+ import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx"
6
+ import { hasContentType } from "../utils"
7
+
8
+ export const UIDContentType = "UIDContent"
9
+
10
+ export const isUIDContent = (u: unknown): u is UIDContent =>
11
+ hasContentType(u) && u.__TYPE__ === UIDContentType
12
+
13
+ type UIDLegacy = string
14
+
15
+ export const UIDLegacy = (ctx: LegacyContentCtx) =>
16
+ new t.Type<UIDContent, WithTypes<UIDLegacy>, unknown>(
17
+ "UIDLegacy",
18
+ isUIDContent,
19
+ (u) => {
20
+ return pipe(
21
+ t.string.decode(u),
22
+ either.map((uid) =>
23
+ UIDContent.encode({ value: uid, __TYPE__: UIDContentType }),
24
+ ),
25
+ )
26
+ },
27
+
28
+ (uid: UIDContent) => {
29
+ return {
30
+ content: uid.value,
31
+ types: { [ctx.keyOfType]: "UID" },
32
+ }
33
+ },
34
+ )
4
35
 
5
36
  export const UIDContent = t.type({
6
- __TYPE__: t.literal(type),
37
+ __TYPE__: t.literal(UIDContentType),
7
38
  value: t.string,
8
39
  })
9
40
 
10
41
  export type UIDContent = t.TypeOf<typeof UIDContent>
11
- export const UIDContentType = type
@@ -0,0 +1,76 @@
1
+ import * as t from "io-ts"
2
+
3
+ import type { LegacyContentCtx } from "../LegacyContentCtx"
4
+ import {
5
+ GroupContent,
6
+ GroupContentType,
7
+ GroupLegacy,
8
+ isGroupContent,
9
+ } from "./GroupContent"
10
+ import { isNestableContent, NestableContent, NestableLegacy } from "./nestable"
11
+ import {
12
+ isSlicesContent,
13
+ SlicesContent,
14
+ SlicesContentType,
15
+ SlicesLegacy,
16
+ } from "./slices"
17
+ import {
18
+ isUIDContent,
19
+ UIDContent,
20
+ UIDContentType,
21
+ UIDLegacy,
22
+ } from "./UIDContent"
23
+
24
+ export const WidgetContent = t.union([
25
+ GroupContent,
26
+ NestableContent,
27
+ UIDContent,
28
+ SlicesContent,
29
+ ])
30
+
31
+ export const isWidgetContent = (u: unknown): u is WidgetContent =>
32
+ isGroupContent(u) ||
33
+ isNestableContent(u) ||
34
+ isUIDContent(u) ||
35
+ isSlicesContent(u)
36
+
37
+ export type WidgetContent = t.TypeOf<typeof WidgetContent>
38
+ export type WidgetTypes = WidgetContent["__TYPE__"]
39
+
40
+ export const WidgetLegacy = (ctx: LegacyContentCtx) => {
41
+ return {
42
+ decode(value: unknown) {
43
+ if (!ctx.fieldType) return
44
+
45
+ const codec = (() => {
46
+ switch (ctx.fieldType) {
47
+ case "UID":
48
+ return UIDLegacy(ctx)
49
+ case "Group":
50
+ return GroupLegacy(ctx)
51
+ case "Choice":
52
+ case "Slices":
53
+ return SlicesLegacy(ctx)
54
+ default:
55
+ return NestableLegacy(ctx)
56
+ }
57
+ })()
58
+
59
+ if (!codec) return
60
+
61
+ return codec.decode(value)
62
+ },
63
+ encode(value: WidgetContent) {
64
+ switch (value.__TYPE__) {
65
+ case UIDContentType:
66
+ return UIDLegacy(ctx).encode(value)
67
+ case GroupContentType:
68
+ return GroupLegacy(ctx).encode(value)
69
+ case SlicesContentType:
70
+ return SlicesLegacy(ctx).encode(value)
71
+ default:
72
+ return NestableLegacy(ctx).encode(value)
73
+ }
74
+ },
75
+ }
76
+ }
@@ -1,27 +1,5 @@
1
- import * as t from "io-ts"
2
-
3
- import { GroupContent, GroupContentType } from "./GroupContent"
4
- import { NestableContent, NestableTypes } from "./nestable"
5
- import { SlicesContent, SlicesContentType } from "./slices"
6
- import { UIDContent, UIDContentType } from "./UIDContent"
7
-
8
1
  export * from "./GroupContent"
9
2
  export * from "./nestable"
10
3
  export * from "./slices"
11
4
  export * from "./UIDContent"
12
-
13
- export const WidgetContent = t.union([
14
- GroupContent,
15
- NestableContent,
16
- UIDContent,
17
- SlicesContent,
18
- ])
19
-
20
- export type WidgetContent = t.TypeOf<typeof WidgetContent>
21
-
22
- export const WidgetTypes = {
23
- ...NestableTypes,
24
- UID: UIDContentType,
25
- Group: GroupContentType,
26
- slices: SlicesContentType,
27
- } as const
5
+ export * from "./WidgetContent"
@@ -1,11 +1,40 @@
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 { BooleanContentType as type } from "../../../documents/widgets/nestable/BooleanContent"
5
+ import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
6
+ import { hasContentType } from "../../utils"
7
+
8
+ export const BooleanContentType = "BooleanContent"
9
+ export const isBooleanContent = (u: unknown): u is BooleanContent =>
10
+ hasContentType(u) && u.__TYPE__ === BooleanContentType
11
+
12
+ type BooleanLegacy = boolean
13
+
14
+ export const BooleanLegacy = (ctx: LegacyContentCtx) =>
15
+ new t.Type<BooleanContent, WithTypes<BooleanLegacy>, unknown>(
16
+ "BooleanLegacy",
17
+ isBooleanContent,
18
+ (u) => {
19
+ return pipe(
20
+ t.boolean.decode(u),
21
+ either.map((b) =>
22
+ BooleanContent.encode({ value: b, __TYPE__: BooleanContentType }),
23
+ ),
24
+ )
25
+ },
26
+
27
+ (b: BooleanContent) => {
28
+ return {
29
+ content: b.value,
30
+ types: { [ctx.keyOfType]: "Boolean" },
31
+ }
32
+ },
33
+ )
4
34
 
5
35
  export const BooleanContent = t.strict({
6
- __TYPE__: t.literal(type),
36
+ __TYPE__: t.literal(BooleanContentType),
7
37
  value: t.boolean,
8
38
  })
9
39
 
10
40
  export type BooleanContent = t.TypeOf<typeof BooleanContent>
11
- export const BooleanContentType = type
@@ -1,17 +1,88 @@
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
- EmbedContentC as EmbedNoType,
5
- EmbedContentType as type,
6
- } from "../../../documents/widgets/nestable/EmbedContent"
5
+ import { withOptionals } from "../../../utils/Objects"
6
+ import { NumberOrNull, StringOrNull } from "../../../validators"
7
+ import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
8
+ import { hasContentType } from "../../utils"
9
+
10
+ export const EmbedContentType = "EmbedContent"
11
+
12
+ export const isEmbedContent = (u: unknown): u is EmbedContent =>
13
+ hasContentType(u) && u.__TYPE__ === EmbedContentType
14
+
15
+ export const EmbedContentLegacy = t.exact(
16
+ t.intersection([
17
+ t.type({
18
+ embed_url: t.string,
19
+ type: t.string,
20
+ }),
21
+ t.partial({
22
+ version: t.union([t.string, t.number, t.null]),
23
+ title: StringOrNull,
24
+ author_name: StringOrNull,
25
+ author_url: StringOrNull,
26
+ provider_name: StringOrNull,
27
+ provider_url: StringOrNull,
28
+ cache_age: t.union([t.string, t.number, t.null]),
29
+ thumbnail_url: StringOrNull,
30
+ thumbnail_width: NumberOrNull,
31
+ thumbnail_height: NumberOrNull,
32
+ html: StringOrNull,
33
+ }),
34
+ ]),
35
+ )
36
+
37
+ export type EmbedLegacy = t.TypeOf<typeof EmbedContentLegacy>
38
+
39
+ export const EmbedLegacy = (ctx: LegacyContentCtx) =>
40
+ new t.Type<EmbedContent, WithTypes<EmbedLegacy>, unknown>(
41
+ "EmbedLegacy",
42
+ isEmbedContent,
43
+ (u) => {
44
+ return pipe(
45
+ EmbedContentLegacy.decode(u),
46
+ either.map((embed) =>
47
+ EmbedContent.encode({
48
+ ...embed,
49
+ __TYPE__: EmbedContentType,
50
+ }),
51
+ ),
52
+ )
53
+ },
54
+
55
+ (embed: EmbedContent) => {
56
+ return {
57
+ content: withOptionals<EmbedLegacy>(
58
+ {
59
+ embed_url: embed.embed_url,
60
+ type: embed.type,
61
+ },
62
+ [
63
+ ["author_name", embed.author_name],
64
+ ["author_url", embed.author_url],
65
+ ["cache_age", embed.cache_age],
66
+ ["html", embed.html],
67
+ ["provider_name", embed.provider_name],
68
+ ["provider_url", embed.provider_url],
69
+ ["thumbnail_height", embed.thumbnail_height],
70
+ ["thumbnail_width", embed.thumbnail_width],
71
+ ["thumbnail_url", embed.thumbnail_url],
72
+ ["title", embed.title],
73
+ ["version", embed.version],
74
+ ],
75
+ ),
76
+ types: { [ctx.keyOfType]: "Embed" },
77
+ }
78
+ },
79
+ )
7
80
 
8
81
  export const EmbedContent = t.intersection([
9
- EmbedNoType,
82
+ EmbedContentLegacy,
10
83
  t.strict({
11
- __TYPE__: t.literal(type),
12
- all: t.unknown,
84
+ __TYPE__: t.literal(EmbedContentType),
13
85
  }),
14
86
  ])
15
87
 
16
88
  export type EmbedContent = t.TypeOf<typeof EmbedContent>
17
- export const EmbedContentType = type
@@ -0,0 +1,48 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
3
+ import * as t from "io-ts"
4
+
5
+ import { ColorFieldType } from "../../../../customtypes/widgets"
6
+ import TrimmedString from "../../../../validators/TrimmedString"
7
+ import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
8
+ import { hasContentType, hasFieldContentType } from "../../../utils"
9
+ import { FieldContentType } from "./common"
10
+
11
+ export const isColorContent = (u: unknown): u is ColorContent =>
12
+ hasContentType(u) &&
13
+ u.__TYPE__ === FieldContentType &&
14
+ hasFieldContentType(u) &&
15
+ u.type === "Color"
16
+
17
+ export const ColorLegacy = (ctx: LegacyContentCtx) =>
18
+ new t.Type<ColorContent, WithTypes<string>, unknown>(
19
+ "ColorLegacy",
20
+ isColorContent,
21
+ (u) => {
22
+ return pipe(
23
+ TrimmedString.decode(u),
24
+ either.map((f) =>
25
+ ColorContent.encode({
26
+ value: f,
27
+ type: ColorFieldType,
28
+ __TYPE__: FieldContentType,
29
+ }),
30
+ ),
31
+ )
32
+ },
33
+
34
+ (b: ColorContent) => {
35
+ return {
36
+ content: b.value,
37
+ types: { [ctx.keyOfType]: ColorFieldType },
38
+ }
39
+ },
40
+ )
41
+
42
+ export const ColorContent = t.strict({
43
+ type: t.literal(ColorFieldType),
44
+ value: TrimmedString,
45
+ __TYPE__: t.literal(FieldContentType),
46
+ })
47
+
48
+ export type ColorContent = t.TypeOf<typeof ColorContent>
@@ -0,0 +1,48 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
3
+ import * as t from "io-ts"
4
+
5
+ import { DateFieldType } from "../../../../customtypes/widgets"
6
+ import TrimmedString from "../../../../validators/TrimmedString"
7
+ import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
8
+ import { hasContentType, hasFieldContentType } from "../../../utils"
9
+ import { FieldContentType } from "./common"
10
+
11
+ export const isDateContent = (u: unknown): u is DateContent =>
12
+ hasContentType(u) &&
13
+ u.__TYPE__ === FieldContentType &&
14
+ hasFieldContentType(u) &&
15
+ u.type === "Date"
16
+
17
+ export const DateLegacy = (ctx: LegacyContentCtx) =>
18
+ new t.Type<DateContent, WithTypes<string>, unknown>(
19
+ "DateLegacy",
20
+ isDateContent,
21
+ (u) => {
22
+ return pipe(
23
+ TrimmedString.decode(u),
24
+ either.map((f) =>
25
+ DateContent.encode({
26
+ value: f,
27
+ type: DateFieldType,
28
+ __TYPE__: FieldContentType,
29
+ }),
30
+ ),
31
+ )
32
+ },
33
+
34
+ (b: DateContent) => {
35
+ return {
36
+ content: b.value,
37
+ types: { [ctx.keyOfType]: DateFieldType },
38
+ }
39
+ },
40
+ )
41
+
42
+ export const DateContent = t.strict({
43
+ type: t.literal(DateFieldType),
44
+ value: TrimmedString,
45
+ __TYPE__: t.literal(FieldContentType),
46
+ })
47
+
48
+ export type DateContent = t.TypeOf<typeof DateContent>
@@ -0,0 +1,48 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
3
+ import * as t from "io-ts"
4
+
5
+ import { NumberFieldType } from "../../../../customtypes/widgets"
6
+ import TrimmedString from "../../../../validators/TrimmedString"
7
+ import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
8
+ import { hasContentType, hasFieldContentType } from "../../../utils"
9
+ import { FieldContentType } from "./common"
10
+
11
+ export const isNumberContent = (u: unknown): u is NumberContent =>
12
+ hasContentType(u) &&
13
+ u.__TYPE__ === FieldContentType &&
14
+ hasFieldContentType(u) &&
15
+ u.type === "Number"
16
+
17
+ export const NumberLegacy = (ctx: LegacyContentCtx) =>
18
+ new t.Type<NumberContent, WithTypes<string>, unknown>(
19
+ "NumberLegacy",
20
+ isNumberContent,
21
+ (u) => {
22
+ return pipe(
23
+ TrimmedString.decode(u),
24
+ either.map((f) =>
25
+ NumberContent.encode({
26
+ value: f,
27
+ type: NumberFieldType,
28
+ __TYPE__: FieldContentType,
29
+ }),
30
+ ),
31
+ )
32
+ },
33
+
34
+ (b: NumberContent) => {
35
+ return {
36
+ content: b.value,
37
+ types: { [ctx.keyOfType]: NumberFieldType },
38
+ }
39
+ },
40
+ )
41
+
42
+ export const NumberContent = t.strict({
43
+ type: t.literal(NumberFieldType),
44
+ value: TrimmedString,
45
+ __TYPE__: t.literal(FieldContentType),
46
+ })
47
+
48
+ export type NumberContent = t.TypeOf<typeof NumberContent>
@@ -0,0 +1,48 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
3
+ import * as t from "io-ts"
4
+
5
+ import { RangeFieldType } from "../../../../customtypes/widgets"
6
+ import TrimmedString from "../../../../validators/TrimmedString"
7
+ import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
8
+ import { hasContentType, hasFieldContentType } from "../../../utils"
9
+ import { FieldContentType } from "./common"
10
+
11
+ export const isRangeContent = (u: unknown): u is RangeContent =>
12
+ hasContentType(u) &&
13
+ u.__TYPE__ === FieldContentType &&
14
+ hasFieldContentType(u) &&
15
+ u.type === "Range"
16
+
17
+ export const RangeLegacy = (ctx: LegacyContentCtx) =>
18
+ new t.Type<RangeContent, WithTypes<string>, unknown>(
19
+ "RangeLegacy",
20
+ isRangeContent,
21
+ (u) => {
22
+ return pipe(
23
+ TrimmedString.decode(u),
24
+ either.map((f) =>
25
+ RangeContent.encode({
26
+ value: f,
27
+ type: RangeFieldType,
28
+ __TYPE__: FieldContentType,
29
+ }),
30
+ ),
31
+ )
32
+ },
33
+
34
+ (b: RangeContent) => {
35
+ return {
36
+ content: b.value,
37
+ types: { [ctx.keyOfType]: RangeFieldType },
38
+ }
39
+ },
40
+ )
41
+
42
+ export const RangeContent = t.strict({
43
+ type: t.literal(RangeFieldType),
44
+ value: TrimmedString,
45
+ __TYPE__: t.literal(FieldContentType),
46
+ })
47
+
48
+ export type RangeContent = t.TypeOf<typeof RangeContent>
@@ -0,0 +1,48 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
3
+ import * as t from "io-ts"
4
+
5
+ import { SelectFieldType } from "../../../../customtypes/widgets"
6
+ import TrimmedString from "../../../../validators/TrimmedString"
7
+ import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
8
+ import { hasContentType, hasFieldContentType } from "../../../utils"
9
+ import { FieldContentType } from "./common"
10
+
11
+ export const isSelectContent = (u: unknown): u is SelectContent =>
12
+ hasContentType(u) &&
13
+ u.__TYPE__ === FieldContentType &&
14
+ hasFieldContentType(u) &&
15
+ u.type === "Select"
16
+
17
+ export const SelectLegacy = (ctx: LegacyContentCtx) =>
18
+ new t.Type<SelectContent, WithTypes<string>, unknown>(
19
+ "SelectLegacy",
20
+ isSelectContent,
21
+ (u) => {
22
+ return pipe(
23
+ TrimmedString.decode(u),
24
+ either.map((f) =>
25
+ SelectContent.encode({
26
+ value: f,
27
+ type: SelectFieldType,
28
+ __TYPE__: FieldContentType,
29
+ }),
30
+ ),
31
+ )
32
+ },
33
+
34
+ (b: SelectContent) => {
35
+ return {
36
+ content: b.value,
37
+ types: { [ctx.keyOfType]: SelectFieldType },
38
+ }
39
+ },
40
+ )
41
+
42
+ export const SelectContent = t.strict({
43
+ type: t.literal(SelectFieldType),
44
+ value: TrimmedString,
45
+ __TYPE__: t.literal(FieldContentType),
46
+ })
47
+
48
+ export type SelectContent = t.TypeOf<typeof SelectContent>
@@ -0,0 +1,48 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
3
+ import * as t from "io-ts"
4
+
5
+ import { TextFieldType } from "../../../../customtypes/widgets"
6
+ import TrimmedString from "../../../../validators/TrimmedString"
7
+ import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
8
+ import { hasContentType, hasFieldContentType } from "../../../utils"
9
+ import { FieldContentType } from "./common"
10
+
11
+ export const isTextContent = (u: unknown): u is TextContent =>
12
+ hasContentType(u) &&
13
+ u.__TYPE__ === FieldContentType &&
14
+ hasFieldContentType(u) &&
15
+ u.type === "Text"
16
+
17
+ export const TextLegacy = (ctx: LegacyContentCtx) =>
18
+ new t.Type<TextContent, WithTypes<string>, unknown>(
19
+ "TextLegacy",
20
+ isTextContent,
21
+ (u) => {
22
+ return pipe(
23
+ TrimmedString.decode(u),
24
+ either.map((f) =>
25
+ TextContent.encode({
26
+ value: f,
27
+ type: TextFieldType,
28
+ __TYPE__: FieldContentType,
29
+ }),
30
+ ),
31
+ )
32
+ },
33
+
34
+ (b: TextContent) => {
35
+ return {
36
+ content: b.value,
37
+ types: { [ctx.keyOfType]: TextFieldType },
38
+ }
39
+ },
40
+ )
41
+
42
+ export const TextContent = t.strict({
43
+ type: t.literal(TextFieldType),
44
+ value: TrimmedString,
45
+ __TYPE__: t.literal(FieldContentType),
46
+ })
47
+
48
+ export type TextContent = t.TypeOf<typeof TextContent>
@@ -0,0 +1,48 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
3
+ import * as t from "io-ts"
4
+
5
+ import { TimestampFieldType } from "../../../../customtypes/widgets"
6
+ import TrimmedString from "../../../../validators/TrimmedString"
7
+ import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
8
+ import { hasContentType, hasFieldContentType } from "../../../utils"
9
+ import { FieldContentType } from "./common"
10
+
11
+ export const isTimestampContent = (u: unknown): u is TimestampContent =>
12
+ hasContentType(u) &&
13
+ u.__TYPE__ === FieldContentType &&
14
+ hasFieldContentType(u) &&
15
+ u.type === "Timestamp"
16
+
17
+ export const TimestampLegacy = (ctx: LegacyContentCtx) =>
18
+ new t.Type<TimestampContent, WithTypes<string>, unknown>(
19
+ "TimestampLegacy",
20
+ isTimestampContent,
21
+ (u) => {
22
+ return pipe(
23
+ TrimmedString.decode(u),
24
+ either.map((f) =>
25
+ TimestampContent.encode({
26
+ value: f,
27
+ type: TimestampFieldType,
28
+ __TYPE__: FieldContentType,
29
+ }),
30
+ ),
31
+ )
32
+ },
33
+
34
+ (b: TimestampContent) => {
35
+ return {
36
+ content: b.value,
37
+ types: { [ctx.keyOfType]: TimestampFieldType },
38
+ }
39
+ },
40
+ )
41
+
42
+ export const TimestampContent = t.strict({
43
+ type: t.literal(TimestampFieldType),
44
+ value: TrimmedString,
45
+ __TYPE__: t.literal(FieldContentType),
46
+ })
47
+
48
+ export type TimestampContent = t.TypeOf<typeof TimestampContent>
@@ -0,0 +1 @@
1
+ export const FieldContentType = "FieldContent"
@@ -0,0 +1,40 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { ColorContent } from "./ColorContent"
4
+ import { DateContent } from "./DateContent"
5
+ import { NumberContent } from "./NumberContent"
6
+ import { RangeContent } from "./RangeContent"
7
+ import { SelectContent } from "./SelectContent"
8
+ import { TextContent } from "./TextContent"
9
+ import { TimestampContent } from "./TimestampContent"
10
+
11
+ export const FieldType = t.keyof({
12
+ Text: null,
13
+ Date: null,
14
+ Timestamp: null,
15
+ Color: null,
16
+ Number: null,
17
+ Range: null,
18
+ Select: null,
19
+ })
20
+ export type FieldType = t.TypeOf<typeof FieldType>
21
+
22
+ export const FieldContent = t.union([
23
+ DateContent,
24
+ ColorContent,
25
+ NumberContent,
26
+ RangeContent,
27
+ SelectContent,
28
+ TextContent,
29
+ TimestampContent,
30
+ ])
31
+ export type FieldContent = t.TypeOf<typeof FieldContent>
32
+
33
+ export * from "./ColorContent"
34
+ export * from "./common"
35
+ export * from "./DateContent"
36
+ export * from "./NumberContent"
37
+ export * from "./RangeContent"
38
+ export * from "./SelectContent"
39
+ export * from "./TextContent"
40
+ export * from "./TimestampContent"