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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/lib/common/UUID.d.ts +7 -0
  2. package/lib/common/UUID.js +8 -0
  3. package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
  4. package/lib/import/converters/Document.d.ts +1 -2
  5. package/lib/import/converters/Document.js +2 -0
  6. package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
  7. package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
  8. package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
  9. package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
  10. package/lib/import/converters/fields/Slices/SliceItem.d.ts +4 -0
  11. package/lib/import/converters/fields/Slices/SliceItem.js +24 -0
  12. package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
  13. package/lib/import/converters/fields/Slices/Slices.js +16 -0
  14. package/lib/import/converters/fields/Slices/index.d.ts +1 -0
  15. package/lib/import/converters/fields/Slices/index.js +4 -0
  16. package/lib/import/converters/fields/index.d.ts +1 -0
  17. package/lib/import/converters/fields/index.js +1 -0
  18. package/lib/import/converters/fields/nestable/Nestable.d.ts +2 -2
  19. package/lib/import/validators/fields/ImportField.d.ts +11 -1
  20. package/lib/import/validators/fields/ImportField.js +6 -1
  21. package/lib/import/validators/fields/ImportSlices/ImportSliceId.d.ts +9 -0
  22. package/lib/import/validators/fields/ImportSlices/ImportSliceId.js +43 -0
  23. package/lib/import/validators/fields/ImportSlices/ImportSliceItem.d.ts +24 -0
  24. package/lib/import/validators/fields/ImportSlices/ImportSliceItem.js +87 -0
  25. package/lib/import/validators/fields/ImportSlices/ImportSliceItemContent.d.ts +12 -0
  26. package/lib/import/validators/fields/ImportSlices/ImportSliceItemContent.js +41 -0
  27. package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
  28. package/lib/import/validators/fields/ImportSlices/ImportSlices.js +29 -0
  29. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +14 -0
  30. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +60 -0
  31. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
  32. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
  33. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
  34. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
  35. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
  36. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
  37. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
  38. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
  39. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
  40. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
  41. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
  42. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
  43. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
  44. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
  45. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
  46. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
  47. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
  48. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
  49. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
  50. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
  51. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
  52. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
  53. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
  54. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
  55. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
  56. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
  57. package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
  58. package/lib/import/validators/fields/ImportSlices/index.js +4 -0
  59. package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
  60. package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
  61. package/lib/import/validators/fields/Slices/SharedSlice/SharedSlice.d.ts +14 -0
  62. package/lib/import/validators/fields/Slices/SharedSlice/SharedSlice.js +60 -0
  63. package/lib/import/validators/fields/Slices/SharedSlice/errors.d.ts +5 -0
  64. package/lib/import/validators/fields/Slices/SharedSlice/errors.js +8 -0
  65. package/lib/import/validators/fields/Slices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
  66. package/lib/import/validators/fields/Slices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
  67. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
  68. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +38 -0
  69. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
  70. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
  71. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/errors.d.ts +5 -0
  72. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/errors.js +9 -0
  73. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
  74. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
  75. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
  76. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
  77. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
  78. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceId.js +39 -0
  79. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceItems.d.ts +11 -0
  80. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceItems.js +25 -0
  81. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
  82. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceType.js +24 -0
  83. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
  84. package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceVariation.js +24 -0
  85. package/lib/import/validators/fields/Slices/SharedSlice/fields/index.d.ts +6 -0
  86. package/lib/import/validators/fields/Slices/SharedSlice/fields/index.js +9 -0
  87. package/lib/import/validators/fields/Slices/SharedSlice/index.d.ts +3 -0
  88. package/lib/import/validators/fields/Slices/SharedSlice/index.js +6 -0
  89. package/lib/import/validators/fields/Slices/SharedSlice/utils.d.ts +339 -0
  90. package/lib/import/validators/fields/Slices/SharedSlice/utils.js +11 -0
  91. package/lib/import/validators/fields/Slices/Slices.d.ts +8 -0
  92. package/lib/import/validators/fields/Slices/Slices.js +29 -0
  93. package/lib/import/validators/fields/Slices/index.d.ts +1 -0
  94. package/lib/import/validators/fields/Slices/index.js +4 -0
  95. package/lib/import/validators/fields/Slices/utils.d.ts +4 -0
  96. package/lib/import/validators/fields/Slices/utils.js +35 -0
  97. package/lib/import/validators/fields/Slices.d.ts +4 -0
  98. package/lib/import/validators/fields/Slices.js +12 -0
  99. package/lib/import/validators/fields/nestable/Image.d.ts +30 -47
  100. package/lib/import/validators/fields/nestable/Image.js +22 -53
  101. package/lib/utils/io-ts.d.ts +2 -0
  102. package/lib/utils/io-ts.js +22 -0
  103. package/lib/validators/BasicTypes.d.ts +1 -0
  104. package/lib/validators/BasicTypes.js +2 -1
  105. package/lib/validators/NonEmptyString.js +2 -1
  106. package/package.json +4 -2
  107. package/src/common/UUID.ts +18 -0
  108. package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
  109. package/src/import/converters/Document.ts +8 -3
  110. package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
  111. package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
  112. package/src/import/converters/fields/Slices/Slices.ts +20 -0
  113. package/src/import/converters/fields/Slices/index.ts +1 -0
  114. package/src/import/converters/fields/index.ts +1 -0
  115. package/src/import/converters/fields/nestable/Nestable.ts +2 -2
  116. package/src/import/validators/fields/ImportField.ts +7 -2
  117. package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
  118. package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +114 -0
  119. package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +6 -0
  120. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +20 -0
  121. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +61 -0
  122. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
  123. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
  124. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
  125. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
  126. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
  127. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
  128. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
  129. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
  130. package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
  131. package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
  132. package/src/import/validators/fields/ImportSlices/index.ts +1 -0
  133. package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
  134. package/src/utils/io-ts.ts +29 -0
  135. package/src/validators/BasicTypes.ts +5 -0
  136. package/src/validators/NonEmptyString.ts +4 -4
