@prismicio/types-internal 2.5.0-alpha.2 → 2.5.0-alpha.4
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.d.ts +957 -45
- package/lib/content/fields/GroupContent.d.ts +8 -8
- package/lib/content/fields/GroupContent.js +14 -32
- package/lib/content/fields/WidgetContent.d.ts +957 -45
- package/lib/content/fields/nestable/NestableContent.d.ts +155 -3
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +232 -4
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +5 -2
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +194 -4
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +314 -10
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +0 -3
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +80 -3
- package/lib/content/fields/slices/Slice/RepeatableContent.js +4 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +314 -10
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +0 -2
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +155 -3
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +0 -1
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +155 -3
- package/lib/content/fields/slices/Slice/index.d.ts +586 -16
- package/lib/content/fields/slices/SliceItem.d.ts +586 -16
- package/lib/content/fields/slices/SlicesContent.d.ts +817 -57
- package/lib/customtypes/CustomType.d.ts +2042 -690
- package/lib/customtypes/Section.d.ts +2028 -676
- package/lib/customtypes/diff/SharedSlice.d.ts +678 -2
- package/lib/customtypes/diff/Variation.d.ts +678 -3
- package/lib/customtypes/widgets/Group.d.ts +996 -15
- package/lib/customtypes/widgets/Group.js +15 -27
- package/lib/customtypes/widgets/Widget.d.ts +1684 -7
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +168 -2
- package/lib/customtypes/widgets/slices/LegacySlice.js +1 -1
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +670 -2
- package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +674 -3
- package/lib/customtypes/widgets/slices/Slices.d.ts +1522 -7
- package/package.json +1 -1
- package/src/content/fields/GroupContent.ts +24 -48
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +6 -3
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +4 -7
- package/src/content/fields/slices/Slice/RepeatableContent.ts +9 -2
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +3 -5
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +1 -3
- package/src/customtypes/widgets/Group.ts +34 -61
- package/src/customtypes/widgets/slices/LegacySlice.ts +2 -2
package/package.json
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
type NestableWidget,
|
|
13
13
|
GroupFieldType,
|
|
14
14
|
} from "../../customtypes"
|
|
15
|
-
import { refineType } from "../../validators/function"
|
|
16
15
|
import {
|
|
17
16
|
FieldOrSliceType,
|
|
18
17
|
getFieldCtx,
|
|
@@ -23,50 +22,9 @@ import { hasContentType } from "../utils"
|
|
|
23
22
|
import { isNestableContent, NestableContent, NestableLegacy } from "./nestable"
|
|
24
23
|
import { repeatableContentWithDefaultNestableContentValues } from "./withDefaultValues"
|
|
25
24
|
|
|
25
|
+
export const GroupItemContentType = "GroupItemContent" as const
|
|
26
26
|
export const GroupContentType = "GroupContentType" as const
|
|
27
|
-
export const isGroupContent = (u: unknown): u is GroupContent =>
|
|
28
|
-
hasContentType(u) && u.__TYPE__ === GroupContentType
|
|
29
|
-
|
|
30
|
-
const MAX_GROUP_DEPTH = 1
|
|
31
|
-
const getGroupDepth = (group: GroupContent, depth = 0): number => {
|
|
32
|
-
// Stop searching when we're over limit
|
|
33
|
-
if (depth > MAX_GROUP_DEPTH) return depth
|
|
34
|
-
|
|
35
|
-
for (const item of group.value) {
|
|
36
|
-
for (const [_key, widget] of item.value) {
|
|
37
|
-
if (isGroupContent(widget)) {
|
|
38
|
-
depth = Math.max(depth, getGroupDepth(widget, depth + 1))
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
27
|
|
|
43
|
-
return depth
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const GroupContent: t.Type<GroupContent> = refineType(
|
|
47
|
-
t.recursion("GroupContent", () =>
|
|
48
|
-
t.strict({
|
|
49
|
-
__TYPE__: t.literal(GroupContentType),
|
|
50
|
-
value: t.array(GroupItemContent),
|
|
51
|
-
}),
|
|
52
|
-
),
|
|
53
|
-
"GroupContent",
|
|
54
|
-
(g) => {
|
|
55
|
-
if (getGroupDepth(g) > MAX_GROUP_DEPTH) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`GroupContent is nested too deeply (max ${MAX_GROUP_DEPTH} level)`,
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return true
|
|
62
|
-
},
|
|
63
|
-
)
|
|
64
|
-
export type GroupContent = {
|
|
65
|
-
__TYPE__: typeof GroupContentType
|
|
66
|
-
value: GroupItemContent[]
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export const GroupItemContentType = "GroupItemContent" as const
|
|
70
28
|
export const GroupItemContent: t.Type<GroupItemContent> = t.recursion(
|
|
71
29
|
"GroupItemContent",
|
|
72
30
|
() =>
|
|
@@ -82,6 +40,29 @@ export type GroupItemContent = {
|
|
|
82
40
|
value: [string, NestableContent | GroupContent][]
|
|
83
41
|
}
|
|
84
42
|
|
|
43
|
+
export const GroupContent: t.Type<GroupContent> = t.recursion(
|
|
44
|
+
"GroupContent",
|
|
45
|
+
() =>
|
|
46
|
+
t.strict({
|
|
47
|
+
__TYPE__: t.literal(GroupContentType),
|
|
48
|
+
value: t.array(GroupItemContent),
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
export type GroupContent = {
|
|
52
|
+
__TYPE__: typeof GroupContentType
|
|
53
|
+
value: GroupItemContent[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const isGroupContent = (u: unknown): u is GroupContent =>
|
|
57
|
+
hasContentType(u) &&
|
|
58
|
+
u.__TYPE__ === GroupContentType &&
|
|
59
|
+
GroupContent.decode(u)._tag === "Right"
|
|
60
|
+
|
|
61
|
+
export const GroupContentDefaultValue: GroupContent = {
|
|
62
|
+
__TYPE__: GroupContentType,
|
|
63
|
+
value: [],
|
|
64
|
+
}
|
|
65
|
+
|
|
85
66
|
const itemLegacyReader = t.record(t.string, t.unknown)
|
|
86
67
|
type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>
|
|
87
68
|
|
|
@@ -178,11 +159,6 @@ export const GroupLegacy = (
|
|
|
178
159
|
)
|
|
179
160
|
}
|
|
180
161
|
|
|
181
|
-
export const GroupContentDefaultValue: GroupContent = {
|
|
182
|
-
__TYPE__: GroupContentType,
|
|
183
|
-
value: [],
|
|
184
|
-
}
|
|
185
|
-
|
|
186
162
|
export function groupContentWithDefaultValues(
|
|
187
163
|
customType: Group,
|
|
188
164
|
content: GroupContent,
|
|
@@ -79,9 +79,12 @@ export const ValidatedSpans = <C extends typeof Span | typeof SpanLegacy>(
|
|
|
79
79
|
)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// We allow any
|
|
83
|
-
//
|
|
84
|
-
|
|
82
|
+
// We allow any codec here and let TypeScript infer the resulting codec.
|
|
83
|
+
// Typing it more precisely creates conflicts.
|
|
84
|
+
//
|
|
85
|
+
// Using `t.Mixed` rather than `t.Type<A, O>` causes `data.linkTo` to be
|
|
86
|
+
// typed as `any`. It seems to be an issue with the `nullable` helper.
|
|
87
|
+
const ImageBlockCodec = <A, O>(linkCodec: t.Type<A, O>) =>
|
|
85
88
|
t.exact(
|
|
86
89
|
t.intersection([
|
|
87
90
|
t.type({
|
|
@@ -59,15 +59,14 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
59
59
|
legacyReader.decode(slice),
|
|
60
60
|
either.map((parsedSlice) => {
|
|
61
61
|
const repeat =
|
|
62
|
-
((
|
|
62
|
+
(() => {
|
|
63
63
|
const itemsCtx = getFieldCtx("repeat", ctx)
|
|
64
64
|
const result = RepeatableWidgetsLegacy(itemsCtx).decode(
|
|
65
65
|
parsedSlice.repeat,
|
|
66
66
|
)
|
|
67
67
|
if (!result || isLeft(result)) return
|
|
68
68
|
return result.right
|
|
69
|
-
|
|
70
|
-
})() as t.TypeOf<typeof RepeatableWidgets>) || []
|
|
69
|
+
})() || []
|
|
71
70
|
|
|
72
71
|
const nonRepeat = Object.entries(
|
|
73
72
|
parsedSlice["non-repeat"] || {},
|
|
@@ -214,8 +213,7 @@ export function traverseCompositeSliceContent({
|
|
|
214
213
|
model:
|
|
215
214
|
model?.type === "SharedSlice" ? model?.fields.items : model?.repeat,
|
|
216
215
|
content: content.widget.repeat,
|
|
217
|
-
|
|
218
|
-
})(transformWidget) as t.TypeOf<typeof RepeatableWidgets>
|
|
216
|
+
})(transformWidget)
|
|
219
217
|
|
|
220
218
|
return transformSlice({
|
|
221
219
|
key: sliceKey,
|
|
@@ -275,8 +273,7 @@ export function migrateCompositeSlice(
|
|
|
275
273
|
[],
|
|
276
274
|
),
|
|
277
275
|
}
|
|
278
|
-
|
|
279
|
-
}, []) as t.TypeOf<typeof RepeatableWidgets>,
|
|
276
|
+
}, []),
|
|
280
277
|
},
|
|
281
278
|
}
|
|
282
279
|
}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
3
|
import type { LegacyContentCtx } from "../../../LegacyContentCtx"
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
GroupContent,
|
|
6
|
+
GroupItemContentType,
|
|
7
|
+
GroupItemLegacy,
|
|
8
|
+
} from "../../GroupContent"
|
|
5
9
|
import { NestableContent } from "../../nestable"
|
|
6
10
|
|
|
7
11
|
export const RepeatableWidgetsLegacy = (ctx: LegacyContentCtx) => {
|
|
8
12
|
return t.array(GroupItemLegacy(ctx))
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
const RepeatableWidget = t.tuple([
|
|
15
|
+
const RepeatableWidget = t.tuple([
|
|
16
|
+
t.string,
|
|
17
|
+
t.union([NestableContent, GroupContent]),
|
|
18
|
+
])
|
|
12
19
|
const RepeatableWidgetsBlock = t.strict({
|
|
13
20
|
__TYPE__: t.literal(GroupItemContentType),
|
|
14
21
|
value: t.array(RepeatableWidget),
|
|
@@ -61,7 +61,7 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
61
61
|
legacyReader.decode(slice),
|
|
62
62
|
either.map((parsedSlice) => {
|
|
63
63
|
const items =
|
|
64
|
-
((
|
|
64
|
+
(() => {
|
|
65
65
|
const itemsCtx = getFieldCtx("items", ctx, [
|
|
66
66
|
"variations",
|
|
67
67
|
parsedSlice.variation,
|
|
@@ -71,8 +71,7 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
71
71
|
)
|
|
72
72
|
if (!result || isLeft(result)) return
|
|
73
73
|
return result.right
|
|
74
|
-
|
|
75
|
-
})() as t.TypeOf<typeof RepeatableWidgets>) || []
|
|
74
|
+
})() || []
|
|
76
75
|
|
|
77
76
|
const primary = Object.entries(parsedSlice.primary).reduce<
|
|
78
77
|
Record<string, SlicePrimaryContent>
|
|
@@ -250,8 +249,7 @@ export function traverseSharedSliceContent({
|
|
|
250
249
|
path: path.concat([{ key: "items", type: "items" }]),
|
|
251
250
|
model: model?.fields.items,
|
|
252
251
|
content: content.widget.items,
|
|
253
|
-
|
|
254
|
-
})(transformWidget) as t.TypeOf<typeof RepeatableWidgets>
|
|
252
|
+
})(transformWidget)
|
|
255
253
|
|
|
256
254
|
return transformSlice({
|
|
257
255
|
key: sliceKey,
|
|
@@ -27,7 +27,6 @@ import type {
|
|
|
27
27
|
SharedSliceItemContent,
|
|
28
28
|
SimpleSliceItemContent,
|
|
29
29
|
} from "../SliceItem"
|
|
30
|
-
import type { RepeatableWidgets } from "./RepeatableContent"
|
|
31
30
|
|
|
32
31
|
export const SimpleSliceContent = t.union([NestableContent, GroupContent])
|
|
33
32
|
export type SimpleSliceContent = t.TypeOf<typeof SimpleSliceContent>
|
|
@@ -160,8 +159,7 @@ export function migrateSimpleSlice(
|
|
|
160
159
|
[],
|
|
161
160
|
),
|
|
162
161
|
}
|
|
163
|
-
|
|
164
|
-
}, []) as t.TypeOf<typeof RepeatableWidgets>,
|
|
162
|
+
}, []),
|
|
165
163
|
},
|
|
166
164
|
}
|
|
167
165
|
}
|
|
@@ -2,75 +2,48 @@ import * as t from "io-ts"
|
|
|
2
2
|
|
|
3
3
|
import { WidgetKey } from "../../common"
|
|
4
4
|
import { StringOrNull } from "../../validators"
|
|
5
|
-
import { refineType } from "../../validators/function"
|
|
6
5
|
import { NestableWidget } from "./nestable/NestableWidget"
|
|
7
6
|
|
|
8
7
|
export const GroupFieldType = "Group"
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
// We're obliged to use `t.Mixed` here, otherwise the factory would be
|
|
10
|
+
// referencing itself and TypeScript would infer its type as `any`
|
|
11
|
+
const createGroupConfig = <TWidgets extends t.Mixed>(widgets: TWidgets) =>
|
|
10
12
|
t.exact(
|
|
11
13
|
t.partial({
|
|
12
14
|
label: StringOrNull,
|
|
13
15
|
repeat: t.boolean,
|
|
14
|
-
fields: t.record(
|
|
15
|
-
WidgetKey,
|
|
16
|
-
t.union([Group, NestableWidget as t.Type<NestableWidget>]),
|
|
17
|
-
),
|
|
16
|
+
fields: t.record(WidgetKey, widgets),
|
|
18
17
|
}),
|
|
19
|
-
)
|
|
20
|
-
)
|
|
21
|
-
export type GroupConfig = {
|
|
22
|
-
label?: string | null | undefined
|
|
23
|
-
repeat?: boolean
|
|
24
|
-
fields?: Record<string, Group | NestableWidget>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const MAX_GROUP_DEPTH = 1
|
|
28
|
-
const getGroupDepth = (group: Group, depth = 0): number => {
|
|
29
|
-
// Stop searching when we're over limit
|
|
30
|
-
if (depth > MAX_GROUP_DEPTH) return depth
|
|
31
|
-
|
|
32
|
-
for (const key in group.config?.fields) {
|
|
33
|
-
const field = group.config?.fields[key]
|
|
34
|
-
if (field?.type === GroupFieldType) {
|
|
35
|
-
depth = Math.max(depth, getGroupDepth(field, depth + 1))
|
|
36
|
-
}
|
|
37
|
-
}
|
|
18
|
+
)
|
|
38
19
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
t.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return true
|
|
67
|
-
},
|
|
20
|
+
// We're obliged to use `t.Mixed` here, otherwise the factory would be
|
|
21
|
+
// referencing itself and TypeScript would infer its type as `any`
|
|
22
|
+
const createGroup = <TWidgets extends t.Mixed>(widgets: TWidgets) =>
|
|
23
|
+
t.exact(
|
|
24
|
+
t.intersection([
|
|
25
|
+
t.type({
|
|
26
|
+
type: t.literal(GroupFieldType),
|
|
27
|
+
}),
|
|
28
|
+
t.partial({
|
|
29
|
+
fieldset: StringOrNull,
|
|
30
|
+
icon: t.string,
|
|
31
|
+
description: t.string,
|
|
32
|
+
config: createGroupConfig(widgets),
|
|
33
|
+
}),
|
|
34
|
+
]),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
export const NestedGroupConfig = createGroupConfig(NestableWidget)
|
|
38
|
+
export type NestedGroupConfig = t.TypeOf<typeof NestedGroupConfig>
|
|
39
|
+
|
|
40
|
+
export const NestedGroup = createGroup(NestableWidget)
|
|
41
|
+
export type NestedGroup = t.TypeOf<typeof NestedGroup>
|
|
42
|
+
|
|
43
|
+
export const GroupConfig = createGroupConfig(
|
|
44
|
+
t.union([NestableWidget, NestedGroup]),
|
|
68
45
|
)
|
|
46
|
+
export type GroupConfig = t.TypeOf<typeof GroupConfig>
|
|
69
47
|
|
|
70
|
-
export
|
|
71
|
-
|
|
72
|
-
fieldset?: string | null | undefined
|
|
73
|
-
icon?: string
|
|
74
|
-
description?: string
|
|
75
|
-
config?: GroupConfig
|
|
76
|
-
}
|
|
48
|
+
export const Group = createGroup(t.union([NestableWidget, NestedGroup]))
|
|
49
|
+
export type Group = t.TypeOf<typeof Group>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { NestedGroup } from "../Group"
|
|
4
4
|
import { NestableWidget } from "../nestable/NestableWidget"
|
|
5
5
|
import type { DynamicSlice, StaticSlice } from "./Slice"
|
|
6
6
|
|
|
7
|
-
export const LegacySlice = t.union([NestableWidget,
|
|
7
|
+
export const LegacySlice = t.union([NestableWidget, NestedGroup])
|
|
8
8
|
|
|
9
9
|
export type LegacySlice = t.TypeOf<typeof LegacySlice>
|
|
10
10
|
|