@prismicio/types-internal 2.2.0-alpha.2 → 2.2.0-alpha.21

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 (244) 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/WidgetContent.d.ts +56 -56
  12. package/lib/content/fields/nestable/NestableContent.d.ts +7 -7
  13. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +35 -12
  14. package/lib/content/fields/nestable/RichTextContent/Blocks.js +5 -5
  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/import/converters/Document.d.ts +2 -2
  27. package/lib/import/converters/Document.js +6 -6
  28. package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
  29. package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
  30. package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
  31. package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
  32. package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
  33. package/lib/import/converters/fields/Slices/Slices.js +16 -0
  34. package/lib/import/converters/fields/Slices/index.d.ts +1 -0
  35. package/lib/import/converters/fields/Slices/index.js +4 -0
  36. package/lib/import/converters/fields/UID.d.ts +1 -1
  37. package/lib/import/converters/fields/UID.js +0 -2
  38. package/lib/import/converters/fields/index.d.ts +1 -0
  39. package/lib/import/converters/fields/index.js +1 -0
  40. package/lib/import/converters/fields/nestable/Embed.d.ts +2 -1
  41. package/lib/import/converters/fields/nestable/Embed.js +24 -5
  42. package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
  43. package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
  44. package/lib/import/converters/fields/nestable/GeooPoint.d.ts +3 -0
  45. package/lib/import/converters/fields/nestable/GeooPoint.js +15 -0
  46. package/lib/import/converters/fields/nestable/Image.d.ts +6 -18
  47. package/lib/import/converters/fields/nestable/Image.js +47 -24
  48. package/lib/import/converters/fields/nestable/Link.d.ts +3 -2
  49. package/lib/import/converters/fields/nestable/Link.js +62 -11
  50. package/lib/import/converters/fields/nestable/Nestable.d.ts +4 -3
  51. package/lib/import/converters/fields/nestable/Nestable.js +9 -3
  52. package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
  53. package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
  54. package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
  55. package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
  56. package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
  57. package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
  58. package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
  59. package/lib/import/converters/fields/nestable/RichText/textBlock.js +34 -0
  60. package/lib/import/converters/fields/nestable/RichText.d.ts +4 -0
  61. package/lib/import/converters/fields/nestable/RichText.js +55 -0
  62. package/lib/import/converters/fields/nestable/index.d.ts +3 -0
  63. package/lib/import/converters/fields/nestable/index.js +3 -0
  64. package/lib/import/validators/Document.js +4 -9
  65. package/lib/import/validators/fields/ImportField.d.ts +68 -68
  66. package/lib/import/validators/fields/ImportField.js +8 -4
  67. package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
  68. package/lib/import/validators/fields/ImportSlices/ImportSlices.js +29 -0
  69. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +14 -0
  70. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
  71. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
  72. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
  73. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
  74. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
  75. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
  76. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
  77. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
  78. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
  79. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
  80. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
  81. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
  82. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
  83. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
  84. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
  85. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
  86. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
  87. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
  88. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
  89. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
  90. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
  91. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
  92. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
  93. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
  94. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
  95. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
  96. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
  97. package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
  98. package/lib/import/validators/fields/ImportSlices/index.js +4 -0
  99. package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
  100. package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
  101. package/lib/import/validators/fields/UID.d.ts +2 -2
  102. package/lib/import/validators/fields/UID.js +1 -1
  103. package/lib/import/validators/fields/nestable/Embed.d.ts +8 -22
  104. package/lib/import/validators/fields/nestable/Embed.js +5 -28
  105. package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
  106. package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
  107. package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
  108. package/lib/import/validators/fields/nestable/Image/default.js +19 -0
  109. package/lib/import/validators/fields/nestable/Image/index.d.ts +45 -0
  110. package/lib/import/validators/fields/nestable/Image/index.js +41 -0
  111. package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
  112. package/lib/import/validators/fields/nestable/Image/merge.js +44 -0
  113. package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
  114. package/lib/import/validators/fields/nestable/Image/model.js +2 -0
  115. package/lib/import/validators/fields/nestable/Image/validators.d.ts +35 -0
  116. package/lib/import/validators/fields/nestable/Image/validators.js +31 -0
  117. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
  118. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
  119. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
  120. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +26 -0
  121. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
  122. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
  123. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
  124. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
  125. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +8 -0
  126. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +11 -0
  127. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +70 -0
  128. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
  129. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +65 -0
  130. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +20 -0
  131. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
  132. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
  133. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
  134. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
  135. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
  136. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
  137. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +17 -0
  138. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +22 -0
  139. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
  140. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
  141. package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
  142. package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
  143. package/lib/import/validators/fields/nestable/Link.d.ts +33 -0
  144. package/lib/import/validators/fields/nestable/Link.js +16 -11
  145. package/lib/import/validators/fields/nestable/Nestable.d.ts +65 -62
  146. package/lib/import/validators/fields/nestable/Nestable.js +18 -6
  147. package/lib/import/validators/fields/nestable/index.d.ts +5 -1
  148. package/lib/import/validators/fields/nestable/index.js +7 -1
  149. package/lib/utils/DocumentId.d.ts +2 -0
  150. package/lib/utils/DocumentId.js +7 -0
  151. package/lib/utils/Objects.d.ts +1 -1
  152. package/lib/utils/Objects.js +1 -1
  153. package/lib/utils/io-ts.d.ts +2 -0
  154. package/lib/utils/io-ts.js +22 -0
  155. package/lib/validators/BasicTypes.d.ts +0 -1
  156. package/lib/validators/BasicTypes.js +7 -8
  157. package/lib/validators/DefaultOrElse.js +1 -1
  158. package/lib/validators/NonEmptyString.js +1 -1
  159. package/lib/validators/NumberRange.d.ts +32 -0
  160. package/lib/validators/NumberRange.js +40 -0
  161. package/lib/validators/function.d.ts +20 -0
  162. package/lib/validators/function.js +41 -1
  163. package/lib/validators/index.d.ts +1 -0
  164. package/lib/validators/index.js +3 -1
  165. package/package.json +4 -2
  166. package/src/common/Asset.ts +25 -0
  167. package/src/common/Embed.ts +22 -0
  168. package/src/common/UUID.ts +19 -0
  169. package/src/common/index.ts +2 -0
  170. package/src/content/fields/nestable/RichTextContent/Blocks.ts +1 -1
  171. package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
  172. package/src/customtypes/CustomType.ts +13 -0
  173. package/src/import/converters/Document.ts +10 -7
  174. package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
  175. package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
  176. package/src/import/converters/fields/Slices/Slices.ts +20 -0
  177. package/src/import/converters/fields/Slices/index.ts +1 -0
  178. package/src/import/converters/fields/UID.ts +1 -5
  179. package/src/import/converters/fields/index.ts +1 -0
  180. package/src/import/converters/fields/nestable/Embed.ts +29 -7
  181. package/src/import/converters/fields/nestable/GeoPoint.ts +16 -0
  182. package/src/import/converters/fields/nestable/Image.ts +69 -44
  183. package/src/import/converters/fields/nestable/Link.ts +77 -0
  184. package/src/import/converters/fields/nestable/Nestable.ts +17 -6
  185. package/src/import/converters/fields/nestable/RichText/embedBlock.ts +14 -0
  186. package/src/import/converters/fields/nestable/RichText/imageBlock.ts +14 -0
  187. package/src/import/converters/fields/nestable/RichText/index.ts +23 -0
  188. package/src/import/converters/fields/nestable/RichText/textBlock.ts +35 -0
  189. package/src/import/converters/fields/nestable/index.ts +3 -0
  190. package/src/import/validators/Document.ts +4 -12
  191. package/src/import/validators/fields/ImportField.ts +12 -6
  192. package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
  193. package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +116 -0
  194. package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +6 -0
  195. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +20 -0
  196. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +64 -0
  197. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
  198. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
  199. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
  200. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
  201. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
  202. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
  203. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
  204. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
  205. package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
  206. package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
  207. package/src/import/validators/fields/ImportSlices/index.ts +1 -0
  208. package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
  209. package/src/import/validators/fields/UID.ts +2 -2
  210. package/src/import/validators/fields/nestable/Embed.ts +6 -51
  211. package/src/import/validators/fields/nestable/GeoPoint.ts +21 -0
  212. package/src/import/validators/fields/nestable/Image/default.ts +25 -0
  213. package/src/import/validators/fields/nestable/Image/index.ts +73 -0
  214. package/src/import/validators/fields/nestable/Image/merge.ts +64 -0
  215. package/src/import/validators/fields/nestable/Image/model.ts +18 -0
  216. package/src/import/validators/fields/nestable/Image/validators.ts +45 -0
  217. package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +39 -0
  218. package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +41 -0
  219. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +44 -0
  220. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +13 -0
  221. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +13 -0
  222. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +56 -0
  223. package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +44 -0
  224. package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +4 -0
  225. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +24 -0
  226. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +8 -0
  227. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +26 -0
  228. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +2 -0
  229. package/src/import/validators/fields/nestable/ImportRichText/index.ts +2 -0
  230. package/src/import/validators/fields/nestable/Link.ts +59 -0
  231. package/src/import/validators/fields/nestable/Nestable.ts +19 -4
  232. package/src/import/validators/fields/nestable/index.ts +5 -1
  233. package/src/utils/DocumentId.ts +8 -0
  234. package/src/utils/Objects.ts +2 -2
  235. package/src/utils/io-ts.ts +29 -0
  236. package/src/validators/BasicTypes.ts +13 -11
  237. package/src/validators/DefaultOrElse.ts +1 -1
  238. package/src/validators/NonEmptyString.ts +4 -5
  239. package/src/validators/NumberRange.ts +51 -0
  240. package/src/validators/function.ts +44 -0
  241. package/src/validators/index.ts +1 -0
  242. package/lib/import/validators/fields/nestable/Image.d.ts +0 -24
  243. package/lib/import/validators/fields/nestable/Image.js +0 -45
  244. package/src/import/validators/fields/nestable/Image.ts +0 -90