@@ -0,0 +1,7 @@
1
+ import * as t from "io-ts";
2
+ interface UUIDBrand {
3
+ readonly UUID: unique symbol;
4
+ }
5
+ export declare const UUID: t.BrandC<t.StringC, UUIDBrand>;
6
+ export declare type UUID = t.TypeOf<typeof UUID>;
7
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UUID = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const io_ts_types_1 = require("io-ts-types");
7
+ const uuid_1 = require("uuid");
8
+ exports.UUID = (0, io_ts_types_1.withMessage)(t.brand(t.string, (s) => (0, uuid_1.validate)(s), "UUID"), () => "The value must be a valid UUID");
@@ -14,5 +14,4 @@ const RepeatableWidgetsBlock = t.strict({
14
14
  __TYPE__: t.literal(GroupContent_1.GroupItemContentType),
15
15
  value: t.array(RepeatableWidget),
16
16
  });
17
- t.array(RepeatableWidget);
18
17
  exports.RepeatableWidgets = t.array(RepeatableWidgetsBlock);
@@ -1,5 +1,4 @@
1
- import type { Asset } from "../../common";
2
- import type { Embed } from "../../common/Embed";
1
+ import type { Asset, Embed } from "../../common";
3
2
  import type { Document } from "../../content";
4
3
  import type { ImportDocument } from "../validators";
5
4
  export declare function convertImportToContent(document: ImportDocument, assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>): Document;
