@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,53 +1,55 @@
1
- import * as t from 'io-ts'
2
- import { StringOrNull } from '../validators/StringOrNull'
3
- import { Either, right, left } from 'fp-ts/lib/Either'
4
- import { withFallback } from 'io-ts-types/lib/withFallback'
5
-
6
- import { Format } from './Format'
7
- import { DynamicWidget } from './widgets/Widget'
8
- import SharedSlice from './widgets/slices/SharedSlice'
9
- import { DynamicSlice } from './widgets/slices/Slice'
10
- import { DynamicSlices } from './widgets/slices/Slices'
11
- import WidgetTypes from './widgets/WidgetTypes'
12
- import SlicesTypes from './widgets/slices/SlicesTypes'
13
-
14
- import { StaticSection, DynamicSection, sectionReader, Sections } from './Section'
1
+ import { Either, left, right } from "fp-ts/lib/Either"
2
+ import * as t from "io-ts"
3
+ import { withFallback } from "io-ts-types/lib/withFallback"
4
+
5
+ import { StringOrNull } from "../validators"
6
+ import { Format } from "./Format"
7
+ import {
8
+ DynamicSection,
9
+ sectionReader,
10
+ Sections,
11
+ StaticSection,
12
+ } from "./Section"
13
+ import type SharedSlice from "./widgets/slices/SharedSlice"
14
+ import type { DynamicSlice } from "./widgets/slices/Slice"
15
+ import type { DynamicSlices } from "./widgets/slices/Slices"
16
+ import SlicesTypes from "./widgets/slices/SlicesTypes"
17
+ import type { DynamicWidget } from "./widgets/Widget"
18
+ import WidgetTypes from "./widgets/WidgetTypes"
15
19
 
