@prismicio/types-internal 2.2.0-traverse.alpha-0 → 2.2.0-traverse.alpha-2

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 (40) hide show
  1. package/lib/_internal/utils.d.ts +21 -4
  2. package/lib/_internal/utils.js +11 -0
  3. package/lib/content/Document.d.ts +2185 -13
  4. package/lib/content/Document.js +130 -35
  5. package/lib/content/fields/GroupContent.d.ts +11 -4
  6. package/lib/content/fields/GroupContent.js +31 -15
  7. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +8 -6
  8. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +33 -36
  9. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -6
  10. package/lib/content/fields/slices/Slice/SharedSliceContent.js +28 -38
  11. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +10 -0
  12. package/lib/content/fields/slices/Slice/SimpleSliceContent.js +60 -1
  13. package/lib/content/fields/slices/SliceItem.d.ts +15 -0
  14. package/lib/content/fields/slices/SliceItem.js +15 -1
  15. package/lib/content/fields/slices/SlicesContent.d.ts +4 -3
  16. package/lib/content/fields/slices/SlicesContent.js +125 -62
  17. package/lib/customtypes/CustomType.d.ts +4 -0
  18. package/lib/customtypes/CustomType.js +18 -1
  19. package/lib/customtypes/Section.d.ts +3 -0
  20. package/lib/customtypes/diff/SharedSlice.d.ts +6 -0
  21. package/lib/customtypes/widgets/Widget.d.ts +3 -0
  22. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +5 -0
  23. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +8 -0
  24. package/lib/customtypes/widgets/slices/SharedSlice.js +3 -0
  25. package/lib/customtypes/widgets/slices/Slices.d.ts +6 -0
  26. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +3 -0
  27. package/package.json +1 -1
  28. package/src/_internal/utils.ts +63 -7
  29. package/src/content/Document.ts +177 -42
  30. package/src/content/fields/GroupContent.ts +50 -16
  31. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +55 -44
  32. package/src/content/fields/slices/Slice/SharedSliceContent.ts +43 -49
  33. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +99 -1
  34. package/src/content/fields/slices/SliceItem.ts +39 -3
  35. package/src/content/fields/slices/SlicesContent.ts +172 -69
  36. package/src/customtypes/CustomType.ts +21 -0
  37. package/src/customtypes/widgets/slices/CompositeSlice.ts +6 -0
  38. package/src/customtypes/widgets/slices/SharedSlice.ts +12 -0
  39. package/lib/validators/NullOrT.d.ts +0 -2
  40. package/lib/validators/NullOrT.js +0 -12
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectWidgets = exports.traverseDocument = exports.DocumentLegacy = exports.Document = void 0;
3
+ exports.migrateDocument = exports.collectWidgets = exports.traverseDocument = exports.DocumentLegacy = exports.Document = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const Either_1 = require("fp-ts/lib/Either");
@@ -72,7 +72,7 @@ function extractMetadata(data) {
72
72
  slugs,
73
73
  };
74
74
  }