@@ -13,6 +13,8 @@ function convertWidget(field, assets, embeds) {
13
13
  switch (field.type) {
14
14
  case "UID":
15
15
  return (0, fields_1.uidConverter)(field.value);
16
+ case "Slices":
17
+ return (0, fields_1.importSlicesConverter)(field.value, assets, embeds);
16
18
  default:
17
19
  return (0, fields_1.convertNestableWidget)(field, assets, embeds);
18
20
  }
@@ -0,0 +1,4 @@
1
+ import type { Asset, Embed } from "../../../../common";
2
+ import type { SliceItemContent } from "../../../../content";
3
+ import type { SharedSlice as ImportSharedSlice } from "../../../validators/fields/ImportSlices/SharedSlice";
4
+ export declare const sharedSliceConverter: (slice: ImportSharedSlice, assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>) => SliceItemContent;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sharedSliceConverter = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const SharedSliceContent_1 = require("./SharedSliceContent");
6
+ // TODO should we put it together with SharedSliceId validator?
7
+ const buildSharedSliceId = (slice_type) => `${slice_type}$${(0, uuid_1.v4)()}`;
8
+ const sharedSliceConverter = (slice, assets, embeds) => {
9
+ var _a, _b;
10
+ // Right now we only support SharedSlices, if we support more types of slices in the future we'll need to select a correct converter here
11
+ const widget = (0, SharedSliceContent_1.importSharedSliceContentConverter)(slice, assets, embeds);
12
+ return {
13
+ key: (_a = slice.id) !== null && _a !== void 0 ? _a : buildSharedSliceId(slice.slice_type),
14
+ name: slice.slice_type,
15
+ maybeLabel: (_b = slice.slice_label) !== null && _b !== void 0 ? _b : undefined,
16
+ widget,
17
+ };
18
+ };
19
+ exports.sharedSliceConverter = sharedSliceConverter;
@@ -0,0 +1,10 @@
1
+ import type { Asset, Embed } from "../../../../common";
2
+ import type { SharedSliceContent } from "../../../../content";
3
+ import type { SharedSlice as ImportSharedSlice } from "../../../validators/fields/ImportSlices/SharedSlice";
4
+ /**
5
+ * Builds SharedSliceContent model from ImportSharedSlice
6
+ * @param field ImportSharedSlice to be converted - a single slice from the slices array in the import document
7
+ * @param assets assets that are required for a conversion of a nestable widget
8
+ * @param embeds embeds that are required for a conversion of a nestable widget
9
+ */
10
+ export declare const importSharedSliceContentConverter: (field: ImportSharedSlice, assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>) => SharedSliceContent;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.importSharedSliceContentConverter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const function_1 = require("fp-ts/function");
6
+ const O = (0, tslib_1.__importStar)(require("fp-ts/Option"));
7
+ const R = (0, tslib_1.__importStar)(require("fp-ts/Record"));
8
+ const content_1 = require("../../../../content");
9
+ const nestable_1 = require("../nestable");
10
+ /**
11
+ * Converts the ImportSharedSliceContent which is a record of widget keys and ImportNestable values to a record of widget keys and NestableContent values.
12
+ *
13
+ * @param content a single ImportSharedSliceContent
14
+ * @param assets assets that are required for a conversion of a nestable widget
15
+ * @param embeds embeds that are required for a conversion of a nestable widget
16
+ */
17
+ const sharedSliceContentConverter = (content, assets, embeds) => (0, function_1.pipe)(content,
18
+ // convertNestableWidget can theoretically return undefined, so we need to filter out those values
19
+ R.filterMap((contentValue) => (0, function_1.pipe)(contentValue, (content) => (0, nestable_1.convertNestableWidget)(content, assets, embeds), O.fromNullable)));
20
+ /**
21
+ * Converts a list of items to a list of repeatable widgets.
22
+ * Each ImportSharedSliceContent element is a record of fields, but in the content model it is represented as a list of tuples (key, value)
23
+ *
24
+ * For example, given the following slice content:
25
+ * {
26
+ * "slice_text": (ImportNestable),
27
+ * "slice_number": (ImportNestable),
28
+ * }
29
+ *
30
+ * has to be converted to:
31
+ *
32
+ * {
33
+ * __TYPE__: "GroupItemContentType",
34
+ * value: [
35
+ * ["slice_text", (NestableContent)],
36
+ * ["slice_number", (NestableContent)],
37
+ * ]
38
+ * }
39
+ *
40
+ * @param items list of items to be converted
41
+ * @param assets assets that are required for a conversion of a nestable widget
42
+ */
43
+ const itemsConverter = (items, assets, embeds) => items.map((item) => (0, function_1.pipe)(sharedSliceContentConverter(item, assets, embeds), (record) => Object.entries(record), (entries) => ({ __TYPE__: content_1.GroupItemContentType, value: entries })));
44
+ /**
45
+ * Builds SharedSliceContent model from ImportSharedSlice
46
+ * @param field ImportSharedSlice to be converted - a single slice from the slices array in the import document
47
+ * @param assets assets that are required for a conversion of a nestable widget
48
+ * @param embeds embeds that are required for a conversion of a nestable widget
49
+ */
50
+ const importSharedSliceContentConverter = (field, assets, embeds) => ({
51
+ __TYPE__: content_1.SharedSliceContentType,
52
+ primary: field.primary
53
+ ? sharedSliceContentConverter(field.primary, assets, embeds)
54
+ : {},
55
+ items: field.items ? itemsConverter(field.items, assets, embeds) : [],
56
+ variation: field.variation,
57
+ });
58
+ exports.importSharedSliceContentConverter = importSharedSliceContentConverter;
@@ -0,0 +1,4 @@
1
+ import type { Asset } from "../../../../common";
2
+ import type { SharedSliceContent } from "../../../../content";
3
+ import type { SharedSlice as ImportSharedSlice } from "../../../validators/fields/Slices/SharedSlice";
4
+ export declare const importSliceItemConverter: (field: ImportSharedSlice, assets: Record<string, Asset>) => SharedSliceContent;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.importSliceItemConverter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const function_1 = require("fp-ts/function");
6
+ const O = (0, tslib_1.__importStar)(require("fp-ts/Option"));
7
+ const R = (0, tslib_1.__importStar)(require("fp-ts/Record"));
8
+ const content_1 = require("../../../../content");
9
+ const nestable_1 = require("../nestable");
10
+ const importSliceItemContentConverter = (content, assets) => (0, function_1.pipe)(content,
11
+ // convertNestableWidget can theoretically return undefined, so we need to filter out those values
12
+ R.filterMap((contentValue) => (0, function_1.pipe)(contentValue, (content) => (0, nestable_1.convertNestableWidget)(content, assets), O.fromNullable)));
13
+ const itemsToRepeatableWidgetsConverter = (items, assets) => items.map((item) => (0, function_1.pipe)(importSliceItemContentConverter(item, assets), (record) => Object.entries(record), (entries) => ({ __TYPE__: content_1.GroupItemContentType, value: entries })));
14
+ const importSliceItemConverter = (field, assets) => ({
15
+ __TYPE__: content_1.SharedSliceContentType,
16
+ primary: field.primary
17
+ ? importSliceItemContentConverter(field.primary, assets)
18
+ : {},
19
+ items: field.items
20
+ ? itemsToRepeatableWidgetsConverter(field.items, assets)
21
+ : [],
22
+ variation: field.variation,
23
+ });
24
+ exports.importSliceItemConverter = importSliceItemConverter;
@@ -0,0 +1,4 @@
1
+ import type { Asset, Embed } from "../../../../common";
2
+ import type { SlicesContent } from "../../../../content";
3
+ import type { ImportSlices } from "../../../validators/fields/ImportSlices";
4
+ export declare const importSlicesConverter: (field: ImportSlices["value"], assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>) => SlicesContent | undefined;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.importSlicesConverter = void 0;
4
+ const SharedSlice_1 = require("./SharedSlice");
5
+ const importSlicesConverter = (field, assets, embeds) => {
6
+ if (field === null)
7
+ return;
8
+ return {
9
+ value: field.map((slice) => {
10
+ // Right now we only support SharedSlices, if we support more types of slices in the future we'll need to select a correct converter here
11
+ return (0, SharedSlice_1.sharedSliceConverter)(slice, assets, embeds);
12
+ }),
13
+ __TYPE__: "SliceContentType",
14
+ };
15
+ };
16
+ exports.importSlicesConverter = importSlicesConverter;
@@ -0,0 +1 @@
1
+ export * from "./Slices";
@@ -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("./Slices"), exports);
@@ -1,2 +1,3 @@
1
1
  export * from "./nestable";
