@prismicio/types-internal 0.1.1 → 0.2.3

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 (292) hide show
  1. package/README.md +13 -13
  2. package/{dist → lib}/customtypes/CustomType.d.ts +697 -715
  3. package/{dist → lib}/customtypes/CustomType.js +42 -52
  4. package/{dist → lib}/customtypes/Format.d.ts +0 -0
  5. package/{dist → lib}/customtypes/Format.js +0 -0
  6. package/{dist → lib}/customtypes/Section.d.ts +1035 -1062
  7. package/lib/customtypes/Section.js +21 -0
  8. package/lib/customtypes/index.d.ts +4 -0
  9. package/lib/customtypes/index.js +9 -0
  10. package/{dist → lib}/customtypes/widgets/Group.d.ts +45 -45
  11. package/lib/customtypes/widgets/Group.js +24 -0
  12. package/{dist → lib}/customtypes/widgets/UID.d.ts +4 -4
  13. package/lib/customtypes/widgets/UID.js +21 -0
  14. package/{dist → lib}/customtypes/widgets/Widget.d.ts +1036 -1063
  15. package/lib/customtypes/widgets/Widget.js +27 -0
  16. package/{dist → lib}/customtypes/widgets/WidgetTypes.d.ts +0 -0
  17. package/{dist → lib}/customtypes/widgets/WidgetTypes.js +0 -0
  18. package/lib/customtypes/widgets/index.d.ts +7 -0
  19. package/lib/customtypes/widgets/index.js +14 -0
  20. package/{dist → lib}/customtypes/widgets/nestable/BooleanField.d.ts +3 -3
  21. package/lib/customtypes/widgets/nestable/BooleanField.js +21 -0
  22. package/{dist → lib}/customtypes/widgets/nestable/Color.d.ts +4 -4
  23. package/lib/customtypes/widgets/nestable/Color.js +20 -0
  24. package/{dist → lib}/customtypes/widgets/nestable/Date.d.ts +4 -4
  25. package/lib/customtypes/widgets/nestable/Date.js +21 -0
  26. package/{dist → lib}/customtypes/widgets/nestable/Embed.d.ts +4 -4
  27. package/lib/customtypes/widgets/nestable/Embed.js +21 -0
  28. package/{dist → lib}/customtypes/widgets/nestable/GeoPoint.d.ts +4 -4
  29. package/lib/customtypes/widgets/nestable/GeoPoint.js +19 -0
  30. package/lib/customtypes/widgets/nestable/Image.d.ts +23 -0
  31. package/lib/customtypes/widgets/nestable/Image.js +29 -0
  32. package/{dist → lib}/customtypes/widgets/nestable/IntegrationField.d.ts +4 -4
  33. package/lib/customtypes/widgets/nestable/IntegrationField.js +21 -0
  34. package/{dist → lib}/customtypes/widgets/nestable/Link.d.ts +4 -4
  35. package/lib/customtypes/widgets/nestable/Link.js +54 -0
  36. package/{dist → lib}/customtypes/widgets/nestable/NestableWidget.d.ts +42 -42
  37. package/lib/customtypes/widgets/nestable/NestableWidget.js +37 -0
  38. package/{dist → lib}/customtypes/widgets/nestable/Number.d.ts +4 -4
  39. package/lib/customtypes/widgets/nestable/Number.js +24 -0
  40. package/{dist → lib}/customtypes/widgets/nestable/Range.d.ts +4 -4
  41. package/lib/customtypes/widgets/nestable/Range.js +24 -0
  42. package/{dist → lib}/customtypes/widgets/nestable/RichText.d.ts +6 -6
  43. package/lib/customtypes/widgets/nestable/RichText.js +111 -0
  44. package/lib/customtypes/widgets/nestable/Select.d.ts +15 -0
  45. package/lib/customtypes/widgets/nestable/Select.js +22 -0
  46. package/{dist → lib}/customtypes/widgets/nestable/Separator.d.ts +3 -3
  47. package/lib/customtypes/widgets/nestable/Separator.js +18 -0
  48. package/{dist → lib}/customtypes/widgets/nestable/Text.d.ts +4 -4
  49. package/lib/customtypes/widgets/nestable/Text.js +21 -0
  50. package/{dist → lib}/customtypes/widgets/nestable/Timestamp.d.ts +4 -4
  51. package/lib/customtypes/widgets/nestable/Timestamp.js +21 -0
  52. package/lib/customtypes/widgets/nestable/index.d.ts +15 -0
  53. package/{dist → lib}/customtypes/widgets/nestable/index.js +0 -0
  54. package/{dist → lib}/customtypes/widgets/shared/ImageConstraint.d.ts +3 -3
  55. package/lib/customtypes/widgets/shared/ImageConstraint.js +31 -0
  56. package/lib/customtypes/widgets/shared/index.d.ts +1 -0
  57. package/{dist → lib}/customtypes/widgets/shared/index.js +0 -0
  58. package/{dist → lib}/customtypes/widgets/slices/CompositeSlice.d.ts +87 -87
  59. package/lib/customtypes/widgets/slices/CompositeSlice.js +25 -0
  60. package/{dist → lib}/customtypes/widgets/slices/LegacySlice.d.ts +86 -95
  61. package/lib/customtypes/widgets/slices/LegacySlice.js +8 -0
  62. package/{dist → lib}/customtypes/widgets/slices/SharedSlice.d.ts +84 -84
  63. package/lib/customtypes/widgets/slices/SharedSlice.js +35 -0
  64. package/{dist → lib}/customtypes/widgets/slices/SharedSliceRef.d.ts +2 -2
  65. package/lib/customtypes/widgets/slices/SharedSliceRef.js +9 -0
  66. package/lib/customtypes/widgets/slices/Slice.d.ts +6 -0
  67. package/{dist → lib}/customtypes/widgets/slices/Slice.js +0 -0
  68. package/{dist → lib}/customtypes/widgets/slices/Slices.d.ts +1550 -1604
  69. package/lib/customtypes/widgets/slices/Slices.js +93 -0
  70. package/{dist → lib}/customtypes/widgets/slices/SlicesTypes.d.ts +0 -0
  71. package/{dist → lib}/customtypes/widgets/slices/SlicesTypes.js +0 -0
  72. package/lib/customtypes/widgets/slices/index.d.ts +7 -0
  73. package/lib/customtypes/widgets/slices/index.js +16 -0
  74. package/lib/documents/DocumentData.d.ts +8 -0
  75. package/lib/documents/DocumentData.js +28 -0
  76. package/lib/documents/index.d.ts +2 -0
  77. package/lib/documents/index.js +7 -0
  78. package/lib/documents/widgets/EmptyContent.d.ts +8 -0
  79. package/lib/documents/widgets/EmptyContent.js +9 -0
  80. package/lib/documents/widgets/GroupContent.d.ts +16 -0
  81. package/lib/documents/widgets/GroupContent.js +59 -0
  82. package/lib/documents/widgets/SimpleWidgetContent.d.ts +20 -0
  83. package/lib/documents/widgets/SimpleWidgetContent.js +75 -0
  84. package/lib/documents/widgets/StaticWidgetContent.d.ts +10 -0
  85. package/lib/documents/widgets/StaticWidgetContent.js +26 -0
  86. package/lib/documents/widgets/UIDContent.d.ts +7 -0
  87. package/lib/documents/widgets/UIDContent.js +10 -0
  88. package/lib/documents/widgets/index.d.ts +35 -0
  89. package/lib/documents/widgets/index.js +36 -0
  90. package/lib/documents/widgets/nestable/BooleanContent.d.ts +8 -0
  91. package/lib/documents/widgets/nestable/BooleanContent.js +11 -0
  92. package/lib/documents/widgets/nestable/EmbedContent.d.ts +40 -0
  93. package/lib/documents/widgets/nestable/EmbedContent.js +36 -0
  94. package/lib/documents/widgets/nestable/FieldContent.d.ts +12 -0
  95. package/lib/documents/widgets/nestable/FieldContent.js +37 -0
  96. package/lib/documents/widgets/nestable/GeoPointContent.d.ts +17 -0
  97. package/lib/documents/widgets/nestable/GeoPointContent.js +13 -0
  98. package/lib/documents/widgets/nestable/ImageContent.d.ts +127 -0
  99. package/lib/documents/widgets/nestable/ImageContent.js +41 -0
  100. package/lib/documents/widgets/nestable/IntegrationFieldsContent.d.ts +8 -0
  101. package/lib/documents/widgets/nestable/IntegrationFieldsContent.js +16 -0
  102. package/lib/documents/widgets/nestable/Link/DocumentLink.d.ts +12 -0
  103. package/lib/documents/widgets/nestable/Link/DocumentLink.js +13 -0
  104. package/lib/documents/widgets/nestable/Link/ExternalLink.d.ts +24 -0
  105. package/lib/documents/widgets/nestable/Link/ExternalLink.js +24 -0
  106. package/lib/documents/widgets/nestable/Link/FileLink.d.ts +22 -0
  107. package/lib/documents/widgets/nestable/Link/FileLink.js +24 -0
  108. package/lib/documents/widgets/nestable/Link/ImageLink.d.ts +28 -0
  109. package/lib/documents/widgets/nestable/Link/ImageLink.js +26 -0
  110. package/lib/documents/widgets/nestable/Link/LinkContent.d.ts +36 -0
  111. package/lib/documents/widgets/nestable/Link/LinkContent.js +13 -0
  112. package/lib/documents/widgets/nestable/Link/index.d.ts +89 -0
  113. package/lib/documents/widgets/nestable/Link/index.js +35 -0
  114. package/lib/documents/widgets/nestable/SeparatorContent.d.ts +7 -0
  115. package/lib/documents/widgets/nestable/SeparatorContent.js +10 -0
  116. package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +274 -0
  117. package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +97 -0
  118. package/lib/documents/widgets/nestable/StructuredTextContent/index.d.ts +9 -0
  119. package/lib/documents/widgets/nestable/StructuredTextContent/index.js +14 -0
  120. package/lib/documents/widgets/nestable/index.d.ts +26 -0
  121. package/lib/documents/widgets/nestable/index.js +40 -0
  122. package/lib/documents/widgets/slices/CompositeSliceContent.d.ts +14 -0
  123. package/lib/documents/widgets/slices/CompositeSliceContent.js +50 -0
  124. package/lib/documents/widgets/slices/SharedSliceContent.d.ts +15 -0
  125. package/lib/documents/widgets/slices/SharedSliceContent.js +62 -0
  126. package/lib/documents/widgets/slices/SimpleSliceContent.d.ts +6 -0
  127. package/lib/documents/widgets/slices/SimpleSliceContent.js +6 -0
  128. package/lib/documents/widgets/slices/SliceWidgetContent.d.ts +8 -0
  129. package/lib/documents/widgets/slices/SliceWidgetContent.js +26 -0
  130. package/lib/documents/widgets/slices/SlicesContent.d.ts +17 -0
  131. package/lib/documents/widgets/slices/SlicesContent.js +51 -0
  132. package/lib/documents/widgets/slices/index.d.ts +5 -0
  133. package/lib/documents/widgets/slices/index.js +8 -0
  134. package/lib/index.d.ts +3 -0
  135. package/lib/index.js +7 -0
  136. package/lib/validators/DateFromString.d.ts +3 -0
  137. package/lib/validators/DateFromString.js +10 -0
  138. package/lib/validators/DateFromStringOrNumber.d.ts +3 -0
  139. package/lib/validators/DateFromStringOrNumber.js +10 -0
  140. package/lib/validators/DateFromTsMs.d.ts +3 -0
  141. package/lib/validators/DateFromTsMs.js +10 -0
  142. package/lib/validators/IntFromNumber.d.ts +5 -0
  143. package/lib/validators/IntFromNumber.js +14 -0
  144. package/lib/validators/IntFromPixels.d.ts +8 -0
  145. package/lib/validators/IntFromPixels.js +24 -0
  146. package/lib/validators/NonEmptyString.d.ts +3 -0
  147. package/lib/validators/NonEmptyString.js +6 -0
  148. package/lib/validators/NonEmptyStringOrNull.d.ts +3 -0
  149. package/lib/validators/NonEmptyStringOrNull.js +15 -0
  150. package/lib/validators/NumberOrNull.d.ts +3 -0
  151. package/lib/validators/NumberOrNull.js +6 -0
  152. package/lib/validators/StringFromBoolean.d.ts +5 -0
  153. package/lib/validators/StringFromBoolean.js +10 -0
  154. package/lib/validators/StringFromNumber.d.ts +5 -0
  155. package/lib/validators/StringFromNumber.js +10 -0
  156. package/lib/validators/StringOrNull.d.ts +3 -0
  157. package/lib/validators/StringOrNull.js +6 -0
  158. package/lib/validators/function.d.ts +14 -0
  159. package/lib/validators/function.js +60 -0
  160. package/lib/validators/index.d.ts +12 -0
  161. package/lib/validators/index.js +27 -0
  162. package/package.json +30 -18
  163. package/src/customtypes/CustomType.ts +173 -116
  164. package/src/customtypes/Format.ts +3 -3
  165. package/src/customtypes/Section.ts +26 -13
  166. package/src/customtypes/index.ts +4 -4
  167. package/src/customtypes/widgets/Group.ts +21 -20
  168. package/src/customtypes/widgets/UID.ts +18 -17
  169. package/src/customtypes/widgets/Widget.ts +22 -23
  170. package/src/customtypes/widgets/WidgetTypes.ts +21 -21
  171. package/src/customtypes/widgets/index.ts +7 -7
  172. package/src/customtypes/widgets/nestable/BooleanField.ts +19 -19
  173. package/src/customtypes/widgets/nestable/Color.ts +17 -16
  174. package/src/customtypes/widgets/nestable/Date.ts +19 -18
  175. package/src/customtypes/widgets/nestable/Embed.ts +19 -18
  176. package/src/customtypes/widgets/nestable/GeoPoint.ts +17 -16
  177. package/src/customtypes/widgets/nestable/Image.ts +26 -26
  178. package/src/customtypes/widgets/nestable/IntegrationField.ts +18 -17
  179. package/src/customtypes/widgets/nestable/Link.ts +80 -68
  180. package/src/customtypes/widgets/nestable/NestableWidget.ts +32 -32
  181. package/src/customtypes/widgets/nestable/Number.ts +22 -21
  182. package/src/customtypes/widgets/nestable/Range.ts +22 -21
  183. package/src/customtypes/widgets/nestable/RichText.ts +164 -134
  184. package/src/customtypes/widgets/nestable/Select.ts +22 -21
  185. package/src/customtypes/widgets/nestable/Separator.ts +15 -14
  186. package/src/customtypes/widgets/nestable/Text.ts +18 -17
  187. package/src/customtypes/widgets/nestable/Timestamp.ts +19 -18
  188. package/src/customtypes/widgets/nestable/index.ts +15 -15
  189. package/src/customtypes/widgets/shared/ImageConstraint.ts +31 -29
  190. package/src/customtypes/widgets/shared/index.ts +1 -1
  191. package/src/customtypes/widgets/slices/CompositeSlice.ts +21 -21
  192. package/src/customtypes/widgets/slices/LegacySlice.ts +5 -10
  193. package/src/customtypes/widgets/slices/SharedSlice.ts +33 -31
  194. package/src/customtypes/widgets/slices/SharedSliceRef.ts +6 -6
  195. package/src/customtypes/widgets/slices/Slice.ts +4 -4
  196. package/src/customtypes/widgets/slices/Slices.ts +95 -73
  197. package/src/customtypes/widgets/slices/SlicesTypes.ts +3 -3
  198. package/src/customtypes/widgets/slices/index.ts +7 -7
  199. package/src/documents/DocumentData.ts +54 -0
  200. package/src/documents/index.ts +2 -0
  201. package/src/documents/widgets/EmptyContent.ts +8 -0
  202. package/src/documents/widgets/GroupContent.ts +91 -0
  203. package/src/documents/widgets/SimpleWidgetContent.ts +96 -0
  204. package/src/documents/widgets/StaticWidgetContent.ts +46 -0
  205. package/src/documents/widgets/UIDContent.ts +18 -0
  206. package/src/documents/widgets/index.ts +56 -0
  207. package/src/documents/widgets/nestable/BooleanContent.ts +21 -0
  208. package/src/documents/widgets/nestable/EmbedContent.ts +54 -0
  209. package/src/documents/widgets/nestable/FieldContent.ts +45 -0
  210. package/src/documents/widgets/nestable/GeoPointContent.ts +18 -0
  211. package/src/documents/widgets/nestable/ImageContent.ts +51 -0
  212. package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +26 -0
  213. package/src/documents/widgets/nestable/Link/DocumentLink.ts +18 -0
  214. package/src/documents/widgets/nestable/Link/ExternalLink.ts +31 -0
  215. package/src/documents/widgets/nestable/Link/FileLink.ts +29 -0
  216. package/src/documents/widgets/nestable/Link/ImageLink.ts +31 -0
  217. package/src/documents/widgets/nestable/Link/LinkContent.ts +22 -0
  218. package/src/documents/widgets/nestable/Link/index.ts +33 -0
  219. package/src/documents/widgets/nestable/SeparatorContent.ts +8 -0
  220. package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +122 -0
  221. package/src/documents/widgets/nestable/StructuredTextContent/index.ts +25 -0
  222. package/src/documents/widgets/nestable/index.ts +35 -0
  223. package/src/documents/widgets/slices/CompositeSliceContent.ts +77 -0
  224. package/src/documents/widgets/slices/SharedSliceContent.ts +94 -0
  225. package/src/documents/widgets/slices/SimpleSliceContent.ts +4 -0
  226. package/src/documents/widgets/slices/SliceWidgetContent.ts +51 -0
  227. package/src/documents/widgets/slices/SlicesContent.ts +91 -0
  228. package/src/documents/widgets/slices/index.ts +5 -0
  229. package/src/index.ts +3 -1
  230. package/src/validators/DateFromString.ts +17 -0
  231. package/src/validators/DateFromStringOrNumber.ts +17 -0
  232. package/src/validators/DateFromTsMs.ts +17 -0
  233. package/src/validators/IntFromNumber.ts +22 -24
  234. package/src/validators/IntFromPixels.ts +27 -26
  235. package/src/validators/NonEmptyString.ts +9 -0
  236. package/src/validators/NonEmptyStringOrNull.ts +22 -0
  237. package/src/validators/NumberOrNull.ts +5 -0
  238. package/src/validators/StringFromBoolean.ts +17 -19
  239. package/src/validators/StringFromNumber.ts +17 -19
  240. package/src/validators/StringOrNull.ts +4 -2
  241. package/src/validators/function.ts +71 -0
  242. package/src/validators/index.ts +12 -0
  243. package/dist/customtypes/Section.js +0 -40
  244. package/dist/customtypes/index.d.ts +0 -4
  245. package/dist/customtypes/index.js +0 -30
  246. package/dist/customtypes/widgets/Group.js +0 -45
  247. package/dist/customtypes/widgets/UID.js +0 -42
  248. package/dist/customtypes/widgets/Widget.js +0 -51
  249. package/dist/customtypes/widgets/index.d.ts +0 -7
  250. package/dist/customtypes/widgets/index.js +0 -35
  251. package/dist/customtypes/widgets/nestable/BooleanField.js +0 -42
  252. package/dist/customtypes/widgets/nestable/Color.js +0 -41
  253. package/dist/customtypes/widgets/nestable/Date.js +0 -42
  254. package/dist/customtypes/widgets/nestable/Embed.js +0 -42
  255. package/dist/customtypes/widgets/nestable/GeoPoint.js +0 -40
  256. package/dist/customtypes/widgets/nestable/Image.d.ts +0 -23
  257. package/dist/customtypes/widgets/nestable/Image.js +0 -50
  258. package/dist/customtypes/widgets/nestable/IntegrationField.js +0 -42
  259. package/dist/customtypes/widgets/nestable/Link.js +0 -78
  260. package/dist/customtypes/widgets/nestable/NestableWidget.js +0 -58
  261. package/dist/customtypes/widgets/nestable/Number.js +0 -45
  262. package/dist/customtypes/widgets/nestable/Range.js +0 -45
  263. package/dist/customtypes/widgets/nestable/RichText.js +0 -134
  264. package/dist/customtypes/widgets/nestable/Select.d.ts +0 -15
  265. package/dist/customtypes/widgets/nestable/Select.js +0 -45
  266. package/dist/customtypes/widgets/nestable/Separator.js +0 -39
  267. package/dist/customtypes/widgets/nestable/Text.js +0 -42
  268. package/dist/customtypes/widgets/nestable/Timestamp.js +0 -42
  269. package/dist/customtypes/widgets/nestable/index.d.ts +0 -15
  270. package/dist/customtypes/widgets/shared/ImageConstraint.js +0 -48
  271. package/dist/customtypes/widgets/shared/index.d.ts +0 -1
  272. package/dist/customtypes/widgets/slices/CompositeSlice.js +0 -46
  273. package/dist/customtypes/widgets/slices/LegacySlice.js +0 -34
  274. package/dist/customtypes/widgets/slices/SharedSlice.js +0 -56
  275. package/dist/customtypes/widgets/slices/SharedSliceRef.js +0 -30
  276. package/dist/customtypes/widgets/slices/Slice.d.ts +0 -6
  277. package/dist/customtypes/widgets/slices/Slices.js +0 -106
  278. package/dist/customtypes/widgets/slices/index.d.ts +0 -7
  279. package/dist/customtypes/widgets/slices/index.js +0 -37
  280. package/dist/index.d.ts +0 -1
  281. package/dist/index.js +0 -23
  282. package/dist/index.js.map +0 -1
  283. package/dist/validators/IntFromNumber.d.ts +0 -7
  284. package/dist/validators/IntFromNumber.js +0 -35
  285. package/dist/validators/IntFromPixels.d.ts +0 -7
  286. package/dist/validators/IntFromPixels.js +0 -43
  287. package/dist/validators/StringFromBoolean.d.ts +0 -7
  288. package/dist/validators/StringFromBoolean.js +0 -31
  289. package/dist/validators/StringFromNumber.d.ts +0 -7
  290. package/dist/validators/StringFromNumber.js +0 -31
  291. package/dist/validators/StringOrNull.d.ts +0 -2
  292. package/dist/validators/StringOrNull.js +0 -24
