@prismicio/types-internal 2.2.1 → 2.3.0

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 (193) hide show
  1. package/lib/content/Document.d.ts +10 -4
  2. package/lib/content/Document.js +45 -11
  3. package/lib/content/fields/GroupContent.d.ts +1 -0
  4. package/lib/content/fields/GroupContent.js +13 -1
  5. package/lib/content/fields/nestable/BooleanContent.d.ts +2 -0
  6. package/lib/content/fields/nestable/BooleanContent.js +11 -1
  7. package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +2 -0
  8. package/lib/content/fields/nestable/FieldContent/SelectContent.js +12 -1
  9. package/lib/content/fields/nestable/NestableContent.d.ts +2 -0
  10. package/lib/content/fields/nestable/NestableContent.js +12 -1
  11. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1 -0
  12. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +13 -1
  13. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +2 -1
  14. package/lib/content/fields/slices/Slice/SharedSliceContent.js +16 -1
  15. package/lib/content/fields/slices/SliceItem.d.ts +3 -0
  16. package/lib/content/fields/slices/SliceItem.js +24 -1
  17. package/lib/content/fields/slices/SlicesContent.d.ts +1 -0
  18. package/lib/content/fields/slices/SlicesContent.js +23 -1
  19. package/lib/content/fields/withDefaultValues.d.ts +6 -0
  20. package/lib/content/fields/withDefaultValues.js +38 -0
  21. package/lib/import/converters/Document.d.ts +4 -0
  22. package/lib/import/converters/Document.js +21 -0
  23. package/lib/import/converters/fields/Group.d.ts +4 -0
  24. package/lib/import/converters/fields/Group.js +14 -0
  25. package/lib/import/converters/fields/RepeatableZone.d.ts +317 -0
  26. package/lib/import/converters/fields/RepeatableZone.js +15 -0
  27. package/lib/import/converters/fields/RepeatableZoneItem.d.ts +11 -0
  28. package/lib/import/converters/fields/RepeatableZoneItem.js +19 -0
  29. package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
  30. package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
  31. package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
  32. package/lib/import/converters/fields/Slices/SharedSliceContent.js +23 -0
  33. package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
  34. package/lib/import/converters/fields/Slices/Slices.js +16 -0
  35. package/lib/import/converters/fields/Slices/index.d.ts +1 -0
  36. package/lib/import/converters/fields/Slices/index.js +4 -0
  37. package/lib/import/converters/fields/UID.d.ts +3 -0
  38. package/lib/import/converters/fields/UID.js +10 -0
  39. package/lib/import/converters/fields/index.d.ts +4 -0
  40. package/lib/import/converters/fields/index.js +7 -0
  41. package/lib/import/converters/fields/nestable/Boolean.d.ts +3 -0
  42. package/lib/import/converters/fields/nestable/Boolean.js +12 -0
  43. package/lib/import/converters/fields/nestable/Color.d.ts +3 -0
  44. package/lib/import/converters/fields/nestable/Color.js +13 -0
  45. package/lib/import/converters/fields/nestable/Date.d.ts +3 -0
  46. package/lib/import/converters/fields/nestable/Date.js +15 -0
  47. package/lib/import/converters/fields/nestable/Embed.d.ts +4 -0
  48. package/lib/import/converters/fields/nestable/Embed.js +32 -0
  49. package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
  50. package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
  51. package/lib/import/converters/fields/nestable/Image.d.ts +28 -0
  52. package/lib/import/converters/fields/nestable/Image.js +67 -0
  53. package/lib/import/converters/fields/nestable/Link.d.ts +4 -0
  54. package/lib/import/converters/fields/nestable/Link.js +70 -0
  55. package/lib/import/converters/fields/nestable/Nestable.d.ts +5 -0
  56. package/lib/import/converters/fields/nestable/Nestable.js +35 -0
  57. package/lib/import/converters/fields/nestable/Number.d.ts +3 -0
  58. package/lib/import/converters/fields/nestable/Number.js +13 -0
  59. package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
  60. package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
  61. package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
  62. package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
  63. package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
  64. package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
  65. package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
  66. package/lib/import/converters/fields/nestable/RichText/textBlock.js +54 -0
  67. package/lib/import/converters/fields/nestable/Select.d.ts +3 -0
  68. package/lib/import/converters/fields/nestable/Select.js +13 -0
  69. package/lib/import/converters/fields/nestable/Text.d.ts +3 -0
  70. package/lib/import/converters/fields/nestable/Text.js +13 -0
  71. package/lib/import/converters/fields/nestable/Timestamp.d.ts +3 -0
  72. package/lib/import/converters/fields/nestable/Timestamp.js +13 -0
  73. package/lib/import/converters/fields/nestable/index.d.ts +13 -0
  74. package/lib/import/converters/fields/nestable/index.js +16 -0
  75. package/lib/import/converters/index.d.ts +2 -0
  76. package/lib/import/converters/index.js +5 -0
  77. package/lib/import/index.d.ts +2 -0
  78. package/lib/import/index.js +5 -0
  79. package/lib/import/validators/Document.d.ts +6 -0
  80. package/lib/import/validators/Document.js +64 -0
  81. package/lib/import/validators/fields/ImportContent.d.ts +5 -0
  82. package/lib/import/validators/fields/ImportContent.js +21 -0
  83. package/lib/import/validators/fields/ImportField.d.ts +141 -0
  84. package/lib/import/validators/fields/ImportField.js +33 -0
  85. package/lib/import/validators/fields/ImportGroup.d.ts +345 -0
  86. package/lib/import/validators/fields/ImportGroup.js +27 -0
  87. package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
  88. package/lib/import/validators/fields/ImportSlices/ImportSlices.js +30 -0
  89. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +16 -0
  90. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
  91. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
  92. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
  93. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
  94. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
  95. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
  96. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
  97. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
  98. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
  99. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
  100. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
  101. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +4 -0
  102. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +7 -0
  103. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
  104. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
  105. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +342 -0
  106. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
  107. package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
  108. package/lib/import/validators/fields/ImportSlices/index.js +4 -0
  109. package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
  110. package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
  111. package/lib/import/validators/fields/RepeatableZone.d.ts +11 -0
  112. package/lib/import/validators/fields/RepeatableZone.js +14 -0
  113. package/lib/import/validators/fields/RepeatableZoneItem.d.ts +11 -0
  114. package/lib/import/validators/fields/RepeatableZoneItem.js +39 -0
  115. package/lib/import/validators/fields/UID.d.ts +6 -0
  116. package/lib/import/validators/fields/UID.js +15 -0
  117. package/lib/import/validators/fields/index.d.ts +4 -0
  118. package/lib/import/validators/fields/index.js +7 -0
  119. package/lib/import/validators/fields/nestable/Boolean.d.ts +6 -0
  120. package/lib/import/validators/fields/nestable/Boolean.js +6 -0
  121. package/lib/import/validators/fields/nestable/Color.d.ts +6 -0
  122. package/lib/import/validators/fields/nestable/Color.js +15 -0
  123. package/lib/import/validators/fields/nestable/Date.d.ts +6 -0
  124. package/lib/import/validators/fields/nestable/Date.js +19 -0
  125. package/lib/import/validators/fields/nestable/Embed.d.ts +13 -0
  126. package/lib/import/validators/fields/nestable/Embed.js +31 -0
  127. package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
  128. package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
  129. package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
  130. package/lib/import/validators/fields/nestable/Image/default.js +19 -0
  131. package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
  132. package/lib/import/validators/fields/nestable/Image/index.js +32 -0
  133. package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
  134. package/lib/import/validators/fields/nestable/Image/merge.js +44 -0
  135. package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
  136. package/lib/import/validators/fields/nestable/Image/model.js +2 -0
  137. package/lib/import/validators/fields/nestable/Image/validators.d.ts +132 -0
  138. package/lib/import/validators/fields/nestable/Image/validators.js +43 -0
  139. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
  140. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
  141. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
  142. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +32 -0
  143. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
  144. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
  145. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
  146. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
  147. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +22 -0
  148. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +13 -0
  149. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +78 -0
  150. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
  151. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +79 -0
  152. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +27 -0
  153. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
  154. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
  155. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
  156. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
  157. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.d.ts +12 -0
  158. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.js +16 -0
  159. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
  160. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
  161. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +15 -0
  162. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +20 -0
  163. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
  164. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
  165. package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
  166. package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
  167. package/lib/import/validators/fields/nestable/Link.d.ts +53 -0
  168. package/lib/import/validators/fields/nestable/Link.js +35 -0
  169. package/lib/import/validators/fields/nestable/Nestable.d.ts +192 -0
  170. package/lib/import/validators/fields/nestable/Nestable.js +71 -0
  171. package/lib/import/validators/fields/nestable/Number.d.ts +17 -0
  172. package/lib/import/validators/fields/nestable/Number.js +17 -0
  173. package/lib/import/validators/fields/nestable/Select.d.ts +16 -0
  174. package/lib/import/validators/fields/nestable/Select.js +19 -0
  175. package/lib/import/validators/fields/nestable/Text.d.ts +6 -0
  176. package/lib/import/validators/fields/nestable/Text.js +6 -0
  177. package/lib/import/validators/fields/nestable/Timestamp.d.ts +7 -0
  178. package/lib/import/validators/fields/nestable/Timestamp.js +19 -0
  179. package/lib/import/validators/fields/nestable/index.d.ts +14 -0
  180. package/lib/import/validators/fields/nestable/index.js +19 -0
  181. package/lib/import/validators/index.d.ts +2 -0
  182. package/lib/import/validators/index.js +5 -0
  183. package/package.json +1 -1
  184. package/src/content/Document.ts +68 -14
  185. package/src/content/fields/GroupContent.ts +16 -0
  186. package/src/content/fields/nestable/BooleanContent.ts +11 -0
  187. package/src/content/fields/nestable/FieldContent/SelectContent.ts +12 -1
  188. package/src/content/fields/nestable/NestableContent.ts +16 -0
  189. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +25 -0
  190. package/src/content/fields/slices/Slice/SharedSliceContent.ts +32 -1
  191. package/src/content/fields/slices/SliceItem.ts +43 -1
  192. package/src/content/fields/slices/SlicesContent.ts +30 -0
  193. package/src/content/fields/withDefaultValues.ts +48 -0