2
+ export * from "./Slices";
2
3
  export * from "./UID";
@@ -2,4 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  (0, tslib_1.__exportStar)(require("./nestable"), exports);
5
+ (0, tslib_1.__exportStar)(require("./Slices"), exports);
5
6
  (0, tslib_1.__exportStar)(require("./UID"), exports);
@@ -1,5 +1,5 @@
1
1
  import type { Asset } from "../../../../common";
2
2
  import type { Embed } from "../../../../common/Embed";
3
- import type { WidgetContent } from "../../../../content";
3
+ import type { NestableContent } from "../../../../content";
4
4
  import type { ImportNestable } from "../../../validators";
5
- export declare function convertNestableWidget(field: ImportNestable, assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>): WidgetContent | undefined;
5
+ export declare function convertNestableWidget(field: ImportNestable, assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>): NestableContent | undefined;
@@ -1,7 +1,8 @@
1
1
  import type { StaticWidget } from "../../../customtypes";
2
+ import { ImportSlices } from "./ImportSlices";
2
3
  import { ImportNestable } from "./nestable";
3
4
  import { ImportUID } from "./UID";
4
- export declare type ImportField = ImportUID | ImportNestable;
5
+ export declare type ImportField = ImportUID | ImportSlices | ImportNestable;
5
6
  export declare const ImportField: {
6
7
  is(u: unknown): u is ImportNestable;
7
8
  decode: (field: StaticWidget) => (content: unknown) => {
@@ -121,5 +122,14 @@ export declare const ImportField: {
121
122
  type: "UID";
122
123
  value: string | null;
123
124
  }>;
125
+ } | {
126
+ codec: import("io-ts").Type<{
127
+ type: "Slices";
128
+ value: import("./ImportSlices/SharedSlice").SharedSlice[] | null;
129
+ }, import("./ImportSlices/SharedSlice").SharedSlice[] | undefined, unknown>;
130
+ result: import("io-ts").Validation<{
131
+ type: "Slices";
132
+ value: import("./ImportSlices/SharedSlice").SharedSlice[] | null;
133
+ }>;
124
134
  };
125
135
  };