@@ -1,32 +1,32 @@
1
- import * as t from 'io-ts'
1
+ import * as t from "io-ts"
2
2
 
3
- import SlicesTypes from './SlicesTypes'
3
+ import { StringOrNull } from "../../../validators"
4
4
  import NestableWidget from "../nestable/NestableWidget"
5
- import { StringOrNull } from '../../../validators/StringOrNull'
5
+ import SlicesTypes from "./SlicesTypes"
6
6
 
7
7
  const CompositeSliceConfig = t.exact(
8
- t.partial({
9
- label: StringOrNull
10
- })
8
+ t.partial({
9
+ label: StringOrNull,
10
+ }),
11
11
  )
12
12
  type CompositeSliceConfig = t.TypeOf<typeof CompositeSliceConfig>
13
13
 
14
14
  const CompositeSlice = t.exact(
15
- t.intersection([
16
- t.type({
17
- type: t.literal(SlicesTypes.Slice)
18
- }),
19
- t.partial({
20
- fieldset: StringOrNull,
21
- description: t.string,
22
- icon: t.string,
23
- display: t.string,
24
- 'non-repeat': t.record(t.string, NestableWidget),
25
- repeat: t.record(t.string, NestableWidget),
26
- config: CompositeSliceConfig
27
- })
28
- ])
15
+ t.intersection([
16
+ t.type({
17
+ type: t.literal(SlicesTypes.Slice),
18
+ }),
19
+ t.partial({
20
+ fieldset: StringOrNull,
21
+ description: t.string,
22
+ icon: t.string,
23
+ display: t.string,
24
+ "non-repeat": t.record(t.string, NestableWidget),
25
+ repeat: t.record(t.string, NestableWidget),
26
+ config: CompositeSliceConfig,
27
+ }),
28
+ ]),
29
29
  )
