@prismicio/types-internal 2.2.0-traverse.alpha-4 → 2.2.0-traverse.alpha-6
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/content/Document.js +2 -8
- package/lib/content/fields/slices/SliceItem.d.ts +2 -0
- package/lib/content/fields/slices/SliceItem.js +9 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +4 -1
- package/lib/content/fields/slices/SlicesContent.js +1 -1
- package/package.json +1 -1
- package/src/content/Document.ts +3 -12
- package/src/content/fields/slices/SliceItem.ts +14 -0
- package/src/content/fields/slices/SlicesContent.ts +7 -4
package/lib/content/Document.js
CHANGED
|
@@ -123,7 +123,7 @@ function traverseDocument({ document, customType, }) {
|
|
|
123
123
|
? fieldModel
|
|
124
124
|
: undefined,
|
|
125
125
|
content,
|
|
126
|
-
})(transformWidget, transformSlice);
|
|
126
|
+
})({ transformWidget, transformSlice });
|
|
127
127
|
case "GroupContentType":
|
|
128
128
|
return (0, fields_1.traverseGroupContent)({
|
|
129
129
|
path,
|
|
@@ -191,13 +191,7 @@ function migrateDocument(document, customType) {
|
|
|
191
191
|
document,
|
|
192
192
|
customType,
|
|
193
193
|
})({
|
|
194
|
-
transformSlice:
|
|
195
|
-
if ((0, fields_1.isCompositeSliceItemContent)(content) && (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
|
|
196
|
-
return (0, fields_1.migrateCompositeSlice)(model, content);
|
|
197
|
-
if ((0, fields_1.isSimpleSliceItemContent)(content) && (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
|
|
198
|
-
return (0, fields_1.migrateSimpleSlice)(model, content);
|
|
199
|
-
return content;
|
|
200
|
-
},
|
|
194
|
+
transformSlice: fields_1.migrateSliceItem,
|
|
201
195
|
});
|
|
202
196
|
}
|
|
203
197
|
exports.migrateDocument = migrateDocument;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { TraverseSliceContentFn } from "../../../_internal/utils";
|
|
2
3
|
import { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
|
|
3
4
|
import { CompositeSliceContent } from "./Slice/CompositeSliceContent";
|
|
4
5
|
import { SharedSliceContent } from "./Slice/SharedSliceContent";
|
|
@@ -3475,3 +3476,4 @@ export declare const SlicesItemLegacy: (ctx: LegacyContentCtx) => t.Type<{
|
|
|
3475
3476
|
} & {
|
|
3476
3477
|
label?: string | null | undefined;
|
|
3477
3478
|
}>, unknown>;
|
|
3479
|
+
export declare const migrateSliceItem: TraverseSliceContentFn;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SlicesItemLegacy = exports.isSimpleSliceItemContent = exports.isCompositeSliceItemContent = exports.isSharedSliceItemContent = exports.SliceItemContent = void 0;
|
|
3
|
+
exports.migrateSliceItem = 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");
|
|
@@ -74,3 +74,11 @@ const SlicesItemLegacy = (ctx) => {
|
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
76
|
exports.SlicesItemLegacy = SlicesItemLegacy;
|
|
77
|
+
const migrateSliceItem = ({ model, content, }) => {
|
|
78
|
+
if (isCompositeSliceItemContent(content) && (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
|
|
79
|
+
return (0, CompositeSliceContent_1.migrateCompositeSlice)(model, content);
|
|
80
|
+
if (isSimpleSliceItemContent(content) && (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
|
|
81
|
+
return (0, SimpleSliceContent_1.migrateSimpleSlice)(model, content);
|
|
82
|
+
return content;
|
|
83
|
+
};
|
|
84
|
+
exports.migrateSliceItem = migrateSliceItem;
|
|
@@ -5100,5 +5100,8 @@ export declare function traverseSlices({ path, key, model, content, }: {
|
|
|
5100
5100
|
key: string;
|
|
5101
5101
|
content: SlicesContent;
|
|
5102
5102
|
model?: StaticSlices | undefined;
|
|
5103
|
-
}): (transformWidget
|
|
5103
|
+
}): ({ transformWidget, transformSlice, }: {
|
|
5104
|
+
transformWidget?: TraverseWidgetContentFn;
|
|
5105
|
+
transformSlice?: TraverseSliceContentFn;
|
|
5106
|
+
}) => SlicesContent | undefined;
|
|
5104
5107
|
export {};
|
|
@@ -105,7 +105,7 @@ function findSliceModel(slicesPath, model, content) {
|
|
|
105
105
|
return sharedSliceModel() || migratedSliceModel() || legacySliceModel();
|
|
106
106
|
}
|
|
107
107
|
function traverseSlices({ path, key, model, content, }) {
|
|
108
|
-
return (transformWidget, transformSlice) => {
|
|
108
|
+
return ({ transformWidget = ({ content }) => content, transformSlice = ({ content }) => content, }) => {
|
|
109
109
|
const value = content.value.reduce((acc, sliceContent) => {
|
|
110
110
|
const sliceModel = model && findSliceModel(path, model, sliceContent);
|
|
111
111
|
const convertedSlice = (() => {
|
package/package.json
CHANGED
package/src/content/Document.ts
CHANGED
|
@@ -16,10 +16,7 @@ import {
|
|
|
16
16
|
StaticCustomType,
|
|
17
17
|
} from "../customtypes"
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
isSimpleSliceItemContent,
|
|
21
|
-
migrateCompositeSlice,
|
|
22
|
-
migrateSimpleSlice,
|
|
19
|
+
migrateSliceItem,
|
|
23
20
|
traverseGroupContent,
|
|
24
21
|
traverseSlices,
|
|
25
22
|
WidgetContent,
|
|
@@ -217,7 +214,7 @@ export function traverseDocument({
|
|
|
217
214
|
? fieldModel
|
|
218
215
|
: undefined,
|
|
219
216
|
content,
|
|
220
|
-
})(transformWidget, transformSlice)
|
|
217
|
+
})({ transformWidget, transformSlice })
|
|
221
218
|
case "GroupContentType":
|
|
222
219
|
return traverseGroupContent({
|
|
223
220
|
path,
|
|
@@ -305,12 +302,6 @@ export function migrateDocument(
|
|
|
305
302
|
document,
|
|
306
303
|
customType,
|
|
307
304
|
})({
|
|
308
|
-
transformSlice:
|
|
309
|
-
if (isCompositeSliceItemContent(content) && model?.type === "SharedSlice")
|
|
310
|
-
return migrateCompositeSlice(model, content)
|
|
311
|
-
if (isSimpleSliceItemContent(content) && model?.type === "SharedSlice")
|
|
312
|
-
return migrateSimpleSlice(model, content)
|
|
313
|
-
return content
|
|
314
|
-
},
|
|
305
|
+
transformSlice: migrateSliceItem,
|
|
315
306
|
})
|
|
316
307
|
}
|
|
@@ -3,6 +3,7 @@ import { isLeft } from "fp-ts/lib/Either"
|
|
|
3
3
|
import { pipe } from "fp-ts/lib/function"
|
|
4
4
|
import * as t from "io-ts"
|
|
5
5
|
|
|
6
|
+
import type { TraverseSliceContentFn } from "../../../_internal/utils"
|
|
6
7
|
import { nullable } from "../../../validators/function"
|
|
7
8
|
import {
|
|
8
9
|
getFieldCtx,
|
|
@@ -15,6 +16,7 @@ import { SliceContent, SliceLegacy } from "./Slice"
|
|
|
15
16
|
import {
|
|
16
17
|
CompositeSliceContent,
|
|
17
18
|
isCompositeSliceContent,
|
|
19
|
+
migrateCompositeSlice,
|
|
18
20
|
} from "./Slice/CompositeSliceContent"
|
|
19
21
|
import {
|
|
20
22
|
isSharedSliceContent,
|
|
@@ -22,6 +24,7 @@ import {
|
|
|
22
24
|
} from "./Slice/SharedSliceContent"
|
|
23
25
|
import {
|
|
24
26
|
isSimpleSliceContent,
|
|
27
|
+
migrateSimpleSlice,
|
|
25
28
|
SimpleSliceContent,
|
|
26
29
|
} from "./Slice/SimpleSliceContent"
|
|
27
30
|
|
|
@@ -117,3 +120,14 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
|
|
|
117
120
|
},
|
|
118
121
|
)
|
|
119
122
|
}
|
|
123
|
+
|
|
124
|
+
export const migrateSliceItem: TraverseSliceContentFn = ({
|
|
125
|
+
model,
|
|
126
|
+
content,
|
|
127
|
+
}) => {
|
|
128
|
+
if (isCompositeSliceItemContent(content) && model?.type === "SharedSlice")
|
|
129
|
+
return migrateCompositeSlice(model, content)
|
|
130
|
+
if (isSimpleSliceItemContent(content) && model?.type === "SharedSlice")
|
|
131
|
+
return migrateSimpleSlice(model, content)
|
|
132
|
+
return content
|
|
133
|
+
}
|
|
@@ -180,10 +180,13 @@ export function traverseSlices({
|
|
|
180
180
|
content: SlicesContent
|
|
181
181
|
model?: StaticSlices | undefined
|
|
182
182
|
}) {
|
|
183
|
-
return (
|
|
184
|
-
transformWidget
|
|
185
|
-
transformSlice
|
|
186
|
-
|
|
183
|
+
return ({
|
|
184
|
+
transformWidget = ({ content }) => content,
|
|
185
|
+
transformSlice = ({ content }) => content,
|
|
186
|
+
}: {
|
|
187
|
+
transformWidget?: TraverseWidgetContentFn
|
|
188
|
+
transformSlice?: TraverseSliceContentFn
|
|
189
|
+
}): SlicesContent | undefined => {
|
|
187
190
|
const value = content.value.reduce<SlicesContent["value"]>(
|
|
188
191
|
(acc, sliceContent) => {
|
|
189
192
|
const sliceModel = model && findSliceModel(path, model, sliceContent)
|