75
- function parseLegacyDocument(legacyDoc) {
75
+ function parseLegacyDocument(legacyDoc, customType) {
76
76
  const result = (0, function_1.pipe)(
77
77
  // ensure it's the right document format first
78
78
  t.record(common_1.WidgetKey, t.unknown).decode(legacyDoc), fp_ts_1.either.chain((doc) => {
@@ -81,7 +81,7 @@ function parseLegacyDocument(legacyDoc) {
81
81
  // parse the actual widgets
82
82
  return DocumentLegacyCodec(types).decode(widgets);
83
83
  }));
84
- return (0, Either_1.isLeft)(result) ? undefined : result.right;
84
+ return (0, Either_1.isLeft)(result) ? undefined : migrateDocument(result.right, customType);
85
85
  }
86
86
  function encodeToLegacyDocument(document) {
87
87
  const encoded = DocumentLegacyCodec().encode(document);
@@ -100,41 +100,49 @@ exports.DocumentLegacy = {
100
100
  * @param transform: A user function that provides a way to transform any kind of content wherever it is in a structured Prismic object content.
101
101
  * @returns a transformed document with the user's transformation applied with the transform function
102
102
  */
103
- function traverseDocument(document, model) {
104
- return (transform) => {
105
- const fieldDefs = model &&
103
+ function traverseDocument({ document, model, }) {
104
+ return ({ transformWidget = ({ content }) => content, transformSlice = ({ content }) => content, }) => {
105
+ const fieldModels = model &&
106
106
  (0, customtypes_1.flattenStaticWidgets)(model).reduce((acc, [key, def]) => ({ ...acc, [key]: def }), {});
107
107
  return Object.entries(document).reduce((acc, [key, content]) => {
108
- const fieldDef = fieldDefs && fieldDefs[key];
109
- const path = [{ key, type: content.__TYPE__ }];
110
- const transformedWidgetContent = (() => {
108
+ const fieldModel = fieldModels && fieldModels[key];
109
+ const path = utils_1.ContentPath.make([
110
+ { key: model === null || model === void 0 ? void 0 : model.id, type: "CustomType" },
111
+ { key, type: "Widget" },
112
+ ]);
113
+ const transformedWidget = (() => {
111
114
  switch (content.__TYPE__) {
112
115
  case "SliceContentType":
113
116
  return (0, fields_1.traverseSlices)({
114
117
  path,
115
- model: (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Slices" || (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Choice"
116
- ? fieldDef
118
+ key,
119
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Slices" || (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Choice"
120
+ ? fieldModel
117
121
  : undefined,
118
122
  content,
119
- })(transform);
123
+ })(transformWidget, transformSlice);
120
124
  case "GroupContentType":
121
125
  return (0, fields_1.traverseGroupContent)({
122
126
  path,
123
- model: (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Group" ? fieldDef : undefined,
127
+ key,
128
+ apiId: key,
129
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Group" ? fieldModel : undefined,
124
130
  content,
125
- })(transform);
131
+ })(transformWidget);
126
132
  default:
127
- return content;
133
+ return transformWidget({
134
+ path,
135
+ key,
136
+ apiId: key,
137
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Group" &&
138
+ (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Slices" &&
139
+ (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Choice"
140
+ ? fieldModel
141
+ : undefined,
142
+ content,
143
+ });
128
144
  }
129
145
  })();
130
- const transformedWidget = transformedWidgetContent &&
131
- transform({
132
- path,
133
- key,
134
- apiId: key,
135
- model: fieldDef,
136
- content: transformedWidgetContent,
137
- });
138
146
  return {
139
147
  ...acc,
140
148
  ...(transformedWidget ? { [key]: transformedWidget } : {}),
@@ -143,21 +151,108 @@ function traverseDocument(document, model) {
143
151
  };
144
152
  }
145
153
  exports.traverseDocument = traverseDocument;
146
- /**
147
- * The goal is to be able to collect all widgets or slices of a given type at any level of nesting inside a prismic content
148
- *
149
- * @param document parsed prismic content
150
- * @param is typeguard to match specifically the type of widget we want to collect
151
- * @returns a record containing the path of the widget as key and the typed collected content as value
152
- */
154
+ // /**
155
+ // * The goal is to be able to collect all widgets or slices of a given type at any level of nesting inside a prismic content
156
+ // *
157
+ // * @param document parsed prismic content
158
+ // * @param is typeguard to match specifically the type of widget we want to collect
159
+ // * @returns a record containing the path of the widget as key and the typed collected content as value
160
+ // */
153
161
  function collectWidgets(document, is) {
154
162
  const collected = {};
155
- traverseDocument(document)(({ content, path }) => {
156
- const key = utils_1.ContentPath.serialize(path);
157
- if (is(content, path))
158
- collected[key] = content;
159
- return content;
163
+ traverseDocument({ document })({
164
+ transformWidget: ({ content, path }) => {
165
+ const key = utils_1.ContentPath.serialize(path);
166
+ if (is(content, path))
167
+ collected[key] = content;
168
+ return content;
169
+ },
160
170
  });
161
171
  return collected;
162
172
  }
163
173
  exports.collectWidgets = collectWidgets;
174
+ function migrateCompositeSlice(model, content) {
175
+ return {
176
+ key: content.key,
177
+ name: model.sliceName,
178
+ maybeLabel: content.maybeLabel,
179
+ widget: {
180
+ __TYPE__: "SharedSliceContent",
181
+ variation: model.variationId,
182
+ primary: Object.entries(content.widget.nonRepeat).reduce((acc, [fieldKey, fieldContent]) => {
183
+ var _a;
184
+ return ((_a = model.fields.primary) === null || _a === void 0 ? void 0 : _a[fieldKey])
185
+ ? { ...acc, [fieldKey]: fieldContent }
186
+ : acc;
187
+ }, {}),
188
+ items: content.widget.repeat.map((groupItem) => {
189
+ return {
190
+ __TYPE__: "GroupItemContent",
191
+ value: groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
192
+ var _a;
193
+ return ((_a = model.fields.items) === null || _a === void 0 ? void 0 : _a[fieldKey])
194
+ ? acc.concat([[fieldKey, fieldContent]])
195
+ : acc;
196
+ }, []),
197
+ };
198
+ }, []),
199
+ },
200
+ };
201
+ }
202
+ function migrateSimpleSlice(model, content) {
203
+ var _a;
204
+ if (content.widget.__TYPE__ === "GroupContentType") {
205
+ return {
206
+ key: content.key,
207
+ name: model.sliceName,
208
+ maybeLabel: content.maybeLabel,
209
+ widget: {
210
+ __TYPE__: "SharedSliceContent",
211
+ variation: model.variationId,
212
+ primary: {},
213
+ items: content.widget.value.map((groupItem) => {
214
+ return {
215
+ __TYPE__: "GroupItemContent",
216
+ value: groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
217
+ var _a;
218
+ return ((_a = model.fields.items) === null || _a === void 0 ? void 0 : _a[fieldKey])
219
+ ? acc.concat([[fieldKey, fieldContent]])
220
+ : acc;
221
+ }, []),
222
+ };
223
+ }, []),
224
+ },
225
+ };
226
+ }
227
+ return {
228
+ key: content.key,
229
+ name: model.sliceName,
230
+ maybeLabel: content.maybeLabel,
231
+ widget: {
232
+ __TYPE__: "SharedSliceContent",
233
+ variation: model.variationId,
234
+ primary: ((_a = model.fields.primary) === null || _a === void 0 ? void 0 : _a[content.name])
235
+ ? { [content.key]: content.widget }
236
+ : {},
237
+ items: [],
238
+ },
239
+ };
240
+ }
241
+ function migrateDocument(document, model) {
242
+ const needsMigration = Object.values((0, customtypes_1.collectSharedSlices)(model)).some((slice) => Boolean(slice.legacyPaths));
243
+ if (!needsMigration)
244
+ return document;
245
+ return traverseDocument({
246
+ document,
247
+ model,
248
+ })({
249
+ transformSlice: ({ content, model }) => {
250
+ if ((0, fields_1.isCompositeSliceItemContent)(content) && (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
251
+ return migrateCompositeSlice(model, content);
252
+ if ((0, fields_1.isSimpleSliceItemContent)(content) && (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
253
+ return migrateSimpleSlice(model, content);
254
+ return content;
255
+ },
256
+ });
257
+ }
258
+ exports.migrateDocument = migrateDocument;
@@ -1,6 +1,6 @@
1
1
  import * as t from "io-ts";
2
- import type { ContentPath, TraverseContentFn } from "../../_internal/utils";
3
- import type { Group } from "../../customtypes";
2
+ import type { ContentPath, TraverseWidgetContentFn } from "../../_internal/utils";
3
+ import type { Group, NestableWidget } from "../../customtypes";
4
4
  import { LegacyContentCtx, WithTypes } from "../LegacyContentCtx";
5
5
  export declare const GroupItemContentType: "GroupItemContent";
6
6
  export declare const GroupItemContent: t.ExactC<t.TypeC<{
@@ -1438,9 +1438,16 @@ export declare const GroupContent: t.ExactC<t.TypeC<{
1438
1438
  }>>>;
1439
1439
  }>>;
1440
1440
  export declare type GroupContent = t.TypeOf<typeof GroupContent>;
1441
- export declare function traverseGroupContent({ path, model, content, }: {
1441
+ export declare function traverseGroupContent({ path, key, apiId, model, content, }: {
1442
1442
  path: ContentPath;
1443
+ key: string;
1444
+ apiId: string;
1443
1445
  content: GroupContent;
1444
1446
  model?: Group | undefined;
1445
- }): (transform: TraverseContentFn) => GroupContent | undefined;
1447
+ }): (transform: TraverseWidgetContentFn) => GroupContent | undefined;
1448
+ export declare function traverseGroupItemsContent({ path, model, content, }: {
1449
+ path: ContentPath;
1450
+ content: Array<GroupItemContent>;
1451
+ model?: Record<string, NestableWidget> | undefined;
1452
+ }): (transform: TraverseWidgetContentFn) => Array<GroupItemContent>;
1446
1453
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseGroupContent = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
3
+ exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const Either_1 = require("fp-ts/lib/Either");
@@ -81,24 +81,44 @@ exports.GroupContent = t.strict({
81
81
  __TYPE__: t.literal(exports.GroupContentType),
82
82
  value: t.array(exports.GroupItemContent),
83
83
  });
84
- function traverseGroupContent({ path, model, content, }) {
84
+ function traverseGroupContent({ path, key, apiId, model, content, }) {
85
85
  return (transform) => {
86
- const groupItems = content.value.map((groupItem, index) => {
86
+ var _a;
87
+ const groupItems = traverseGroupItemsContent({
88
+ path,
89
+ model: (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.fields,
90
+ content: content.value,
91
+ })(transform);
92
+ return transform({
93
+ path,
94
+ key,
95
+ apiId,
96
+ model,
97
+ content: {
98
+ __TYPE__: content.__TYPE__,
99
+ value: groupItems,
100
+ },
101
+ });
102
+ };
103
+ }
104
+ exports.traverseGroupContent = traverseGroupContent;
105
+ function traverseGroupItemsContent({ path, model, content, }) {
106
+ return (transform) => {
107
+ return content.map((groupItem, index) => {
108
+ const groupItemPath = path.concat([
109
+ { key: index.toString(), type: "GroupItem" },
110
+ ]);
87
111
  const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
88
- var _a, _b;
89
- const fieldDef = (_b = (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b[fieldKey];
112
+ const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
90
113
  const transformedField = transform({
91
- path: path.concat([
92
- { key: index.toString(), type: "GroupItem" },
93
- { key: fieldKey, type: fieldContent.__TYPE__ },
94
- ]),
114
+ path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
95
115
  key: fieldKey,
96
116
  apiId: fieldKey,
97
117
  model: fieldDef,
98
118
  content: fieldContent,
99
119
  });
100
120
  // Can happen if the transform function returns undefined to filter out a field
101
- if (!transformedField)
121
+ if (!transformedField || !(0, nestable_1.isNestableContent)(transformedField))
102
122
  return acc;
103
123
  return acc.concat([[fieldKey, transformedField]]);
104
124
  }, []);
@@ -107,10 +127,6 @@ function traverseGroupContent({ path, model, content, }) {
107
127
  value: groupItemFields,
108
128
  };
109
129
  });
110
- return {
111
- __TYPE__: content.__TYPE__,
112
- value: groupItems,
113
- };
114
130
  };
115
131
  }
116
- exports.traverseGroupContent = traverseGroupContent;
132
+ exports.traverseGroupItemsContent = traverseGroupItemsContent;
@@ -1,7 +1,8 @@
1
1
  import * as t from "io-ts";
2
- import type { ContentPath, TraverseContentFn } from "../../../../_internal/utils";
3
- import type { CompositeSlice } from "../../../../customtypes";
2
+ import type { ContentPath, TraverseSliceContentFn, TraverseWidgetContentFn } from "../../../../_internal/utils";
3
+ import type { CompositeSliceFields, VariationFields } from "../../../../customtypes";
4
4
  import { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx";
5
+ import type { CompositeSliceItemContent, SharedSliceItemContent } from "../SliceItem";
5
6
  export declare const CompositeSliceContentType = "CompositeSliceContent";
6
7
  export declare const isCompositeSliceContent: (u: unknown) => u is {
7
8
  __TYPE__: "CompositeSliceContent";
@@ -1701,9 +1702,10 @@ export declare const CompositeSliceContent: t.ExactC<t.TypeC<{
1701
1702
  }>>>;
1702
1703
  }>>;
1703
1704
  export declare type CompositeSliceContent = t.TypeOf<typeof CompositeSliceContent>;
1704
- export declare function traverseCompositeSliceContent({ path, sliceName, model, content, }: {
1705
+ export declare function traverseCompositeSliceContent({ path, sliceKey, sliceName, model, content, }: {
1705
1706
  path: ContentPath;
1707
+ sliceKey: string;
1706
1708
  sliceName: string;
1707
- content: CompositeSliceContent;
1708
- model?: CompositeSlice | undefined;
1709
- }): (transform: TraverseContentFn) => CompositeSliceContent | undefined;
1709
+ content: CompositeSliceItemContent;
1710
+ model?: VariationFields | CompositeSliceFields | undefined;
1711
+ }): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SharedSliceItemContent | CompositeSliceItemContent | undefined;
@@ -8,6 +8,7 @@ const function_1 = require("fp-ts/lib/function");
8
8
  const t = (0, tslib_1.__importStar)(require("io-ts"));
9
9
  const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
10
10
  const utils_1 = require("../../../utils");
11
+ const GroupContent_1 = require("../../GroupContent");
11
12
  const nestable_1 = require("../../nestable");
12
13
  const RepeatableContent_1 = require("./RepeatableContent");
13
14
  exports.CompositeSliceContentType = "CompositeSliceContent";
@@ -79,15 +80,19 @@ exports.CompositeSliceContent = t.strict({
79
80
  nonRepeat: t.record(t.string, nestable_1.NestableContent),
80
81
  repeat: RepeatableContent_1.RepeatableWidgets,
81
82
  });
82
- function traverseCompositeSliceContent({ path, sliceName, model, content, }) {
83
- return (transform) => {
84
- const primary = Object.entries(content.nonRepeat).reduce((acc, [fieldKey, fieldContent]) => {
85
- var _a;
86
- const fieldDef = (_a = model === null || model === void 0 ? void 0 : model["non-repeat"]) === null || _a === void 0 ? void 0 : _a[fieldKey];
87
- const transformedField = transform({
83
+ function traverseCompositeSliceContent({ path, sliceKey, sliceName, model, content, }) {
84
+ return (transformWidget, transformSlice) => {
85
+ const primary = Object.entries(content.widget.nonRepeat).reduce((acc, [fieldKey, fieldContent]) => {
86
+ const fieldDef = (() => {
87
+ var _a, _b, _c, _d;
88
+ return (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice"
89
+ ? (_b = (_a = model === null || model === void 0 ? void 0 : model.fields) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b[fieldKey]
90
+ : (_d = (_c = model === null || model === void 0 ? void 0 : model.fields) === null || _c === void 0 ? void 0 : _c.repeat) === null || _d === void 0 ? void 0 : _d[fieldKey];
91
+ })();
92
+ const transformedField = transformWidget({
88
93
  path: path.concat([
89
94
  { key: "non-repeat", type: "primary" },
90
- { key: fieldKey, type: fieldContent.__TYPE__ },
95
+ { key: fieldKey, type: "Widget" },
91
96
  ]),
92
97
  key: fieldKey,
93
98
  apiId: sliceName,
@@ -95,42 +100,34 @@ function traverseCompositeSliceContent({ path, sliceName, model, content, }) {
95
100
  content: fieldContent,
96
101
  });
97
102
  // Can happen if the transform function returns undefined to filter out a field
98
- if (!transformedField)
103
+ if (!transformedField || !(0, nestable_1.isNestableContent)(transformedField))
99
104
  return acc;
100
105
  return {
101
106
  ...acc,
102
107
  [fieldKey]: transformedField,
103
108
  };
104
109
  }, {});
105
- const items = content.repeat.map((itemBlock) => {
106
- const itemBlockFields = itemBlock.value.reduce((acc, [fieldKey, fieldContent]) => {
107
- var _a;
108
- const fieldDef = (_a = model === null || model === void 0 ? void 0 : model.repeat) === null || _a === void 0 ? void 0 : _a[fieldKey];
109
- const transformedField = transform({
110
- path: path.concat([
111
- { key: "repeat", type: "items" },
112
- { key: fieldKey, type: fieldContent.__TYPE__ },
113
- ]),
114
- key: fieldKey,
115
- apiId: sliceName,
116
- model: fieldDef,
117
- content: fieldContent,
118
- });
119
- // Can happen if the transform function returns undefined to filter out a field
120
- if (!transformedField)
121
- return acc;
122
- return acc.concat([[fieldKey, transformedField]]);
123
- }, []);
124
- return {
125
- __TYPE__: itemBlock.__TYPE__,
126
- value: itemBlockFields,
127
- };
110
+ const items = (0, GroupContent_1.traverseGroupItemsContent)({
111
+ path: path.concat([{ key: "repeat", type: "items" }]),
112
+ model: (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice"
113
+ ? model === null || model === void 0 ? void 0 : model.fields.items
114
+ : model === null || model === void 0 ? void 0 : model.fields.repeat,
115
+ content: content.widget.repeat,
116
+ })(transformWidget);
117
+ return transformSlice({
118
+ key: sliceKey,
119
+ apiId: sliceName,
120
+ path,
121
+ model,
122
+ content: {
123
+ ...content,
124
+ widget: {
125
+ __TYPE__: "CompositeSliceContent",
126
+ repeat: items,
127
+ nonRepeat: primary,
128
+ },
129
+ },
128
130
  });
129
- return {
130
- __TYPE__: content.__TYPE__,
131
- repeat: items,
132
- nonRepeat: primary,
133
- };
134
131
  };
135
132
  }
136
133
  exports.traverseCompositeSliceContent = traverseCompositeSliceContent;
@@ -1,7 +1,8 @@
1
1
  import * as t from "io-ts";
2
- import type { ContentPath, TraverseContentFn } from "../../../../_internal/utils";
3
- import type { SharedSlice } from "../../../../customtypes";
2
+ import type { ContentPath, TraverseSliceContentFn, TraverseWidgetContentFn } from "../../../../_internal/utils";
3
+ import type { VariationFields } from "../../../../customtypes";
4
4
  import { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx";
5
+ import type { SharedSliceItemContent } from "../SliceItem";
5
6
  export declare const SharedSliceContentType = "SharedSliceContent";
6
7
  export declare const isSharedSliceContent: (u: unknown) => u is {
7
8
  __TYPE__: "SharedSliceContent";
@@ -1705,9 +1706,10 @@ export declare const SharedSliceContent: t.ExactC<t.TypeC<{
1705
1706
  }>>>;
1706
1707
  }>>;
1707
1708
  export declare type SharedSliceContent = t.TypeOf<typeof SharedSliceContent>;
1708
- export declare function traverseSharedSliceContent({ path, sliceName, model, content, }: {
1709
+ export declare function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content, }: {
1709
1710
  path: ContentPath;
1711
+ sliceKey: string;
1710
1712
  sliceName: string;
1711
- content: SharedSliceContent;
1712
- model?: SharedSlice | undefined;
1713
- }): (transform: TraverseContentFn) => SharedSliceContent | undefined;
1713
+ content: SharedSliceItemContent;
1714
+ model?: VariationFields | undefined;
1715
+ }): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SharedSliceItemContent | undefined;
@@ -9,6 +9,7 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
9
9
  const io_ts_types_1 = require("io-ts-types");
10
10
  const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
11
11
  const utils_1 = require("../../../utils");
12
+ const GroupContent_1 = require("../../GroupContent");
12
13
  const nestable_1 = require("../../nestable");
13
14
  const RepeatableContent_1 = require("./RepeatableContent");
14
15
  exports.SharedSliceContentType = "SharedSliceContent";
@@ -96,16 +97,15 @@ exports.SharedSliceContent = t.strict({
96
97
  primary: t.record(t.string, nestable_1.NestableContent),
97
98
  items: RepeatableContent_1.RepeatableWidgets,
98
99
  });
99
- function traverseSharedSliceContent({ path, sliceName, model, content, }) {
100
- return (transform) => {
101
- const variationDef = model === null || model === void 0 ? void 0 : model.variations.find((v) => v.id === content.variation);
102
- const primary = Object.entries(content.primary).reduce((acc, [fieldKey, fieldContent]) => {
103
- var _a;
104
- const fieldDef = variationDef && ((_a = variationDef.primary) === null || _a === void 0 ? void 0 : _a[fieldKey]);
105
- const transformedField = transform({
100
+ function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content, }) {
101
+ return (transformWidget, transformSlice) => {
102
+ const primary = Object.entries(content.widget.primary).reduce((acc, [fieldKey, fieldContent]) => {
103
+ var _a, _b;
104
+ const fieldDef = (_b = (_a = model === null || model === void 0 ? void 0 : model.fields) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b[fieldKey];
105
+ const transformedField = transformWidget({
106
106
  path: path.concat([
107
107
  { key: "primary", type: "primary" },
108
- { key: fieldKey, type: fieldContent.__TYPE__ },
108
+ { key: fieldKey, type: "Widget" },
109
109
  ]),
110
110
  key: fieldKey,
111
111
  apiId: sliceName,
@@ -113,43 +113,33 @@ function traverseSharedSliceContent({ path, sliceName, model, content, }) {
113
113
  content: fieldContent,
114
114
  });
115
115
  // Can happen if the transform function returns undefined to filter out a field
116
- if (!transformedField)
116
+ if (!transformedField || !(0, nestable_1.isNestableContent)(transformedField))
117
117
  return acc;
118
118
  return {
119
119
  ...acc,
120
120
  [fieldKey]: transformedField,
121
121
  };
122
122
  }, {});
123
- const items = content.items.map((itemBlock) => {
124
- const itemBlockFields = itemBlock.value.reduce((acc, [fieldKey, fieldContent]) => {
125
- var _a;
126
- const fieldDef = variationDef && ((_a = variationDef.items) === null || _a === void 0 ? void 0 : _a[fieldKey]);
127
- const transformedField = transform({
128
- path: path.concat([
129
- { key: "items", type: "items" },
130
- { key: fieldKey, type: fieldContent.__TYPE__ },
131
- ]),
132
- key: fieldKey,
133
- apiId: sliceName,
134
- model: fieldDef,
135
- content: fieldContent,
136
- });
137
- // Can happen if the transform function returns undefined to filter out a field
138
- if (!transformedField)
139
- return acc;
140
- return acc.concat([[fieldKey, transformedField]]);
141
- }, []);
142
- return {
143
- __TYPE__: itemBlock.__TYPE__,
144
- value: itemBlockFields,
145
- };
123
+ const items = (0, GroupContent_1.traverseGroupItemsContent)({
124
+ path: path.concat([{ key: "items", type: "items" }]),
125
+ model: model === null || model === void 0 ? void 0 : model.fields.items,
126
+ content: content.widget.items,
127
+ })(transformWidget);
128
+ return transformSlice({
129
+ key: sliceKey,
130
+ apiId: sliceName,
131
+ path,
132
+ model: model,
133
+ content: {
134
+ ...content,
135
+ widget: {
136
+ __TYPE__: "SharedSliceContent",
137
+ variation: content.widget.variation,
138
+ primary,
139
+ items,
140
+ },
141
+ },
146
142
  });
147
- return {
148
- __TYPE__: content.__TYPE__,
149
- variation: content.variation,
150
- primary,
151
- items,
152
- };
153
143
  };
154
144
  }
155
145
  exports.traverseSharedSliceContent = traverseSharedSliceContent;
@@ -1,5 +1,8 @@
1
1
  import * as t from "io-ts";
2
+ import type { ContentPath, TraverseSliceContentFn, TraverseWidgetContentFn } from "../../../../_internal/utils";
3
+ import type { Group, NestableWidget, VariationFields } from "../../../../customtypes";
2
4
  import type { LegacyContentCtx } from "../../../LegacyContentCtx";
5
+ import type { SharedSliceItemContent, SimpleSliceItemContent } from "../SliceItem";
3
6
  export declare const SimpleSliceContent: t.UnionC<[t.UnionC<[t.ExactC<t.TypeC<{
4
7
  type: t.StringC;
5
8
  __TYPE__: t.LiteralC<"EmptyContent">;
@@ -1689,3 +1692,10 @@ export declare const SimpleSliceLegacy: (ctx: LegacyContentCtx) => {
1689
1692
  }>);
1690
1693
  encode: (value: SimpleSliceContent) => import("../../../LegacyContentCtx").WithTypes<unknown> | undefined;
1691
1694
  };
1695
+ export declare function traverseSimpleSliceContent({ path, sliceKey, sliceName, model, content, }: {
1696
+ path: ContentPath;
1697
+ sliceKey: string;
1698
+ sliceName: string;
1699
+ content: SimpleSliceItemContent;
1700
+ model?: VariationFields | Group | NestableWidget | undefined;
1701
+ }): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SharedSliceItemContent | SimpleSliceItemContent | undefined;