30
30
  type CompositeSlice = t.TypeOf<typeof CompositeSlice>
31
31
 
32
- export default CompositeSlice
32
+ export default CompositeSlice
@@ -1,15 +1,10 @@
1
- import * as t from 'io-ts'
1
+ import * as t from "io-ts"
2
2
 
3
- import UID from '../UID'
4
- import NestableWidget from '../nestable/NestableWidget'
5
- import Group from '../Group'
3
+ import Group from "../Group"
4
+ import NestableWidget from "../nestable/NestableWidget"
6
5
 
7
- const LegacySlice = t.union([
8
- UID,
9
- NestableWidget,
10
- Group
11
- ])
6
+ const LegacySlice = t.union([NestableWidget, Group])
12
7
 
13
8
  type LegacySlice = t.TypeOf<typeof LegacySlice>
14
9
 
15
- export default LegacySlice
10
+ export default LegacySlice
@@ -1,42 +1,44 @@
1
- import * as t from 'io-ts'
2
- import { withFallback } from 'io-ts-types/lib/withFallback'
3
- import NestableWidget from '../nestable/NestableWidget'
4
- import SlicesTypes from './SlicesTypes'
1
+ import * as t from "io-ts"
2
+ import { withFallback } from "io-ts-types/lib/withFallback"
5
3
 
