@prismicio/types-internal 2.2.1-alpha.0 → 2.2.1-remove-import.alpha-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/lib/common/UUID.d.ts +1 -2
  2. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +1 -2
  3. package/lib/content/fields/slices/Slice/SimpleSliceContent.js +2 -4
  4. package/package.json +1 -1
  5. package/src/common/UUID.ts +1 -1
  6. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +1 -2
  7. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +2 -5
  8. package/lib/import/converters/Document.d.ts +0 -4
  9. package/lib/import/converters/Document.js +0 -21
  10. package/lib/import/converters/fields/Group.d.ts +0 -4
  11. package/lib/import/converters/fields/Group.js +0 -14
  12. package/lib/import/converters/fields/RepeatableZone.d.ts +0 -317
  13. package/lib/import/converters/fields/RepeatableZone.js +0 -15
  14. package/lib/import/converters/fields/RepeatableZoneItem.d.ts +0 -11
  15. package/lib/import/converters/fields/RepeatableZoneItem.js +0 -19
  16. package/lib/import/converters/fields/Slices/SharedSlice.d.ts +0 -4
  17. package/lib/import/converters/fields/Slices/SharedSlice.js +0 -19
  18. package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +0 -10
  19. package/lib/import/converters/fields/Slices/SharedSliceContent.js +0 -23
  20. package/lib/import/converters/fields/Slices/Slices.d.ts +0 -4
  21. package/lib/import/converters/fields/Slices/Slices.js +0 -16
  22. package/lib/import/converters/fields/Slices/index.d.ts +0 -1
  23. package/lib/import/converters/fields/Slices/index.js +0 -4
  24. package/lib/import/converters/fields/UID.d.ts +0 -3
  25. package/lib/import/converters/fields/UID.js +0 -10
  26. package/lib/import/converters/fields/index.d.ts +0 -4
  27. package/lib/import/converters/fields/index.js +0 -7
  28. package/lib/import/converters/fields/nestable/Boolean.d.ts +0 -3
  29. package/lib/import/converters/fields/nestable/Boolean.js +0 -12
  30. package/lib/import/converters/fields/nestable/Color.d.ts +0 -3
  31. package/lib/import/converters/fields/nestable/Color.js +0 -13
  32. package/lib/import/converters/fields/nestable/Date.d.ts +0 -3
  33. package/lib/import/converters/fields/nestable/Date.js +0 -15
  34. package/lib/import/converters/fields/nestable/Embed.d.ts +0 -4
  35. package/lib/import/converters/fields/nestable/Embed.js +0 -32
  36. package/lib/import/converters/fields/nestable/GeoPoint.d.ts +0 -3
  37. package/lib/import/converters/fields/nestable/GeoPoint.js +0 -15
  38. package/lib/import/converters/fields/nestable/Image.d.ts +0 -28
  39. package/lib/import/converters/fields/nestable/Image.js +0 -67
  40. package/lib/import/converters/fields/nestable/Link.d.ts +0 -4
  41. package/lib/import/converters/fields/nestable/Link.js +0 -70
  42. package/lib/import/converters/fields/nestable/Nestable.d.ts +0 -5
  43. package/lib/import/converters/fields/nestable/Nestable.js +0 -35
  44. package/lib/import/converters/fields/nestable/Number.d.ts +0 -3
  45. package/lib/import/converters/fields/nestable/Number.js +0 -13
  46. package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +0 -4
  47. package/lib/import/converters/fields/nestable/RichText/embedBlock.js +0 -14
  48. package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +0 -4
  49. package/lib/import/converters/fields/nestable/RichText/imageBlock.js +0 -12
  50. package/lib/import/converters/fields/nestable/RichText/index.d.ts +0 -4
  51. package/lib/import/converters/fields/nestable/RichText/index.js +0 -22
  52. package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +0 -4
  53. package/lib/import/converters/fields/nestable/RichText/textBlock.js +0 -54
  54. package/lib/import/converters/fields/nestable/Select.d.ts +0 -3
  55. package/lib/import/converters/fields/nestable/Select.js +0 -13
  56. package/lib/import/converters/fields/nestable/Text.d.ts +0 -3
  57. package/lib/import/converters/fields/nestable/Text.js +0 -13
  58. package/lib/import/converters/fields/nestable/Timestamp.d.ts +0 -3
  59. package/lib/import/converters/fields/nestable/Timestamp.js +0 -13
  60. package/lib/import/converters/fields/nestable/index.d.ts +0 -13
  61. package/lib/import/converters/fields/nestable/index.js +0 -16
  62. package/lib/import/converters/index.d.ts +0 -2
  63. package/lib/import/converters/index.js +0 -5
  64. package/lib/import/index.d.ts +0 -2
  65. package/lib/import/index.js +0 -5
  66. package/lib/import/validators/Document.d.ts +0 -6
  67. package/lib/import/validators/Document.js +0 -64
  68. package/lib/import/validators/fields/ImportContent.d.ts +0 -5
  69. package/lib/import/validators/fields/ImportContent.js +0 -21
  70. package/lib/import/validators/fields/ImportField.d.ts +0 -141
  71. package/lib/import/validators/fields/ImportField.js +0 -33
  72. package/lib/import/validators/fields/ImportGroup.d.ts +0 -345
  73. package/lib/import/validators/fields/ImportGroup.js +0 -27
  74. package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +0 -8
  75. package/lib/import/validators/fields/ImportSlices/ImportSlices.js +0 -30
  76. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +0 -16
  77. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +0 -61
  78. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +0 -4
  79. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +0 -7
  80. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +0 -2
  81. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +0 -15
  82. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +0 -9
  83. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +0 -39
  84. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +0 -11
  85. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +0 -24
  86. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +0 -11
  87. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +0 -24
  88. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +0 -4
  89. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +0 -7
  90. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +0 -3
  91. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +0 -6
  92. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +0 -342
  93. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +0 -11
  94. package/lib/import/validators/fields/ImportSlices/index.d.ts +0 -1
  95. package/lib/import/validators/fields/ImportSlices/index.js +0 -4
  96. package/lib/import/validators/fields/ImportSlices/utils.d.ts +0 -4
  97. package/lib/import/validators/fields/ImportSlices/utils.js +0 -35
  98. package/lib/import/validators/fields/RepeatableZone.d.ts +0 -11
  99. package/lib/import/validators/fields/RepeatableZone.js +0 -14
  100. package/lib/import/validators/fields/RepeatableZoneItem.d.ts +0 -11
  101. package/lib/import/validators/fields/RepeatableZoneItem.js +0 -39
  102. package/lib/import/validators/fields/UID.d.ts +0 -6
  103. package/lib/import/validators/fields/UID.js +0 -15
  104. package/lib/import/validators/fields/index.d.ts +0 -4
  105. package/lib/import/validators/fields/index.js +0 -7
  106. package/lib/import/validators/fields/nestable/Boolean.d.ts +0 -6
  107. package/lib/import/validators/fields/nestable/Boolean.js +0 -6
  108. package/lib/import/validators/fields/nestable/Color.d.ts +0 -6
  109. package/lib/import/validators/fields/nestable/Color.js +0 -15
  110. package/lib/import/validators/fields/nestable/Date.d.ts +0 -6
  111. package/lib/import/validators/fields/nestable/Date.js +0 -19
  112. package/lib/import/validators/fields/nestable/Embed.d.ts +0 -13
  113. package/lib/import/validators/fields/nestable/Embed.js +0 -31
  114. package/lib/import/validators/fields/nestable/GeoPoint.d.ts +0 -13
  115. package/lib/import/validators/fields/nestable/GeoPoint.js +0 -13
  116. package/lib/import/validators/fields/nestable/Image/default.d.ts +0 -22
  117. package/lib/import/validators/fields/nestable/Image/default.js +0 -19
  118. package/lib/import/validators/fields/nestable/Image/index.d.ts +0 -26
  119. package/lib/import/validators/fields/nestable/Image/index.js +0 -32
  120. package/lib/import/validators/fields/nestable/Image/merge.d.ts +0 -23
  121. package/lib/import/validators/fields/nestable/Image/merge.js +0 -44
  122. package/lib/import/validators/fields/nestable/Image/model.d.ts +0 -18
  123. package/lib/import/validators/fields/nestable/Image/model.js +0 -2
  124. package/lib/import/validators/fields/nestable/Image/validators.d.ts +0 -132
  125. package/lib/import/validators/fields/nestable/Image/validators.js +0 -43
  126. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +0 -6
  127. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +0 -25
  128. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +0 -24
  129. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +0 -32
  130. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +0 -6
  131. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +0 -18
  132. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +0 -10
  133. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +0 -11
  134. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +0 -22
  135. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +0 -13
  136. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +0 -78
  137. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +0 -43
  138. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +0 -79
  139. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +0 -27
  140. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +0 -4
  141. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +0 -7
  142. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +0 -24
  143. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +0 -18
  144. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.d.ts +0 -12
  145. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.js +0 -16
  146. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +0 -5
  147. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +0 -10
  148. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +0 -15
  149. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +0 -20
  150. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +0 -2
  151. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +0 -5
  152. package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +0 -2
  153. package/lib/import/validators/fields/nestable/ImportRichText/index.js +0 -7
  154. package/lib/import/validators/fields/nestable/Link.d.ts +0 -53
  155. package/lib/import/validators/fields/nestable/Link.js +0 -35
  156. package/lib/import/validators/fields/nestable/Nestable.d.ts +0 -192
  157. package/lib/import/validators/fields/nestable/Nestable.js +0 -71
  158. package/lib/import/validators/fields/nestable/Number.d.ts +0 -17
  159. package/lib/import/validators/fields/nestable/Number.js +0 -17
  160. package/lib/import/validators/fields/nestable/Select.d.ts +0 -16
  161. package/lib/import/validators/fields/nestable/Select.js +0 -19
  162. package/lib/import/validators/fields/nestable/Text.d.ts +0 -6
  163. package/lib/import/validators/fields/nestable/Text.js +0 -6
  164. package/lib/import/validators/fields/nestable/Timestamp.d.ts +0 -7
  165. package/lib/import/validators/fields/nestable/Timestamp.js +0 -19
  166. package/lib/import/validators/fields/nestable/index.d.ts +0 -14
  167. package/lib/import/validators/fields/nestable/index.js +0 -19
  168. package/lib/import/validators/index.d.ts +0 -2
  169. package/lib/import/validators/index.js +0 -5
  170. package/src/import/converters/Document.ts +0 -38
  171. package/src/import/converters/fields/Group.ts +0 -18
  172. package/src/import/converters/fields/RepeatableZone.ts +0 -19
  173. package/src/import/converters/fields/RepeatableZoneItem.ts +0 -32
  174. package/src/import/converters/fields/Slices/SharedSlice.ts +0 -24
  175. package/src/import/converters/fields/Slices/SharedSliceContent.ts +0 -27
  176. package/src/import/converters/fields/Slices/Slices.ts +0 -20
  177. package/src/import/converters/fields/Slices/index.ts +0 -1
  178. package/src/import/converters/fields/UID.ts +0 -9
  179. package/src/import/converters/fields/index.ts +0 -4
  180. package/src/import/converters/fields/nestable/Boolean.ts +0 -13
  181. package/src/import/converters/fields/nestable/Color.ts +0 -14
  182. package/src/import/converters/fields/nestable/Date.ts +0 -17
  183. package/src/import/converters/fields/nestable/Embed.ts +0 -37
  184. package/src/import/converters/fields/nestable/GeoPoint.ts +0 -16
  185. package/src/import/converters/fields/nestable/Image.ts +0 -91
  186. package/src/import/converters/fields/nestable/Link.ts +0 -77
  187. package/src/import/converters/fields/nestable/Nestable.ts +0 -55
  188. package/src/import/converters/fields/nestable/Number.ts +0 -14
  189. package/src/import/converters/fields/nestable/RichText/embedBlock.ts +0 -17
  190. package/src/import/converters/fields/nestable/RichText/imageBlock.ts +0 -17
  191. package/src/import/converters/fields/nestable/RichText/index.ts +0 -23
  192. package/src/import/converters/fields/nestable/RichText/textBlock.ts +0 -62
  193. package/src/import/converters/fields/nestable/Select.ts +0 -14
  194. package/src/import/converters/fields/nestable/Text.ts +0 -14
  195. package/src/import/converters/fields/nestable/Timestamp.ts +0 -14
  196. package/src/import/converters/fields/nestable/index.ts +0 -13
  197. package/src/import/converters/index.ts +0 -2
  198. package/src/import/index.ts +0 -2
  199. package/src/import/validators/Document.ts +0 -103
  200. package/src/import/validators/fields/ImportContent.ts +0 -30
  201. package/src/import/validators/fields/ImportField.ts +0 -36
  202. package/src/import/validators/fields/ImportGroup.ts +0 -45
  203. package/src/import/validators/fields/ImportSlices/ImportSlices.ts +0 -56
  204. package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +0 -104
  205. package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +0 -6
  206. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +0 -20
  207. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +0 -65
  208. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +0 -45
  209. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +0 -45
  210. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +0 -4
  211. package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +0 -3
  212. package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +0 -21
  213. package/src/import/validators/fields/ImportSlices/index.ts +0 -1
  214. package/src/import/validators/fields/ImportSlices/utils.ts +0 -43
  215. package/src/import/validators/fields/RepeatableZone.ts +0 -21
  216. package/src/import/validators/fields/RepeatableZoneItem.ts +0 -64
  217. package/src/import/validators/fields/UID.ts +0 -27
  218. package/src/import/validators/fields/index.ts +0 -4
  219. package/src/import/validators/fields/nestable/Boolean.ts +0 -7
  220. package/src/import/validators/fields/nestable/Color.ts +0 -28
  221. package/src/import/validators/fields/nestable/Date.ts +0 -34
  222. package/src/import/validators/fields/nestable/Embed.ts +0 -41
  223. package/src/import/validators/fields/nestable/GeoPoint.ts +0 -21
  224. package/src/import/validators/fields/nestable/Image/default.ts +0 -22
  225. package/src/import/validators/fields/nestable/Image/index.ts +0 -66
  226. package/src/import/validators/fields/nestable/Image/merge.ts +0 -64
  227. package/src/import/validators/fields/nestable/Image/model.ts +0 -18
  228. package/src/import/validators/fields/nestable/Image/validators.ts +0 -70
  229. package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +0 -39
  230. package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +0 -54
  231. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +0 -44
  232. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +0 -13
  233. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +0 -17
  234. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +0 -56
  235. package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +0 -48
  236. package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +0 -4
  237. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +0 -24
  238. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.ts +0 -19
  239. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +0 -8
  240. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +0 -24
  241. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +0 -2
  242. package/src/import/validators/fields/nestable/ImportRichText/index.ts +0 -2
  243. package/src/import/validators/fields/nestable/Link.ts +0 -59
  244. package/src/import/validators/fields/nestable/Nestable.ts +0 -88
  245. package/src/import/validators/fields/nestable/Number.ts +0 -38
  246. package/src/import/validators/fields/nestable/Select.ts +0 -38
  247. package/src/import/validators/fields/nestable/Text.ts +0 -7
  248. package/src/import/validators/fields/nestable/Timestamp.ts +0 -39
  249. package/src/import/validators/fields/nestable/index.ts +0 -14
  250. package/src/import/validators/index.ts +0 -2
