@prismicio/types-internal 3.8.0 → 3.9.0-alpha.0
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/fields/RepeatableContent.d.ts +47 -45
- package/lib/customtypes/CustomType.d.ts +216 -18
- package/lib/customtypes/Section.d.ts +216 -18
- package/lib/customtypes/diff/SharedSlice.d.ts +96 -8
- package/lib/customtypes/diff/Variation.d.ts +96 -8
- package/lib/customtypes/widgets/Group.d.ts +138 -6
- package/lib/customtypes/widgets/Widget.d.ts +351 -21
- package/lib/customtypes/widgets/nestable/Link.d.ts +46 -2
- package/lib/customtypes/widgets/nestable/Link.js +73 -1
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +23 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +46 -2
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +46 -2
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +184 -8
- package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +105 -6
- package/lib/customtypes/widgets/slices/Slices.d.ts +468 -28
- package/package.json +1 -1
- package/src/customtypes/widgets/nestable/Link.ts +128 -2
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -727
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
- package/lib/customtypes/widgets/slices/SliceWidget.d.ts +0 -327
- package/lib/customtypes/widgets/slices/SliceWidget.js +0 -8
package/package.json
CHANGED
|
@@ -58,6 +58,132 @@ const MasksArrayString = new t.Type<ReadonlyArray<string>, object, unknown>(
|
|
|
58
58
|
(res) => res,
|
|
59
59
|
)
|
|
60
60
|
|
|
61
|
+
const CustomTypeLevel2Fields = new t.Type<readonly string[], readonly string[]>(
|
|
62
|
+
"CustomTypeLevel2Fields",
|
|
63
|
+
(u: unknown): u is readonly string[] =>
|
|
64
|
+
Array.isArray(u) && u.every((item) => typeof item === "string"),
|
|
65
|
+
(u: unknown, context: t.Context) =>
|
|
66
|
+
either.chain(t.array(t.string).validate(u, context), (fields) => {
|
|
67
|
+
// duplicates not allowed
|
|
68
|
+
const filtered = new Set(fields)
|
|
69
|
+
return filtered.size === fields.length
|
|
70
|
+
? t.success(fields)
|
|
71
|
+
: t.failure(u, context, "Fields have duplicates.")
|
|
72
|
+
}),
|
|
73
|
+
(a) => a,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
const CustomTypeLevel2 = t.union([
|
|
77
|
+
t.string,
|
|
78
|
+
t.exact(
|
|
79
|
+
t.intersection([
|
|
80
|
+
t.type({
|
|
81
|
+
id: t.string,
|
|
82
|
+
}),
|
|
83
|
+
t.partial({
|
|
84
|
+
fields: CustomTypeLevel2Fields,
|
|
85
|
+
}),
|
|
86
|
+
]),
|
|
87
|
+
),
|
|
88
|
+
])
|
|
89
|
+
|
|
90
|
+
const CustomTypesLevel2 = new t.Type<
|
|
91
|
+
readonly t.TypeOf<typeof CustomTypeLevel2>[],
|
|
92
|
+
readonly t.OutputOf<typeof CustomTypeLevel2>[]
|
|
93
|
+
>(
|
|
94
|
+
"CustomTypesLevel2",
|
|
95
|
+
(u: unknown): u is readonly t.TypeOf<typeof CustomTypeLevel2>[] =>
|
|
96
|
+
Array.isArray(u) && u.every((item) => CustomTypeLevel2.is(item)),
|
|
97
|
+
(u: unknown, context: t.Context) =>
|
|
98
|
+
either.chain(t.array(CustomTypeLevel2).validate(u, context), (cts) => {
|
|
99
|
+
// duplicates not allowed
|
|
100
|
+
const filtered = new Set(
|
|
101
|
+
cts.map((ct) => (typeof ct === "string" ? ct : ct.id)),
|
|
102
|
+
)
|
|
103
|
+
return filtered.size === cts.length
|
|
104
|
+
? t.success(cts)
|
|
105
|
+
: t.failure(u, context, "Custom types have duplicates.")
|
|
106
|
+
}),
|
|
107
|
+
(a) => a,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
const CustomTypeLevel1Field = t.union([
|
|
111
|
+
t.string,
|
|
112
|
+
t.strict({
|
|
113
|
+
id: t.string,
|
|
114
|
+
customtypes: CustomTypesLevel2,
|
|
115
|
+
}),
|
|
116
|
+
])
|
|
117
|
+
|
|
118
|
+
const CustomTypeLevel1Fields = new t.Type<
|
|
119
|
+
readonly t.TypeOf<typeof CustomTypeLevel1Field>[],
|
|
120
|
+
readonly t.OutputOf<typeof CustomTypeLevel1Field>[]
|
|
121
|
+
>(
|
|
122
|
+
"CustomTypeLevel1Fields",
|
|
123
|
+
(u: unknown): u is readonly t.TypeOf<typeof CustomTypeLevel1Field>[] =>
|
|
124
|
+
Array.isArray(u) && u.every((item) => CustomTypeLevel1Field.is(item)),
|
|
125
|
+
(u: unknown, context: t.Context) =>
|
|
126
|
+
either.chain(
|
|
127
|
+
t.array(CustomTypeLevel1Field).validate(u, context),
|
|
128
|
+
(fields) => {
|
|
129
|
+
// duplicates not allowed
|
|
130
|
+
const filtered = new Set(
|
|
131
|
+
fields.map((field) => (typeof field === "string" ? field : field.id)),
|
|
132
|
+
)
|
|
133
|
+
return filtered.size === fields.length
|
|
134
|
+
? t.success(fields)
|
|
135
|
+
: t.failure(u, context, "Fields have duplicates.")
|
|
136
|
+
},
|
|
137
|
+
),
|
|
138
|
+
(a) => a,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
const CustomTypeLevel1 = t.union([
|
|
142
|
+
t.string,
|
|
143
|
+
t.exact(
|
|
144
|
+
t.intersection([
|
|
145
|
+
t.type({
|
|
146
|
+
id: t.string,
|
|
147
|
+
}),
|
|
148
|
+
t.partial({
|
|
149
|
+
fields: CustomTypeLevel1Fields,
|
|
150
|
+
}),
|
|
151
|
+
]),
|
|
152
|
+
),
|
|
153
|
+
])
|
|
154
|
+
|
|
155
|
+
const CustomTypes = new t.Type<
|
|
156
|
+
readonly t.TypeOf<typeof CustomTypeLevel1>[],
|
|
157
|
+
readonly t.OutputOf<typeof CustomTypeLevel1>[]
|
|
158
|
+
>(
|
|
159
|
+
"CustomTypes",
|
|
160
|
+
(u: unknown): u is readonly t.TypeOf<typeof CustomTypeLevel1>[] =>
|
|
161
|
+
Array.isArray(u) && u.every((item) => CustomTypeLevel1.is(item)),
|
|
162
|
+
(u: unknown, context: t.Context) =>
|
|
163
|
+
either.chain(t.array(CustomTypeLevel1).validate(u, context), (cts) => {
|
|
164
|
+
// if a ct appears more than once as a string, we allow it (legacy)
|
|
165
|
+
// if a ct appears once as a string and then again via object (or vice versa), we don't allow it
|
|
166
|
+
// if a ct appears more than once as an object, we don't allow it
|
|
167
|
+
const strings = new Set<string>()
|
|
168
|
+
const objects = new Set<string>()
|
|
169
|
+
for (const ct of cts) {
|
|
170
|
+
let failed = false
|
|
171
|
+
if (typeof ct === "string") {
|
|
172
|
+
failed = objects.has(ct)
|
|
173
|
+
strings.add(ct)
|
|
174
|
+
} else {
|
|
175
|
+
const { id } = ct
|
|
176
|
+
failed = strings.has(id) || objects.has(id)
|
|
177
|
+
objects.add(id)
|
|
178
|
+
}
|
|
179
|
+
if (failed)
|
|
180
|
+
return t.failure(u, context, "Custom types have duplicates.")
|
|
181
|
+
}
|
|
182
|
+
return t.success(cts)
|
|
183
|
+
}),
|
|
184
|
+
(a) => a,
|
|
185
|
+
)
|
|
186
|
+
|
|
61
187
|
export const LinkFieldType = "Link"
|
|
62
188
|
|
|
63
189
|
export const LinkConfig = t.exact(
|
|
@@ -74,8 +200,8 @@ export const LinkConfig = t.exact(
|
|
|
74
200
|
]),
|
|
75
201
|
null,
|
|
76
202
|
),
|
|
77
|
-
customtypes:
|
|
78
|
-
masks: MasksArrayString,
|
|
203
|
+
customtypes: CustomTypes,
|
|
204
|
+
masks: MasksArrayString, // legacy definition of the custom types allowed
|
|
79
205
|
tags: MasksArrayString,
|
|
80
206
|
allowTargetBlank: t.boolean,
|
|
81
207
|
allowText: t.boolean,
|