6
- const IMAGE_PLACEHOLDER_URL = 'https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format'
4
+ import NestableWidget from "../nestable/NestableWidget"
5
+ import SlicesTypes from "./SlicesTypes"
6
+
7
+ const IMAGE_PLACEHOLDER_URL =
8
+ "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"
7
9
 
8
10
  const Variation = t.exact(
9
- t.intersection([
10
- t.type({
11
- id: t.string,
12
- name: t.string,
13
- description: t.string,
14
- imageUrl: withFallback(t.string, IMAGE_PLACEHOLDER_URL),
15
- docURL: t.string,
16
- version: t.string
17
- }),
18
- t.partial({
19
- display: t.string,
20
- primary: t.record(t.string, NestableWidget),
21
- items: t.record(t.string, NestableWidget)
22
- })
23
- ])
11
+ t.intersection([
12
+ t.type({
13
+ id: t.string,
14
+ name: t.string,
15
+ description: t.string,
16
+ imageUrl: withFallback(t.string, IMAGE_PLACEHOLDER_URL),
17
+ docURL: t.string,
18
+ version: t.string,
19
+ }),
20
+ t.partial({
21
+ display: t.string,
22
+ primary: t.record(t.string, NestableWidget),
23
+ items: t.record(t.string, NestableWidget),
24
+ }),
25
+ ]),
24
26
  )
