@prismicio/types-internal
Advanced tools
Comparing version 2.2.0-traverse.alpha-3 to 2.2.0-traverse.alpha-4
@@ -103,3 +103,6 @@ "use strict"; | ||
*/ | ||
function traverseDocument({ document, model, }) { | ||
function traverseDocument({ document, customType, }) { | ||
const model = customType && customtypes_1.StaticCustomType.is(customType) | ||
? simplifyCustomType(customType) | ||
: customType; | ||
return ({ transformWidget = ({ content }) => content, transformSlice = ({ content }) => content, }) => { | ||
@@ -155,2 +158,8 @@ const fieldModels = model && | ||
exports.traverseDocument = traverseDocument; | ||
function simplifyCustomType(customType) { | ||
return { | ||
customTypeId: customType === null || customType === void 0 ? void 0 : customType.id, | ||
fields: Object.fromEntries((0, customtypes_1.flattenStaticWidgets)(customType)), | ||
}; | ||
} | ||
// /** | ||
@@ -177,3 +186,6 @@ // * 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 | ||
function migrateDocument(document, customType) { | ||
const needsMigration = Object.values((0, customtypes_1.collectSharedSlices)(customType)).some((slice) => Boolean(slice.legacyPaths)); | ||
const model = customtypes_1.StaticCustomType.is(customType) | ||
? simplifyCustomType(customType) | ||
: customType; | ||
const needsMigration = Object.values((0, customtypes_1.collectSharedSlices)(model)).some((slice) => Boolean(slice.legacyPaths)); | ||
if (!needsMigration) | ||
@@ -183,3 +195,3 @@ return document; | ||
document, | ||
model: customType, | ||
customType, | ||
})({ | ||
@@ -186,0 +198,0 @@ transformSlice: ({ content, model }) => { |
{ | ||
"name": "@prismicio/types-internal", | ||
"version": "2.2.0-traverse.alpha-3", | ||
"version": "2.2.0-traverse.alpha-4", | ||
"description": "Prismic types for Custom Types and Prismic Data", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -12,4 +12,9 @@ import { either } from "fp-ts" | ||
import { WidgetKey } from "../common" | ||
import { type StaticWidget, collectSharedSlices } from "../customtypes" | ||
import { | ||
type StaticWidget, | ||
collectSharedSlices, | ||
flattenStaticWidgets, | ||
StaticCustomType, | ||
} from "../customtypes" | ||
import { | ||
isCompositeSliceItemContent, | ||
@@ -168,10 +173,17 @@ isSimpleSliceItemContent, | ||
document, | ||
model, | ||
customType, | ||
}: { | ||
document: Document | ||
model?: { | ||
customTypeId: string | ||
fields: Record<string, StaticWidget> | ||
} | ||
customType?: | ||
| StaticCustomType | ||
| { | ||
customTypeId: string | ||
fields: Record<string, StaticWidget> | ||
} | ||
| undefined | ||
}) { | ||
const model = | ||
customType && StaticCustomType.is(customType) | ||
? simplifyCustomType(customType) | ||
: customType | ||
return ({ | ||
@@ -243,2 +255,12 @@ transformWidget = ({ content }) => content, | ||
function simplifyCustomType(customType: StaticCustomType): { | ||
customTypeId: string | ||
fields: Record<string, StaticWidget> | ||
} { | ||
return { | ||
customTypeId: customType?.id, | ||
fields: Object.fromEntries(flattenStaticWidgets(customType)), | ||
} | ||
} | ||
// /** | ||
@@ -269,8 +291,13 @@ // * 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 | ||
document: Document, | ||
customType: { | ||
customTypeId: string | ||
fields: Record<string, StaticWidget> | ||
}, | ||
customType: | ||
| StaticCustomType | ||
| { | ||
customTypeId: string | ||
fields: Record<string, StaticWidget> | ||
}, | ||
) { | ||
const needsMigration = Object.values(collectSharedSlices(customType)).some( | ||
const model = StaticCustomType.is(customType) | ||
? simplifyCustomType(customType) | ||
: customType | ||
const needsMigration = Object.values(collectSharedSlices(model)).some( | ||
(slice) => Boolean(slice.legacyPaths), | ||
@@ -283,3 +310,3 @@ ) | ||
document, | ||
model: customType, | ||
customType, | ||
})({ | ||
@@ -286,0 +313,0 @@ transformSlice: ({ content, model }) => { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2714776
65629