@prismicio/types-internal 2.2.0-alpha.1 → 2.2.0-alpha.11

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 (286) hide show
  1. package/lib/common/Asset.d.ts +16 -0
  2. package/lib/common/Asset.js +11 -0
  3. package/lib/common/Embed.d.ts +15 -0
  4. package/lib/common/Embed.js +10 -0
  5. package/lib/common/UUID.d.ts +7 -0
  6. package/lib/common/UUID.js +8 -0
  7. package/lib/common/index.d.ts +2 -0
  8. package/lib/common/index.js +2 -0
  9. package/lib/content/Document.d.ts +40 -40
  10. package/lib/content/fields/GroupContent.d.ts +12 -12
  11. package/lib/content/fields/GroupContent.js +11 -4
  12. package/lib/content/fields/WidgetContent.d.ts +56 -56
  13. package/lib/content/fields/nestable/NestableContent.d.ts +7 -7
  14. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +12 -12
  15. package/lib/content/fields/nestable/RichTextContent/index.d.ts +9 -9
  16. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +14 -14
  17. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -5
  18. package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
  19. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +14 -14
  20. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +14 -14
  21. package/lib/content/fields/slices/Slice/index.d.ts +30 -30
  22. package/lib/content/fields/slices/SliceItem.d.ts +30 -30
  23. package/lib/content/fields/slices/SlicesContent.d.ts +42 -42
  24. package/lib/customtypes/CustomType.d.ts +2 -0
  25. package/lib/customtypes/CustomType.js +8 -1
  26. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +0 -157
  27. package/lib/customtypes/widgets/nestable/NestableWidget.js +1 -17
  28. package/lib/import/converters/Document.d.ts +3 -2
  29. package/lib/import/converters/Document.js +11 -7
  30. package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
  31. package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
  32. package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
  33. package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
  34. package/lib/import/converters/fields/Slices/SliceItem.d.ts +4 -0
  35. package/lib/import/converters/fields/Slices/SliceItem.js +24 -0
  36. package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
  37. package/lib/import/converters/fields/Slices/Slices.js +16 -0
  38. package/lib/import/converters/fields/Slices/index.d.ts +1 -0
  39. package/lib/import/converters/fields/Slices/index.js +4 -0
  40. package/lib/import/converters/fields/UID.d.ts +3 -0
  41. package/lib/import/converters/fields/UID.js +12 -0
  42. package/lib/import/converters/fields/index.d.ts +2 -0
  43. package/lib/import/converters/fields/index.js +2 -0
  44. package/lib/import/converters/fields/nestable/Boolean.d.ts +3 -0
  45. package/lib/import/converters/fields/nestable/Boolean.js +12 -0
  46. package/lib/import/converters/fields/nestable/Color.js +9 -6
  47. package/lib/import/converters/fields/nestable/Date.d.ts +1 -1
  48. package/lib/import/converters/fields/nestable/Date.js +5 -5
  49. package/lib/import/converters/fields/nestable/Embed.d.ts +4 -0
  50. package/lib/import/converters/fields/nestable/Embed.js +32 -0
  51. package/lib/import/converters/fields/nestable/GeooPoint.d.ts +3 -0
  52. package/lib/import/converters/fields/nestable/GeooPoint.js +15 -0
  53. package/lib/import/converters/fields/nestable/Image.d.ts +4 -0
  54. package/lib/import/converters/fields/nestable/Image.js +55 -0
  55. package/lib/import/converters/fields/nestable/Link.d.ts +4 -0
  56. package/lib/import/converters/fields/nestable/Link.js +70 -0
  57. package/lib/import/converters/fields/nestable/Nestable.d.ts +4 -2
  58. package/lib/import/converters/fields/nestable/Nestable.js +11 -1
  59. package/lib/import/converters/fields/nestable/Number.js +9 -6
  60. package/lib/import/converters/fields/nestable/Select.js +9 -6
  61. package/lib/import/converters/fields/nestable/Text.js +9 -6
  62. package/lib/import/converters/fields/nestable/Timestamp.d.ts +1 -1
  63. package/lib/import/converters/fields/nestable/Timestamp.js +9 -6
  64. package/lib/import/converters/fields/nestable/index.d.ts +5 -0
  65. package/lib/import/converters/fields/nestable/index.js +5 -0
  66. package/lib/import/validators/Document.d.ts +4 -4
  67. package/lib/import/validators/Document.js +38 -46
  68. package/lib/import/validators/fields/ImportContent.d.ts +5 -0
  69. package/lib/import/validators/fields/ImportContent.js +21 -0
  70. package/lib/import/validators/fields/ImportField.d.ts +135 -0
  71. package/lib/import/validators/fields/ImportField.js +29 -0
  72. package/lib/import/validators/fields/ImportSlices/ImportSliceId.d.ts +9 -0
  73. package/lib/import/validators/fields/ImportSlices/ImportSliceId.js +43 -0
  74. package/lib/import/validators/fields/ImportSlices/ImportSliceItem.d.ts +24 -0
  75. package/lib/import/validators/fields/ImportSlices/ImportSliceItem.js +87 -0
  76. package/lib/import/validators/fields/ImportSlices/ImportSliceItemContent.d.ts +12 -0
  77. package/lib/import/validators/fields/ImportSlices/ImportSliceItemContent.js +41 -0
  78. package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
  79. package/lib/import/validators/fields/ImportSlices/ImportSlices.js +29 -0
  80. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +14 -0
  81. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +60 -0
  82. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
  83. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
  84. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
  85. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
  86. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
  87. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
  88. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
  89. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
  90. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
  91. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
  92. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
  93. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
  94. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
  95. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
  96. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
  97. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
  98. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
  99. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
  100. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
  101. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
  102. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
  103. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
  104. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
  105. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
  106. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
  107. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
  108. package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
  109. package/lib/import/validators/fields/ImportSlices/index.js +4 -0
  110. package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
  111. package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
  112. package/lib/import/validators/fields/Slices/SharedSlice/SharedSlice.d.ts +14 -0
  113. package/lib/import/validators/fields/Slices/SharedSlice/SharedSlice.js +60 -0
  114. package/lib/import/validators/fields/Slices/SharedSlice/errors.d.ts +5 -0
  115. package/lib/import/validators/fields/Slices/SharedSlice/errors.js +8 -0
  116. package/lib/import/validators/fields/Slices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
  117. package/lib/import/validators/fields/Slices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
  118. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
  119. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +38 -0
  120. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
  121. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
  122. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/errors.d.ts +5 -0
  123. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/errors.js +9 -0
  124. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
  125. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
  126. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
  127. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
  128. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
  129. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceId.js +39 -0
  130. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceItems.d.ts +11 -0
  131. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceItems.js +25 -0
  132. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
  133. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceType.js +24 -0
  134. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
  135. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceVariation.js +24 -0
  136. package/lib/import/validators/fields/Slices/SharedSlice/fields/index.d.ts +6 -0
  137. package/lib/import/validators/fields/Slices/SharedSlice/fields/index.js +9 -0
  138. package/lib/import/validators/fields/Slices/SharedSlice/index.d.ts +3 -0
  139. package/lib/import/validators/fields/Slices/SharedSlice/index.js +6 -0
  140. package/lib/import/validators/fields/Slices/SharedSlice/utils.d.ts +339 -0
  141. package/lib/import/validators/fields/Slices/SharedSlice/utils.js +11 -0
  142. package/lib/import/validators/fields/Slices/Slices.d.ts +8 -0
  143. package/lib/import/validators/fields/Slices/Slices.js +29 -0
  144. package/lib/import/validators/fields/Slices/index.d.ts +1 -0
  145. package/lib/import/validators/fields/Slices/index.js +4 -0
  146. package/lib/import/validators/fields/Slices/utils.d.ts +4 -0
  147. package/lib/import/validators/fields/Slices/utils.js +35 -0
  148. package/lib/import/validators/fields/Slices.d.ts +4 -0
  149. package/lib/import/validators/fields/Slices.js +12 -0
  150. package/lib/import/validators/fields/UID.d.ts +6 -0
  151. package/lib/import/validators/fields/UID.js +15 -0
  152. package/lib/import/validators/fields/index.d.ts +1 -5
  153. package/lib/import/validators/fields/index.js +1 -0
  154. package/lib/import/validators/fields/nestable/Boolean.d.ts +6 -0
  155. package/lib/import/validators/fields/nestable/Boolean.js +6 -0
  156. package/lib/import/validators/fields/nestable/Color.d.ts +5 -4
  157. package/lib/import/validators/fields/nestable/Color.js +4 -4
  158. package/lib/import/validators/fields/nestable/Date.d.ts +5 -3
  159. package/lib/import/validators/fields/nestable/Date.js +4 -2
  160. package/lib/import/validators/fields/nestable/Embed.d.ts +10 -0
  161. package/lib/import/validators/fields/nestable/Embed.js +36 -0
  162. package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
  163. package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
  164. package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +26 -0
  165. package/lib/import/validators/fields/nestable/Image/Decoder.js +40 -0
  166. package/lib/import/validators/fields/nestable/Image/Validator.d.ts +37 -0
  167. package/lib/import/validators/fields/nestable/Image/Validator.js +26 -0
  168. package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
  169. package/lib/import/validators/fields/nestable/Image/index.js +28 -0
  170. package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
  171. package/lib/import/validators/fields/nestable/Image/model.js +2 -0
  172. package/lib/import/validators/fields/nestable/Image.d.ts +45 -0
  173. package/lib/import/validators/fields/nestable/Image.js +45 -0
  174. package/lib/import/validators/fields/nestable/Link.d.ts +38 -0
  175. package/lib/import/validators/fields/nestable/Link.js +35 -0
  176. package/lib/import/validators/fields/nestable/Nestable.d.ts +120 -4
  177. package/lib/import/validators/fields/nestable/Nestable.js +59 -28
  178. package/lib/import/validators/fields/nestable/Number.d.ts +16 -9
  179. package/lib/import/validators/fields/nestable/Number.js +5 -4
  180. package/lib/import/validators/fields/nestable/Select.d.ts +15 -8
  181. package/lib/import/validators/fields/nestable/Select.js +4 -2
  182. package/lib/import/validators/fields/nestable/Text.d.ts +6 -3
  183. package/lib/import/validators/fields/nestable/Text.js +2 -1
  184. package/lib/import/validators/fields/nestable/Timestamp.d.ts +5 -3
  185. package/lib/import/validators/fields/nestable/Timestamp.js +4 -2
  186. package/lib/import/validators/fields/nestable/index.d.ts +6 -0
  187. package/lib/import/validators/fields/nestable/index.js +6 -0
  188. package/lib/utils/DocumentId.d.ts +1 -0
  189. package/lib/utils/DocumentId.js +7 -0
  190. package/lib/utils/Objects.d.ts +1 -0
  191. package/lib/utils/Objects.js +5 -1
  192. package/lib/utils/io-ts.d.ts +2 -0
  193. package/lib/utils/io-ts.js +22 -0
  194. package/lib/validators/BasicTypes.d.ts +9 -0
  195. package/lib/validators/BasicTypes.js +20 -1
  196. package/lib/validators/DefaultOrElse.d.ts +5 -0
  197. package/lib/validators/DefaultOrElse.js +21 -0
  198. package/lib/validators/NonEmptyString.js +2 -1
  199. package/lib/validators/NumberRange.d.ts +32 -0
  200. package/lib/validators/NumberRange.js +40 -0
  201. package/lib/validators/function.d.ts +20 -0
  202. package/lib/validators/function.js +41 -1
  203. package/lib/validators/index.d.ts +2 -1
  204. package/lib/validators/index.js +4 -2
  205. package/package.json +6 -3
  206. package/src/common/Asset.ts +25 -0
  207. package/src/common/Embed.ts +22 -0
  208. package/src/common/UUID.ts +18 -0
  209. package/src/common/index.ts +2 -0
  210. package/src/content/fields/GroupContent.ts +9 -5
  211. package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
  212. package/src/customtypes/CustomType.ts +13 -0
  213. package/src/customtypes/widgets/nestable/NestableWidget.ts +0 -17
  214. package/src/import/converters/Document.ts +26 -10
  215. package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
  216. package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
  217. package/src/import/converters/fields/Slices/Slices.ts +20 -0
  218. package/src/import/converters/fields/Slices/index.ts +1 -0
  219. package/src/import/converters/fields/UID.ts +13 -0
  220. package/src/import/converters/fields/index.ts +2 -0
  221. package/src/import/converters/fields/nestable/Boolean.ts +13 -0
  222. package/src/import/converters/fields/nestable/Color.ts +7 -5
  223. package/src/import/converters/fields/nestable/Date.ts +12 -13
  224. package/src/import/converters/fields/nestable/Embed.ts +37 -0
  225. package/src/import/converters/fields/nestable/GeooPoint.ts +16 -0
  226. package/src/import/converters/fields/nestable/Image.ts +73 -0
  227. package/src/import/converters/fields/nestable/Link.ts +77 -0
  228. package/src/import/converters/fields/nestable/Nestable.ts +21 -2
  229. package/src/import/converters/fields/nestable/Number.ts +7 -5
  230. package/src/import/converters/fields/nestable/Select.ts +7 -5
  231. package/src/import/converters/fields/nestable/Text.ts +7 -5
  232. package/src/import/converters/fields/nestable/Timestamp.ts +8 -6
  233. package/src/import/converters/fields/nestable/index.ts +5 -0
  234. package/src/import/validators/Document.ts +86 -79
  235. package/src/import/validators/fields/ImportContent.ts +30 -0
  236. package/src/import/validators/fields/ImportField.ts +30 -0
  237. package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
  238. package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +114 -0
  239. package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +6 -0
  240. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +20 -0
  241. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +61 -0
  242. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
  243. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
  244. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
  245. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
  246. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
  247. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
  248. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
  249. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
  250. package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
  251. package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
  252. package/src/import/validators/fields/ImportSlices/index.ts +1 -0
  253. package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
  254. package/src/import/validators/fields/UID.ts +27 -0
  255. package/src/import/validators/fields/index.ts +1 -7
  256. package/src/import/validators/fields/nestable/Boolean.ts +7 -0
  257. package/src/import/validators/fields/nestable/Color.ts +23 -23
  258. package/src/import/validators/fields/nestable/Date.ts +26 -27
  259. package/src/import/validators/fields/nestable/Embed.ts +54 -0
  260. package/src/import/validators/fields/nestable/GeoPoint.ts +21 -0
  261. package/src/import/validators/fields/nestable/Image/Decoder.ts +61 -0
  262. package/src/import/validators/fields/nestable/Image/Validator.ts +35 -0
  263. package/src/import/validators/fields/nestable/Image/index.ts +45 -0
  264. package/src/import/validators/fields/nestable/Image/model.ts +18 -0
  265. package/src/import/validators/fields/nestable/Link.ts +54 -0
  266. package/src/import/validators/fields/nestable/Nestable.ts +65 -26
  267. package/src/import/validators/fields/nestable/Number.ts +32 -30
  268. package/src/import/validators/fields/nestable/Select.ts +32 -30
  269. package/src/import/validators/fields/nestable/Text.ts +6 -6
  270. package/src/import/validators/fields/nestable/Timestamp.ts +29 -26
  271. package/src/import/validators/fields/nestable/index.ts +6 -0
  272. package/src/utils/DocumentId.ts +9 -0
  273. package/src/utils/Objects.ts +10 -0
  274. package/src/utils/io-ts.ts +29 -0
  275. package/src/validators/BasicTypes.ts +53 -0
  276. package/src/validators/DefaultOrElse.ts +24 -0
  277. package/src/validators/NonEmptyString.ts +4 -4
  278. package/src/validators/NumberRange.ts +51 -0
  279. package/src/validators/function.ts +44 -0
  280. package/src/validators/index.ts +2 -1
  281. package/lib/import/converters/fields/utils.d.ts +0 -1
  282. package/lib/import/converters/fields/utils.js +0 -10
  283. package/lib/validators/NullOrT.d.ts +0 -2
  284. package/lib/validators/NullOrT.js +0 -13
  285. package/src/import/converters/fields/utils.ts +0 -7
  286. package/src/validators/NullOrT.ts +0 -18