@@ -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,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>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSliceType = 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 customtypes_1 = require("../../../../../../customtypes");
9
+ const validators_1 = require("../../../../../../validators");
10
+ const utils_1 = require("../utils");
11
+ /**
12
+ * slice_type - the validated slice_type
13
+ * 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)
14
+ */
15
+ const SharedSliceTypeShape = t.strict({
16
+ slice_type: validators_1.NonEmptyString,
17
+ slice: customtypes_1.SharedSlice,
18
+ });
19
+ /**
20
+ * 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.
21
+ * @param slices all the SharedSlices from the custom type
22
+ */
23
+ const SharedSliceType = (slices) => new t.Type("slice_type", (u) => SharedSliceTypeShape.is(u), (u, c) => (0, function_1.pipe)(validators_1.NonEmptyString.validate(u, c), E.chain((slice_type) => (0, function_1.pipe)((0, utils_1.findSlice)(slices)(slice_type), E.fold((err) => t.failure(u, c, err), (data) => t.success({ slice_type, data }))))), ({ slice_type }) => slice_type);
24
+ exports.SharedSliceType = SharedSliceType;
@@ -0,0 +1,11 @@
1
+ import * as t from "io-ts";
2
+ import { SharedSlice, Variation } from "../../../../../../customtypes";
3
+ export declare type SharedSliceVariation = {
4
+ variation: string;
5
+ data: Variation;
6
+ };
7
+ /**
8
+ * 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.
9
+ * @param slice SharedSlice from the custom type
10
+ */
11
+ export declare const SharedSliceVariation: (slice: SharedSlice) => t.Type<SharedSliceVariation, string, unknown>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSliceVariation = 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 customtypes_1 = require("../../../../../../customtypes");
9
+ const validators_1 = require("../../../../../../validators");
10
+ const utils_1 = require("../utils");
11
+ /**
12
+ * variation - the validated variation of the slice
13
+ * 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.
14
+ */
15
+ const SharedSliceVariationShape = t.strict({
16
+ variation: validators_1.NonEmptyString,
17
+ data: customtypes_1.Variation,
18
+ });
19
+ /**
20
+ * 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.
21
+ * @param slice SharedSlice from the custom type
22
+ */
23
+ const SharedSliceVariation = (slice) => new t.Type("variation", (u) => SharedSliceVariationShape.is(u), (u, c) => (0, function_1.pipe)(validators_1.NonEmptyString.validate(u, c), E.chain((variation) => (0, function_1.pipe)((0, utils_1.findSliceVariation)(slice)(variation), E.fold((err) => t.failure(u, c, err), (data) => t.success({ variation, data }))))), ({ variation }) => variation);
24
+ exports.SharedSliceVariation = SharedSliceVariation;
@@ -0,0 +1,4 @@
1
+ export * from "./OptionalSharedSliceId";
2
+ export * from "./SharedSliceId";
3
+ export * from "./SharedSliceType";
4
+ export * from "./SharedSliceVariation";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./OptionalSharedSliceId"), exports);
5
+ (0, tslib_1.__exportStar)(require("./SharedSliceId"), exports);
6
+ (0, tslib_1.__exportStar)(require("./SharedSliceType"), exports);
7
+ (0, tslib_1.__exportStar)(require("./SharedSliceVariation"), exports);
@@ -0,0 +1,3 @@
1
+ export * from "./errors";
2
+ export * from "./fields";
3
+ export * from "./SharedSlice";
@@ -0,0 +1,6 @@
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("./fields"), exports);
6
+ (0, tslib_1.__exportStar)(require("./SharedSlice"), exports);
@@ -0,0 +1,342 @@
1
+ import * as E from "fp-ts/Either";
2
+ import type { SharedSlice as SharedSliceCustomType } from "../../../../../customtypes";
3
+ import type { Variation } from "../../../../../customtypes";
4
+ export declare const findSlice: (slices: SharedSliceCustomType[]) => (sliceId: string) => E.Either<string, {
5
+ id: string;
6
+ type: "SharedSlice";
7
+ name: string;
8
+ variations: readonly ({
9
+ id: string;
10
+ name: string;
11
+ description: string;
12
+ imageUrl: string;
13
+ docURL: string;
14
+ version: string;
15
+ } & {
16
+ display?: string;
17
+ primary?: {
18
+ [x: string]: ({
19
+ type: "Boolean";
20
+ } & {
21
+ config?: {
22
+ label?: string | null | undefined;
23
+ default_value?: boolean;
24
+ placeholder_true?: string;
25
+ placeholder_false?: string;
26
+ };
27
+ }) | ({
28
+ type: "Color";
29
+ } & {
30
+ fieldset?: string | null | undefined;
31
+ config?: {
32
+ label?: string | null | undefined;
33
+ placeholder?: string;
34
+ };
35
+ }) | ({
36
+ type: "Date";
37
+ } & {
38
+ fieldset?: string | null | undefined;
39
+ config?: {
40
+ label?: string | null | undefined;
41
+ placeholder?: string;
42
+ default?: string;
43
+ };
44
+ }) | ({
45
+ type: "Embed";
46
+ } & {
47
+ fieldset?: string | null | undefined;
48
+ config?: {
49
+ label?: string | null | undefined;
50
+ placeholder?: string;
51
+ useAsTitle?: boolean;
52
+ };
53
+ }) | ({
54
+ type: "GeoPoint";
55
+ } & {
56
+ fieldset?: string | null | undefined;
57
+ config?: {
58
+ label?: string | null | undefined;
59
+ };
60
+ }) | ({
61
+ type: "Image";
62
+ } & {
63
+ fieldset?: string | null | undefined;
64
+ config?: {
65
+ label?: string | null | undefined;
66
+ placeholder?: string;
67
+ constraint?: {
68
+ width?: number | null;
69
+ height?: number | null;
70
+ };
71
+ thumbnails?: readonly ({
72
+ name: string;
73
+ } & {
74
+ width?: number | null;
75
+ height?: number | null;
76
+ })[];
77
+ };
78
+ }) | ({
79
+ type: "IntegrationFields";
80
+ } & {
81
+ fieldset?: string | null | undefined;
82
+ config?: {
83
+ label?: string | null | undefined;
84
+ placeholder?: string;
85
+ catalog?: string;
86
+ };
87
+ }) | ({
88
+ type: "Link";
89
+ } & {
90
+ fieldset?: string | null | undefined;
91
+ config?: {
92
+ label?: string | null | undefined;
93
+ useAsTitle?: boolean;
94
+ placeholder?: string;
95
+ select?: "media" | "document" | "web" | null;
96
+ customtypes?: readonly string[];
97
+ masks?: readonly string[];
98
+ tags?: readonly string[];
99
+ allowTargetBlank?: boolean;
100
+ };
101
+ }) | ({
102
+ type: "Number";
103
+ } & {
104
+ fieldset?: string | null | undefined;
105
+ config?: {
106
+ label?: string | null | undefined;
107
+ placeholder?: string;
108
+ min?: number;
109
+ max?: number;
110
+ step?: number;
111
+ };
112
+ }) | ({
113
+ type: "Range";
114
+ } & {
115
+ fieldset?: string | null | undefined;
116
+ config?: {
117
+ label?: string | null | undefined;
118
+ placeholder?: string;
119
+ min?: number;
120
+ max?: number;
121
+ step?: number;
122
+ };
123
+ }) | ({
124
+ type: "StructuredText";
125
+ } & {
126
+ fieldset?: string | null | undefined;
127
+ config?: {
128
+ label?: string | null | undefined;
129
+ placeholder?: string;
130
+ useAsTitle?: boolean;
131
+ single?: string;
132
+ multi?: string;
133
+ imageConstraint?: {
134
+ width?: number | null;
135
+ height?: number | null;
136
+ };
137
+ labels?: readonly string[];
138
+ allowTargetBlank?: boolean;
139
+ };
140
+ }) | ({
141
+ type: "Select";
142
+ } & {
143
+ fieldset?: string | null | undefined;
144
+ config?: {
145
+ label?: string | null | undefined;
146
+ placeholder?: string;
147
+ default_value?: string;
148
+ options?: readonly string[];
149
+ };
150
+ }) | ({
151
+ type: "Separator";
152
+ } & {
153
+ config?: {
154
+ label?: string | null | undefined;
155
+ };
156
+ }) | ({
157
+ type: "Text";
158
+ } & {
159
+ fieldset?: string | null | undefined;
160
+ config?: {
161
+ label?: string | null | undefined;
162
+ useAsTitle?: boolean;
163
+ placeholder?: string;
164
+ };
165
+ }) | ({
166
+ type: "Timestamp";
167
+ } & {
168
+ fieldset?: string | null | undefined;
169
+ config?: {
170
+ label?: string | null | undefined;
171
+ placeholder?: string;
172
+ default?: string;
173
+ };
174
+ });
175
+ };
176
+ items?: {
177
+ [x: string]: ({
178
+ type: "Boolean";
179
+ } & {
180
+ config?: {
181
+ label?: string | null | undefined;
182
+ default_value?: boolean;
183
+ placeholder_true?: string;
184
+ placeholder_false?: string;
185
+ };
186
+ }) | ({
187
+ type: "Color";
188
+ } & {
189
+ fieldset?: string | null | undefined;
190
+ config?: {
191
+ label?: string | null | undefined;
192
+ placeholder?: string;
193
+ };
194
+ }) | ({
195
+ type: "Date";
196
+ } & {
197
+ fieldset?: string | null | undefined;
198
+ config?: {
199
+ label?: string | null | undefined;
200
+ placeholder?: string;
201
+ default?: string;
202
+ };
203
+ }) | ({
204
+ type: "Embed";
205
+ } & {
206
+ fieldset?: string | null | undefined;
207
+ config?: {
208
+ label?: string | null | undefined;
209
+ placeholder?: string;
210
+ useAsTitle?: boolean;
211
+ };
212
+ }) | ({
213
+ type: "GeoPoint";
214
+ } & {
215
+ fieldset?: string | null | undefined;
216
+ config?: {
217
+ label?: string | null | undefined;
218
+ };
219
+ }) | ({
220
+ type: "Image";
221
+ } & {
222
+ fieldset?: string | null | undefined;
223
+ config?: {
224
+ label?: string | null | undefined;
225
+ placeholder?: string;
226
+ constraint?: {
227
+ width?: number | null;
228
+ height?: number | null;
229
+ };
230
+ thumbnails?: readonly ({
231
+ name: string;
232
+ } & {
233
+ width?: number | null;
234
+ height?: number | null;
235
+ })[];
236
+ };
237
+ }) | ({
238
+ type: "IntegrationFields";
239
+ } & {
240
+ fieldset?: string | null | undefined;
241
+ config?: {
242
+ label?: string | null | undefined;
243
+ placeholder?: string;
244
+ catalog?: string;
245
+ };
246
+ }) | ({
247
+ type: "Link";
248
+ } & {
249
+ fieldset?: string | null | undefined;
250
+ config?: {
251
+ label?: string | null | undefined;
252
+ useAsTitle?: boolean;
253
+ placeholder?: string;
254
+ select?: "media" | "document" | "web" | null;
255
+ customtypes?: readonly string[];
256
+ masks?: readonly string[];
257
+ tags?: readonly string[];
258
+ allowTargetBlank?: boolean;
259
+ };
260
+ }) | ({
261
+ type: "Number";
262
+ } & {
263
+ fieldset?: string | null | undefined;
264
+ config?: {
265
+ label?: string | null | undefined;
266
+ placeholder?: string;
267
+ min?: number;
268
+ max?: number;
269
+ step?: number;
270
+ };
271
+ }) | ({
272
+ type: "Range";
273
+ } & {
274
+ fieldset?: string | null | undefined;
275
+ config?: {
276
+ label?: string | null | undefined;
277
+ placeholder?: string;
278
+ min?: number;
279
+ max?: number;
280
+ step?: number;
281
+ };
282
+ }) | ({
283
+ type: "StructuredText";
284
+ } & {
285
+ fieldset?: string | null | undefined;
286
+ config?: {
287
+ label?: string | null | undefined;
288
+ placeholder?: string;
289
+ useAsTitle?: boolean;
290
+ single?: string;
291
+ multi?: string;
292
+ imageConstraint?: {
293
+ width?: number | null;
294
+ height?: number | null;
295
+ };
296
+ labels?: readonly string[];
297
+ allowTargetBlank?: boolean;
298
+ };
299
+ }) | ({
300
+ type: "Select";
301
+ } & {
302
+ fieldset?: string | null | undefined;
303
+ config?: {
304
+ label?: string | null | undefined;
305
+ placeholder?: string;
306
+ default_value?: string;
307
+ options?: readonly string[];
308
+ };
309
+ }) | ({
310
+ type: "Separator";
311
+ } & {
312
+ config?: {
313
+ label?: string | null | undefined;
314
+ };
315
+ }) | ({
316
+ type: "Text";
317
+ } & {
318
+ fieldset?: string | null | undefined;
319
+ config?: {
320
+ label?: string | null | undefined;
321
+ useAsTitle?: boolean;
322
+ placeholder?: string;
323
+ };
324
+ }) | ({
325
+ type: "Timestamp";
326
+ } & {
327
+ fieldset?: string | null | undefined;
328
+ config?: {
329
+ label?: string | null | undefined;
330
+ placeholder?: string;
331
+ default?: string;
332
+ };
333
+ });
334
+ };
335
+ })[];
336
+ } & {
337
+ description?: string;
338
+ legacyPaths?: {
339
+ [x: string]: string;
340
+ };
341
+ }>;
342
+ export declare const findSliceVariation: (slice: SharedSliceCustomType) => (variation: string) => E.Either<string, Variation>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findSliceVariation = exports.findSlice = 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 errors_1 = require("./errors");
8
+ const findSlice = (slices) => (sliceId) => (0, function_1.pipe)(slices.find((slice) => slice.id === sliceId), E.fromNullable(errors_1.SharedSliceErrors.SliceTypeNotFound(sliceId)));
9
+ exports.findSlice = findSlice;
10
+ const findSliceVariation = (slice) => (variation) => (0, function_1.pipe)(slice.variations.find((v) => v.id === variation), E.fromNullable(errors_1.SharedSliceErrors.VariationNotFound(variation, slice.id)));
11
+ exports.findSliceVariation = findSliceVariation;
@@ -0,0 +1 @@
1
+ export * from "./ImportSlices";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./ImportSlices"), exports);
@@ -0,0 +1,4 @@
1
+ import { SharedSlice as SharedSliceCustomType, StaticSlices } from "../../../../customtypes";
2
+ import type { SharedSlice, SharedSliceId } from "./SharedSlice";
3
+ export declare const extractSupportedSlices: (staticSlices: StaticSlices) => SharedSliceCustomType[];
4
+ export declare const findImportSharedSliceDuplicateIds: (slices: SharedSlice[]) => SharedSliceId[];
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findImportSharedSliceDuplicateIds = exports.extractSupportedSlices = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const A = (0, tslib_1.__importStar)(require("fp-ts/Array"));
6
+ const function_1 = require("fp-ts/function");
7
+ const O = (0, tslib_1.__importStar)(require("fp-ts/Option"));
8
+ const customtypes_1 = require("../../../../customtypes");
9
+ // Extracts all supported slices from the static slices object
10
+ // For now we only support the SharedSlice, if we want to support other slices in the future, we have to add them here
11
+ const extractSupportedSlices = (staticSlices) => {
12
+ var _a, _b;
13
+ return (0, function_1.pipe)(Object.values((_b = (_a = staticSlices.config) === null || _a === void 0 ? void 0 : _a.choices) !== null && _b !== void 0 ? _b : {}).map((slice) => (0, function_1.pipe)(customtypes_1.SharedSlice.decode(slice), O.fromEither)), A.compact);
14
+ };
15
+ exports.extractSupportedSlices = extractSupportedSlices;
16
+ const findImportSharedSliceDuplicateIds = (slices) => {
17
+ const duplicatesMap = slices.reduce((acc, { id }) => {
18
+ var _a;
19
+ if (id) {
20
+ const currentNumOfDuplicates = (_a = acc[id]) !== null && _a !== void 0 ? _a : 0;
21
+ return {
22
+ ...acc,
23
+ [id]: acc[id] === undefined ? 0 : currentNumOfDuplicates + 1,
24
+ };
25
+ }
26
+ return acc;
27
+ }, {});
28
+ return Object.entries(duplicatesMap).flatMap(([id, numOfDuplicates]) => {
29
+ if (numOfDuplicates > 0) {
30
+ return [id];
31
+ }
32
+ return [];
33
+ });
34
+ };
35
+ exports.findImportSharedSliceDuplicateIds = findImportSharedSliceDuplicateIds;
@@ -0,0 +1,11 @@
1
+ import * as t from "io-ts";
2
+ import type { WidgetKey } from "../../../common";
3
+ import type { NestableWidget } from "../../../customtypes";
4
+ import { RepeatableZoneItem } from "./RepeatableZoneItem";
5
+ export declare type RepeatableZone = t.TypeOf<ReturnType<typeof RepeatableZone>>;
6
+ /**
7
+ * A custom type for a repeatable zone. This type of structure can be found 'items' field of a slice or in the group field.
8
+ *
9
+ * @param fieldModels a record of all nestable widgets that can be used in the zone
10
+ */
11
+ export declare const RepeatableZone: (fieldModels: Record<WidgetKey, NestableWidget>) => t.ArrayC<t.Type<RepeatableZoneItem, RepeatableZoneItem, unknown>>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RepeatableZone = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const function_1 = require("../../../validators/function");
7
+ const RepeatableZoneItem_1 = require("./RepeatableZoneItem");
8
+ /**
9
+ * A custom type for a repeatable zone. This type of structure can be found 'items' field of a slice or in the group field.
10
+ *
11
+ * @param fieldModels a record of all nestable widgets that can be used in the zone
12
+ */
13
+ const RepeatableZone = (fieldModels) => (0, function_1.withCustomError)(t.array((0, RepeatableZoneItem_1.RepeatableZoneItem)(fieldModels)), () => "The repeatable zone value must be an array");
14
+ exports.RepeatableZone = RepeatableZone;
@@ -0,0 +1,11 @@
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 RepeatableZoneItem = Record<WidgetKey, ImportNestable>;
6
+ /**
7
+ * A custom type for an item of a repeatable zone. This type of structure can be found in the 'primary' and 'items' fields of a slice or in the group field.
8
+ *
9
+ * @param fieldModels a record of all nestable widgets that can be used in the zone
10
+ */
11
+ export declare const RepeatableZoneItem: (fieldModels: Record<WidgetKey, NestableWidget>) => t.Type<RepeatableZoneItem, RepeatableZoneItem, unknown>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RepeatableZoneItem = 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 function_2 = require("../../../validators/function");
10
+ const nestable_1 = require("./nestable");
11
+ /**
12
+ * A custom type for an item of a repeatable zone. This type of structure can be found in the 'primary' and 'items' fields of a slice or in the group field.
13
+ *
14
+ * @param fieldModels a record of all nestable widgets that can be used in the zone
15
+ */
16
+ const RepeatableZoneItem = (fieldModels) => new t.Type("RepeatableZoneItem", (u) => t.record(common_1.WidgetKey, t.unknown).is(u) &&
17
+ Object.values(u).reduce((acc, value) => acc && nestable_1.ImportNestable.is(value), true), (u, c) => {
18
+ const codecEntries = Object.entries(fieldModels).map(([key, model]) => [key, nestable_1.ImportNestable.getCodec(model)]);
19
+ const groupCodec = (0, function_2.withCustomError)(t.partial({
20
+ ...Object.fromEntries(codecEntries),
21
+ }), () => "The value must be an object");
22
+ return (0, function_1.pipe)(groupCodec.validate(u, c), E.chain((decodedContent) => {
23
+ // Validate if all fields are present in the model
24
+ const keys = Object.keys(decodedContent);
25
+ const errors = keys.flatMap((key) => fieldModels[key]
26
+ ? []
27
+ : [
28
+ {
29
+ value: decodedContent[key],
30
+ context: c,
31
+ message: `The field '${key}' is not defined in the custom type`,
32
+ },
33
+ ]);
34
+ return errors.length > 0
35
+ ? t.failures(errors)
36
+ : t.success(decodedContent); // We can never have a key with decoded value 'undefined' so we can ignore the type derived from t.partial
37
+ }));
38
+ }, t.identity);
39
+ exports.RepeatableZoneItem = RepeatableZoneItem;