@prismicio/types-internal 2.2.0-traverse.alpha-1 → 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.
- package/lib/_internal/utils.d.ts +21 -4
- package/lib/_internal/utils.js +11 -0
- package/lib/content/Document.d.ts +2185 -13
- package/lib/content/Document.js +130 -35
- package/lib/content/fields/GroupContent.d.ts +6 -4
- package/lib/content/fields/GroupContent.js +13 -9
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +8 -6
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +31 -16
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -6
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +26 -18
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +10 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +60 -1
- package/lib/content/fields/slices/SliceItem.d.ts +15 -0
- package/lib/content/fields/slices/SliceItem.js +15 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +4 -3
- package/lib/content/fields/slices/SlicesContent.js +125 -60
- package/lib/customtypes/CustomType.d.ts +4 -0
- package/lib/customtypes/CustomType.js +18 -1
- package/lib/customtypes/Section.d.ts +3 -0
- package/lib/customtypes/diff/SharedSlice.d.ts +6 -0
- package/lib/customtypes/widgets/Widget.d.ts +3 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +5 -0
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +8 -0
- package/lib/customtypes/widgets/slices/SharedSlice.js +3 -0
- package/lib/customtypes/widgets/slices/Slices.d.ts +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +3 -0
- package/package.json +1 -1
- package/src/_internal/utils.ts +63 -7
- package/src/content/Document.ts +177 -42
- package/src/content/fields/GroupContent.ts +25 -12
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +54 -21
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +42 -26
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +99 -1
- package/src/content/fields/slices/SliceItem.ts +39 -3
- package/src/content/fields/slices/SlicesContent.ts +172 -67
- package/src/customtypes/CustomType.ts +21 -0
- package/src/customtypes/widgets/slices/CompositeSlice.ts +6 -0
- package/src/customtypes/widgets/slices/SharedSlice.ts +12 -0
package/lib/content/Document.js
CHANGED
|
@@ -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 (
|
|
105
|
-
const
|
|
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
|
|
109
|
-
const path = [
|
|
110
|
-
|
|
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
|
-
|
|
116
|
-
|
|
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
|
-
})(
|
|
123
|
+
})(transformWidget, transformSlice);
|
|
120
124
|
case "GroupContentType":
|
|
121
125
|
return (0, fields_1.traverseGroupContent)({
|
|
122
126
|
path,
|
|
123
|
-
|
|
127
|
+
key,
|
|
128
|
+
apiId: key,
|
|
129
|
+
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Group" ? fieldModel : undefined,
|
|
124
130
|
content,
|
|
125
|
-
})(
|
|
131
|
+
})(transformWidget);
|
|
126
132
|
default:
|
|
127
|
-
return
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
import type { ContentPath,
|
|
2
|
+
import type { ContentPath, TraverseWidgetContentFn } from "../../_internal/utils";
|
|
3
3
|
import type { Group, NestableWidget } from "../../customtypes";
|
|
4
4
|
import { LegacyContentCtx, WithTypes } from "../LegacyContentCtx";
|
|
5
5
|
export declare const GroupItemContentType: "GroupItemContent";
|
|
@@ -1438,14 +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:
|
|
1447
|
+
}): (transform: TraverseWidgetContentFn) => GroupContent | undefined;
|
|
1446
1448
|
export declare function traverseGroupItemsContent({ path, model, content, }: {
|
|
1447
1449
|
path: ContentPath;
|
|
1448
1450
|
content: Array<GroupItemContent>;
|
|
1449
1451
|
model?: Record<string, NestableWidget> | undefined;
|
|
1450
|
-
}): (transform:
|
|
1452
|
+
}): (transform: TraverseWidgetContentFn) => Array<GroupItemContent>;
|
|
1451
1453
|
export {};
|
|
@@ -81,7 +81,7 @@ 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
86
|
var _a;
|
|
87
87
|
const groupItems = traverseGroupItemsContent({
|
|
@@ -89,10 +89,16 @@ function traverseGroupContent({ path, model, content, }) {
|
|
|
89
89
|
model: (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.fields,
|
|
90
90
|
content: content.value,
|
|
91
91
|
})(transform);
|
|
92
|
-
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
return transform({
|
|
93
|
+
path,
|
|
94
|
+
key,
|
|
95
|
+
apiId,
|
|
96
|
+
model,
|
|
97
|
+
content: {
|
|
98
|
+
__TYPE__: content.__TYPE__,
|
|
99
|
+
value: groupItems,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
96
102
|
};
|
|
97
103
|
}
|
|
98
104
|
exports.traverseGroupContent = traverseGroupContent;
|
|
@@ -105,16 +111,14 @@ function traverseGroupItemsContent({ path, model, content, }) {
|
|
|
105
111
|
const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
106
112
|
const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
|
|
107
113
|
const transformedField = transform({
|
|
108
|
-
path: groupItemPath.concat([
|
|
109
|
-
{ key: fieldKey, type: fieldContent.__TYPE__ },
|
|
110
|
-
]),
|
|
114
|
+
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
|
|
111
115
|
key: fieldKey,
|
|
112
116
|
apiId: fieldKey,
|
|
113
117
|
model: fieldDef,
|
|
114
118
|
content: fieldContent,
|
|
115
119
|
});
|
|
116
120
|
// Can happen if the transform function returns undefined to filter out a field
|
|
117
|
-
if (!transformedField)
|
|
121
|
+
if (!transformedField || !(0, nestable_1.isNestableContent)(transformedField))
|
|
118
122
|
return acc;
|
|
119
123
|
return acc.concat([[fieldKey, transformedField]]);
|
|
120
124
|
}, []);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
import type { ContentPath,
|
|
3
|
-
import type {
|
|
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:
|
|
1708
|
-
model?:
|
|
1709
|
-
}): (
|
|
1709
|
+
content: CompositeSliceItemContent;
|
|
1710
|
+
model?: VariationFields | CompositeSliceFields | undefined;
|
|
1711
|
+
}): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SharedSliceItemContent | CompositeSliceItemContent | undefined;
|
|
@@ -80,15 +80,19 @@ exports.CompositeSliceContent = t.strict({
|
|
|
80
80
|
nonRepeat: t.record(t.string, nestable_1.NestableContent),
|
|
81
81
|
repeat: RepeatableContent_1.RepeatableWidgets,
|
|
82
82
|
});
|
|
83
|
-
function traverseCompositeSliceContent({ path, sliceName, model, content, }) {
|
|
84
|
-
return (
|
|
85
|
-
const primary = Object.entries(content.nonRepeat).reduce((acc, [fieldKey, fieldContent]) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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({
|
|
89
93
|
path: path.concat([
|
|
90
94
|
{ key: "non-repeat", type: "primary" },
|
|
91
|
-
{ key: fieldKey, type:
|
|
95
|
+
{ key: fieldKey, type: "Widget" },
|
|
92
96
|
]),
|
|
93
97
|
key: fieldKey,
|
|
94
98
|
apiId: sliceName,
|
|
@@ -96,7 +100,7 @@ function traverseCompositeSliceContent({ path, sliceName, model, content, }) {
|
|
|
96
100
|
content: fieldContent,
|
|
97
101
|
});
|
|
98
102
|
// Can happen if the transform function returns undefined to filter out a field
|
|
99
|
-
if (!transformedField)
|
|
103
|
+
if (!transformedField || !(0, nestable_1.isNestableContent)(transformedField))
|
|
100
104
|
return acc;
|
|
101
105
|
return {
|
|
102
106
|
...acc,
|
|
@@ -105,14 +109,25 @@ function traverseCompositeSliceContent({ path, sliceName, model, content, }) {
|
|
|
105
109
|
}, {});
|
|
106
110
|
const items = (0, GroupContent_1.traverseGroupItemsContent)({
|
|
107
111
|
path: path.concat([{ key: "repeat", type: "items" }]),
|
|
108
|
-
model: model === null || model === void 0 ? void 0 : model.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
},
|
|
130
|
+
});
|
|
116
131
|
};
|
|
117
132
|
}
|
|
118
133
|
exports.traverseCompositeSliceContent = traverseCompositeSliceContent;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
import type { ContentPath,
|
|
3
|
-
import type {
|
|
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:
|
|
1712
|
-
model?:
|
|
1713
|
-
}): (
|
|
1713
|
+
content: SharedSliceItemContent;
|
|
1714
|
+
model?: VariationFields | undefined;
|
|
1715
|
+
}): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SharedSliceItemContent | undefined;
|
|
@@ -97,16 +97,15 @@ exports.SharedSliceContent = t.strict({
|
|
|
97
97
|
primary: t.record(t.string, nestable_1.NestableContent),
|
|
98
98
|
items: RepeatableContent_1.RepeatableWidgets,
|
|
99
99
|
});
|
|
100
|
-
function traverseSharedSliceContent({ path, sliceName, model, content, }) {
|
|
101
|
-
return (
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
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({
|
|
107
106
|
path: path.concat([
|
|
108
107
|
{ key: "primary", type: "primary" },
|
|
109
|
-
{ key: fieldKey, type:
|
|
108
|
+
{ key: fieldKey, type: "Widget" },
|
|
110
109
|
]),
|
|
111
110
|
key: fieldKey,
|
|
112
111
|
apiId: sliceName,
|
|
@@ -114,7 +113,7 @@ function traverseSharedSliceContent({ path, sliceName, model, content, }) {
|
|
|
114
113
|
content: fieldContent,
|
|
115
114
|
});
|
|
116
115
|
// Can happen if the transform function returns undefined to filter out a field
|
|
117
|
-
if (!transformedField)
|
|
116
|
+
if (!transformedField || !(0, nestable_1.isNestableContent)(transformedField))
|
|
118
117
|
return acc;
|
|
119
118
|
return {
|
|
120
119
|
...acc,
|
|
@@ -123,15 +122,24 @@ function traverseSharedSliceContent({ path, sliceName, model, content, }) {
|
|
|
123
122
|
}, {});
|
|
124
123
|
const items = (0, GroupContent_1.traverseGroupItemsContent)({
|
|
125
124
|
path: path.concat([{ key: "items", type: "items" }]),
|
|
126
|
-
model:
|
|
127
|
-
content: content.items,
|
|
128
|
-
})(
|
|
129
|
-
return {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
},
|
|
142
|
+
});
|
|
135
143
|
};
|
|
136
144
|
}
|
|
137
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleSliceLegacy = exports.isSimpleSliceContent = exports.SimpleSliceContent = void 0;
|
|
3
|
+
exports.traverseSimpleSliceContent = exports.SimpleSliceLegacy = exports.isSimpleSliceContent = exports.SimpleSliceContent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const GroupContent_1 = require("../../GroupContent");
|
|
@@ -26,3 +26,62 @@ const SimpleSliceLegacy = (ctx) => {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
exports.SimpleSliceLegacy = SimpleSliceLegacy;
|
|
29
|
+
function traverseSimpleSliceContent({ path, sliceKey, sliceName, model, content, }) {
|
|
30
|
+
return (transformWidget, transformSlice) => {
|
|
31
|
+
if ((0, GroupContent_1.isGroupContent)(content.widget)) {
|
|
32
|
+
const convertedGroupWidget = (0, GroupContent_1.traverseGroupContent)({
|
|
33
|
+
path,
|
|
34
|
+
key: content.key,
|
|
35
|
+
apiId: content.name,
|
|
36
|
+
model: (() => {
|
|
37
|
+
if ((model === null || model === void 0 ? void 0 : model.type) === "Group")
|
|
38
|
+
return model;
|
|
39
|
+
if ((model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
|
|
40
|
+
return {
|
|
41
|
+
type: "Group",
|
|
42
|
+
config: { fields: model.fields.items || {} },
|
|
43
|
+
};
|
|
44
|
+
return;
|
|
45
|
+
})(),
|
|
46
|
+
content: content.widget,
|
|
47
|
+
})(transformWidget);
|
|
48
|
+
return (convertedGroupWidget &&
|
|
49
|
+
transformSlice({
|
|
50
|
+
key: content.key,
|
|
51
|
+
apiId: content.name,
|
|
52
|
+
path,
|
|
53
|
+
model,
|
|
54
|
+
content: {
|
|
55
|
+
...content,
|
|
56
|
+
widget: convertedGroupWidget,
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
const convertedNestable = transformWidget({
|
|
61
|
+
key: content.key,
|
|
62
|
+
apiId: content.name,
|
|
63
|
+
path,
|
|
64
|
+
model: (() => {
|
|
65
|
+
var _a;
|
|
66
|
+
if ((model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
|
|
67
|
+
return (_a = model.fields.primary) === null || _a === void 0 ? void 0 : _a[content.name];
|
|
68
|
+
if ((model === null || model === void 0 ? void 0 : model.type) !== "Group")
|
|
69
|
+
return model;
|
|
70
|
+
return;
|
|
71
|
+
})(),
|
|
72
|
+
content: content.widget,
|
|
73
|
+
});
|
|
74
|
+
return (convertedNestable &&
|
|
75
|
+
transformSlice({
|
|
76
|
+
key: sliceKey,
|
|
77
|
+
apiId: sliceName,
|
|
78
|
+
path,
|
|
79
|
+
model,
|
|
80
|
+
content: {
|
|
81
|
+
...content,
|
|
82
|
+
widget: convertedNestable,
|
|
83
|
+
},
|
|
84
|
+
}));
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.traverseSimpleSliceContent = traverseSimpleSliceContent;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
|
|
3
|
+
import { CompositeSliceContent } from "./Slice/CompositeSliceContent";
|
|
4
|
+
import { SharedSliceContent } from "./Slice/SharedSliceContent";
|
|
5
|
+
import { SimpleSliceContent } from "./Slice/SimpleSliceContent";
|
|
3
6
|
export declare const SliceItemContent: t.TypeC<{
|
|
4
7
|
key: t.StringC;
|
|
5
8
|
name: t.StringC;
|
|
@@ -1828,6 +1831,18 @@ export declare const SliceItemContent: t.TypeC<{
|
|
|
1828
1831
|
}>>]>]>;
|
|
1829
1832
|
}>;
|
|
1830
1833
|
export declare type SliceItemContent = t.TypeOf<typeof SliceItemContent>;
|
|
1834
|
+
export declare type SharedSliceItemContent = Omit<SliceItemContent, "widget"> & {
|
|
1835
|
+
widget: SharedSliceContent;
|
|
1836
|
+
};
|
|
1837
|
+
export declare function isSharedSliceItemContent(item: SliceItemContent): item is SharedSliceItemContent;
|
|
1838
|
+
export declare type CompositeSliceItemContent = Omit<SliceItemContent, "widget"> & {
|
|
1839
|
+
widget: CompositeSliceContent;
|
|
1840
|
+
};
|
|
1841
|
+
export declare function isCompositeSliceItemContent(item: SliceItemContent): item is CompositeSliceItemContent;
|
|
1842
|
+
export declare type SimpleSliceItemContent = Omit<SliceItemContent, "widget"> & {
|
|
1843
|
+
widget: SimpleSliceContent;
|
|
1844
|
+
};
|
|
1845
|
+
export declare function isSimpleSliceItemContent(item: SliceItemContent): item is SimpleSliceItemContent;
|
|
1831
1846
|
export declare const SlicesItemLegacy: (ctx: LegacyContentCtx) => t.Type<{
|
|
1832
1847
|
key: string;
|
|
1833
1848
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SlicesItemLegacy = exports.SliceItemContent = void 0;
|
|
3
|
+
exports.SlicesItemLegacy = exports.isSimpleSliceItemContent = exports.isCompositeSliceItemContent = exports.isSharedSliceItemContent = exports.SliceItemContent = 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");
|
|
@@ -8,6 +8,8 @@ const function_1 = require("fp-ts/lib/function");
|
|
|
8
8
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
9
9
|
const function_2 = require("../../../validators/function");
|
|
10
10
|
const LegacyContentCtx_1 = require("../../LegacyContentCtx");
|
|
11
|
+
const GroupContent_1 = require("../GroupContent");
|
|
12
|
+
const nestable_1 = require("../nestable");
|
|
11
13
|
const Slice_1 = require("./Slice");
|
|
12
14
|
const CompositeSliceContent_1 = require("./Slice/CompositeSliceContent");
|
|
13
15
|
const SharedSliceContent_1 = require("./Slice/SharedSliceContent");
|
|
@@ -18,6 +20,18 @@ exports.SliceItemContent = t.type({
|
|
|
18
20
|
maybeLabel: t.union([t.string, t.undefined]),
|
|
19
21
|
widget: Slice_1.SliceContent,
|
|
20
22
|
});
|
|
23
|
+
function isSharedSliceItemContent(item) {
|
|
24
|
+
return (0, SharedSliceContent_1.isSharedSliceContent)(item.widget);
|
|
25
|
+
}
|
|
26
|
+
exports.isSharedSliceItemContent = isSharedSliceItemContent;
|
|
27
|
+
function isCompositeSliceItemContent(item) {
|
|
28
|
+
return (0, CompositeSliceContent_1.isCompositeSliceContent)(item.widget);
|
|
29
|
+
}
|
|
30
|
+
exports.isCompositeSliceItemContent = isCompositeSliceItemContent;
|
|
31
|
+
function isSimpleSliceItemContent(item) {
|
|
32
|
+
return (0, GroupContent_1.isGroupContent)(item.widget) || (0, nestable_1.isNestableContent)(item.widget);
|
|
33
|
+
}
|
|
34
|
+
exports.isSimpleSliceItemContent = isSimpleSliceItemContent;
|
|
21
35
|
const itemLegacyReader = t.exact(t.intersection([
|
|
22
36
|
t.type({
|
|
23
37
|
key: t.string,
|