25
27
 
26
28
  type Variation = t.TypeOf<typeof Variation>
27
29
 
28
30
  const SharedSlice = t.exact(
29
- t.intersection([
30
- t.type({
31
- id: t.string,
32
- type: t.literal(SlicesTypes.SharedSlice),
33
- name: t.string,
34
- variations: t.array(Variation)
35
- }),
36
- t.partial({
37
- description: t.string
38
- })
39
- ])
31
+ t.intersection([
32
+ t.type({
33
+ id: t.string,
34
+ type: t.literal(SlicesTypes.SharedSlice),
35
+ name: t.string,
36
+ variations: t.array(Variation),
37
+ }),
38
+ t.partial({
39
+ description: t.string,
40
+ }),
41
+ ]),
40
42
  )
41
43
 
42
44
  type SharedSlice = t.TypeOf<typeof SharedSlice>
@@ -1,12 +1,12 @@
1
- import * as t from 'io-ts'
1
+ import * as t from "io-ts"
2
2
 
3
- import SlicesTypes from './SlicesTypes'
3
+ import SlicesTypes from "./SlicesTypes"
4
4
 
5
5
  const SharedSliceRef = t.exact(
6
- t.type({
7
- type: t.literal(SlicesTypes.SharedSlice)
8
- })
6
+ t.type({
7
+ type: t.literal(SlicesTypes.SharedSlice),
8
+ }),
9
9
  )
10
10
  type SharedSliceRef = t.TypeOf<typeof SharedSliceRef>
11
11
 
12
- export default SharedSliceRef
12
+ export default SharedSliceRef
@@ -1,7 +1,7 @@
1
- import SharedSlice from "./SharedSlice";
2
- import CompositeSlice from "./CompositeSlice";
3
- import LegacySlice from "./LegacySlice";
4
- import SharedSliceRef from "./SharedSliceRef";
1
+ import type CompositeSlice from "./CompositeSlice"
2
+ import type LegacySlice from "./LegacySlice"
3
+ import type SharedSlice from "./SharedSlice"
4
+ import type SharedSliceRef from "./SharedSliceRef"
5
5
 
6
6
  export type DynamicSlice = CompositeSlice | LegacySlice | SharedSliceRef
7
7
  export type StaticSlice = CompositeSlice | LegacySlice | SharedSlice
@@ -1,51 +1,60 @@
1
- import * as t from 'io-ts'
2
- import { StringOrNull } from '../../../validators/StringOrNull'
3
- import WidgetTypes from '../WidgetTypes'
4
- import { Format } from '../../Format'
5
- import LegacySlice from './LegacySlice'
6
- import CompositeSlice from './CompositeSlice'
7
- import SharedSliceRef from './SharedSliceRef'
8
- import SharedSlice from './SharedSlice'
9
- import SlicesTypes from './SlicesTypes'
1
+ import * as t from "io-ts"
2
+
3
+ import { StringOrNull } from "../../../validators"
4
+ import { Format } from "../../Format"
5
+ import WidgetTypes from "../WidgetTypes"
6
+ import CompositeSlice from "./CompositeSlice"
7
+ import LegacySlice from "./LegacySlice"
8
+ import SharedSlice from "./SharedSlice"
9
+ import SharedSliceRef from "./SharedSliceRef"
10
+ import SlicesTypes from "./SlicesTypes"
10
11
 