@@ -1,6 +1,7 @@
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
6
  const UID_1 = require("./UID");
6
7
  exports.ImportField = {
@@ -12,8 +13,12 @@ exports.ImportField = {
12
13
  switch (field.type) {
13
14
  case "UID":
14
15
  return { codec: UID_1.ImportUID, result: UID_1.ImportUID.decode(content) };
15
- case "Choice":
16
16
  case "Slices":
17
+ return {
18
+ codec: (0, ImportSlices_1.ImportSlices)(field),
19
+ result: (0, ImportSlices_1.ImportSlices)(field).decode(content),
20
+ };
21
+ case "Choice":
17
22
  case "Group":
18
23
  throw new Error(`Unsupported type of field ${field.type}`);
19
24
  default:
@@ -0,0 +1,9 @@
1
+ import * as t from "io-ts";
2
+ import { UUID } from "../../../../common/UUID";
3
+ export declare type ImportSliceId = `${string}$${UUID}`;
4
+ export declare const ImportSliceIdValidationError: {
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 ImportSliceId: t.Type<string, string, unknown>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportSliceId = exports.ImportSliceIdValidationError = 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.ImportSliceIdValidationError = {
12
+ Base: baseErrorText,
13
+ IncorrectUUID: (uuid) => `Incorrect UUID: '${uuid}' - ${baseErrorText}`,
14
+ IncorrectSliceType: (sliceType) => `Incorrect slice_type: '${sliceType}' - ${baseErrorText}`,
15
+ };
16
+ exports.ImportSliceId = new t.Type("ImportSliceId", (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.ImportSliceIdValidationError.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
+ const correctErrorKey = (tupleErrorContext === null || tupleErrorContext === void 0 ? void 0 : tupleErrorContext.key) === "0" ? "slice_type" : "uuid";
30
+ const codec = (tupleErrorContext === null || tupleErrorContext === void 0 ? void 0 : tupleErrorContext.key) === "0" ? validators_1.NonEmptyString : UUID_1.UUID;
31
+ const actual = (tupleErrorContext === null || tupleErrorContext === void 0 ? void 0 : tupleErrorContext.key) === "0" ? sliceName : uuid;
32
+ return {
33
+ ...error,
34
+ context: [
35
+ ...error.context.slice(0, -1),
36
+ { key: correctErrorKey, type: codec, actual },
37
+ ],
38
+ message: (tupleErrorContext === null || tupleErrorContext === void 0 ? void 0 : tupleErrorContext.key) === "0"
39
+ ? exports.ImportSliceIdValidationError.IncorrectSliceType(sliceName)
40
+ : exports.ImportSliceIdValidationError.IncorrectUUID(uuid),
41
+ };
42
+ })));
43
+ }), E.map(([sliceName, uuid]) => `${sliceName}$${uuid}`)), (sliceId) => sliceId);
@@ -0,0 +1,24 @@
1
+ import * as t from "io-ts";
2
+ import { SharedSlice } from "../../../../customtypes";
3
+ import { ImportSliceId } from "./ImportSliceId";
4
+ import { ImportSliceItemContent } from "./ImportSliceItemContent";
5
+ export declare const ImportSliceItemErrors: {
6
+ readonly SliceTypeNotFound: (slice_type: string) => string;
7
+ readonly VariationNotFound: (variation: string, slice_type: string) => string;
8
+ readonly SliceContentItemErrors: {
9
+ readonly UnknownField: (sliceName: string, sliceContentField: "primary" | "items", fieldName: string) => string;
10
+ readonly InvalidSliceItemContent: (sliceName: string, sliceContentField: "primary" | "items") => string;
11
+ };
12
+ readonly InvalidItemsArray: (slice_type: string) => string;
13
+ };
14
+ export declare type ImportSliceItem = {
15
+ id: ImportSliceId | null | undefined;
16
+ slice_type: string;
17
+ name: string;
18
+ variation: string;
19
+ primary: ImportSliceItemContent | null | undefined;
20
+ items: ImportSliceItemContent[] | null | undefined;
21
+ slice_label: string | null | undefined;
22
+ version: string | null | undefined;
23
+ };
24
+ export declare const ImportSliceItem: (sharedSlices: SharedSlice[]) => t.Type<ImportSliceItem, ImportSliceItem, unknown>;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportSliceItem = exports.ImportSliceItemErrors = 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 io_ts_types_1 = require("io-ts-types");
9
+ const customtypes_1 = require("../../../../customtypes");
10
+ const validators_1 = require("../../../../validators");
11
+ const ImportSliceId_1 = require("./ImportSliceId");
12
+ const ImportSliceItemContent_1 = require("./ImportSliceItemContent");
13
+ exports.ImportSliceItemErrors = {
14
+ SliceTypeNotFound: (slice_type) => `Slice '${slice_type}' not found in document's custom type`,
15
+ VariationNotFound: (variation, slice_type) => `Variation '${variation}' not found for Slice '${slice_type}'`,
16
+ SliceContentItemErrors: ImportSliceItemContent_1.SliceItemContentErrors,
17
+ InvalidItemsArray: (slice_type) => `Invalid value for 'items' array in Slice '${slice_type}'. Must be an array of key-value records.`,
18
+ };
19
+ const SliceTypeWithSliceDataShape = t.type({
20
+ slice_type: validators_1.NonEmptyString,
21
+ slice: customtypes_1.SharedSlice,
22
+ });
23
+ const findSlice = (slices) => (sliceId) => (0, function_1.pipe)(slices.find((slice) => slice.id === sliceId), E.fromNullable(exports.ImportSliceItemErrors.SliceTypeNotFound(sliceId)));
24
+ const SliceTypeWithSliceData = (slices) => new t.Type("slice_type", (u) => SliceTypeWithSliceDataShape.is(u), (u, c) => (0, function_1.pipe)(validators_1.NonEmptyString.validate(u, c), E.chain((slice_type) => (0, function_1.pipe)(findSlice(slices)(slice_type), E.fold((err) => t.failure(u, c, err), (data) => t.success({ slice_type, data }))))), ({ slice_type }) => slice_type);
25
+ const SliceVariationWithVariationDataShape = t.type({
26
+ variation: validators_1.NonEmptyString,
27
+ data: customtypes_1.Variation,
28
+ });
29
+ const findSliceVariation = (slice) => (variation) => (0, function_1.pipe)(slice.variations.find((v) => v.id === variation), E.fromNullable(exports.ImportSliceItemErrors.VariationNotFound(variation, slice.id)));
30
+ const SliceVariationWithVariationData = (slice) => new t.Type("variation", (u) => SliceVariationWithVariationDataShape.is(u), (u, c) => (0, function_1.pipe)(validators_1.NonEmptyString.validate(u, c), E.chain((variation) => (0, function_1.pipe)(findSliceVariation(slice)(variation), E.fold((err) => t.failure(u, c, err), (data) => t.success({ variation, data }))))), ({ variation }) => variation);
31
+ const SliceId = new t.Type("ImportSliceId", (u) => u === null || u === undefined || ImportSliceId_1.ImportSliceId.is(u), (u, c) => {
32
+ if (u === null || u === undefined)
33
+ return t.success(u);
34
+ return ImportSliceId_1.ImportSliceId.validate(u, c);
35
+ }, t.identity);
36
+ const SliceLabel = t.union([t.undefined, t.null, validators_1.String]);
37
+ const SliceVersion = t.union([t.undefined, t.null, validators_1.String]);
38
+ const ImportSliceItemShape = t.type({
39
+ id: SliceId,
40
+ slice_type: validators_1.NonEmptyString,
41
+ name: validators_1.String,
42
+ variation: validators_1.NonEmptyString,
43
+ primary: t.union([t.undefined, t.null, t.record(validators_1.NonEmptyString, t.unknown)]),
44
+ items: t.union([
45
+ t.undefined,
46
+ t.null,
47
+ t.array(t.record(validators_1.NonEmptyString, t.unknown)),
48
+ ]),
49
+ slice_label: SliceLabel,
50
+ version: SliceVersion,
51
+ });
52
+ const baseFields = (sharedSlices) => t.type({
53
+ id: SliceId,
54
+ slice_type: SliceTypeWithSliceData(sharedSlices),
55
+ slice_label: SliceLabel,
56
+ version: SliceVersion,
57
+ });
58
+ const variationData = (slice) => t.type({ variation: SliceVariationWithVariationData(slice) });
59
+ const Items = (sliceName, model) => {
60
+ const ItemContentCodec = (0, ImportSliceItemContent_1.ImportSliceItemContent)(sliceName, "items", model);
61
+ return new t.Type("Items", (u) => t.array(ItemContentCodec).is(u), (u, c) => (0, function_1.pipe)((0, io_ts_types_1.withMessage)(t.array(t.unknown), () => exports.ImportSliceItemErrors.InvalidItemsArray(sliceName)).validate(u, c), E.chain((arr) => t.array(ItemContentCodec).validate(arr, c))), t.identity);
62
+ };
63
+ const ImportSliceItem = (sharedSlices) => new t.Type("ImportSliceItem", (u) => ImportSliceItemShape.is(u), (u, c) => (0, function_1.pipe)(baseFields(sharedSlices).validate(u, c), E.chain((decoded) => (0, function_1.pipe)(variationData(decoded.slice_type.data).validate(u, c), E.map(({ variation }) => ({ ...decoded, variation })))), E.chain((decoded) => {
64
+ var _a;
65
+ return (0, function_1.pipe)(t
66
+ .partial({
67
+ primary: (0, ImportSliceItemContent_1.ImportSliceItemContent)(decoded.slice_type.slice_type, "primary", (_a = decoded.variation.data.primary) !== null && _a !== void 0 ? _a : {}),
68
+ })
69
+ .validate(u, c), E.map(({ primary }) => ({ ...decoded, primary })));
70
+ }), E.chain((decoded) => {
71
+ var _a;
72
+ return (0, function_1.pipe)(t
73
+ .partial({
74
+ items: Items(decoded.slice_type.slice_type, (_a = decoded.variation.data.items) !== null && _a !== void 0 ? _a : {}),
75
+ })
76
+ .validate(u, c), E.map(({ items }) => ({ ...decoded, items })));
77
+ }), E.map(({ id, slice_type, variation, primary, items, slice_label, version, }) => ({
78
+ id,
79
+ slice_type: slice_type.slice_type,
80
+ name: slice_type.data.name,
81
+ variation: variation.variation,
82
+ primary,
83
+ items,
84
+ slice_label,
85
+ version: version !== null && version !== void 0 ? version : variation.data.version,
86
+ }))), t.identity);
87
+ exports.ImportSliceItem = ImportSliceItem;
@@ -0,0 +1,12 @@
1
+ import * as t from "io-ts";
2
+ import { WidgetKey } from "../../../../common";
3
+ import type { NestableWidget } from "../../../../customtypes";
4
+ import { ImportNestable } from "../nestable";
5
+ declare type SliceContentField = "primary" | "items";
6
+ export declare const SliceItemContentErrors: {
7
+ readonly UnknownField: (sliceName: string, sliceContentField: SliceContentField, fieldName: string) => string;
8
+ readonly InvalidSliceItemContent: (sliceName: string, sliceContentField: SliceContentField) => string;
9
+ };
10
+ export declare type ImportSliceItemContent = Record<WidgetKey, ImportNestable>;
11
+ export declare const ImportSliceItemContent: (sliceName: string, sliceContentField: "primary" | "items", sliceFieldModels: Record<WidgetKey, NestableWidget>) => t.Type<ImportSliceItemContent, ImportSliceItemContent, unknown>;
12
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportSliceItemContent = exports.SliceItemContentErrors = 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 io_ts_types_1 = require("io-ts-types");
9
+ const common_1 = require("../../../../common");
10
+ const io_ts_1 = require("../../../../utils/io-ts");
11
+ const nestable_1 = require("../nestable");
12
+ exports.SliceItemContentErrors = {
13
+ UnknownField: (sliceName, sliceContentField, fieldName) => `Unsupported field '${fieldName}'for ${sliceContentField} content in Slice '${sliceName}'`,
14
+ InvalidSliceItemContent: (sliceName, sliceContentField) => {
15
+ return `Invalid value for '${sliceContentField}' content in Slice '${sliceName}'. Must be a key-value record.`;
16
+ },
17
+ };
18
+ const SliceItemContentEntry = (sliceName, sliceContentField, sliceFieldModels) => new t.Type("SliceItemContentEntry", (u) => t.tuple([common_1.WidgetKey, t.unknown]).is(u) && nestable_1.ImportNestable.is(u[1]), (u, c) => {
19
+ return (0, function_1.pipe)(t.tuple([common_1.WidgetKey, t.unknown]).validate(u, c), E.chain(([key, content]) => {
20
+ const model = sliceFieldModels[key];
21
+ if (!model) {
22
+ return t.failure([key, content], [...c, { key, actual: content, type: t.unknown }], exports.SliceItemContentErrors.UnknownField(sliceName, sliceContentField, key));
23
+ }
24
+ const { codec, result } = nestable_1.ImportNestable.decode(model)(content);
25
+ return (0, function_1.pipe)(result, E.map((decodedContent) => [
26
+ key,
27
+ decodedContent,
28
+ ]), E.mapLeft((errors) => errors.map((error) => {
29
+ const context = [
30
+ ...c,
31
+ ...error.context.filter(({ key }) => !!key),
32
+ { key, actual: content, type: codec },
33
+ ];
34
+ const updatedError = { ...error, context };
35
+ return updatedError;
36
+ })));
37
+ }));
38
+ }, t.identity);
39
+ const RawContent = (sliceName, sliceContentField) => (0, io_ts_types_1.withMessage)(t.record(common_1.WidgetKey, t.unknown), () => exports.SliceItemContentErrors.InvalidSliceItemContent(sliceName, sliceContentField));
40
+ const ImportSliceItemContent = (sliceName, sliceContentField, sliceFieldModels) => new t.Type("ImportSliceItemContent", (u) => t.record(common_1.WidgetKey, t.unknown).is(u), (u, c) => (0, function_1.pipe)(RawContent(sliceName, sliceContentField).validate(u, c), E.chain((rawContent) => (0, function_1.pipe)(Object.entries(rawContent).map((entry) => SliceItemContentEntry(sliceName, sliceContentField, sliceFieldModels).validate(entry, c)), io_ts_1.combineValidationResults, E.map((entries) => entries.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}))))), t.identity);
41
+ exports.ImportSliceItemContent = ImportSliceItemContent;
@@ -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,60 @@
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 fields_1 = require("./fields");
10
+ const SharedSliceShape = t.type({
11
+ id: fields_1.OptionalSharedSliceId,
12
+ slice_type: validators_1.NonEmptyString,
13
+ name: validators_1.String,
14
+ variation: validators_1.NonEmptyString,
15
+ primary: t.union([t.undefined, t.null, t.record(validators_1.NonEmptyString, t.unknown)]),
16
+ items: t.union([
17
+ t.undefined,
18
+ t.null,
19
+ t.array(t.record(validators_1.NonEmptyString, t.unknown)),
20
+ ]),
21
+ slice_label: t.union([t.undefined, t.null, validators_1.String]),
22
+ version: t.union([t.undefined, t.null, validators_1.String]),
23
+ });
24
+ const SharedSlice = (sharedSlices) => new t.Type("SharedSlice", (u) => SharedSliceShape.is(u), (u, c) => (0, function_1.pipe)(
25
+ // We validate the base fields that we can validate directly based on the provided 'sharedSlices'
26
+ t
27
+ .type({
28
+ id: fields_1.OptionalSharedSliceId,
29
+ slice_type: (0, fields_1.SharedSliceType)(sharedSlices),
30
+ slice_label: t.union([t.undefined, t.null, validators_1.String]),
31
+ version: t.union([t.undefined, t.null, validators_1.String]),
32
+ })
33
+ .validate(u, c), E.chain((decoded) => (0, function_1.pipe)(
34
+ // We validate the 'variation' field, for which we need the SharedSlice custom type retrieved in the first step
35
+ t
36
+ .type({
37
+ variation: (0, fields_1.SharedSliceVariation)(decoded.slice_type.data),
38
+ })
39
+ .validate(u, c), E.map(({ variation }) => ({ ...decoded, variation })))), E.chain((decoded) => {
40
+ var _a, _b;
41
+ return (0, function_1.pipe)(
42
+ // We validate the 'primary' and 'items' content fields, for which we need the Variation custom type retrieved in the previous step
43
+ t
44
+ .partial({
45
+ primary: (0, fields_1.SharedSliceContent)(decoded.slice_type.slice_type, "primary", (_a = decoded.variation.data.primary) !== null && _a !== void 0 ? _a : {}),
46
+ // We need to use this wrapper codec instead of using t.array(SharedSliceContent) directly in order to get proper custom error messages
47
+ items: validators_1.AnyArray.pipe(t.array((0, fields_1.SharedSliceContent)(decoded.slice_type.slice_type, "items", (_b = decoded.variation.data.items) !== null && _b !== void 0 ? _b : {}))),
48
+ })
49
+ .validate(u, c), E.map(({ primary, items }) => ({ ...decoded, primary, items })));
50
+ }), E.map(({ id, slice_type, variation, primary, items, slice_label, version, }) => ({
51
+ id,
52
+ slice_type: slice_type.slice_type,
53
+ name: slice_type.data.name,
54
+ variation: variation.variation,
55
+ primary,
56
+ items,
57
+ slice_label,
58
+ version: version !== null && version !== void 0 ? version : variation.data.version,
59
+ }))), t.identity);
60
+ 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
+ };