@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
import
|
|
2
|
+
import { ContentPath, TraverseSliceContentFn, TraverseWidgetContentFn } from "../../../_internal/utils";
|
|
3
3
|
import { type StaticSlices } from "../../../customtypes";
|
|
4
4
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
|
|
5
5
|
export declare const SlicesContentType = "SliceContentType";
|
|
@@ -5095,9 +5095,10 @@ export declare const SlicesContent: t.TypeC<{
|
|
|
5095
5095
|
}>>;
|
|
5096
5096
|
}>;
|
|
5097
5097
|
export declare type SlicesContent = t.TypeOf<typeof SlicesContent>;
|
|
5098
|
-
export declare function traverseSlices({ path, model, content, }: {
|
|
5098
|
+
export declare function traverseSlices({ path, key, model, content, }: {
|
|
5099
5099
|
path: ContentPath;
|
|
5100
|
+
key: string;
|
|
5100
5101
|
content: SlicesContent;
|
|
5101
5102
|
model?: StaticSlices | undefined;
|
|
5102
|
-
}): (
|
|
5103
|
+
}): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SlicesContent | undefined;
|
|
5103
5104
|
export {};
|
|
@@ -5,14 +5,15 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
7
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const utils_1 = require("../../../_internal/utils");
|
|
8
9
|
const customtypes_1 = require("../../../customtypes");
|
|
9
|
-
const
|
|
10
|
-
const GroupContent_1 = require("../GroupContent");
|
|
10
|
+
const utils_2 = require("../../utils");
|
|
11
11
|
const CompositeSliceContent_1 = require("./Slice/CompositeSliceContent");
|
|
12
12
|
const SharedSliceContent_1 = require("./Slice/SharedSliceContent");
|
|
13
|
+
const SimpleSliceContent_1 = require("./Slice/SimpleSliceContent");
|
|
13
14
|
const SliceItem_1 = require("./SliceItem");
|
|
14
15
|
exports.SlicesContentType = "SliceContentType";
|
|
15
|
-
const isSlicesContent = (u) => (0,
|
|
16
|
+
const isSlicesContent = (u) => (0, utils_2.hasContentType)(u) && u.__TYPE__ === exports.SlicesContentType;
|
|
16
17
|
exports.isSlicesContent = isSlicesContent;
|
|
17
18
|
const SlicesLegacy = (ctx) => {
|
|
18
19
|
const codec = t.array((0, SliceItem_1.SlicesItemLegacy)(ctx));
|
|
@@ -36,66 +37,130 @@ exports.SlicesContent = t.type({
|
|
|
36
37
|
__TYPE__: t.literal(exports.SlicesContentType),
|
|
37
38
|
value: t.array(SliceItem_1.SliceItemContent),
|
|
38
39
|
});
|
|
39
|
-
function
|
|
40
|
-
|
|
40
|
+
function findSliceModel(slicesPath, model, content) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const defaultModel = (_b = (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.choices) === null || _b === void 0 ? void 0 : _b[content.name];
|
|
43
|
+
// regular case for shared slices
|
|
44
|
+
const sharedSliceModel = () => {
|
|
45
|
+
if ((0, SliceItem_1.isSharedSliceItemContent)(content)) {
|
|
46
|
+
if (defaultModel && (0, customtypes_1.isStaticSharedSlice)(defaultModel)) {
|
|
47
|
+
const variationDef = defaultModel.variations.find((v) => v.id === content.widget.variation);
|
|
48
|
+
return variationDef
|
|
49
|
+
? {
|
|
50
|
+
type: "SharedSlice",
|
|
51
|
+
sliceName: defaultModel.id,
|
|
52
|
+
variationId: variationDef.id,
|
|
53
|
+
fields: {
|
|
54
|
+
primary: variationDef.primary || {},
|
|
55
|
+
items: variationDef.items || {},
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
: undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
};
|
|
63
|
+
const migratedSliceModel = () => {
|
|
64
|
+
var _a;
|
|
65
|
+
const legacyContentPath = utils_1.ContentPath.append(utils_1.ContentPath.serialize(slicesPath), content.name);
|
|
66
|
+
const migratedSliceModel = Object.values(((_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.choices) || {}).find((sliceModel) => {
|
|
67
|
+
var _a;
|
|
68
|
+
if ((0, customtypes_1.isStaticSharedSlice)(sliceModel)) {
|
|
69
|
+
return !!((_a = sliceModel.legacyPaths) === null || _a === void 0 ? void 0 : _a[legacyContentPath]);
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
});
|
|
73
|
+
if (!migratedSliceModel)
|
|
74
|
+
return;
|
|
75
|
+
const migratedVariation = migratedSliceModel === null || migratedSliceModel === void 0 ? void 0 : migratedSliceModel.variations.find((v) => { var _a; return v.id === ((_a = migratedSliceModel.legacyPaths) === null || _a === void 0 ? void 0 : _a[legacyContentPath]); });
|
|
76
|
+
if (!migratedVariation)
|
|
77
|
+
return;
|
|
78
|
+
return {
|
|
79
|
+
type: "SharedSlice",
|
|
80
|
+
sliceName: migratedSliceModel.id,
|
|
81
|
+
variationId: migratedVariation.id,
|
|
82
|
+
fields: {
|
|
83
|
+
primary: migratedVariation.primary || {},
|
|
84
|
+
items: migratedVariation.items || {},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const legacySliceModel = () => {
|
|
89
|
+
if (!defaultModel)
|
|
90
|
+
return;
|
|
91
|
+
if ((0, customtypes_1.isCompositeSlice)(defaultModel)) {
|
|
92
|
+
return {
|
|
93
|
+
type: "Slice",
|
|
94
|
+
fields: {
|
|
95
|
+
"non-repeat": defaultModel["non-repeat"] || {},
|
|
96
|
+
repeat: defaultModel.repeat || {},
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if ((0, customtypes_1.isLegacySlice)(defaultModel)) {
|
|
101
|
+
return defaultModel;
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
};
|
|
105
|
+
return sharedSliceModel() || migratedSliceModel() || legacySliceModel();
|
|
106
|
+
}
|
|
107
|
+
function traverseSlices({ path, key, model, content, }) {
|
|
108
|
+
return (transformWidget, transformSlice) => {
|
|
41
109
|
const value = content.value.reduce((acc, sliceContent) => {
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
110
|
+
const sliceModel = model && findSliceModel(path, model, sliceContent);
|
|
111
|
+
const convertedSlice = (() => {
|
|
112
|
+
if ((0, SliceItem_1.isSharedSliceItemContent)(sliceContent))
|
|
113
|
+
return (0, SharedSliceContent_1.traverseSharedSliceContent)({
|
|
114
|
+
path: path.concat({
|
|
115
|
+
key: sliceContent.key,
|
|
116
|
+
type: "SharedSlice",
|
|
117
|
+
}),
|
|
118
|
+
sliceKey: sliceContent.key,
|
|
119
|
+
sliceName: sliceContent.name,
|
|
120
|
+
model: (sliceModel === null || sliceModel === void 0 ? void 0 : sliceModel.type) === "SharedSlice" ? sliceModel : undefined,
|
|
121
|
+
content: sliceContent,
|
|
122
|
+
})(transformWidget, transformSlice);
|
|
123
|
+
if ((0, SliceItem_1.isCompositeSliceItemContent)(sliceContent))
|
|
124
|
+
return (0, CompositeSliceContent_1.traverseCompositeSliceContent)({
|
|
125
|
+
path: path.concat({
|
|
126
|
+
key: sliceContent.key,
|
|
127
|
+
type: "Slice",
|
|
128
|
+
}),
|
|
129
|
+
sliceKey: sliceContent.key,
|
|
130
|
+
sliceName: sliceContent.name,
|
|
131
|
+
model: (sliceModel === null || sliceModel === void 0 ? void 0 : sliceModel.type) === "Slice" ||
|
|
132
|
+
(sliceModel === null || sliceModel === void 0 ? void 0 : sliceModel.type) === "SharedSlice"
|
|
133
|
+
? sliceModel
|
|
134
|
+
: undefined,
|
|
135
|
+
content: sliceContent,
|
|
136
|
+
})(transformWidget, transformSlice);
|
|
137
|
+
if ((0, SliceItem_1.isSimpleSliceItemContent)(sliceContent))
|
|
138
|
+
return (0, SimpleSliceContent_1.traverseSimpleSliceContent)({
|
|
139
|
+
path: path.concat({
|
|
140
|
+
key: sliceContent.key,
|
|
141
|
+
type: "LegacySlice",
|
|
142
|
+
}),
|
|
143
|
+
sliceKey: sliceContent.key,
|
|
144
|
+
sliceName: sliceContent.name,
|
|
145
|
+
model: sliceModel && (sliceModel === null || sliceModel === void 0 ? void 0 : sliceModel.type) !== "Slice"
|
|
146
|
+
? sliceModel
|
|
147
|
+
: undefined,
|
|
148
|
+
content: sliceContent,
|
|
149
|
+
})(transformWidget, transformSlice);
|
|
150
|
+
return;
|
|
81
151
|
})();
|
|
82
|
-
|
|
83
|
-
key: sliceContent.key,
|
|
84
|
-
apiId: sliceContent.name,
|
|
85
|
-
path: slicePath,
|
|
86
|
-
model: sliceModel,
|
|
87
|
-
content: convertedSliceWidget,
|
|
88
|
-
});
|
|
89
|
-
const convertedSliceParent = convertedSlice && {
|
|
90
|
-
...sliceContent,
|
|
91
|
-
widget: convertedSlice,
|
|
92
|
-
};
|
|
93
|
-
return convertedSliceParent ? acc.concat(convertedSliceParent) : acc;
|
|
152
|
+
return convertedSlice ? acc.concat(convertedSlice) : acc;
|
|
94
153
|
}, []);
|
|
95
|
-
return {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
154
|
+
return transformWidget({
|
|
155
|
+
path,
|
|
156
|
+
key,
|
|
157
|
+
apiId: key,
|
|
158
|
+
model,
|
|
159
|
+
content: {
|
|
160
|
+
__TYPE__: content.__TYPE__,
|
|
161
|
+
value,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
99
164
|
};
|
|
100
165
|
}
|
|
101
166
|
exports.traverseSlices = traverseSlices;
|
|
@@ -1344,6 +1344,9 @@ export declare const StaticCustomType: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
1344
1344
|
})[];
|
|
1345
1345
|
} & {
|
|
1346
1346
|
description?: string;
|
|
1347
|
+
legacyPaths?: {
|
|
1348
|
+
[x: string]: string;
|
|
1349
|
+
};
|
|
1347
1350
|
});
|
|
1348
1351
|
};
|
|
1349
1352
|
};
|
|
@@ -2396,4 +2399,5 @@ export declare function validateSlices(customType: CustomType, sharedSlices: Map
|
|
|
2396
2399
|
export declare function collectWidgets(customType: CustomType, f: (ref: string, widget: DynamicWidget) => DynamicWidget | undefined): CustomType;
|
|
2397
2400
|
export declare function filterMissingSharedSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): CustomType;
|
|
2398
2401
|
export declare function flattenCustomTypeFields(customType: StaticCustomType): Partial<Record<string, StaticWidget>>;
|
|
2402
|
+
export declare function collectSharedSlices(customType: StaticCustomType): Record<string, SharedSlice>;
|
|
2399
2403
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenStaticWidgets = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
|
|
3
|
+
exports.collectSharedSlices = exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenStaticWidgets = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const Either_1 = require("fp-ts/lib/Either");
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
@@ -147,3 +147,20 @@ function flattenCustomTypeFields(customType) {
|
|
|
147
147
|
}), {});
|
|
148
148
|
}
|
|
149
149
|
exports.flattenCustomTypeFields = flattenCustomTypeFields;
|
|
150
|
+
function collectSharedSlices(customType) {
|
|
151
|
+
return flattenStaticWidgets(customType).reduce((acc, [, w]) => {
|
|
152
|
+
var _a;
|
|
153
|
+
if (w.type === "Slices" || w.type === "Choice") {
|
|
154
|
+
return {
|
|
155
|
+
...acc,
|
|
156
|
+
...Object.entries(((_a = w.config) === null || _a === void 0 ? void 0 : _a.choices) || {}).reduce((sliceZoneAcc, [sliceKey, sliceModel]) => {
|
|
157
|
+
return sliceModel.type === "SharedSlice"
|
|
158
|
+
? { ...sliceZoneAcc, [sliceKey]: sliceModel }
|
|
159
|
+
: sliceZoneAcc;
|
|
160
|
+
}, {}),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return acc;
|
|
164
|
+
}, {});
|
|
165
|
+
}
|
|
166
|
+
exports.collectSharedSlices = collectSharedSlices;
|
|
@@ -340,6 +340,9 @@ export declare const SliceComparator: {
|
|
|
340
340
|
})[];
|
|
341
341
|
} & {
|
|
342
342
|
description?: string;
|
|
343
|
+
legacyPaths?: {
|
|
344
|
+
[x: string]: string;
|
|
345
|
+
};
|
|
343
346
|
}) | undefined, sliceB?: ({
|
|
344
347
|
id: string;
|
|
345
348
|
type: "SharedSlice";
|
|
@@ -674,5 +677,8 @@ export declare const SliceComparator: {
|
|
|
674
677
|
})[];
|
|
675
678
|
} & {
|
|
676
679
|
description?: string;
|
|
680
|
+
legacyPaths?: {
|
|
681
|
+
[x: string]: string;
|
|
682
|
+
};
|
|
677
683
|
}) | undefined): SliceDiff | undefined;
|
|
678
684
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { PickOnly } from "../../../_internal/utils";
|
|
2
3
|
import type { DynamicSlice, StaticSlice } from "./Slice";
|
|
3
4
|
export declare const CompositeSliceType = "Slice";
|
|
4
5
|
export declare const CompositeSliceConfig: t.ExactC<t.PartialC<{
|
|
@@ -331,4 +332,8 @@ export declare const CompositeSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
331
332
|
}>>;
|
|
332
333
|
}>]>>;
|
|
333
334
|
export declare type CompositeSlice = t.TypeOf<typeof CompositeSlice>;
|
|
335
|
+
export declare type CompositeSliceFields = {
|
|
336
|
+
type: "Slice";
|
|
337
|
+
fields: PickOnly<CompositeSlice, "non-repeat" | "repeat">;
|
|
338
|
+
};
|
|
334
339
|
export declare function isCompositeSlice(slice: DynamicSlice | StaticSlice): slice is CompositeSlice;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { PickOnly } from "../../../_internal/utils";
|
|
2
3
|
import type { SharedSliceRef } from "./SharedSliceRef";
|
|
3
4
|
import type { DynamicSlice, StaticSlice } from "./Slice";
|
|
4
5
|
export declare const Variation: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
@@ -326,6 +327,12 @@ export declare const Variation: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
326
327
|
}>]>>]>>;
|
|
327
328
|
}>]>>;
|
|
328
329
|
export declare type Variation = t.TypeOf<typeof Variation>;
|
|
330
|
+
export declare type VariationFields = {
|
|
331
|
+
type: "SharedSlice";
|
|
332
|
+
sliceName: string;
|
|
333
|
+
variationId: string;
|
|
334
|
+
fields: PickOnly<Variation, "primary" | "items">;
|
|
335
|
+
};
|
|
329
336
|
export declare const SharedSliceType = "SharedSlice";
|
|
330
337
|
export declare const SharedSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
331
338
|
id: t.StringC;
|
|
@@ -657,6 +664,7 @@ export declare const SharedSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
657
664
|
}>]>>>;
|
|
658
665
|
}>, t.PartialC<{
|
|
659
666
|
description: t.StringC;
|
|
667
|
+
legacyPaths: t.RecordC<t.StringC, t.StringC>;
|
|
660
668
|
}>]>>;
|
|
661
669
|
export declare type SharedSlice = t.TypeOf<typeof SharedSlice>;
|
|
662
670
|
export declare function isStaticSharedSlice(slice: StaticSlice): slice is SharedSlice;
|
|
@@ -23,6 +23,8 @@ exports.Variation = t.exact(t.intersection([
|
|
|
23
23
|
}),
|
|
24
24
|
]));
|
|
25
25
|
exports.SharedSliceType = "SharedSlice";
|
|
26
|
+
const LegacyPath = t.string;
|
|
27
|
+
const VariationId = t.string;
|
|
26
28
|
exports.SharedSlice = t.exact(t.intersection([
|
|
27
29
|
t.type({
|
|
28
30
|
id: t.string,
|
|
@@ -32,6 +34,7 @@ exports.SharedSlice = t.exact(t.intersection([
|
|
|
32
34
|
}),
|
|
33
35
|
t.partial({
|
|
34
36
|
description: t.string,
|
|
37
|
+
legacyPaths: t.record(LegacyPath, VariationId),
|
|
35
38
|
}),
|
|
36
39
|
]));
|
|
37
40
|
function isStaticSharedSlice(slice) {
|
|
@@ -1653,6 +1653,9 @@ export declare const StaticSlicesConfig: t.ExactC<t.PartialC<{
|
|
|
1653
1653
|
})[];
|
|
1654
1654
|
} & {
|
|
1655
1655
|
description?: string;
|
|
1656
|
+
legacyPaths?: {
|
|
1657
|
+
[x: string]: string;
|
|
1658
|
+
};
|
|
1656
1659
|
}, unknown, unknown>]>>;
|
|
1657
1660
|
}>>;
|
|
1658
1661
|
export declare type StaticSlicesConfig = t.TypeOf<typeof StaticSlicesConfig>;
|
|
@@ -3328,6 +3331,9 @@ export declare const StaticSlices: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
3328
3331
|
})[];
|
|
3329
3332
|
} & {
|
|
3330
3333
|
description?: string;
|
|
3334
|
+
legacyPaths?: {
|
|
3335
|
+
[x: string]: string;
|
|
3336
|
+
};
|
|
3331
3337
|
});
|
|
3332
3338
|
};
|
|
3333
3339
|
}, unknown, unknown>;
|
|
@@ -335,5 +335,8 @@ export declare const findSlice: (slices: SharedSliceCustomType[]) => (sliceId: s
|
|
|
335
335
|
})[];
|
|
336
336
|
} & {
|
|
337
337
|
description?: string;
|
|
338
|
+
legacyPaths?: {
|
|
339
|
+
[x: string]: string;
|
|
340
|
+
};
|
|
338
341
|
}>;
|
|
339
342
|
export declare const findSliceVariation: (slice: SharedSliceCustomType) => (variation: string) => E.Either<string, Variation>;
|
package/package.json
CHANGED
package/src/_internal/utils.ts
CHANGED
|
@@ -1,9 +1,41 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
SharedSliceItemContent,
|
|
3
|
+
SliceItemContent,
|
|
4
|
+
WidgetContent,
|
|
5
|
+
} from "../content"
|
|
6
|
+
import type {
|
|
7
|
+
CompositeSliceFields,
|
|
8
|
+
Group,
|
|
9
|
+
NestableWidget,
|
|
10
|
+
StaticSlices,
|
|
11
|
+
UID,
|
|
12
|
+
VariationFields,
|
|
13
|
+
} from "../customtypes"
|
|
3
14
|
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
15
|
+
export type PickOnly<T, K extends keyof T> = Pick<T, K> & {
|
|
16
|
+
[P in Exclude<keyof T, K>]?: never
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type TraverseSliceContentFn = <
|
|
20
|
+
S extends SliceItemContent | SharedSliceItemContent,
|
|
21
|
+
D extends VariationFields | CompositeSliceFields | Group | NestableWidget,
|
|
22
|
+
>({
|
|
23
|
+
path,
|
|
24
|
+
key,
|
|
25
|
+
apiId,
|
|
26
|
+
model,
|
|
27
|
+
content,
|
|
28
|
+
}: {
|
|
29
|
+
path: ContentPath
|
|
30
|
+
key: string
|
|
31
|
+
apiId: string
|
|
32
|
+
model?: D | undefined
|
|
33
|
+
content: S
|
|
34
|
+
}) => S | SharedSliceItemContent | undefined
|
|
35
|
+
|
|
36
|
+
export type TraverseWidgetContentFn = <
|
|
37
|
+
C extends WidgetContent,
|
|
38
|
+
D extends NestableWidget | StaticSlices | Group | UID,
|
|
7
39
|
>({
|
|
8
40
|
path,
|
|
9
41
|
key,
|
|
@@ -21,8 +53,10 @@ export type TraverseContentFn = <
|
|
|
21
53
|
export type ContentPathEntry = {
|
|
22
54
|
type:
|
|
23
55
|
| "CustomType"
|
|
24
|
-
|
|
|
25
|
-
|
|
|
56
|
+
| "Widget"
|
|
57
|
+
| "SharedSlice"
|
|
58
|
+
| "Slice"
|
|
59
|
+
| "LegacySlice"
|
|
26
60
|
| "GroupItem"
|
|
27
61
|
| "primary"
|
|
28
62
|
| "items"
|
|
@@ -36,4 +70,26 @@ export const ContentPath = {
|
|
|
36
70
|
serialize(path: ContentPath): string {
|
|
37
71
|
return path.map((entry) => entry.key).join(PATH_SEPARATOR)
|
|
38
72
|
},
|
|
73
|
+
current(path: ContentPath): ContentPathEntry | undefined {
|
|
74
|
+
return path[path.length - 1]
|
|
75
|
+
},
|
|
76
|
+
append(path: string, strElement: string): string {
|
|
77
|
+
return path + PATH_SEPARATOR + strElement
|
|
78
|
+
},
|
|
79
|
+
make(
|
|
80
|
+
entries: Array<{
|
|
81
|
+
key?: ContentPathEntry["key"] | undefined
|
|
82
|
+
type: ContentPathEntry["type"]
|
|
83
|
+
}>,
|
|
84
|
+
): ContentPath {
|
|
85
|
+
return entries.reduce<ContentPath>((acc, { key, type }) => {
|
|
86
|
+
return key ? acc.concat({ key, type }) : acc
|
|
87
|
+
}, [])
|
|
88
|
+
},
|
|
39
89
|
}
|
|
90
|
+
|
|
91
|
+
export type SliceModel =
|
|
92
|
+
| VariationFields
|
|
93
|
+
| NestableWidget
|
|
94
|
+
| CompositeSliceFields
|
|
95
|
+
| Group
|