11
12
  const SlicesLabels = t.union([
12
- t.record(
13
- t.string,
14
- t.array(
15
- t.exact(
16
- t.intersection([
17
- t.type({
18
- name: t.string
19
- }),
20
- t.partial({
21
- display: t.string
22
- })
23
- ])
24
- )
25
- )
26
- ),
27
- t.null
13
+ t.record(
14
+ t.string,
15
+ t.array(
16
+ t.exact(
17
+ t.intersection([
18
+ t.type({
19
+ name: t.string,
20
+ }),
21
+ t.partial({
22
+ display: t.string,
23
+ }),
24
+ ]),
25
+ ),
26
+ ),
27
+ ),
28
+ t.null,
28
29
  ])
29
30
  type SlicesLabels = t.TypeOf<typeof SlicesLabels>
30
31
 
31
32
  export function slicesConfigReader<F extends Format>(format: F) {
32
- return t.exact(
33
- t.partial({
34
- label: StringOrNull,
35
- labels: SlicesLabels,
36
- choices: t.record(t.string, t.union([
37
- LegacySlice,
38
- CompositeSlice,
39
- (() => {
40
- switch(format) {
41
- case Format.Static: return SharedSlice
42
- case Format.Dynamic: return SharedSliceRef
43
- default: throw new Error(`Invalid Format Exception: ${format} doesn't exist`)
44
- }
45
- })()
46
- ]))
47
- })
48
- )
33
+ return t.exact(
34
+ t.partial({
35
+ label: StringOrNull,
36
+ labels: SlicesLabels,
37
+ choices: t.record(
38
+ t.string,
39
+ t.union([
40
+ LegacySlice,
41
+ CompositeSlice,
42
+ (() => {
43
+ switch (format) {
44
+ case Format.Static:
45
+ return SharedSlice
46
+ case Format.Dynamic:
47
+ return SharedSliceRef
48
+ default:
49
+ throw new Error(
50
+ `Invalid Format Exception: ${format} doesn't exist`,
51
+ )
52
+ }
53
+ })(),
54
+ ]),
55
+ ),
56
+ }),
57
+ )
49
58
  }
50
59
  export const StaticSlicesConfig = slicesConfigReader(Format.Static)
51
60
  export type StaticSlicesConfig = t.TypeOf<typeof StaticSlicesConfig>
@@ -54,34 +63,41 @@ export const DynamicSlicesConfig = slicesConfigReader(Format.Dynamic)
54
63
  export type DynamicSlicesConfig = t.TypeOf<typeof DynamicSlicesConfig>
55
64
 
56
65
  const SlicesConfig = {
57
- toStatic(config: DynamicSlicesConfig, sharedSlices: Map<string, SharedSlice>): StaticSlicesConfig {
58
- const choices: {[key: string]: LegacySlice | CompositeSlice | SharedSlice } = Object.entries(config.choices || {})
59
- .reduce((acc, [ref, slice]) => {
60
- if(slice.type === SlicesTypes.SharedSlice) {
61
- const sharedSlice = sharedSlices.get(ref)
62
- if(sharedSlice) return { ...acc, [ref]: sharedSlice }
63
- else return acc
64
- } else {
65
- return { ...acc, [ref]: slice }
66
- }
67
- }, {})
68
-
69
- return { ...config, choices } as StaticSlicesConfig
70
- }
66
+ toStatic(
67
+ config: DynamicSlicesConfig,
68
+ sharedSlices: Map<string, SharedSlice>,
69
+ ): StaticSlicesConfig {
70
+ const choices: {
71
+ [key: string]: LegacySlice | CompositeSlice | SharedSlice
72
+ } = Object.entries(config.choices || {}).reduce((acc, [ref, slice]) => {
73
+ if (slice.type === SlicesTypes.SharedSlice) {
74
+ const sharedSlice = sharedSlices.get(ref)
75
+ if (sharedSlice) return { ...acc, [ref]: sharedSlice }
76
+ else return acc
77
+ } else {
78
+ return { ...acc, [ref]: slice }
79
+ }
80
+ }, {})
81
+
82
+ return { ...config, choices } as StaticSlicesConfig
83
+ },
71
84
  }
72
85
 
73
86
  export function slicesReader<F extends Format>(format: F) {
74
- return t.exact(
75
- t.intersection([
76
- t.type({
77
- type: t.union([t.literal(WidgetTypes.Slices), t.literal(WidgetTypes.LegacySlices)])
78
- }),
79
- t.partial({
80
- fieldset: StringOrNull,
81
- config: slicesConfigReader(format)
82
- })
83
- ])
84
- )
87
+ return t.exact(
88
+ t.intersection([
89
+ t.type({
90
+ type: t.union([
91
+ t.literal(WidgetTypes.Slices),
92
+ t.literal(WidgetTypes.LegacySlices),
93
+ ]),
94
+ }),
95
+ t.partial({
96
+ fieldset: StringOrNull,
97
+ config: slicesConfigReader(format),
98
+ }),
99
+ ]),
100
+ )
85
101
  }
86
102
 
87
103
  export const StaticSlices = slicesReader(Format.Static)
@@ -91,10 +107,16 @@ export const DynamicSlices = slicesReader(Format.Dynamic)
91
107
  export type DynamicSlices = t.TypeOf<typeof DynamicSlices>
92
108
 