16
20
  class CustomTypeSlicesError extends Error {
17
- slices: Array<string>
18
- message: string
19
-
20
- constructor(slices: Array<string>) {
21
- super()
22
- this.slices = slices
23
- this.message = this._formatError(slices)
24
- }
25
-
26
- _formatError(slicesRefs: Array<string>) {
27
- const slicesMsg = slicesRefs.map(ref => `\t - ${ref}`);
28
- return (
29
- `The following slices doesn't exists in your Prismic repository:
30
- ${slicesMsg.join('\n')}
21
+ slices: Array<string>
22
+ override message: string
23
+
24
+ constructor(slices: Array<string>) {
25
+ super()
26
+ this.slices = slices
27
+ this.message = this._formatError(slices)
28
+ }
29
+
30
+ _formatError(slicesRefs: Array<string>) {
31
+ const slicesMsg = slicesRefs.map((ref) => `\t - ${ref}`)
32
+ return `The following slices doesn't exists in your Prismic repository:
33
+ ${slicesMsg.join("\n")}
31
34
  `
32
- )
33
- }
35
+ }
34
36
  }
35
37
 
36
38
  function customTypeReader<F extends Format>(format: F) {
37
- return t.exact(
38
- t.intersection([
39
- t.type({
40
- id: t.string,
41
- label: StringOrNull,
42
- repeatable: withFallback(t.boolean, true),
43
- json: t.record(t.string, sectionReader(format)),
44
- status: withFallback(t.boolean, true)
45
- }),
46
- t.partial({
47
- hash: t.string
48
- })
49
- ])
50
- )
39
+ return t.exact(
40
+ t.intersection([
41
+ t.type({
42
+ id: t.string,
43
+ label: StringOrNull,
44
+ repeatable: withFallback(t.boolean, true),
45
+ json: t.record(t.string, sectionReader(format)),
46
+ status: withFallback(t.boolean, true),
47
+ }),
48
+ t.partial({
49
+ hash: t.string,
50
+ }),
51
+ ]),
52
+ )
51
53
  }
52
54
 
53
55
  export const StaticCustomType = customTypeReader(Format.Static)
@@ -57,86 +59,141 @@ export const CustomType = customTypeReader(Format.Dynamic)
57
59
  export type CustomType = t.TypeOf<typeof CustomType>
58
60
 
59
61
  function _retrieveSharedSlicesRef(customType: CustomType): Array<string> {
60
- const flattenWidgets: Array<[string, DynamicWidget]> = Object.entries(customType.json)
61
- .reduce((acc: Array<[string, DynamicWidget]>, [, section]: [string, DynamicSection]) => {
62
- const sectionWidgets: Array<[string, DynamicWidget]> = Object.entries(section)
63
- return acc.concat(sectionWidgets);
64
- }, [])
65
-
66
- const slicezones = flattenWidgets.filter(([, widget]: [string, DynamicWidget]) => widget.type === WidgetTypes.Slices) as Array<[string, DynamicSlices]>
67
-
68
- const allSharedRefs = slicezones.reduce((acc: Array<string>, [, slicezone]) => {
69
- const sharedRefs = Object.entries(slicezone.config && slicezone.config.choices ? slicezone.config.choices : {})
70
- .filter(([, slice]: [string, DynamicSlice]) => slice.type === SlicesTypes.SharedSlice)
71
- .map(([key]) => key)
72
- return acc.concat(sharedRefs);
73
- }, []);
74
-
75
- return allSharedRefs
62
+ const flattenWidgets: Array<[string, DynamicWidget]> = Object.entries(
63
+ customType.json,
64
+ ).reduce(
65
+ (
66
+ acc: Array<[string, DynamicWidget]>,
67
+ [, section]: [string, DynamicSection],
68
+ ) => {
69
+ const sectionWidgets: Array<[string, DynamicWidget]> =
70
+ Object.entries(section)
71
+ return acc.concat(sectionWidgets)
72
+ },
73
+ [],
74
+ )
75
+
76
+ const slicezones = flattenWidgets.filter(
77
+ ([, widget]: [string, DynamicWidget]) => widget.type === WidgetTypes.Slices,
78
+ ) as Array<[string, DynamicSlices]>
79
+
80
+ const allSharedRefs = slicezones.reduce(
81
+ (acc: Array<string>, [, slicezone]) => {
82
+ const sharedRefs = Object.entries(
83
+ slicezone.config && slicezone.config.choices
84
+ ? slicezone.config.choices
85
+ : {},
86
+ )
87
+ .filter(
88
+ ([, slice]: [string, DynamicSlice]) =>
89
+ slice.type === SlicesTypes.SharedSlice,
90
+ )
91
+ .map(([key]) => key)
92
+ return acc.concat(sharedRefs)
93
+ },
94
+ [],
95
+ )
96
+
97
+ return allSharedRefs
76
98
  }
77
99
 
78
- function _mapSharedSlicesRefs<A>(customType: CustomType): (mapFn: (ref: string) => A) => Array<A> {
79
- const refs = _retrieveSharedSlicesRef(customType)
100
+ function _mapSharedSlicesRefs<A>(
101
+ customType: CustomType,
102
+ ): (mapFn: (ref: string) => A) => Array<A> {
103
+ const refs = _retrieveSharedSlicesRef(customType)
80
104
 
81
- return function(mapFn: (ref: string) => A): Array<A> {
82
- return refs.map(mapFn)
83
- }
105
+ return function (mapFn: (ref: string) => A): Array<A> {
106
+ return refs.map(mapFn)
107
+ }
84
108
  }
85
109
 
86
- export function toStatic(customType: CustomType, sharedSlices: Map<string, SharedSlice>): StaticCustomType {
87
- const json = Object.entries(customType.json)
88
- .reduce((acc: { [key: string]: StaticSection }, [sectionKey, dynSection]: [string, DynamicSection]) => {
89
- return { ...acc, [sectionKey]: Sections.toStatic(dynSection, sharedSlices) };
90
- }, {})
91
-
92
- return { ...customType, json } as StaticCustomType;
110
+ export function toStatic(
111
+ customType: CustomType,
112
+ sharedSlices: Map<string, SharedSlice>,
113
+ ): StaticCustomType {
114
+ const json = Object.entries(customType.json).reduce(
115
+ (
116
+ acc: { [key: string]: StaticSection },
117
+ [sectionKey, dynSection]: [string, DynamicSection],
118
+ ) => {
119
+ return {
120
+ ...acc,
121
+ [sectionKey]: Sections.toStatic(dynSection, sharedSlices),
122
+ }
123
+ },
124
+ {},
125
+ )
126
+
127
+ return { ...customType, json } as StaticCustomType
93
128
  }
94
129
 
95
- export function validateSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): Either<CustomTypeSlicesError, CustomType> {
96
- const missingSlices = _mapSharedSlicesRefs<string | undefined>(customType)((ref: string) => {
97
- const slice: SharedSlice | undefined = sharedSlices.get(ref)
98
- const isMissing = !Boolean(slice)
99
- if(isMissing) return ref
100
- }).filter(Boolean) as Array<string>
101
-
102
- if(missingSlices.length > 0) return left(new CustomTypeSlicesError(missingSlices))
103
- else return right(customType)
130
+ export function validateSlices(
131
+ customType: CustomType,
132
+ sharedSlices: Map<string, SharedSlice>,
133
+ ): Either<CustomTypeSlicesError, CustomType> {
134
+ const missingSlices = _mapSharedSlicesRefs<string | undefined>(customType)(
135
+ (ref: string) => {
136
+ const slice: SharedSlice | undefined = sharedSlices.get(ref)
137
+ const isMissing = !slice
138
+ if (isMissing) return ref
139
+ return
140
+ },
141
+ ).filter(Boolean) as Array<string>
142
+
143
+ if (missingSlices.length > 0)
144
+ return left(new CustomTypeSlicesError(missingSlices))
145
+ else return right(customType)
104
146
  }
105
147
 
106
- export function collectWidgets(customType: CustomType, f:((ref: string, widget: DynamicWidget) => DynamicWidget|undefined)): CustomType {
107
- const json = Object.entries(customType.json)
108
- .reduce((acc, [sectionId, section]: [string, DynamicSection]) => {
109
- const updatedSection = Object
110
- .entries(section)
111
- .reduce((acc, [ref, widget]) => {
112
- const updatedWidget = f(ref, widget)
113
- if (!!updatedWidget) {
114
- return {...acc, [ref]: updatedWidget}
115
- }
116
- return acc;
117
- }, {});
118
- return {...acc, [sectionId]: updatedSection};
119
- }, {});
120
-
121
- return { ...customType, json };
148
+ export function collectWidgets(
149
+ customType: CustomType,
150
+ f: (ref: string, widget: DynamicWidget) => DynamicWidget | undefined,
151
+ ): CustomType {
152
+ const json = Object.entries(customType.json).reduce(
153
+ (acc, [sectionId, section]: [string, DynamicSection]) => {
154
+ const updatedSection = Object.entries(section).reduce(
155
+ (acc, [ref, widget]) => {
156
+ const updatedWidget = f(ref, widget)
157
+ if (updatedWidget) {
158
+ return { ...acc, [ref]: updatedWidget }
159
+ }
160
+ return acc
161
+ },
162
+ {},
163
+ )
164
+ return { ...acc, [sectionId]: updatedSection }
165
+ },
166
+ {},
167
+ )
168
+
169
+ return { ...customType, json }
122
170
  }
123
171
 
124
- export function filterMissingSharedSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): CustomType {
125
- return collectWidgets(customType, (_widgetId, widget) => {
126
- if (widget.type === WidgetTypes.Slices) {
127
- if(!widget.config || !widget.config.choices) return widget
128
-
129
- const choices = Object.entries(widget.config.choices)
130
- .reduce((acc, [ sliceId, sliceValue ]: [string, DynamicSlice]) => {
131
- if (sliceValue.type === SlicesTypes.SharedSlice && !sharedSlices.get(sliceId)) return acc
132
- return { ...acc, [sliceId]: sliceValue }
133
- }, {})
134
-
135
- const config = { ...widget.config, choices }
136
-
137
- return {...widget, config }
138
- }
139
-
140
- return widget
141
- })
142
- }
172
+ export function filterMissingSharedSlices(
173
+ customType: CustomType,
174
+ sharedSlices: Map<string, SharedSlice>,
175
+ ): CustomType {
176
+ return collectWidgets(customType, (_widgetId, widget) => {
177
+ if (widget.type === WidgetTypes.Slices) {
178
+ if (!widget.config || !widget.config.choices) return widget
179
+
180
+ const choices = Object.entries(widget.config.choices).reduce(
181
+ (acc, [sliceId, sliceValue]: [string, DynamicSlice]) => {
182
+ if (
183
+ sliceValue.type === SlicesTypes.SharedSlice &&
184
+ !sharedSlices.get(sliceId)
185
+ )
186
+ return acc
187
+ return { ...acc, [sliceId]: sliceValue }
188
+ },
189
+ {},
190
+ )
191
+
192
+ const config = { ...widget.config, choices }
193
+
194
+ return { ...widget, config }
195
+ }
196
+
197
+ return widget
198
+ })
199
+ }
@@ -1,4 +1,4 @@
1
1
  export enum Format {
2
- Static = 'static',
3
- Dynamic = 'dynamic'
4
- }
2
+ Static = "static",
3
+ Dynamic = "dynamic",
4
+ }
@@ -1,11 +1,16 @@
1
- import * as t from 'io-ts'
1
+ import * as t from "io-ts"
2
2
 
3
- import { Format } from './Format'
4
- import { widgetReader, StaticWidget, DynamicWidget, Widgets } from './widgets/Widget'
5
- import SharedSlice from './widgets/slices/SharedSlice'
3
+ import { Format } from "./Format"
4
+ import type SharedSlice from "./widgets/slices/SharedSlice"
5
+ import {
6
+ DynamicWidget,
7
+ StaticWidget,
8
+ widgetReader,
9
+ Widgets,
10
+ } from "./widgets/Widget"
6
11
 
7
12
  export function sectionReader<F extends Format>(format: F) {
8
- return t.record(t.string, widgetReader(format))
13
+ return t.record(t.string, widgetReader(format))
9
14
  }
10
15
 
11
16
  export const StaticSection = sectionReader(Format.Static)
@@ -15,11 +20,19 @@ export const DynamicSection = sectionReader(Format.Dynamic)
15
20
  export type DynamicSection = t.TypeOf<typeof DynamicSection>
16
21
 
17
22
  export const Sections = {
18
- toStatic(dynamic: DynamicSection, sharedSlices: Map<string, SharedSlice>): StaticSection {
19
- const section = Object.entries(dynamic)
20
- .reduce((acc: { [key: string]: StaticWidget }, [widgetKey, widget]: [string, DynamicWidget]) => {
21
- return {...acc, [widgetKey]: Widgets.toStatic(widget, sharedSlices)}
22
- }, {})
23
- return section as StaticSection
24
- }
25
- }
23
+ toStatic(
24
+ dynamic: DynamicSection,
25
+ sharedSlices: Map<string, SharedSlice>,
26
+ ): StaticSection {
27
+ const section = Object.entries(dynamic).reduce(
28
+ (
29
+ acc: { [key: string]: StaticWidget },
30
+ [widgetKey, widget]: [string, DynamicWidget],
31
+ ) => {
32
+ return { ...acc, [widgetKey]: Widgets.toStatic(widget, sharedSlices) }
33
+ },
34
+ {},
35
+ )
36
+ return section as StaticSection
37
+ },
38
+ }
@@ -1,4 +1,4 @@
1
- export { Format } from './Format'
2
- export * as Section from './Section'
3
- export * as Widgets from './widgets'
4
- export * from './CustomType'
1
+ export * from "./CustomType"
2
+ export { Format } from "./Format"
3
+ export * as Section from "./Section"
4
+ export * as Widgets from "./widgets"
@@ -1,29 +1,30 @@
1
- import * as t from 'io-ts'
2
- import { StringOrNull } from '../../validators/StringOrNull'
3
- import WidgetTypes from './WidgetTypes'
4
- import NestableWidget from './nestable/NestableWidget'
1
+ import * as t from "io-ts"
2
+
3
+ import { StringOrNull } from "../../validators"
4
+ import NestableWidget from "./nestable/NestableWidget"
5
+ import WidgetTypes from "./WidgetTypes"
5
6
 
6
7
  const GroupConfig = t.exact(
7
- t.partial({
8
- label: StringOrNull,
9
- repeat: t.boolean,
10
- fields: t.record(t.string, NestableWidget)
11
- })
8
+ t.partial({
9
+ label: StringOrNull,
10
+ repeat: t.boolean,
11
+ fields: t.record(t.string, NestableWidget),
12
+ }),
12
13
  )
13
14
  type GroupConfig = t.TypeOf<typeof GroupConfig>
14
15
 
15
16
  const Group = t.exact(
16
- t.intersection([
17
- t.type({
18
- type: t.literal(WidgetTypes.Group)
19
- }),
20
- t.partial({
21
- fieldset: StringOrNull,
22
- icon: t.string,
23
- description: t.string,
24
- config: GroupConfig
25
- })
26
- ])
17
+ t.intersection([
18
+ t.type({
19
+ type: t.literal(WidgetTypes.Group),
20
+ }),
21
+ t.partial({
22
+ fieldset: StringOrNull,
23
+ icon: t.string,
24
+ description: t.string,
25
+ config: GroupConfig,
26
+ }),
27
+ ]),
27
28
  )
28
29
  type Group = t.TypeOf<typeof Group>
29
30
 
@@ -1,26 +1,27 @@
1
- import * as t from 'io-ts'
2
- import { StringOrNull } from '../../validators/StringOrNull'
3
- import WidgetTypes from './WidgetTypes'
1
+ import * as t from "io-ts"
2
+
3
+ import { StringOrNull } from "../../validators"
4
+ import WidgetTypes from "./WidgetTypes"
4
5
 
5
6
  const UIDConfig = t.exact(
6
- t.partial({
7
- label: StringOrNull,
8
- useAsTitle: t.boolean,
9
- placeholder: t.string
10
- })
7
+ t.partial({
8
+ label: StringOrNull,
9
+ useAsTitle: t.boolean,
10
+ placeholder: t.string,
11
+ }),
11
12
  )
12
13
  type UIDConfig = t.TypeOf<typeof UIDConfig>
13
14
 
14
15
  const UID = t.exact(
15
- t.intersection([
16
- t.type({
17
- type: t.literal(WidgetTypes.UID)
18
- }),
19
- t.partial({
20
- fieldset: StringOrNull,
21
- config: UIDConfig
22
- })
23
- ])
16
+ t.intersection([
17
+ t.type({
18
+ type: t.literal(WidgetTypes.UID),
19
+ }),
20
+ t.partial({
21
+ fieldset: StringOrNull,
22
+ config: UIDConfig,
23
+ }),
24
+ ]),
24
25
  )
25
26
  type UID = t.TypeOf<typeof UID>
26
27
 
@@ -1,20 +1,15 @@
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 { slicesReader, Slices } from './slices/Slices'
6
- import SharedSlice from './slices/SharedSlice'
7
- import { Format } from '../Format'
8
- import Group from './Group'
9
- import WidgetTypes from './WidgetTypes'
3
+ import { Format } from "../Format"
4
+ import Group from "./Group"
5
+ import NestableWidget from "./nestable/NestableWidget"
6
+ import type SharedSlice from "./slices/SharedSlice"
7
+ import { Slices, slicesReader } from "./slices/Slices"
8
+ import UID from "./UID"
9
+ import WidgetTypes from "./WidgetTypes"
10
10
 
11
- export function widgetReader<F extends Format>(format: F){
12
- return t.union([
13
- UID,
14
- NestableWidget,
15
- Group,
16
- slicesReader(format)
17
- ])
11
+ export function widgetReader<F extends Format>(format: F) {
12
+ return t.union([UID, NestableWidget, Group, slicesReader(format)])
18
13
  }
19
14
  export const StaticWidget = widgetReader(Format.Static)
20
15
  export type StaticWidget = t.TypeOf<typeof StaticWidget>
@@ -22,12 +17,16 @@ export type StaticWidget = t.TypeOf<typeof StaticWidget>
22
17
  export const DynamicWidget = widgetReader(Format.Dynamic)
23
18
  export type DynamicWidget = t.TypeOf<typeof DynamicWidget>
24
19
 
25
-
26
20
  export const Widgets = {
27
- toStatic(widget: DynamicWidget, sharedSlices: Map<string, SharedSlice>): StaticWidget {
28
- switch(widget.type) {
29
- case WidgetTypes.Slices: return Slices.toStatic(widget, sharedSlices)
30
- default: return widget as StaticWidget
31
- }
32
- }
33
- }
21
+ toStatic(
22
+ widget: DynamicWidget,
23
+ sharedSlices: Map<string, SharedSlice>,
24
+ ): StaticWidget {
25
+ switch (widget.type) {
26
+ case WidgetTypes.Slices:
27
+ return Slices.toStatic(widget, sharedSlices)
28
+ default:
29
+ return widget as StaticWidget
30
+ }
31
+ },
32
+ }
@@ -1,24 +1,24 @@
1
1
  enum WidgetTypes {
2
- Text = 'Text',
3
- RichText = 'StructuredText',
4
- Color = 'Color',
5
- Image = 'Image',
6
- Date = 'Date',
7
- Timestamp = 'Timestamp',
8
- Number = 'Number',
9
- Range = 'Range',
10
- Select = 'Select',
11
- Link = 'Link',
12
- Embed = 'Embed',
13
- GeoPoint = 'GeoPoint',
14
- Separator = 'Separator',
15
- UID = 'UID',
16
- BooleanField = 'Boolean',
17
- IntegrationField = 'IntegrationFields',
18
- Group = 'Group',
19
- Slices = 'Slices',
20
- // Legacy type for slices
21
- LegacySlices = 'Choice'
2
+ Text = "Text",
3
+ RichText = "StructuredText",
4
+ Color = "Color",
5
+ Image = "Image",
6
+ Date = "Date",
7
+ Timestamp = "Timestamp",
8
+ Number = "Number",
9
+ Range = "Range",
10
+ Select = "Select",
11
+ Link = "Link",
12
+ Embed = "Embed",
13
+ GeoPoint = "GeoPoint",
14
+ Separator = "Separator",
15
+ UID = "UID",
16
+ BooleanField = "Boolean",
17
+ IntegrationField = "IntegrationFields",
18
+ Group = "Group",
19
+ Slices = "Slices",
20
+ // Legacy type for slices
21
+ LegacySlices = "Choice",
22
22
  }
23
23
 
24
- export default WidgetTypes
24
+ export default WidgetTypes
@@ -1,7 +1,7 @@
1
- export * as Nestable from './nestable'
2
- export * as Shared from './shared'
3
- export * as Slices from './slices'
4
- export * as Widget from './Widget'
5
- export { default as Group } from './Group'
6
- export { default as UID } from './UID'
7
- export { default as WidgetTypes } from './WidgetTypes'
1
+ export { default as Group } from "./Group"
2
+ export * as Nestable from "./nestable"
3
+ export * as Shared from "./shared"
4
+ export * as Slices from "./slices"
5
+ export { default as UID } from "./UID"
6
+ export * as Widget from "./Widget"
7
+ export { default as WidgetTypes } from "./WidgetTypes"
@@ -1,30 +1,30 @@
1
- import * as t from 'io-ts'
2
- import { StringOrNull } from '../../../validators/StringOrNull'
3
- import WidgetTypes from '../WidgetTypes'
1
+ import * as t from "io-ts"
2
+
3
+ import { StringOrNull } from "../../../validators"
4
+ import WidgetTypes from "../WidgetTypes"
4
5
 
5
6
  const BooleanConfig = t.exact(
6
- t.partial({
7
- label: StringOrNull,
8
- default_value: t.boolean,
9
- placeholder_true: t.string,
10
- placeholder_false: t.string
11
- })
7
+ t.partial({
8
+ label: StringOrNull,
9
+ default_value: t.boolean,
10
+ placeholder_true: t.string,
11
+ placeholder_false: t.string,
12
+ }),
12
13
  )
13
14
 
14
15
  type BooleanConfig = t.TypeOf<typeof BooleanConfig>
15
16
 
16
17
  const BooleanField = t.exact(
17
- t.intersection([
18
- t.type({
19
- type: t.literal(WidgetTypes.BooleanField)
20
- }),
21
- t.partial({
22
- config: BooleanConfig
23
- })
24
- ])
18
+ t.intersection([
19
+ t.type({
20
+ type: t.literal(WidgetTypes.BooleanField),
21
+ }),
22
+ t.partial({
23
+ config: BooleanConfig,
24
+ }),
25
+ ]),
25
26
  )
26
27
 
27
28
  type BooleanField = t.TypeOf<typeof BooleanField>
28
29
 
29
-
30
- export default BooleanField
30
+ export default BooleanField