@@ -1,18 +1,17 @@
1
1
  import type { DateContent } from "../../../../content"
2
- import type { ImportDate } from "../../.."
3
- import { nullableConverter } from "../utils"
2
+ import type { ImportDate } from "../../../validators"
4
3
 
5
4
  export const dateConverter = (
6
5
  field: ImportDate["value"],
7
- ): DateContent | undefined =>
8
- nullableConverter(field, (value: NonNullable<ImportDate["value"]>) => {
9
- // Iso date looks like this '2023-07-10T13:33:12+0000'
10
- const isoDate = value.toISOString()
11
- const [withoutTime] = isoDate.split("T")
6
+ ): DateContent | undefined => {
7
+ if (field === null) return
12
8
 
13
- return {
14
- type: "Date",
15
- value: withoutTime || isoDate,
16
- __TYPE__: "FieldContent",
17
- }
18
- })
9
+ const isoDate = field.toISOString()
10
+ const [withoutTime] = isoDate.split("T")
11
+
12
+ return {
13
+ type: "Date",
14
+ value: withoutTime || isoDate,
15
+ __TYPE__: "FieldContent",
16
+ }
17
+ }
@@ -0,0 +1,37 @@
1
+ import type { Embed } from "../../../../common"
2
+ import { getEmbedOrThrow } from "../../../../common"
3
+ import type { EmbedContent } from "../../../../content"
4
+ import { withOptionals } from "../../../../utils/Objects"
5
+ import type { ImportEmbed } from "../../../validators"
6
+
7
+ export const embedConverter = (
8
+ field: ImportEmbed["value"],
9
+ embeds: Record<string, Embed | undefined>,
10
+ ): EmbedContent | undefined => {
11
+ if (field === null) return
12
+ const embed = getEmbedOrThrow(embeds)(field.embed_url)
13
+ return withOptionals<EmbedContent>(
14
+ {
15
+ embed_url: field.embed_url,
16
+ type: embed.type,
17
+ all: {
18
+ embed_url: field.embed_url,
19
+ ...embed,
20
+ },
21
+ __TYPE__: "EmbedContent",
22
+ },
23
+ [
24
+ ["version", embed.version],
25
+ ["title", embed.title],
26
+ ["author_name", embed.author_name],
27
+ ["author_url", embed.author_url],
28
+ ["provider_name", embed.provider_name],
29
+ ["provider_url", embed.provider_url],
30
+ ["cache_age", embed.cache_age],
31
+ ["thumbnail_url", embed.thumbnail_url],
32
+ ["thumbnail_width", embed.thumbnail_width],
33
+ ["thumbnail_height", embed.thumbnail_height],
34
+ ["html", embed.html],
35
+ ],
36
+ )
37
+ }
@@ -0,0 +1,16 @@
1
+ import type { GeoPointContent } from "../../../../content"
2
+ import type { ImportGeoPoint } from "../../../validators"
3
+
4
+ export const geopointConverter = (
5
+ field: ImportGeoPoint["value"],
6
+ ): GeoPointContent | undefined => {
7
+ if (field === null) return
8
+
9
+ return {
10
+ position: {
11
+ lat: field.latitude,
12
+ lng: field.longitude,
13
+ },
14
+ __TYPE__: "GeoPointContent",
15
+ }
16
+ }
@@ -0,0 +1,73 @@
1
+ import type { Asset } from "../../../../common"
2
+ import { getAssetOrThrow } from "../../../../common"
3
+ import type { ImageContent } from "../../../../content"
4
+ import { withOptionals } from "../../../../utils/Objects"
5
+ import type { ImageField, ImportImage } from "../../../validators"
6
+
7
+ function convertImage(imageField: ImageField, image: Asset) {
8
+ return withOptionals<Omit<ImageContent, "__TYPE__" | "thumbnails">>(
9
+ {
10
+ origin: {
11
+ id: image.id,
12
+ url: image.origin_url,
13
+ // All images returned form Asset API should have width and height properties.
14
+ width: image.width ?? 0,
15
+ height: image.height ?? 0,
16
+ },
17
+ // All images returned form Asset API should have width and height properties.
18
+ // Image width and height will be only applied if there are no constraints and user didn't overwrite it
19
+ width: imageField?.dimensions?.width ?? image.width ?? 0,
20
+ height: imageField?.dimensions?.height ?? image.height ?? 0,
21
+ // If edit is not provided, we crop constraint width and height from the left upper corner.
22
+ // WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
23
+ edit: {
24
+ zoom: imageField.edit?.zoom ?? 1,
25
+ crop: {
26
+ x: imageField.edit?.x ?? 0,
27
+ y: imageField.edit?.y ?? 0,
28
+ },
29
+ background:
30
+ imageField.edit?.background ??
31
+ (image.extension === "png" ? "transparent" : "#ffffff"),
32
+ },
33
+ url: image.url,
34
+ },
35
+ [
36
+ ["alt", imageField?.alt || image.alt],
37
+ ["credits", imageField?.credit || image.credits],
38
+ ],
39
+ )
40
+ }
41
+
42
+ function convertThumbnails(
43
+ imageField: Exclude<ImportImage["value"], null>,
44
+ assets: Record<Asset["id"], Asset | undefined>,
45
+ ) {
46
+ return Object.entries(imageField.thumbnails).reduce(
47
+ (acc, [thumbnailName, thumbnail]) => {
48
+ return {
49
+ ...acc,
50
+ [thumbnailName]: convertImage(
51
+ thumbnail,
52
+ getAssetOrThrow(assets)(thumbnail.id),
53
+ ),
54
+ }
55
+ },
56
+ {},
57
+ )
58
+ }
59
+
60
+ // All assets from `imageField` must be present in `assets`
61
+ // If not then function will throw an error
62
+ export const imageConverter = (
63
+ imageField: ImportImage["value"],
64
+ assets: Record<Asset["id"], Asset | undefined>,
65
+ ): ImageContent | undefined => {
66
+ if (!imageField) return
67
+
68
+ return {
69
+ ...convertImage(imageField, getAssetOrThrow(assets)(imageField.id)),
70
+ thumbnails: convertThumbnails(imageField, assets),
71
+ __TYPE__: "ImageContent" as const,
72
+ }
73
+ }
@@ -0,0 +1,77 @@
1
+ import type { Asset } from "../../../../common"
2
+ import { getAssetOrThrow } from "../../../../common"
3
+ import type { LinkContent } from "../../../../content"
4
+ import type {
5
+ DocumentLink,
6
+ ImportLink,
7
+ MediaLink,
8
+ WebLink,
9
+ } from "../../../validators"
10
+
11
+ const webLinkConverter = (field: WebLink): LinkContent => ({
12
+ value: {
13
+ url: field.url,
14
+ target: field.target,
15
+ __TYPE__: "ExternalLink",
16
+ },
17
+ __TYPE__: "LinkContent",
18
+ })
19
+
20
+ const documentLinkConverter = (field: DocumentLink): LinkContent => ({
21
+ value: {
22
+ id: field.id,
23
+ __TYPE__: "DocumentLink",
24
+ },
25
+ __TYPE__: "LinkContent",
26
+ })
27
+
28
+ const fileLinkConverter = (field: MediaLink, asset: Asset): LinkContent => ({
29
+ value: {
30
+ id: field.id,
31
+ url: asset.url,
32
+ name: asset.filename ?? "unknown.jpg",
33
+ kind: asset.kind,
34
+ size: asset.size ?? "0",
35
+ __TYPE__: "FileLink",
36
+ },
37
+ __TYPE__: "LinkContent",
38
+ })
39
+
40
+ const imageLinkConverter = (field: MediaLink, asset: Asset): LinkContent => ({
41
+ value: {
42
+ id: field.id,
43
+ url: asset.url,
44
+ height: String(asset.height ?? 1),
45
+ width: String(asset.width ?? 1),
46
+ name: asset.filename ?? "unknown.jpg",
47
+ kind: asset.kind,
48
+ size: asset.size ?? "0",
49
+ __TYPE__: "ImageLink",
50
+ },
51
+ __TYPE__: "LinkContent",
52
+ })
53
+
54
+ export const linkConverter = (
55
+ field: ImportLink["value"],
56
+ assets: Record<string, Asset | undefined>,
57
+ ): LinkContent | undefined => {
58
+ if (field === null) {
59
+ return
60
+ }
61
+
62
+ switch (field.link_type) {
63
+ case "Web":
64
+ return webLinkConverter(field)
65
+ case "Document":
66
+ return documentLinkConverter(field)
67
+ case "Media": {
68
+ const asset = getAssetOrThrow(assets)(field.id)
69
+ switch (asset.kind) {
70
+ case "all":
71
+ return fileLinkConverter(field, asset)
72
+ case "image":
73
+ return imageLinkConverter(field, asset)
74
+ }
75
+ }
76
+ }
77
+ }
@@ -1,8 +1,15 @@
1
- import type { WidgetContent } from "../../../../content"
1
+ import type { Asset } from "../../../../common"
2
+ import type { Embed } from "../../../../common/Embed"
3
+ import type { NestableContent } from "../../../../content"
2
4
  import type { ImportNestable } from "../../../validators"