93
109
  export const Slices = {
94
- toStatic(slices: DynamicSlices, sharedSlices: Map<string, SharedSlice>): StaticSlices {
95
- if(!slices.config) return slices as StaticSlices
96
- else {
97
- return { ...slices, config: SlicesConfig.toStatic(slices.config, sharedSlices) }
98
- }
99
- }
110
+ toStatic(
111
+ slices: DynamicSlices,
112
+ sharedSlices: Map<string, SharedSlice>,
113
+ ): StaticSlices {
114
+ if (!slices.config) return slices as StaticSlices
115
+ else {
116
+ return {
117
+ ...slices,
118
+ config: SlicesConfig.toStatic(slices.config, sharedSlices),
119
+ }
120
+ }
121
+ },
100
122
  }
@@ -1,6 +1,6 @@
1
1
  enum SlicesTypes {
2
- Slice = 'Slice',
3
- SharedSlice = 'SharedSlice'
2
+ Slice = "Slice",
3
+ SharedSlice = "SharedSlice",
4
4
  }
5
5
 
6
- export default SlicesTypes
6
+ export default SlicesTypes
@@ -1,7 +1,7 @@
1
- export { default as CompositeSlice } from './CompositeSlice'
2
- export { default as LegacySlice } from './LegacySlice'
3
- export { default as SharedSlice } from './SharedSlice'
4
- export { default as SharedSliceRef } from './SharedSliceRef'
5
- export { default as SlicesTypes } from './SlicesTypes'
6
- export * as Slice from './Slice'
7
- export * as SliceZone from './Slices'
1
+ export { default as CompositeSlice } from "./CompositeSlice"
2
+ export { default as LegacySlice } from "./LegacySlice"
3
+ export { default as SharedSlice } from "./SharedSlice"
4
+ export { default as SharedSliceRef } from "./SharedSliceRef"
5
+ export * as Slice from "./Slice"
6
+ export * as SliceZone from "./Slices"
7
+ export { default as SlicesTypes } from "./SlicesTypes"
@@ -0,0 +1,54 @@
1
+ import * as O from "fp-ts/lib/Option"
2
+
3
+ import { type WidgetContent, type WidgetKey, Widget } from "./widgets"
4
+
5
+ type DocumentData = Map<WidgetKey, O.Option<WidgetContent>>
6
+ function computeWidget(
7
+ key: WidgetKey,
8
+ widgets: Map<WidgetKey, unknown>,
9
+ widgetTypes: Map<WidgetKey, string>,
10
+ widgetPositions: Map<WidgetKey, number>,
11
+ ): O.Option<WidgetContent> {
12
+ const widget = widgets.get(key)
13
+ if (widget === undefined) {
14
+ return O.none
15
+ }
16
+ return Widget.fromJson(key, widget, widgetTypes, widgetPositions)
17
+ }
18
+
19
+ const DocumentData = {
20
+ getWidget(
21
+ key: WidgetKey,
22
+ widgets: Map<WidgetKey, unknown>,
23
+ widgetTypes: Map<WidgetKey, string>,
24
+ widgetPositions: Map<WidgetKey, number>,
25
+ parsed: Map<string, O.Option<WidgetContent>>,
26
+ ): O.Option<WidgetContent> {
27
+ const widget = parsed.get(key)
28
+ if (widget === undefined) {
29
+ return computeWidget(key, widgets, widgetTypes, widgetPositions)
30
+ }
31
+ return widget
32
+ },
33
+
34
+ fromJson(
35
+ widgets: Map<WidgetKey, unknown>,
36
+ widgetTypes: Map<WidgetKey, string>,
37
+ widgetPositions: Map<WidgetKey, number>,
38
+ ): DocumentData {
39
+ return Array.from(widgets.keys()).reduce<
40
+ Map<WidgetKey, O.Option<WidgetContent>>
41
+ >((acc, widgetKey) => {
42
+ const parsedWidget = this.getWidget(
43
+ widgetKey,
44
+ widgets,
45
+ widgetTypes,
46
+ widgetPositions,
47
+ acc,
48
+ )
49
+ return new Map([...Array.from(acc.entries()), [widgetKey, parsedWidget]])
50
+ }, new Map<WidgetKey, O.Option<WidgetContent>>())
51
+ },
52
+ }
53
+
54
+ export default DocumentData
@@ -0,0 +1,2 @@
1
+ export { default as DocumentData } from "./DocumentData"
2
+ export * as Widgets from "./widgets"
@@ -0,0 +1,8 @@
1
+ export const EmptyContentType = "EmptyContent"
2
+ export type EmptyContent = { type: string; __TYPE__: typeof EmptyContentType }
3
+
4
+ export const EmptyContent = {
5
+ is: (value: unknown): value is EmptyContent => {
6
+ return (value as EmptyContent).__TYPE__ === EmptyContentType
7
+ },
8
+ }
@@ -0,0 +1,91 @@
1
+ import * as A from "fp-ts/Array"
2
+ import * as O from "fp-ts/Option"
3
+ import * as t from "io-ts"
4
+
5
+ import { SimpleWidgetContent } from "./SimpleWidgetContent"
6
+
7
+ export const GroupItemContentType = "GroupItemContent"
8
+ export interface GroupItemContent {
9
+ __TYPE__: typeof GroupItemContentType
10
+ value: Array<[string, SimpleWidgetContent]>
11
+ }
12
+
13
+ export const GroupContentType = "GroupContentType"
14
+ export interface GroupContent {
15
+ __TYPE__: typeof GroupContentType
16
+ value: GroupItemContent[]
17
+ }
18
+
19
+ export const GroupContent = Object.freeze({
20
+ itemsContentsFromJson: (
21
+ prefixedKey: string,
22
+ jsItems: Array<unknown> | undefined,
23
+ fieldTypes: Map<string, string>,
24
+ fieldPositions: Map<string, number>,
25
+ ): Array<GroupItemContent> => {
26
+ if (jsItems) {
27
+ return jsItems.map((jsItem) => {
28
+ if (typeof jsItem === "object" && jsItem !== null) {
29
+ const sorted = Object.entries(jsItem).sort(([k1], [k2]) => {
30
+ const p1 = fieldPositions.get(`${prefixedKey}.${k1}`) ?? 10000
31
+ const p2 = fieldPositions.get(`${prefixedKey}.${k2}`) ?? 10000
32
+ return p1 - p2
33
+ })
34
+
35
+ const w: O.Option<[string, SimpleWidgetContent]>[] = sorted.map(
36
+ ([k, v]) => {
37
+ const kind = fieldTypes.get(`${prefixedKey}.${k}`)
38
+ if (kind) {
39
+ return O.map<
40
+ SimpleWidgetContent,
41
+ [string, SimpleWidgetContent]
42
+ >((content) => {
43
+ return [k, content]
44
+ })(SimpleWidgetContent.from(kind, v))
45
+ } else {
46
+ return O.none
47
+ }
48
+ },
49
+ )
50
+
51
+ return {
52
+ __TYPE__: "GroupItemContent",
53
+ value: A.compact(w),
54
+ }
55
+ } else {
56
+ return {
57
+ __TYPE__: "GroupItemContent",
58
+ value: [],
59
+ }
60
+ }
61
+ })
62
+ } else {
63
+ return []
64
+ }
65
+ },
66
+
67
+ fromJson: (
68
+ prefixes: Array<string>,
69
+ key: string,
70
+ value: unknown,
71
+ fieldTypes: Map<string, string>,
72
+ fieldPositions: Map<string, number>,
73
+ ): O.Option<GroupContent> => {
74
+ const prefixedKey = Array.of(prefixes, [key]).flat().join(".")
75
+
76
+ const maybeJsItems: O.Option<Array<unknown>> = O.fromEither(
77
+ t.array(t.unknown).decode(value),
78
+ )
79
+ return O.map((items: Array<unknown>) => {
80
+ return {
81
+ value: GroupContent.itemsContentsFromJson(
82
+ prefixedKey,
83
+ items,
84
+ fieldTypes,
85
+ fieldPositions,
86
+ ),
87
+ __TYPE__: GroupContentType,
88
+ } as const
89
+ })(maybeJsItems)
90
+ },
91
+ })
@@ -0,0 +1,96 @@
1
+ import { pipe } from "fp-ts/function"
2
+ import * as O from "fp-ts/Option"
3
+ import * as t from "io-ts"
4
+
5
+ import type { EmptyContent } from "./EmptyContent"
6
+ import BooleanContent from "./nestable/BooleanContent"
7
+ import EmbedContent from "./nestable/EmbedContent"
8
+ import FieldContent from "./nestable/FieldContent"
9
+ import { GeoPointContent, GeoPointContentO } from "./nestable/GeoPointContent"
10
+ import { ImageContent, ImageContentO } from "./nestable/ImageContent"
11
+ import IntegrationFieldsContent from "./nestable/IntegrationFieldsContent"
12
+ import { LinkContent } from "./nestable/Link"
13
+ import type { SeparatorContent } from "./nestable/SeparatorContent"
14
+ import { StructuredTextContent } from "./nestable/StructuredTextContent"
15
+ import { UIDContent } from "./UIDContent"
16
+
17
+ //TODO: rework that using import such as EmptyContentType
18
+ export const SimpleWidgetContentType = [
19
+ "EmptyContent",
20
+ "ImageContent",
21
+ "GeoPointContent",
22
+ "EmbedContent",
23
+ "BooleanContent",
24
+ "IntegrationFieldsContent",
25
+ "StructuredTextContent",
26
+ "LinkContent",
27
+ "UIDContent",
28
+ "SeparatorContent",
29
+ "FieldContent",
30
+ ]
31
+
32
+ export type NonEmptySimpleWidgetContent =
33
+ | IntegrationFieldsContent
34
+ | StructuredTextContent
35
+ | ImageContentO
36
+ | GeoPointContentO
37
+ | EmbedContent
38
+ | LinkContent
39
+ | UIDContent
40
+ | SeparatorContent
41
+ | FieldContent
42
+ | BooleanContent
43
+
44
+ export type SimpleWidgetContent = NonEmptySimpleWidgetContent | EmptyContent
45
+
46
+ export function is(value: unknown): value is SimpleWidgetContent {
47
+ const asSwc = value as SimpleWidgetContent
48
+ return SimpleWidgetContentType.includes(asSwc.__TYPE__)
49
+ }
50
+ const valueNullCodec = t.type({
51
+ value: t.null,
52
+ })
53
+ export const SimpleWidgetContent = {
54
+ from: (type: string, content: unknown): O.Option<SimpleWidgetContent> => {
55
+ if (content === null || valueNullCodec.is(content)) {
56
+ const result: EmptyContent = { type: type, __TYPE__: "EmptyContent" }
57
+ return O.some(result)
58
+ }
59
+
60
+ switch (type) {
61
+ case "StructuredText":
62
+ return O.fromEither(StructuredTextContent.decode(content))
63
+ case "IntegrationFields":
64
+ return O.fromEither(IntegrationFieldsContent.decode(content))
65
+ case "Image":
66
+ return pipe(
67
+ O.fromEither(ImageContent.decode(content)),
68
+ O.map((imageContent) => ImageContent.encode(imageContent)),
69
+ )
70
+ case "GeoPoint":
71
+ return pipe(
72
+ O.fromEither(GeoPointContent.decode(content)),
73
+ O.map((geopointContent) => GeoPointContent.encode(geopointContent)),
74
+ )
75
+ case "Embed":
76
+ return O.fromEither(EmbedContent.decode(content))
77
+ case "Link":
78
+ return O.fromEither(LinkContent.decode(content))
79
+ case "UID":
80
+ return O.fromEither(UIDContent.decode(content))
81
+ case "Separator":
82
+ return O.some({ __TYPE__: "SeparatorContent" })
83
+ case "Boolean":
84
+ return O.fromEither(BooleanContent.decode(content))
85
+ default:
86
+ if (FieldContent.types.includes(type)) {
87
+ return FieldContent.forType(type, content)
88
+ } else {
89
+ return O.none
90
+ }
91
+ }
92
+ },
93
+ //TODO: rework that
94
+ is: (value: unknown): value is SimpleWidgetContent =>
95
+ SimpleWidgetContentType.includes((value as SimpleWidgetContent).__TYPE__),
96
+ }