@@ -1,103 +0,0 @@
1
- import { either } from "fp-ts"
2
- import { Either, isLeft } from "fp-ts/Either"
3
- import { pipe } from "fp-ts/lib/function"
4
- import * as t from "io-ts"
5
-
6
- import type { WidgetKey } from "../../common"
7
- import type { StaticCustomType, StaticWidget } from "../../customtypes"
8
- import { flattenCustomTypeFields } from "../../customtypes"
9
- import { isObject } from "../../utils/Objects"
10
- import { withCustomError } from "../../validators/function"
11
- import { ImportField } from "./fields/ImportField"
12
-
13
- const rawImportDocument = withCustomError(
14
- t.UnknownRecord,
15
- () => "document is not an object",
16
- )
17
-
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
- }
36
-
37
- // retrieving the right codec then testing out fieldValue with it.
38
- const { result, codec } = ImportField.decode(model)(content)
39
-
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
- ]
52
-
53
- return { ...error, context }
54
- })
55
- return either.left(errors)
56
- }
57
- return either.right(result.right)
58
- }
59
- }
60
-
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
- )
76
-
77
- if (isLeft(parsedField))
78
- return { ...acc, errors: [...acc.errors, ...parsedField.left] }
79
-
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
- }
90
-
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)),
100
- )
101
- },
102
- t.identity,
103
- )
@@ -1,30 +0,0 @@
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: ${valueCodec.name}`,
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, c) => {
19
- return pipe(
20
- valueCodec.validate(u, c),
21
- either.map((decodedValue) => {
22
- return {
23
- type,
24
- value: decodedValue,
25
- }
26
- }),
27
- )
28
- },
29
- (field) => field.value as unknown as O,
30
- )
@@ -1,36 +0,0 @@
1
- import type { StaticWidget } from "../../../customtypes"
2
- import { ImportGroup } from "./ImportGroup"
3
- import { ImportSlices } from "./ImportSlices"
4
- import { ImportNestable } from "./nestable"
5
-
6
- export type ImportField = ImportSlices | ImportNestable | ImportGroup
7
-
8
- export const ImportField = {
9
- is(u: unknown): u is ImportField {
10
- return ImportField.is(u)
11
- },
12
- decode: (field: StaticWidget) => {
13
- return (content: unknown) => {
14
- switch (field.type) {
15
- case "UID":
16
- throw new Error(
17
- `The field '${field.type}' should be put at the root level of the document`,
18
- )
19
- case "Slices":
20
- return {
21
- codec: ImportSlices(field),
22
- result: ImportSlices(field).decode(content),
23
- }
24
- case "Group":
25
- return {
26
- codec: ImportGroup(field),
27
- result: ImportGroup(field).decode(content),
28
- }
29
- case "Choice":
30
- throw new Error(`Unsupported type of field ${field.type}`)
31
- default:
32
- return ImportNestable.decode(field)(content)
33
- }
34
- }
35
- },
36
- }
@@ -1,45 +0,0 @@
1
- import * as E from "fp-ts/Either"
2
- import { pipe } from "fp-ts/function"
3
- import * as t from "io-ts"
4
-
5
- import type { Group } from "../../../customtypes"
6
- import { EmptyArrayOrElse } from "../../../validators"
7
- import { withCustomError } from "../../../validators/function"
8
- import { ImportContent } from "./ImportContent"
9
- import { RepeatableZone } from "./RepeatableZone"
10
-
11
- export const ImportGroupValue = (groupCustomType?: Group) => {
12
- const fieldsModel = groupCustomType?.config?.fields ?? {}
13
- const groupArrayCodec = RepeatableZone(fieldsModel)
14
-
15
- return withCustomError(
16
- new t.Type<RepeatableZone>(
17
- groupArrayCodec.name,
18
- groupArrayCodec.is,
19
- (u, c) =>
20
- pipe(
21
- groupArrayCodec.validate(u, c),
22
- E.chain((groups) => {
23
- if (
24
- groupCustomType?.config?.repeat === false &&
25
- groups.length > 1
26
- ) {
27
- return t.failure(
28
- groups,
29
- c,
30
- "The custom type for this group field does not allow multiple group items",
31
- )
32
- }
33
- return t.success(groups)
34
- }),
35
- ),
36
- t.identity,
37
- ),
38
- () => "The group field value must be an array",
39
- )
40
- }
41
-
42
- export const ImportGroup = (groupCustomType?: Group) =>
43
- ImportContent("Group", EmptyArrayOrElse(ImportGroupValue(groupCustomType)))
44
-
45
- export type ImportGroup = t.TypeOf<ReturnType<typeof ImportGroup>>
@@ -1,56 +0,0 @@
1
- import * as E from "fp-ts/Either"
2
- import { pipe } from "fp-ts/function"
3
- import * as t from "io-ts"
4
-
5
- import type { StaticSlices } from "../../../../customtypes"
6
- import { EmptyArrayOrElse } from "../../../../validators"
7
- import { ImportContent } from "../ImportContent"
8
- import { SharedSlice } from "./SharedSlice"
9
- import {
10
- extractSupportedSlices,
11
- findImportSharedSliceDuplicateIds,
12
- } from "./utils"
13
-
14
- export const ImportSlices = (staticSlices: StaticSlices) => {
15
- const supportedSlices = extractSupportedSlices(staticSlices)
16
-
17
- // For now we only support the SharedSlice, however if we want to support more in the future
18
- // we would have to change the codec here to something like this: t.array(t.union([ImportSharedSlice(sharedSlices), NewSliceCodec(newSliceCustomTypes)])).
19
- const SharedSliceCodec = SharedSlice(supportedSlices)
20
- const SlicesArrayCodec = t.array(SharedSliceCodec)
21
-
22
- return ImportContent(
23
- "Slices",
24
- EmptyArrayOrElse(
25
- new t.ArrayType<typeof SharedSliceCodec, SharedSlice[]>(
26
- SlicesArrayCodec.name,
27
- (u): u is SharedSlice[] => SlicesArrayCodec.is(u),
28
- (u, c) => {
29
- return pipe(
30
- SlicesArrayCodec.validate(u, c),
31
- E.chain((slices) => {
32
- // This part might not make sense for all Slice types in the future, but for now we only support the SharedSlice
33
- // In case we support more in the future, we would have to filter only the relevant type for this check
34
- const sharedSliceDuplicates =
35
- findImportSharedSliceDuplicateIds(slices)
36
- if (sharedSliceDuplicates.length > 0) {
37
- return t.failure(
38
- slices,
39
- [],
40
- `Duplicate slice IDs detected: ${sharedSliceDuplicates.join(
41
- ", ",
42
- )}`,
43
- )
44
- }
45
- return t.success(slices)
46
- }),
47
- )
48
- },
49
- t.identity,
50
- SharedSliceCodec,
51
- ),
52
- ),
53
- )
54
- }
55
-
56
- export type ImportSlices = t.TypeOf<ReturnType<typeof ImportSlices>>
@@ -1,104 +0,0 @@
1
- import * as E from "fp-ts/Either"
2
- import { pipe } from "fp-ts/function"
3
- import * as t from "io-ts"
4
-
5
- import type { SharedSlice as SharedSliceCustomType } from "../../../../../customtypes"
6
- import { NonEmptyString, String } from "../../../../../validators"
7
- import { RepeatableZone } from "../../RepeatableZone"
8
- import { RepeatableZoneItem } from "../../RepeatableZoneItem"
9
- import {
10
- OptionalSharedSliceId,
11
- SharedSliceId,
12
- SharedSliceType,
13
- SharedSliceVariation,
14
- } from "./fields"
15
-
16
- export type SharedSlice = {
17
- id: SharedSliceId | null | undefined
18
- slice_type: string
19
- name: string
20
- variation: string
21
- primary: RepeatableZoneItem | null | undefined
22
- items: RepeatableZone | null | undefined
23
- slice_label: string | null | undefined
24
- version: string | null | undefined
25
- }
26
-
27
- const SharedSliceShape = t.strict({
28
- id: OptionalSharedSliceId,
29
- slice_type: NonEmptyString,
30
- name: String,
31
- variation: NonEmptyString,
32
- primary: t.union([t.undefined, t.null, t.record(NonEmptyString, t.unknown)]),
33
- items: t.union([
34
- t.undefined,
35
- t.null,
36
- t.array(t.record(NonEmptyString, t.unknown)),
37
- ]),
38
- slice_label: t.union([t.undefined, t.null, String]),
39
- version: t.union([t.undefined, t.null, String]),
40
- })
41
-
42
- export const SharedSlice = (sharedSlices: SharedSliceCustomType[]) =>
43
- new t.Type<SharedSlice>(
44
- "SharedSlice",
45
- (u): u is SharedSlice => SharedSliceShape.is(u),
46
- (u, c) =>
47
- pipe(
48
- // We validate the base fields that we can validate directly based on the provided 'sharedSlices'
49
- t
50
- .type({
51
- id: OptionalSharedSliceId,
52
- slice_type: SharedSliceType(sharedSlices),
53
- slice_label: t.union([t.undefined, t.null, String]),
54
- version: t.union([t.undefined, t.null, String]),
55
- })
56
- .validate(u, c),
57
- E.chain((decoded) =>
58
- pipe(
59
- // We validate the 'variation' field, for which we need the SharedSlice custom type retrieved in the first step
60
- t
61
- .type({
62
- variation: SharedSliceVariation(decoded.slice_type.data),
63
- })
64
- .validate(u, c),
65
- E.map(({ variation }) => ({ ...decoded, variation })),
66
- ),
67
- ),
68
- E.chain((decoded) =>
69
- pipe(
70
- // We validate the 'primary' and 'items' content fields, for which we need the Variation custom type retrieved in the previous step
71
- t
72
- .partial({
73
- primary: RepeatableZoneItem(
74
- decoded.variation.data.primary ?? {},
75
- ),
76
- items: RepeatableZone(decoded.variation.data.items ?? {}),
77
- })
78
- .validate(u, c),
79
- E.map(({ primary, items }) => ({ ...decoded, primary, items })),
80
- ),
81
- ),
82
- E.map(
83
- ({
84
- id,
85
- slice_type,
86
- variation,
87
- primary,
88
- items,
89
- slice_label,
90
- version,
91
- }) => ({
92
- id,
93
- slice_type: slice_type.slice_type,
94
- name: slice_type.data.name,
95
- variation: variation.variation,
96
- primary,
97
- items,
98
- slice_label,
99
- version: version ?? variation.data.version,
100
- }),
101
- ),
102
- ),
103
- t.identity,
104
- )
@@ -1,6 +0,0 @@
1
- export const SharedSliceErrors = {
2
- SliceTypeNotFound: (slice_type: string) =>
3
- `Shared slice '${slice_type}' not found in this slice zone in the document's custom type`,
4
- VariationNotFound: (variation: string, slice_type: string) =>
5
- `Variation '${variation}' not found for Slice '${slice_type}'`,
6
- } as const
@@ -1,20 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- import { SharedSliceId } from "./SharedSliceId"
4
-
5
- // Wrapping the 'SharedSliceId' codec in an optional codec here for the sake of error reporting.
6
- // When using t.union([t.undefined, t.null, SharedSliceId]) we get a nested error context
7
- // with the actual decoding error at position 2 in the context array.
8
- // To avoid mutating the error context we create this new wrapper codec so that the error context will always have desired depth.
9
- export const OptionalSharedSliceId = new t.Type<
10
- SharedSliceId | null | undefined
11
- >(
12
- "OptionalSharedSliceId",
13
- (u): u is SharedSliceId | null | undefined =>
14
- u === null || u === undefined || SharedSliceId.is(u),
15
- (u, c) => {
16
- if (u === null || u === undefined) return t.success(u)
17
- return SharedSliceId.validate(u, c)
18
- },
19
- t.identity,
20
- )
@@ -1,65 +0,0 @@
1
- import * as E from "fp-ts/Either"
2
- import { pipe } from "fp-ts/function"
3
- import * as t from "io-ts"
4
-
5
- import { UUID } from "../../../../../../common/UUID"
6
- import { NonEmptyString } from "../../../../../../validators"
7
-
8
- export type SharedSliceId = `${string}$${UUID}`
9
-
10
- const baseErrorText =
11
- "Slice id must be a non empty string matching the following pattern 'slice_type$uuid'"
12
-
13
- export const SharedSliceIdValidationError = {
14
- Base: baseErrorText,
15
- IncorrectUUID: (uuid: string | undefined) =>
16
- `Incorrect UUID: '${uuid}' - ${baseErrorText}`,
17
- IncorrectSliceType: (sliceType: string | undefined) =>
18
- `Incorrect slice_type: '${sliceType}' - ${baseErrorText}`,
19
- } as const
20
-
21
- export const SharedSliceId = new t.Type<SharedSliceId, string, unknown>(
22
- "SharedSliceId",
23
- (u): u is SharedSliceId => {
24
- if (typeof u !== "string") {
25
- return false
26
- }
27
- const [sliceName, uuid] = u.split("$")
28
- return NonEmptyString.is(sliceName) && UUID.is(uuid)
29
- },
30
- (u, c) =>
31
- pipe(
32
- NonEmptyString.validate(u, c),
33
- E.mapLeft((errors) =>
34
- errors.map(
35
- (error): t.ValidationError => ({
36
- ...error,
37
- message: SharedSliceIdValidationError.Base,
38
- }),
39
- ),
40
- ),
41
- E.chain((sliceId) => {
42
- const [sliceName, uuid] = sliceId.split("$")
43
- return pipe(
44
- t.tuple([NonEmptyString, UUID]).validate([sliceName, uuid], c),
45
- E.mapLeft((errors) =>
46
- errors.map((error): t.ValidationError => {
47
- const tupleErrorContext = error.context[error.context.length - 1]
48
- return {
49
- ...error,
50
- context: [
51
- ...error.context.slice(0, -1), // We don't want the tuple decoder error context
52
- ],
53
- message:
54
- tupleErrorContext?.key === "0"
55
- ? SharedSliceIdValidationError.IncorrectSliceType(sliceName)
56
- : SharedSliceIdValidationError.IncorrectUUID(uuid),
57
- }
58
- }),
59
- ),
60
- )
61
- }),
62
- E.map(([sliceName, uuid]) => `${sliceName}$${uuid}`),
63
- ),
64
- (sliceId) => sliceId,
65
- )
@@ -1,45 +0,0 @@
1
- import * as E from "fp-ts/Either"
2
- import { pipe } from "fp-ts/function"
3
- import * as t from "io-ts"
4
-
5
- import { SharedSlice as SharedSliceCustomType } from "../../../../../../customtypes"
6
- import { NonEmptyString } from "../../../../../../validators"
7
- import { findSlice } from "../utils"
8
-
9
- export type SharedSliceType = {
10
- slice_type: string
11
- data: SharedSliceCustomType
12
- }
13
-
14
- /**
15
- * slice_type - the validated slice_type
16
- * slice - SharedSlice custom type data matching the slice_type. We return it alongside the validated slice_type, because it is needed to decode the 'variation' field in the SharedSlice (see SharedSliceVariation.ts)
17
- */
18
- const SharedSliceTypeShape = t.strict({
19
- slice_type: NonEmptyString,
20
- slice: SharedSliceCustomType,
21
- })
22
-
23
- /**
24
- * Builds the decoder for the 'slice_type' field in the SharedSlice. Alongside the decoded 'slice_type' it also returns the SharedSlice data matching the slice_type.
25
- * @param slices all the SharedSlices from the custom type
26
- */
27
- export const SharedSliceType = (slices: SharedSliceCustomType[]) =>
28
- new t.Type<SharedSliceType, string, unknown>(
29
- "slice_type",
30
- (u): u is SharedSliceType => SharedSliceTypeShape.is(u),
31
- (u, c) =>
32
- pipe(
33
- NonEmptyString.validate(u, c),
34
- E.chain((slice_type) =>
35
- pipe(
36
- findSlice(slices)(slice_type),
37
- E.fold(
38
- (err) => t.failure(u, c, err),
39
- (data) => t.success({ slice_type, data }),
40
- ),
41
- ),
42
- ),
43
- ),
44
- ({ slice_type }) => slice_type,
45
- )
@@ -1,45 +0,0 @@
1
- import * as E from "fp-ts/Either"
2
- import { pipe } from "fp-ts/function"
3
- import * as t from "io-ts"
4
-
5
- import { SharedSlice, Variation } from "../../../../../../customtypes"
6
- import { NonEmptyString } from "../../../../../../validators"
7
- import { findSliceVariation } from "../utils"
8
-
9
- export type SharedSliceVariation = {
10
- variation: string
11
- data: Variation
12
- }
13
-
14
- /**
15
- * variation - the validated variation of the slice
16
- * data - Variation data matching the variation. We return it alongside the validated variation, because it is needed to decode the 'primary' and 'items' fields in the SharedSlice.
17
- */
18
- const SharedSliceVariationShape = t.strict({
19
- variation: NonEmptyString,
20
- data: Variation,
21
- })
22
-
23
- /**
24
- * Builds the decoder for the 'variation' field in the SharedSlice. Alongside the decoded 'variation' it also returns the Variation data matching the variation custom type.
25
- * @param slice SharedSlice from the custom type
26
- */
27
- export const SharedSliceVariation = (slice: SharedSlice) =>
28
- new t.Type<SharedSliceVariation, string, unknown>(
29
- "variation",
30
- (u): u is SharedSliceVariation => SharedSliceVariationShape.is(u),
31
- (u, c) =>
32
- pipe(
33
- NonEmptyString.validate(u, c),
34
- E.chain((variation) =>
35
- pipe(
36
- findSliceVariation(slice)(variation),
37
- E.fold(
38
- (err) => t.failure(u, c, err),
39
- (data) => t.success({ variation, data }),
40
- ),
41
- ),
42
- ),
43
- ),
44
- ({ variation }) => variation,
45
- )
@@ -1,4 +0,0 @@
1
- export * from "./OptionalSharedSliceId"
2
- export * from "./SharedSliceId"
3
- export * from "./SharedSliceType"
4
- export * from "./SharedSliceVariation"
@@ -1,3 +0,0 @@
1
- export * from "./errors"
2
- export * from "./fields"
3
- export * from "./SharedSlice"
@@ -1,21 +0,0 @@
1
- import * as E from "fp-ts/Either"
2
- import { pipe } from "fp-ts/function"
3
-
4
- import type { SharedSlice as SharedSliceCustomType } from "../../../../../customtypes"
5
- import type { Variation } from "../../../../../customtypes"
6
- import { SharedSliceErrors } from "./errors"
7
-
8
- export const findSlice =
9
- (slices: SharedSliceCustomType[]) => (sliceId: string) =>
10
- pipe(
11
- slices.find((slice) => slice.id === sliceId),
12
- E.fromNullable(SharedSliceErrors.SliceTypeNotFound(sliceId)),
13
- )
14
-
15
- export const findSliceVariation =
16
- (slice: SharedSliceCustomType) =>
17
- (variation: string): E.Either<string, Variation> =>
18
- pipe(
19
- slice.variations.find((v) => v.id === variation),
20
- E.fromNullable(SharedSliceErrors.VariationNotFound(variation, slice.id)),
21
- )
@@ -1 +0,0 @@
1
- export * from "./ImportSlices"
@@ -1,43 +0,0 @@
1
- import * as A from "fp-ts/Array"
2
- import { pipe } from "fp-ts/function"
3
- import * as O from "fp-ts/Option"
4
-
5
- import {
6
- SharedSlice as SharedSliceCustomType,
7
- StaticSlices,
8
- } from "../../../../customtypes"
9
- import type { SharedSlice, SharedSliceId } from "./SharedSlice"
10
-
11
- // Extracts all supported slices from the static slices object
12
- // For now we only support the SharedSlice, if we want to support other slices in the future, we have to add them here
13
- export const extractSupportedSlices = (
14
- staticSlices: StaticSlices,
15
- ): SharedSliceCustomType[] =>
16
- pipe(
17
- Object.values(staticSlices.config?.choices ?? {}).map((slice) =>
18
- pipe(SharedSliceCustomType.decode(slice), O.fromEither),
19
- ),
20
- A.compact,
21
- )
22
-
23
- export const findImportSharedSliceDuplicateIds = (
24
- slices: SharedSlice[],
25
- ): SharedSliceId[] => {
26
- const duplicatesMap = slices.reduce((acc, { id }) => {
27
- if (id) {
28
- const currentNumOfDuplicates = acc[id] ?? 0
29
- return {
30
- ...acc,
31
- [id]: acc[id] === undefined ? 0 : currentNumOfDuplicates + 1,
32
- }
33
- }
34
- return acc
35
- }, {} as Record<SharedSliceId, number>)
36
-
37
- return Object.entries(duplicatesMap).flatMap(([id, numOfDuplicates]) => {
38
- if (numOfDuplicates > 0) {
39
- return [id]
40
- }
41
- return []
42
- })
43
- }
@@ -1,21 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- import type { WidgetKey } from "../../../common"
4
- import type { NestableWidget } from "../../../customtypes"
5
- import { withCustomError } from "../../../validators/function"
6
- import { RepeatableZoneItem } from "./RepeatableZoneItem"
7
-
8
- export type RepeatableZone = t.TypeOf<ReturnType<typeof RepeatableZone>>
9
-
10
- /**
11
- * A custom type for a repeatable zone. This type of structure can be found 'items' field of a slice or in the group field.
12
- *
13
- * @param fieldModels a record of all nestable widgets that can be used in the zone
14
- */
15
- export const RepeatableZone = (
16
- fieldModels: Record<WidgetKey, NestableWidget>,
17
- ) =>
18
- withCustomError(
19
- t.array(RepeatableZoneItem(fieldModels)),
20
- () => "The repeatable zone value must be an array",
21
- )