3
5
  import {
6
+ booleanConverter,
4
7
  colorConverter,
5
8
  dateConverter,
9
+ embedConverter,
10
+ geopointConverter,
11
+ imageConverter,
12
+ linkConverter,
6
13
  numberConverter,
7
14
  selectConverter,
8
15
  textConverter,
@@ -11,8 +18,12 @@ import {
11
18
 
12
19
  export function convertNestableWidget(
13
20
  field: ImportNestable,
14
- ): WidgetContent | undefined {
21
+ assets: Record<Asset["id"], Asset | undefined>,
22
+ embeds: Record<string, Embed | undefined>,
23
+ ): NestableContent | undefined {
15
24
  switch (field.type) {
25
+ case "Boolean":
26
+ return booleanConverter(field.value)
16
27
  case "Color":
17
28
  return colorConverter(field.value)
18
29
  case "Select":
@@ -25,6 +36,14 @@ export function convertNestableWidget(
25
36
  return dateConverter(field.value)
26
37
  case "Timestamp":
27
38
  return timestampConverter(field.value)
39
+ case "Embed":
40
+ return embedConverter(field.value, embeds)
41
+ case "GeoPoint":
42
+ return geopointConverter(field.value)
43
+ case "Link":
44
+ return linkConverter(field.value, assets)
45
+ case "Image":
46
+ return imageConverter(field.value, assets)
28
47
  default:
29
48
  throw new Error(
30
49
  `Unsupported type of nestable converter ${JSON.stringify(field)}`,
@@ -1,12 +1,14 @@
1
1
  import type { NumberContent } from "../../../../content"
2
2
  import type { ImportNumber } from "../../../validators"
3
- import { nullableConverter } from "../utils"
4
3
 
5
4
  export const numberConverter = (
6
5
  field: ImportNumber["value"],
7
- ): NumberContent | undefined =>
8
- nullableConverter(field, (value: NonNullable<ImportNumber["value"]>) => ({
6
+ ): NumberContent | undefined => {
7
+ if (field === null) return
8
+
9
+ return {
9
10
  type: "Number",
10
- value: value.toString(),
11
+ value: field.toString(),
11
12
  __TYPE__: "FieldContent",
12
- }))
13
+ }
14
+ }
@@ -1,12 +1,14 @@
1
1
  import type { SelectContent } from "../../../../content"
2
2
  import type { ImportSelect } from "../../../validators"
3
- import { nullableConverter } from "../utils"
4
3
 
5
4
  export const selectConverter = (
6
5
  field: ImportSelect["value"],
7
- ): SelectContent | undefined =>
8
- nullableConverter(field, (value: NonNullable<ImportSelect["value"]>) => ({
6
+ ): SelectContent | undefined => {
7
+ if (field === null) return
8
+
9
+ return {
9
10
  type: "Select",
10
- value: value,
11
+ value: field,
11
12
  __TYPE__: "FieldContent",
12
- }))
13
+ }
14
+ }
@@ -1,12 +1,14 @@
1
1
  import type { TextContent } from "../../../../content"
2
2
  import type { ImportText } from "../../../validators"
3
- import { nullableConverter } from "../utils"
4
3
 
5
4
  export const textConverter = (
6
5
  field: ImportText["value"],
7
- ): TextContent | undefined =>
8
- nullableConverter(field, (value: NonNullable<ImportText["value"]>) => ({
6
+ ): TextContent | undefined => {
7
+ if (field === null) return
8
+
9
+ return {
9
10
  type: "Text",
10
- value: value,
11
+ value: field,
11
12
  __TYPE__: "FieldContent",
12
- }))
13
+ }
14
+ }
@@ -1,12 +1,14 @@
1
1
  import type { TimestampContent } from "../../../../content"
2
- import type { ImportTimestamp } from "../../.."
3
- import { nullableConverter } from "../utils"
2
+ import type { ImportTimestamp } from "../../../validators"
4
3
 
5
4
  export const timestampConverter = (
6
5
  field: ImportTimestamp["value"],
7
- ): TimestampContent | undefined =>
8
- nullableConverter(field, (value: NonNullable<ImportTimestamp["value"]>) => ({
6
+ ): TimestampContent | undefined => {
7
+ if (field === null) return
8
+
9
+ return {
9
10
  type: "Timestamp",
10
- value: value.toISOString(),
11
+ value: field.toISOString(),
11
12
  __TYPE__: "FieldContent",
12
- }))
13
+ }
14
+ }
@@ -1,5 +1,10 @@
1
+ export * from "./Boolean"
1
2
  export * from "./Color"
2
3
  export * from "./Date"
4
+ export * from "./Embed"
5
+ export * from "./GeooPoint"
6
+ export * from "./Image"
7
+ export * from "./Link"
3
8
  export * from "./Nestable"
4
9
  export * from "./Number"
5
10
  export * from "./Select"
@@ -1,96 +1,103 @@
1
- import * as Either from "fp-ts/Either"
1
+ import { either } from "fp-ts"
2
+ import { Either, isLeft } from "fp-ts/Either"
3
+ import { pipe } from "fp-ts/lib/function"
2
4
  import * as t from "io-ts"
5
+ import { withMessage } from "io-ts-types"
3
6
 
4
7
  import type { WidgetKey } from "../../common"
5
- import {
6
- isNestableWidget,
7
- StaticCustomType,
8
- StaticWidget,
9
- } from "../../customtypes"
8
+ import type { StaticCustomType, StaticWidget } from "../../customtypes"
9
+ import { flattenCustomTypeFields } from "../../customtypes"
10
10
  import { isObject } from "../../utils/Objects"
11
- import { getNestableFieldCodec, ImportNestable } from "./fields"
11
+ import { ImportField } from "./fields/ImportField"
12
12
 
13
- export type ImportDocument = Record<WidgetKey, ImportNestable>
14
- export const ImportDocument = (mask: StaticCustomType) =>
15
- new t.Type<ImportDocument, ImportDocument, unknown>(
16
- "ImportDocument",
17
- (u): u is ImportDocument => isObject(u),
18
- (raw: unknown) => {
19
- if (!isObject(raw)) {
20
- const error: t.ValidationError = {
21
- value: raw,
22
- context: [],
23
- message: "document is not an object",
24
- }
25
- return Either.left([error])
26
- }
13
+ const rawImportDocument = withMessage(
14
+ t.record(t.string, t.unknown),
15
+ () => "document is not an object",
16
+ )
27
17
 
28
- // flattening the fields within the tabs
29
- const maskFields = Object.values(mask.json).reduce((acc, tab) => ({
30
- ...acc,
31
- ...tab,
32
- }))
18
+ function validateField(
19
+ document: Record<string, unknown>,
20
+ customType: StaticCustomType,
21
+ ) {
22
+ return (
23
+ key: string,
24
+ content: unknown,
25
+ model?: StaticWidget,
26
+ ): Either<t.Errors, ImportField> => {
27
+ // the field is not defined in the custom type -> extra field or typo
28
+ if (!model) {
29
+ const error: t.ValidationError = {
30
+ value: content,
31
+ context: [{ key: key, type: t.unknown }],
32
+ message: `The field ${key} is not part of the Custom type`,
33
+ }
34
+ return either.left([error])
35
+ }
33
36
 
34
- // Listing all errors for each fields
35
- const { document, errors } = Object.entries(raw).reduce<{
36
- document: ImportDocument
37
- errors: t.Errors
38
- }>(
39
- (acc, [fieldKey, fieldValue]) => {
40
- const maskFieldValue = maskFields[fieldKey]
37
+ // retrieving the right codec then testing out fieldValue with it.
38
+ const { result, codec } = ImportField.decode(model)(content)
41
39
 
42
- // the field is not defined in the custom type -> extra field or typo
43
- if (!maskFieldValue) {
44
- const error: t.ValidationError = {
45
- value: fieldValue,
46
- context: [{ key: fieldKey, type: t.unknown }],
47
- message: `The field ${fieldKey} is not part of the Custom type`,
48
- }
49
- return { ...acc, errors: [...acc.errors, error] }
50
- }
40
+ // error.context is pointing at root when it should point to a `fieldKey`.
41
+ // We need to override the context to make it right.
42
+ if (isLeft(result)) {
43
+ const errors: t.Errors = result.left.map((error) => {
44
+ const contextHead = error.context[0]
45
+ const context = [
46
+ { key: "", actual: document, type: ImportDocument(customType) },
47
+ contextHead
48
+ ? { ...contextHead, key: key }
49
+ : { key: key, actual: content, type: codec },
50
+ ...error.context.slice(1),
51
+ ]
51
52
 
52
- // retrieving the right codec then testing out fieldValue with it.
53
- const fieldCodec = getFieldCodec(maskFieldValue)
54
- const result = fieldCodec.decode(fieldValue)
53
+ return { ...error, context }
54
+ })
55
+ return either.left(errors)
56
+ }
57
+ return either.right(result.right)
58
+ }
59
+ }
55
60
 
56
- // returning validation errors
57
- if (Either.isLeft(result)) {
58
- // error.context is pointing at root when it should point to a `fieldKey`.
59
- // We need to override the context to make it right.
60
- const errors: t.Errors = result.left.map(error => {
61
- const contextHead = error.context[0];
62
- const context = [
63
- { key: '', actual: raw, type: ImportDocument(mask) },
64
- contextHead
65
- ? { ...contextHead, key: fieldKey }
66
- : {key: fieldKey, actual: fieldValue, type: fieldCodec},
67
- ...error.context.slice(1)
68
- ];
61
+ function validateDocument(
62
+ customType: StaticCustomType,
63
+ rawDoc: Record<string, unknown>,
64
+ ) {
65
+ const fieldModels = flattenCustomTypeFields(customType)
66
+ const { document, errors } = Object.entries(rawDoc).reduce<{
67
+ document: ImportDocument
68
+ errors: t.Errors
69
+ }>(
70
+ (acc, [fieldKey, fieldValue]) => {
71
+ const parsedField = validateField(rawDoc, customType)(
72
+ fieldKey,
73
+ fieldValue,
74
+ fieldModels[fieldKey],
75
+ )
69
76
 
70
- return { ...error, context };
71
- });
77
+ if (isLeft(parsedField))
78
+ return { ...acc, errors: [...acc.errors, ...parsedField.left] }
72
79
 
73
- return { ...acc, errors: [...acc.errors, ...errors] };
74
- }
80
+ return {
81
+ ...acc,
82
+ document: { ...acc.document, [fieldKey]: parsedField.right },
83
+ }
84
+ },
85
+ { document: {}, errors: [] },
86
+ )
87
+ if (errors.length > 0) return either.left(errors)
88
+ return either.right(document)
89
+ }
75
90
 
76
- // registering the field as validated
77
- return {
78
- ...acc,
79
- document: { ...acc.document, [fieldKey]: result.right },
80
- }
81
- },
82
- { document: {}, errors: [] },
91
+ export type ImportDocument = Record<WidgetKey, ImportField>
92
+ export const ImportDocument = (customType: StaticCustomType) =>
93
+ new t.Type<ImportDocument, ImportDocument, unknown>(
94
+ "ImportDocument",
95
+ (u): u is ImportDocument => isObject(u),
96
+ (raw: unknown) => {
97
+ return pipe(
98
+ rawImportDocument.decode(raw),
99
+ either.chain((doc) => validateDocument(customType, doc)),
83
100
  )
84
-
85
- // Returning either the errors of
86
- if (errors.length > 0) return Either.left(errors)
87
- return Either.right(document)
88
101
  },
89
102
  t.identity,
90
103
  )
91
-
92
- function getFieldCodec(maskValue: StaticWidget) {
93
- if (isNestableWidget(maskValue)) return getNestableFieldCodec(maskValue)
94
- throw new Error(`Unsupported type of field ${maskValue.type}`)
95
- }
96
-
@@ -0,0 +1,30 @@
1
+ import { either } from "fp-ts"
2
+ import { pipe } from "fp-ts/lib/function"
3
+ import * as t from "io-ts"
4
+
5
+ import type { FieldType } from "../../../customtypes"
6
+ import { isObject } from "../../../utils/Objects"
7
+
8
+ export const ImportContent = <T extends FieldType, A, O = A>(
9
+ type: T,
10
+ valueCodec: t.Type<A, O>,
11
+ ) =>
12
+ new t.Type<{ type: T; value: A }, O>(
13
+ "ImportField",
14
+ (u: unknown): u is { type: T; value: A } => {
15
+ if (!isObject(u)) return false
16
+ return type === u["type"] && valueCodec.is(u["value"])
17
+ },
18
+ (u: unknown) => {
19
+ return pipe(
20
+ valueCodec.decode(u),
21
+ either.map((decodedValue) => {
22
+ return {
23
+ type,
24
+ value: decodedValue,
25
+ }
26
+ }),
27
+ )
28
+ },
29
+ (field) => field.value as unknown as O,
30
+ )
@@ -0,0 +1,30 @@
1
+ import type { StaticWidget } from "../../../customtypes"
2
+ import { ImportSlices } from "./ImportSlices"
3
+ import { ImportNestable } from "./nestable"
4
+ import { ImportUID } from "./UID"
5
+
6
+ export type ImportField = ImportUID | ImportSlices | ImportNestable
7
+
8
+ export const ImportField = {
9
+ is(u: unknown): u is ImportNestable {
10
+ return ImportUID.is(u) || ImportNestable.is(u)
11
+ },
12
+ decode: (field: StaticWidget) => {
13
+ return (content: unknown) => {
14
+ switch (field.type) {
15
+ case "UID":
16
+ return { codec: ImportUID, result: ImportUID.decode(content) }
17
+ case "Slices":
18
+ return {
19
+ codec: ImportSlices(field),
20
+ result: ImportSlices(field).decode(content),
21
+ }
22
+ case "Choice":
23
+ case "Group":
24
+ throw new Error(`Unsupported type of field ${field.type}`)
25
+ default:
26
+ return ImportNestable.decode(field)(content)
27
+ }
28
+ }
29
+ },
30
+ }