@prismicio/types-internal 4.0.0-pr.7.9dec8db → 4.0.0-pr.9.e09af2c
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/dist/content/boolean.d.ts.map +1 -1
- package/dist/content/boolean.js.map +1 -1
- package/dist/content/field.d.ts.map +1 -1
- package/dist/content/field.js +1 -1
- package/dist/content/field.js.map +1 -1
- package/dist/content/group.d.ts.map +1 -1
- package/dist/content/group.js.map +1 -1
- package/dist/content/nestable.d.ts.map +1 -1
- package/dist/content/nestable.js.map +1 -1
- package/dist/helpers/traverseContent.d.ts +4 -4
- package/dist/helpers/traverseContent.d.ts.map +1 -1
- package/dist/helpers/traverseContent.js +4 -2
- package/dist/helpers/traverseContent.js.map +1 -1
- package/dist/helpers/traverseContentWithModel.d.ts +4 -4
- package/dist/helpers/withDefaultContent.d.ts +17 -0
- package/dist/helpers/withDefaultContent.d.ts.map +1 -0
- package/dist/helpers/withDefaultContent.js +113 -0
- package/dist/helpers/withDefaultContent.js.map +1 -0
- package/dist/index.d.ts +21 -20
- package/dist/index.js +2 -1
- package/dist/io-ts.d.ts +1067 -322
- package/dist/io-ts.d.ts.map +1 -1
- package/dist/io-ts.js +3 -2
- package/dist/io-ts.js.map +1 -1
- package/dist/model/slice.d.ts +1251 -643
- package/dist/model/slice.d.ts.map +1 -1
- package/dist/model/slice.js +4 -4
- package/dist/model/slice.js.map +1 -1
- package/dist/model/widget.d.ts +1 -3
- package/dist/model/widget.d.ts.map +1 -1
- package/dist/model/widget.js +5 -2
- package/dist/model/widget.js.map +1 -1
- package/dist/zod4.d.ts +909 -322
- package/dist/zod4.d.ts.map +1 -1
- package/dist/zod4.js +3 -2
- package/dist/zod4.js.map +1 -1
- package/package.json +1 -1
- package/src/content/boolean.ts +0 -13
- package/src/content/field.ts +0 -14
- package/src/content/group.ts +1 -54
- package/src/content/nestable.ts +1 -20
- package/src/helpers/traverseContent.ts +4 -1
- package/src/helpers/withDefaultContent.ts +173 -0
- package/src/index.ts +3 -1
- package/src/io-ts.ts +2 -0
- package/src/model/diff/sharedSlice.ts +2 -2
- package/src/model/diff/variation.ts +7 -7
- package/src/model/slice.ts +6 -8
- package/src/model/widget.ts +6 -2
- package/src/zod4.ts +2 -0
- package/src/content/withDefaultValues.ts +0 -114
package/src/model/widget.ts
CHANGED
|
@@ -46,7 +46,6 @@ export const FieldModelTypeSchema = z.enum([
|
|
|
46
46
|
"Text",
|
|
47
47
|
"Timestamp",
|
|
48
48
|
"Link",
|
|
49
|
-
"Repeatable.Link",
|
|
50
49
|
"Image",
|
|
51
50
|
"IntegrationFields",
|
|
52
51
|
"UID",
|
|
@@ -58,6 +57,11 @@ export const FieldModelTypeSchema = z.enum([
|
|
|
58
57
|
export type FieldModelType = z.infer<typeof FieldModelTypeSchema>
|
|
59
58
|
|
|
60
59
|
// Field and slice types
|
|
61
|
-
export const FieldOrSliceTypeSchema = z.union([
|
|
60
|
+
export const FieldOrSliceTypeSchema = z.union([
|
|
61
|
+
FieldModelTypeSchema,
|
|
62
|
+
SliceModelTypeSchema,
|
|
63
|
+
// Repeatable links are "meta" types like slices and shared slices
|
|
64
|
+
z.literal("Repeatable.Link"),
|
|
65
|
+
])
|
|
62
66
|
|
|
63
67
|
export type FieldOrSliceType = z.infer<typeof FieldOrSliceTypeSchema>
|
package/src/zod4.ts
CHANGED
|
@@ -82,6 +82,7 @@ import {
|
|
|
82
82
|
LegacySliceModelSchema as rawLegacySliceModelSchema,
|
|
83
83
|
CompositeSliceModelSchema as rawCompositeSliceModelSchema,
|
|
84
84
|
SharedSliceModelSchema as rawSharedSliceModelSchema,
|
|
85
|
+
SharedSliceModelVariationSchema as rawSharedSliceModelVariationSchema,
|
|
85
86
|
SharedSliceRefModelSchema as rawSharedSliceRefModelSchema,
|
|
86
87
|
StaticSliceModelSchema as rawStaticSliceModelSchema,
|
|
87
88
|
DynamicSliceModelSchema as rawDynamicSliceModelSchema,
|
|
@@ -167,6 +168,7 @@ export const TimestampModelSchema = toZod4(rawTimestampModelSchema)
|
|
|
167
168
|
export const UIDModelSchema = toZod4(rawUIDModelSchema)
|
|
168
169
|
export const GroupModelSchema = toZod4(rawGroupModelSchema)
|
|
169
170
|
export const NestedGroupModelSchema = toZod4(rawNestedGroupModelSchema)
|
|
171
|
+
export const SharedSliceModelVariationSchema = toZod4(rawSharedSliceModelVariationSchema)
|
|
170
172
|
export const SharedSliceRefModelSchema = toZod4(rawSharedSliceRefModelSchema)
|
|
171
173
|
export const CompositeSliceModelSchema = toZod4(rawCompositeSliceModelSchema)
|
|
172
174
|
export const LegacySliceModelSchema = toZod4(rawLegacySliceModelSchema)
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { GroupModel, NestedGroupModel } from "../model/group"
|
|
2
|
-
import type { NestableModel } from "../model/nestable"
|
|
3
|
-
import { GroupContentType, groupContentWithDefaultValues, GroupContentSchema } from "./group"
|
|
4
|
-
import type { GroupContent } from "./group"
|
|
5
|
-
import { NestableContentDefaultValue } from "./nestable"
|
|
6
|
-
import type { NestableContent } from "./nestable"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Applies default values to slice primary content (non-repeat zone) based on the model configuration.
|
|
10
|
-
* For each widget in the customType that has no corresponding content, this will add the default value.
|
|
11
|
-
*/
|
|
12
|
-
export function withDefaultSlicePrimaryContentValues(
|
|
13
|
-
customType: Record<string, NestableModel | NestedGroupModel>,
|
|
14
|
-
content: Partial<Record<string, NestableContent | GroupContent>>,
|
|
15
|
-
): Record<string, NestableContent | GroupContent> {
|
|
16
|
-
const updatedContent = content as Record<string, NestableContent | GroupContent>
|
|
17
|
-
|
|
18
|
-
for (const [widgetKey, widgetDef] of Object.entries(customType)) {
|
|
19
|
-
const widgetContent = content[widgetKey]
|
|
20
|
-
|
|
21
|
-
if (widgetContent === undefined) {
|
|
22
|
-
if (widgetDef.type === "Group") {
|
|
23
|
-
updatedContent[widgetKey] = groupContentWithDefaultValues(widgetDef, {
|
|
24
|
-
__TYPE__: GroupContentType,
|
|
25
|
-
value: [],
|
|
26
|
-
})
|
|
27
|
-
} else {
|
|
28
|
-
const defaultValue = NestableContentDefaultValue(widgetDef)
|
|
29
|
-
|
|
30
|
-
if (defaultValue) {
|
|
31
|
-
updatedContent[widgetKey] = defaultValue
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
continue
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const maybeGroupContent = GroupContentSchema.safeParse(widgetContent)
|
|
39
|
-
if (widgetDef.type === "Group" && maybeGroupContent.success) {
|
|
40
|
-
updatedContent[widgetKey] = groupContentWithDefaultValues(widgetDef, maybeGroupContent.data)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return updatedContent
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Applies default values to nestable content based on the model configuration.
|
|
49
|
-
* For each widget in the customType that has no corresponding content, this will add the default value.
|
|
50
|
-
*/
|
|
51
|
-
export function withDefaultNestableContentValues(
|
|
52
|
-
customType: Record<string, NestableModel>,
|
|
53
|
-
content: Record<string, NestableContent>,
|
|
54
|
-
): Record<string, NestableContent> {
|
|
55
|
-
return Object.entries(customType).reduce<Record<string, NestableContent>>(
|
|
56
|
-
(updatedContent, [widgetKey, widgetDef]) => {
|
|
57
|
-
if (content[widgetKey] === undefined) {
|
|
58
|
-
const defaultValue = NestableContentDefaultValue(widgetDef)
|
|
59
|
-
return defaultValue !== undefined
|
|
60
|
-
? {
|
|
61
|
-
...updatedContent,
|
|
62
|
-
[widgetKey]: defaultValue,
|
|
63
|
-
}
|
|
64
|
-
: updatedContent
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return updatedContent
|
|
68
|
-
},
|
|
69
|
-
content,
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Applies default values to repeatable content items (like group items or slice repeat zones).
|
|
75
|
-
* For each item, it ensures all required fields have values based on the model configuration.
|
|
76
|
-
*/
|
|
77
|
-
export function repeatableContentWithDefaultNestableContentValues<
|
|
78
|
-
T extends {
|
|
79
|
-
value: [string, GroupContent | NestableContent][]
|
|
80
|
-
},
|
|
81
|
-
>(fields: Record<string, GroupModel | NestableModel>, content: T[]): T[] {
|
|
82
|
-
const groupKeys = Object.entries(fields)
|
|
83
|
-
return content.map((contentItem) => {
|
|
84
|
-
return groupKeys.reduce((updatedContentItem, [key, fieldDef]) => {
|
|
85
|
-
const maybeContentItemValue = contentItem.value.find(([_key]) => _key === key)
|
|
86
|
-
|
|
87
|
-
if (fieldDef.type === "Group") {
|
|
88
|
-
const defaultValue = groupContentWithDefaultValues(
|
|
89
|
-
fieldDef,
|
|
90
|
-
(maybeContentItemValue?.[1] as GroupContent | undefined) ?? {
|
|
91
|
-
__TYPE__: GroupContentType,
|
|
92
|
-
value: [],
|
|
93
|
-
},
|
|
94
|
-
)
|
|
95
|
-
return {
|
|
96
|
-
...updatedContentItem,
|
|
97
|
-
value: [
|
|
98
|
-
// Since there was default content for the group, we need to remove the old one
|
|
99
|
-
...updatedContentItem.value.filter(([_key]) => _key !== key),
|
|
100
|
-
...(defaultValue ? [[key, defaultValue]] : []),
|
|
101
|
-
],
|
|
102
|
-
}
|
|
103
|
-
} else if (!maybeContentItemValue) {
|
|
104
|
-
const defaultValue = NestableContentDefaultValue(fieldDef)
|
|
105
|
-
return {
|
|
106
|
-
...updatedContentItem,
|
|
107
|
-
value: [...updatedContentItem.value, ...(defaultValue ? [[key, defaultValue]] : [])],
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return updatedContentItem
|
|
112
|
-
}, contentItem)
|
|
113
|
-
})
|
|
114
|
-
}
|