@@ -1,9 +1,9 @@
1
1
  import type { StaticWidget } from "../../../customtypes";
2
+ import { ImportSlices } from "./ImportSlices";
2
3
  import { ImportNestable } from "./nestable";
3
- import { ImportUID } from "./UID";
4
- export declare type ImportField = ImportUID | ImportNestable;
4
+ export declare type ImportField = ImportSlices | ImportNestable;
5
5
  export declare const ImportField: {
6
- is(u: unknown): u is ImportNestable;
6
+ is(u: unknown): u is ImportField;
7
7
  decode: (field: StaticWidget) => (content: unknown) => {
8
8
  codec: import("io-ts").Type<{
9
9
  type: "Boolean";
@@ -16,49 +16,43 @@ export declare const ImportField: {
16
16
  value: Date | null;
17
17
  }, Date | undefined, unknown> | import("io-ts").Type<{
18
18
  type: "Embed";
19
- value: ({
19
+ value: {
20
20
  embed_url: string;
21
- type: string;
22
- } & {
23
- version?: string | number | null;
24
- title?: string;
25
- author_name?: string | null;
26
- author_url?: string | null;
27
- provider_name?: string | null;
28
- provider_url?: string | null;
29
- cache_age?: string | number | null;
30
- thumbnail_url?: string | null;
31
- thumbnail_width?: number | null;
32
- thumbnail_height?: number | null;
33
- html?: string | null;
34
- } & {
35
- all: unknown;
36
- }) | null;
37
- }, ({
21
+ } | null;
22
+ }, {
38
23
  embed_url: string;
39
- type: string;
40
- } & {
41
- version?: string | number | null;
42
- title?: string;
43
- author_name?: string | null;
44
- author_url?: string | null;
45
- provider_name?: string | null;
46
- provider_url?: string | null;
47
- cache_age?: string | number | null;
48
- thumbnail_url?: string | null;
49
- thumbnail_width?: number | null;
50
- thumbnail_height?: number | null;
51
- html?: string | null;
52
- } & {
53
- all: unknown;
54
- }) | undefined, unknown> | import("io-ts").Type<{
24
+ } | undefined, unknown> | import("io-ts").Type<{
25
+ type: "GeoPoint";
26
+ value: {
27
+ latitude: number;
28
+ longitude: number;
29
+ } | null;
30
+ }, {
31
+ latitude: number;
32
+ longitude: number;
33
+ } | undefined, unknown> | import("io-ts").Type<{
55
34
  type: "Image";
56
- value: (import("./nestable").ImageField & {
57
- thumbnails: Record<string, import("./nestable").ImageField>;
58
- }) | null;
59
- }, (import("./nestable").ImageField & {
60
- thumbnails: Record<string, import("./nestable").ImageField>;
61
- }) | undefined, unknown> | import("io-ts").Type<{
35
+ value: import("./nestable").ImageFieldWithThumbnails | null;
36
+ }, import("./nestable").ImageFieldWithThumbnails | undefined, unknown> | import("io-ts").Type<{
37
+ type: "Link";
38
+ value: ({
39
+ link_type: "Web";
40
+ url: string;
41
+ } & {
42
+ target?: string;
43
+ }) | {
44
+ link_type: "Document";
45
+ id: string;
46
+ } | {
47
+ link_type: "Media";
48
+ id: string;
49
+ } | null;
50
+ }, {
51
+ link_type: "Document" | "Web" | "Media";
52
+ } | undefined, unknown> | import("io-ts").Type<{
53
+ type: "StructuredText";
54
+ value: import("./nestable").ImportBlock[] | null;
55
+ }, unknown[] | undefined, unknown> | import("io-ts").Type<{
62
56
  type: "Number";
63
57
  value: number | null;
64
58
  }, number | undefined, unknown> | import("io-ts").Type<{
@@ -83,31 +77,37 @@ export declare const ImportField: {
83
77
  }> | import("fp-ts/lib/Either").Right<{
84
78
  type: "Number";
85
79
  value: number | null;
80
+ }> | import("fp-ts/lib/Either").Right<{
81
+ type: "StructuredText";
82
+ value: import("./nestable").ImportBlock[] | null;
83
+ }> | import("fp-ts/lib/Either").Right<{
84
+ type: "Link";
85
+ value: ({
86
+ link_type: "Web";
87
+ url: string;
88
+ } & {
89
+ target?: string;
90
+ }) | {
91
+ link_type: "Document";
92
+ id: string;
93
+ } | {
94
+ link_type: "Media";
95
+ id: string;
96
+ } | null;
86
97
  }> | import("fp-ts/lib/Either").Right<{
87
98
  type: "Image";
88
- value: (import("./nestable").ImageField & {
89
- thumbnails: Record<string, import("./nestable").ImageField>;
90
- }) | null;
99
+ value: import("./nestable").ImageFieldWithThumbnails | null;
100
+ }> | import("fp-ts/lib/Either").Right<{
101
+ type: "GeoPoint";
102
+ value: {
103
+ latitude: number;
104
+ longitude: number;
105
+ } | null;
91
106
  }> | import("fp-ts/lib/Either").Right<{
92
107
  type: "Embed";
93
- value: ({
108
+ value: {
94
109
  embed_url: string;
95
- type: string;
96
- } & {
97
- version?: string | number | null;
98
- title?: string;
99
- author_name?: string | null;
100
- author_url?: string | null;
101
- provider_name?: string | null;
102
- provider_url?: string | null;
103
- cache_age?: string | number | null;
104
- thumbnail_url?: string | null;
105
- thumbnail_width?: number | null;
106
- thumbnail_height?: number | null;
107
- html?: string | null;
108
- } & {
109
- all: unknown;
110
- }) | null;
110
+ } | null;
111
111
  }> | import("fp-ts/lib/Either").Right<{
112
112
  type: "Date";
113
113
  value: Date | null;
@@ -120,12 +120,12 @@ export declare const ImportField: {
120
120
  }>;
121
121
  } | {
122
122
  codec: import("io-ts").Type<{
123
- type: "UID";
124
- value: string | null;
125
- }, string | undefined, unknown>;
123
+ type: "Slices";
124
+ value: import("./ImportSlices/SharedSlice").SharedSlice[] | null;
125
+ }, import("./ImportSlices/SharedSlice").SharedSlice[] | undefined, unknown>;
126
126
  result: import("io-ts").Validation<{
127
- type: "UID";
128
- value: string | null;
127
+ type: "Slices";
128
+ value: import("./ImportSlices/SharedSlice").SharedSlice[] | null;
129
129
  }>;
130
130
  };
131
131
  };
@@ -1,19 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImportField = void 0;
4
+ const ImportSlices_1 = require("./ImportSlices");
4
5
  const nestable_1 = require("./nestable");
5
- const UID_1 = require("./UID");
6
6
  exports.ImportField = {
7
7
  is(u) {
8
- return UID_1.ImportUID.is(u) || nestable_1.ImportNestable.is(u);
8
+ return exports.ImportField.is(u);
9
9
  },
10
10
  decode: (field) => {
11
11
  return (content) => {
12
12
  switch (field.type) {
13
13
  case "UID":
14
- return { codec: UID_1.ImportUID, result: UID_1.ImportUID.decode(content) };
15
- case "Choice":
14
+ throw new Error(`The field '${field.type}' should be put at the root level of the document`);
16
15
  case "Slices":
16
+ return {
17
+ codec: (0, ImportSlices_1.ImportSlices)(field),
18
+ result: (0, ImportSlices_1.ImportSlices)(field).decode(content),
19
+ };
20
+ case "Choice":
17
21
  case "Group":
18
22
  throw new Error(`Unsupported type of field ${field.type}`);
19
23
  default:
@@ -0,0 +1,8 @@
1
+ import * as t from "io-ts";
2
+ import type { StaticSlices } from "../../../../customtypes";
3
+ import { SharedSlice } from "./SharedSlice";
4
+ export declare const ImportSlices: (staticSlices: StaticSlices) => t.Type<{
5
+ type: "Slices";
6
+ value: SharedSlice[] | null;
7
+ }, SharedSlice[] | undefined, unknown>;
8
+ export declare type ImportSlices = t.TypeOf<ReturnType<typeof ImportSlices>>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportSlices = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
+ const function_1 = require("fp-ts/function");
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const validators_1 = require("../../../../validators");
9
+ const ImportContent_1 = require("../ImportContent");
10
+ const SharedSlice_1 = require("./SharedSlice");
11
+ const utils_1 = require("./utils");
12
+ const ImportSlices = (staticSlices) => {
13
+ const supportedSlices = (0, utils_1.extractSupportedSlices)(staticSlices);
14
+ // For now we only support the SharedSlice, however if we want to support more in the future
15
+ // we would have to change the codec here to something like this: t.array(t.union([ImportSharedSlice(sharedSlices), NewSliceCodec(newSliceCustomTypes)])).
16
+ const SlicesArrayCodec = t.array((0, SharedSlice_1.SharedSlice)(supportedSlices));
17
+ return (0, ImportContent_1.ImportContent)("Slices", (0, validators_1.EmptyObjectOrElse)(new t.Type("ImportSlices", (u) => SlicesArrayCodec.is(u), (u, c) => {
18
+ return (0, function_1.pipe)(SlicesArrayCodec.validate(u, c), E.chain((slices) => {
19
+ // This part might not make sense for all Slice types in the future, but for now we only support the SharedSlice
20
+ // In case we support more in the future, we would have to filter only the relevant type for this check
21
+ const sharedSliceDuplicates = (0, utils_1.findImportSharedSliceDuplicateIds)(slices);
22
+ if (sharedSliceDuplicates.length > 0) {
23
+ return t.failure(slices, [], `Duplicate slice IDs detected: ${sharedSliceDuplicates.join(", ")}`);
24
+ }
25
+ return t.success(slices);
26
+ }));
27
+ }, t.identity)));
28
+ };
29
+ exports.ImportSlices = ImportSlices;
@@ -0,0 +1,14 @@
1
+ import * as t from "io-ts";
2
+ import type { SharedSlice as SharedSliceCustomType } from "../../../../../customtypes";
3
+ import { SharedSliceContent, SharedSliceId } from "./fields";
4
+ export declare type SharedSlice = {
5
+ id: SharedSliceId | null | undefined;
6
+ slice_type: string;
7
+ name: string;
8
+ variation: string;
9
+ primary: SharedSliceContent | null | undefined;
10
+ items: SharedSliceContent[] | null | undefined;
11
+ slice_label: string | null | undefined;
12
+ version: string | null | undefined;
13
+ };
14
+ export declare const SharedSlice: (sharedSlices: SharedSliceCustomType[]) => t.Type<SharedSlice, SharedSlice, unknown>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSlice = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
+ const function_1 = require("fp-ts/function");
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const validators_1 = require("../../../../../validators");
9
+ const function_2 = require("../../../../../validators/function");
10
+ const fields_1 = require("./fields");
11
+ const SharedSliceShape = t.strict({
12
+ id: fields_1.OptionalSharedSliceId,
13
+ slice_type: validators_1.NonEmptyString,
14
+ name: validators_1.String,
15
+ variation: validators_1.NonEmptyString,
16
+ primary: t.union([t.undefined, t.null, t.record(validators_1.NonEmptyString, t.unknown)]),
17
+ items: t.union([
18
+ t.undefined,
19
+ t.null,
20
+ t.array(t.record(validators_1.NonEmptyString, t.unknown)),
21
+ ]),
22
+ slice_label: t.union([t.undefined, t.null, validators_1.String]),
23
+ version: t.union([t.undefined, t.null, validators_1.String]),
24
+ });
25
+ const SharedSlice = (sharedSlices) => new t.Type("SharedSlice", (u) => SharedSliceShape.is(u), (u, c) => (0, function_1.pipe)(
26
+ // We validate the base fields that we can validate directly based on the provided 'sharedSlices'
27
+ t
28
+ .type({
29
+ id: fields_1.OptionalSharedSliceId,
30
+ slice_type: (0, fields_1.SharedSliceType)(sharedSlices),
31
+ slice_label: t.union([t.undefined, t.null, validators_1.String]),
32
+ version: t.union([t.undefined, t.null, validators_1.String]),
33
+ })
34
+ .validate(u, c), E.chain((decoded) => (0, function_1.pipe)(
35
+ // We validate the 'variation' field, for which we need the SharedSlice custom type retrieved in the first step
36
+ t
37
+ .type({
38
+ variation: (0, fields_1.SharedSliceVariation)(decoded.slice_type.data),
39
+ })
40
+ .validate(u, c), E.map(({ variation }) => ({ ...decoded, variation })))), E.chain((decoded) => {
41
+ var _a, _b;
42
+ return (0, function_1.pipe)(
43
+ // We validate the 'primary' and 'items' content fields, for which we need the Variation custom type retrieved in the previous step
44
+ t
45
+ .partial({
46
+ primary: (0, fields_1.SharedSliceContent)(decoded.slice_type.slice_type, "primary", (_a = decoded.variation.data.primary) !== null && _a !== void 0 ? _a : {}),
47
+ // We need to use this wrapper codec instead of using t.array(SharedSliceContent) directly in order to get proper custom error messages
48
+ items: (0, function_2.withCustomError)(t.array((0, fields_1.SharedSliceContent)(decoded.slice_type.slice_type, "items", (_b = decoded.variation.data.items) !== null && _b !== void 0 ? _b : {})), () => "The value must be an array"),
49
+ })
50
+ .validate(u, c), E.map(({ primary, items }) => ({ ...decoded, primary, items })));
51
+ }), E.map(({ id, slice_type, variation, primary, items, slice_label, version, }) => ({
52
+ id,
53
+ slice_type: slice_type.slice_type,
54
+ name: slice_type.data.name,
55
+ variation: variation.variation,
56
+ primary,
57
+ items,
58
+ slice_label,
59
+ version: version !== null && version !== void 0 ? version : variation.data.version,
60
+ }))), t.identity);
61
+ exports.SharedSlice = SharedSlice;
@@ -0,0 +1,4 @@
1
+ export declare const SharedSliceErrors: {
2
+ readonly SliceTypeNotFound: (slice_type: string) => string;
3
+ readonly VariationNotFound: (variation: string, slice_type: string) => string;
4
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSliceErrors = void 0;
4
+ exports.SharedSliceErrors = {
5
+ SliceTypeNotFound: (slice_type) => `Shared slice '${slice_type}' not found in this slice zone in the document's custom type`,
6
+ VariationNotFound: (variation, slice_type) => `Variation '${variation}' not found for Slice '${slice_type}'`,
7
+ };
@@ -0,0 +1,2 @@
1
+ import * as t from "io-ts";
2
+ export declare const OptionalSharedSliceId: t.Type<string | null | undefined, string | null | undefined, unknown>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OptionalSharedSliceId = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const SharedSliceId_1 = require("./SharedSliceId");
7
+ // Wrapping the 'SharedSliceId' codec in an optional codec here for the sake of error reporting.
8
+ // When using t.union([t.undefined, t.null, SharedSliceId]) we get a nested error context
9
+ // with the actual decoding error at position 2 in the context array.
10
+ // To avoid mutating the error context we create this new wrapper codec so that the error context will always have desired depth.
11
+ exports.OptionalSharedSliceId = new t.Type("OptionalSharedSliceId", (u) => u === null || u === undefined || SharedSliceId_1.SharedSliceId.is(u), (u, c) => {
12
+ if (u === null || u === undefined)
13
+ return t.success(u);
14
+ return SharedSliceId_1.SharedSliceId.validate(u, c);
15
+ }, t.identity);
@@ -0,0 +1,17 @@
1
+ import * as t from "io-ts";
2
+ import { WidgetKey } from "../../../../../../../common";
3
+ import type { NestableWidget } from "../../../../../../../customtypes";
4
+ import type { ImportNestable } from "../../../../nestable";
5
+ /**
6
+ * Represents the object in the 'primary' field or a single item in the 'items' array in the SharedSlice.
7
+ */
8
+ export declare type SharedSliceContent = Record<WidgetKey, ImportNestable>;
9
+ /**
10
+ * Builds the decoder for a single entry in the 'primary' field or a single item in the 'items' array in the SharedSlice.
11
+ *
12
+ * @param sliceName name of the slice - used for error reporting in order to know which slice is being decoded
13
+ * @param sliceContentField 'primary' or 'items' - used for error reporting in order to know which field of the slice is being decoded
14
+ * @param sliceFieldModels models of the fields of the slice from custom type - used to know which codec to use for decoding each value of the object
15
+ * @constructor
16
+ */
17
+ export declare const SharedSliceContent: (sliceName: string, sliceContentField: "primary" | "items", sliceFieldModels: Record<WidgetKey, NestableWidget>) => t.Type<SharedSliceContent, SharedSliceContent, unknown>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSliceContent = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
+ const function_1 = require("fp-ts/lib/function");
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const common_1 = require("../../../../../../../common");
9
+ const io_ts_1 = require("../../../../../../../utils/io-ts");
10
+ const function_2 = require("../../../../../../../validators/function");
11
+ const SharedSliceContentEntry_1 = require("./SharedSliceContentEntry");
12
+ /**
13
+ * Builds the decoder for a single entry in the 'primary' field or a single item in the 'items' array in the SharedSlice.
14
+ *
15
+ * @param sliceName name of the slice - used for error reporting in order to know which slice is being decoded
16
+ * @param sliceContentField 'primary' or 'items' - used for error reporting in order to know which field of the slice is being decoded
17
+ * @param sliceFieldModels models of the fields of the slice from custom type - used to know which codec to use for decoding each value of the object
18
+ * @constructor
19
+ */
20
+ const SharedSliceContent = (sliceName, sliceContentField, sliceFieldModels) => new t.Type("SharedSliceContent", (u) => t.record(common_1.WidgetKey, t.unknown).is(u), (u, c) => (0, function_1.pipe)(
21
+ // We first decode the raw content object in the shape of Record<WidgetKey, unknown>
22
+ (0, function_2.withCustomError)(t.UnknownRecord, () => "The value must be an object").validate(u, c), E.chain((rawContent) => (0, function_1.pipe)(
23
+ // We split the object into entries because there is no easy other way to decode each value with a different codec
24
+ Object.entries(rawContent).map((entry) => (0, SharedSliceContentEntry_1.SharedSliceContentEntry)(sliceName, sliceContentField, sliceFieldModels).validate(entry, c)),
25
+ // We get a validation result for each entry in the content object (t.Validation<SharedSliceContentEntry>[]),
26
+ // however we want to get a single validation result for the whole array of entries (t.Validation<SharedSliceContentEntry[]>).
27
+ io_ts_1.combineValidationResults,
28
+ // We build the object back from entries if all decoded successfully
29
+ E.map((entries) => entries.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}))))), t.identity);
30
+ exports.SharedSliceContent = SharedSliceContent;
@@ -0,0 +1,43 @@
1
+ import * as t from "io-ts";
2
+ import { WidgetKey } from "../../../../../../../common";
3
+ import type { NestableWidget } from "../../../../../../../customtypes";
4
+ import { ImportNestable } from "../../../../nestable";
5
+ export declare type SharedSliceContentEntry = [WidgetKey, ImportNestable];
6
+ /**
7
+ * Represents a single entry in the 'primary' field or a single entry in an item in the 'items' array in the SharedSlice. It is used to build the SharedSliceContent type from entries of the import object.
8
+ *
9
+ * For example, given the following slice:
10
+ * {
11
+ * "slice_type": "my_slice",
12
+ * "variation": "default",
13
+ * "primary": {
14
+ * "slice_text": "abc", // This is one entry
15
+ * "slice_text2": "def: // This is another entry
16
+ * },
17
+ * "items": [
18
+ * {
19
+ * "slice_number1": 0, // This is one entry
20
+ * "slice_number2": 1 // And this is yet another entry
21
+ * }
22
+ * ]
23
+ * }
24
+ *
25
+ * The 'primary' object is converted to following entries to be decoded:
26
+ * [
27
+ * ["slice_text", "abc"],
28
+ * ["slice_text2", "def"]
29
+ * ]
30
+ * and the first item in the 'items' array is converted to following entries to be decoded:
31
+ * [
32
+ * ["slice_number1", 0],
33
+ * ["slice_number2", 1]
34
+ * ]
35
+ *
36
+ * We decode them as separate entries because each of the values might require a different codec as per what is specified in the SharedSlice custom type.
37
+ * In this way we save on the decoding performance in comparison to a scenario where we would decode the whole content object as a record with a union type decoder for each value.
38
+ *
39
+ * @param sliceName name of the slice - used for error reporting in order to know which slice is being decoded
40
+ * @param sliceContentField 'primary' or 'items' - used for error reporting in order to know which field of the slice is being decoded
41
+ * @param sliceFieldModels models of the fields of the slice from custom type - used to know which codec to use for decoding each value of the object
42
+ */
43
+ export declare const SharedSliceContentEntry: (sliceName: string, sliceContentField: "primary" | "items", sliceFieldModels: Record<WidgetKey, NestableWidget>) => t.Type<SharedSliceContentEntry, SharedSliceContentEntry, unknown>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSliceContentEntry = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
+ const function_1 = require("fp-ts/function");
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const common_1 = require("../../../../../../../common");
9
+ const nestable_1 = require("../../../../nestable");
10
+ const errors_1 = require("./errors");
11
+ /**
12
+ * Represents a single entry in the 'primary' field or a single entry in an item in the 'items' array in the SharedSlice. It is used to build the SharedSliceContent type from entries of the import object.
13
+ *
14
+ * For example, given the following slice:
15
+ * {
16
+ * "slice_type": "my_slice",
17
+ * "variation": "default",
18
+ * "primary": {
19
+ * "slice_text": "abc", // This is one entry
20
+ * "slice_text2": "def: // This is another entry
21
+ * },
22
+ * "items": [
23
+ * {
24
+ * "slice_number1": 0, // This is one entry
25
+ * "slice_number2": 1 // And this is yet another entry
26
+ * }
27
+ * ]
28
+ * }
29
+ *
30
+ * The 'primary' object is converted to following entries to be decoded:
31
+ * [
32
+ * ["slice_text", "abc"],
33
+ * ["slice_text2", "def"]
34
+ * ]
35
+ * and the first item in the 'items' array is converted to following entries to be decoded:
36
+ * [
37
+ * ["slice_number1", 0],
38
+ * ["slice_number2", 1]
39
+ * ]
40
+ *
41
+ * We decode them as separate entries because each of the values might require a different codec as per what is specified in the SharedSlice custom type.
42
+ * In this way we save on the decoding performance in comparison to a scenario where we would decode the whole content object as a record with a union type decoder for each value.
43
+ *
44
+ * @param sliceName name of the slice - used for error reporting in order to know which slice is being decoded
45
+ * @param sliceContentField 'primary' or 'items' - used for error reporting in order to know which field of the slice is being decoded
46
+ * @param sliceFieldModels models of the fields of the slice from custom type - used to know which codec to use for decoding each value of the object
47
+ */
48
+ const SharedSliceContentEntry = (sliceName, sliceContentField, sliceFieldModels) => new t.Type("SharedSliceContentEntry", (u) => t.tuple([common_1.WidgetKey, t.unknown]).is(u) && nestable_1.ImportNestable.is(u[1]), (u, c) => {
49
+ return (0, function_1.pipe)(t.tuple([common_1.WidgetKey, t.unknown]).validate(u, c), E.chain(([key, content]) => {
50
+ const model = sliceFieldModels[key];
51
+ if (!model) {
52
+ return t.failure([key, content], [...c, { key, actual: content, type: t.unknown }], errors_1.SharedSliceContentErrors.UnknownField(sliceName, sliceContentField, key));
53
+ }
54
+ const { codec, result } = nestable_1.ImportNestable.decode(model)(content);
55
+ return (0, function_1.pipe)(result, E.map((decodedContent) => [
56
+ key,
57
+ decodedContent,
58
+ ]), E.mapLeft((errors) => errors.map((error) => {
59
+ const context = [
60
+ ...c,
61
+ ...error.context.filter(({ key }) => !!key),
62
+ { key, actual: content, type: codec },
63
+ ];
64
+ const updatedError = { ...error, context };
65
+ return updatedError;
66
+ })));
67
+ }));
68
+ }, t.identity);
69
+ exports.SharedSliceContentEntry = SharedSliceContentEntry;
@@ -0,0 +1,4 @@
1
+ import type { SharedSliceContentField } from "./types";
2
+ export declare const SharedSliceContentErrors: {
3
+ readonly UnknownField: (sliceName: string, contentField: SharedSliceContentField, fieldName: string) => string;
4
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSliceContentErrors = void 0;
4
+ exports.SharedSliceContentErrors = {
5
+ UnknownField: (sliceName, contentField, fieldName) => `Unsupported field '${fieldName}'for '${contentField}' content in Shared Slice '${sliceName}'`,
6
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./errors";
2
+ export * from "./SharedSliceContent";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./errors"), exports);
5
+ (0, tslib_1.__exportStar)(require("./SharedSliceContent"), exports);
@@ -0,0 +1 @@
1
+ export declare type SharedSliceContentField = "primary" | "items";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import * as t from "io-ts";
2
+ import { UUID } from "../../../../../../common/UUID";
3
+ export declare type SharedSliceId = `${string}$${UUID}`;
4
+ export declare const SharedSliceIdValidationError: {
5
+ readonly Base: "Slice id must be a non empty string matching the following pattern 'slice_type$uuid'";
6
+ readonly IncorrectUUID: (uuid: string | undefined) => string;
7
+ readonly IncorrectSliceType: (sliceType: string | undefined) => string;
8
+ };
9
+ export declare const SharedSliceId: t.Type<string, string, unknown>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSliceId = exports.SharedSliceIdValidationError = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
+ const function_1 = require("fp-ts/function");
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const UUID_1 = require("../../../../../../common/UUID");
9
+ const validators_1 = require("../../../../../../validators");
10
+ const baseErrorText = "Slice id must be a non empty string matching the following pattern 'slice_type$uuid'";
11
+ exports.SharedSliceIdValidationError = {
12
+ Base: baseErrorText,
13
+ IncorrectUUID: (uuid) => `Incorrect UUID: '${uuid}' - ${baseErrorText}`,
14
+ IncorrectSliceType: (sliceType) => `Incorrect slice_type: '${sliceType}' - ${baseErrorText}`,
15
+ };
16
+ exports.SharedSliceId = new t.Type("SharedSliceId", (u) => {
17
+ if (typeof u !== "string") {
18
+ return false;
19
+ }
20
+ const [sliceName, uuid] = u.split("$");
21
+ return validators_1.NonEmptyString.is(sliceName) && UUID_1.UUID.is(uuid);
22
+ }, (u, c) => (0, function_1.pipe)(validators_1.NonEmptyString.validate(u, c), E.mapLeft((errors) => errors.map((error) => ({
23
+ ...error,
24
+ message: exports.SharedSliceIdValidationError.Base,
25
+ }))), E.chain((sliceId) => {
26
+ const [sliceName, uuid] = sliceId.split("$");
27
+ return (0, function_1.pipe)(t.tuple([validators_1.NonEmptyString, UUID_1.UUID]).validate([sliceName, uuid], c), E.mapLeft((errors) => errors.map((error) => {
28
+ const tupleErrorContext = error.context[error.context.length - 1];
29
+ return {
30
+ ...error,
31
+ context: [
32
+ ...error.context.slice(0, -1), // We don't want the tuple decoder error context
33
+ ],
34
+ message: (tupleErrorContext === null || tupleErrorContext === void 0 ? void 0 : tupleErrorContext.key) === "0"
35
+ ? exports.SharedSliceIdValidationError.IncorrectSliceType(sliceName)
36
+ : exports.SharedSliceIdValidationError.IncorrectUUID(uuid),
37
+ };
38
+ })));
39
+ }), E.map(([sliceName, uuid]) => `${sliceName}$${uuid}`)), (sliceId) => sliceId);
@@ -0,0 +1,11 @@
1
+ import * as t from "io-ts";
2
+ import { SharedSlice as SharedSliceCustomType } from "../../../../../../customtypes";
3
+ export declare type SharedSliceType = {
4
+ slice_type: string;
5
+ data: SharedSliceCustomType;
6
+ };
7
+ /**
8
+ * 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.
9
+ * @param slices all the SharedSlices from the custom type
10
+ */
11
+ export declare const SharedSliceType: (slices: SharedSliceCustomType[]) => t.Type<SharedSliceType, string, unknown>;