@prismicio/types-internal 2.5.0 → 2.6.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/_internal/utils.d.ts +2 -2
- package/lib/content/Document.d.ts +588 -1632
- package/lib/content/fields/WidgetContent.d.ts +588 -1632
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +4 -4
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +2 -1
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -2158
- package/lib/content/fields/slices/Slice/RepeatableContent.js +6 -148
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +4 -4
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +1 -1
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +6 -1049
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +7 -10
- package/lib/content/fields/slices/Slice/index.d.ts +27 -754
- package/lib/content/fields/slices/Slice/index.js +0 -1
- package/lib/content/fields/slices/SliceItem.d.ts +325 -1051
- package/lib/content/fields/slices/SlicesContent.d.ts +1771 -2815
- package/package.json +1 -1
- package/src/_internal/utils.ts +1 -2
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +4 -8
- package/src/content/fields/slices/Slice/RepeatableContent.ts +11 -242
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +7 -7
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +17 -21
- package/src/content/fields/slices/Slice/index.ts +0 -1
- package/src/content/fields/slices/SlicesContent.ts +2 -2
|
@@ -1,160 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RepeatableWidgets = exports.RepeatableWidgetsLegacy =
|
|
3
|
+
exports.RepeatableWidgets = exports.RepeatableWidgetsLegacy = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const fp_ts_1 = require("fp-ts");
|
|
6
|
-
const Either_1 = require("fp-ts/lib/Either");
|
|
7
|
-
const function_1 = require("fp-ts/lib/function");
|
|
8
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
9
|
-
const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
|
|
10
|
-
const utils_1 = require("../../../utils");
|
|
11
6
|
const GroupContent_1 = require("../../GroupContent");
|
|
12
7
|
const nestable_1 = require("../../nestable");
|
|
13
|
-
/**
|
|
14
|
-
* This is essentially a copy of `GroupItemContent` that doesn't support
|
|
15
|
-
* nested groups to keep accurate content types for legacy slice.
|
|
16
|
-
*/
|
|
17
|
-
const RepeatableWidgetItemContent = t.strict({
|
|
18
|
-
__TYPE__: t.literal(GroupContent_1.GroupItemContentType),
|
|
19
|
-
value: t.array(t.tuple([t.string, nestable_1.NestableContent])),
|
|
20
|
-
});
|
|
21
|
-
const itemLegacyReader = t.record(t.string, t.unknown);
|
|
22
|
-
/**
|
|
23
|
-
* This is essentially a copy of `GroupItemLegacy` that doesn't support
|
|
24
|
-
* nested groups to keep accurate content types for legacy slice.
|
|
25
|
-
*/
|
|
26
|
-
const RepeatableWidgetItemLegacy = (ctx) => {
|
|
27
|
-
return new t.Type("RepeatableWidgetItemLegacy", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === GroupContent_1.GroupItemContentType, (u) => {
|
|
28
|
-
const parsed = (0, function_1.pipe)(itemLegacyReader.decode(u), fp_ts_1.either.map((items) => {
|
|
29
|
-
const parsedItems = Object.entries(items).reduce((acc, [itemKey, itemValue]) => {
|
|
30
|
-
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(itemKey, ctx);
|
|
31
|
-
const result = (0, nestable_1.NestableLegacy)(itemCtx).decode(itemValue);
|
|
32
|
-
if (!result)
|
|
33
|
-
return acc;
|
|
34
|
-
if ((0, Either_1.isLeft)(result))
|
|
35
|
-
return acc;
|
|
36
|
-
return [...acc, [itemKey, result.right]];
|
|
37
|
-
}, []);
|
|
38
|
-
return {
|
|
39
|
-
value: parsedItems,
|
|
40
|
-
__TYPE__: GroupContent_1.GroupItemContentType,
|
|
41
|
-
};
|
|
42
|
-
}));
|
|
43
|
-
return parsed;
|
|
44
|
-
}, (item) => {
|
|
45
|
-
return item.value.reduce((acc, [key, value]) => {
|
|
46
|
-
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(key, ctx);
|
|
47
|
-
const encoded = (0, nestable_1.NestableLegacy)(itemCtx).encode(value);
|
|
48
|
-
if (!encoded)
|
|
49
|
-
return acc;
|
|
50
|
-
return {
|
|
51
|
-
content: { ...acc.content, [key]: encoded.content },
|
|
52
|
-
types: { ...acc.types, ...encoded.types },
|
|
53
|
-
};
|
|
54
|
-
}, { content: {}, types: {} });
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
const RepeatableWidgetLegacy = (ctx) => {
|
|
58
|
-
const codecDecode = t.array(t.union([t.null, RepeatableWidgetItemLegacy(ctx)]));
|
|
59
|
-
const codecEncode = t.array(RepeatableWidgetItemLegacy(ctx));
|
|
60
|
-
return new t.Type("RepeatableWidgetLegacy", exports.isRepeatableWidgetContent, (items) => {
|
|
61
|
-
return (0, function_1.pipe)(codecDecode.decode(items), fp_ts_1.either.map((parsedItems) => {
|
|
62
|
-
return {
|
|
63
|
-
value: parsedItems.map((i) => {
|
|
64
|
-
if (i === null) {
|
|
65
|
-
return { __TYPE__: GroupContent_1.GroupItemContentType, value: [] };
|
|
66
|
-
}
|
|
67
|
-
else
|
|
68
|
-
return i;
|
|
69
|
-
}),
|
|
70
|
-
__TYPE__: GroupContent_1.GroupContentType,
|
|
71
|
-
};
|
|
72
|
-
}));
|
|
73
|
-
}, (g) => {
|
|
74
|
-
const res = codecEncode.encode(g.value);
|
|
75
|
-
return {
|
|
76
|
-
content: res.map((block) => block.content),
|
|
77
|
-
types: res.reduce((acc, block) => {
|
|
78
|
-
return { ...acc, ...block.types };
|
|
79
|
-
}, { [ctx.keyOfType]: "Group" }),
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
exports.RepeatableWidgetLegacy = RepeatableWidgetLegacy;
|
|
84
|
-
/**
|
|
85
|
-
* This is essentially a copy of `isGroupContent` that doesn't support
|
|
86
|
-
* nested groups to keep accurate content types for legacy slice.
|
|
87
|
-
*/
|
|
88
|
-
const isRepeatableWidgetContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === GroupContent_1.GroupContentType;
|
|
89
|
-
exports.isRepeatableWidgetContent = isRepeatableWidgetContent;
|
|
90
|
-
exports.RepeatableWidgetContent = t.strict({
|
|
91
|
-
__TYPE__: t.literal(GroupContent_1.GroupContentType),
|
|
92
|
-
value: t.array(RepeatableWidgetItemContent),
|
|
93
|
-
});
|
|
94
|
-
/**
|
|
95
|
-
* This is essentially a copy of `traverseGroupContent` that doesn't support
|
|
96
|
-
* nested groups to keep accurate content types for legacy slice.
|
|
97
|
-
*/
|
|
98
|
-
function traverseRepeatableWidgetContent({ path, key, apiId, model, content, }) {
|
|
99
|
-
return (transform) => {
|
|
100
|
-
var _a;
|
|
101
|
-
const repeatableWidgetItems = traverseRepeatableWidgetItemsContent({
|
|
102
|
-
path,
|
|
103
|
-
model: (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.fields,
|
|
104
|
-
content: content.value,
|
|
105
|
-
})(transform);
|
|
106
|
-
return transform({
|
|
107
|
-
path,
|
|
108
|
-
key,
|
|
109
|
-
apiId,
|
|
110
|
-
model,
|
|
111
|
-
content: {
|
|
112
|
-
__TYPE__: content.__TYPE__,
|
|
113
|
-
value: repeatableWidgetItems,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
exports.traverseRepeatableWidgetContent = traverseRepeatableWidgetContent;
|
|
119
|
-
/**
|
|
120
|
-
* This is essentially a copy of `traverseGroupItemContent` that doesn't support
|
|
121
|
-
* nested groups to keep accurate content types for legacy slice.
|
|
122
|
-
*/
|
|
123
|
-
function traverseRepeatableWidgetItemsContent({ path, model, content, }) {
|
|
124
|
-
return (transform) => {
|
|
125
|
-
return content.map((repeatableWidgetItem, index) => {
|
|
126
|
-
const repeatableWidgetItemPath = path.concat([
|
|
127
|
-
{ key: index.toString(), type: "GroupItem" },
|
|
128
|
-
]);
|
|
129
|
-
const repeatableWidgetItemFields = repeatableWidgetItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
130
|
-
const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
|
|
131
|
-
const transformedField = transform({
|
|
132
|
-
path: repeatableWidgetItemPath.concat([
|
|
133
|
-
{ key: fieldKey, type: "Widget" },
|
|
134
|
-
]),
|
|
135
|
-
key: fieldKey,
|
|
136
|
-
apiId: fieldKey,
|
|
137
|
-
model: fieldDef,
|
|
138
|
-
content: fieldContent,
|
|
139
|
-
});
|
|
140
|
-
// Can happen if the transform function returns undefined to filter out a field
|
|
141
|
-
if (!transformedField || !(0, nestable_1.isNestableContent)(transformedField))
|
|
142
|
-
return acc;
|
|
143
|
-
return acc.concat([[fieldKey, transformedField]]);
|
|
144
|
-
}, []);
|
|
145
|
-
return {
|
|
146
|
-
__TYPE__: repeatableWidgetItem.__TYPE__,
|
|
147
|
-
value: repeatableWidgetItemFields,
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
exports.traverseRepeatableWidgetItemsContent = traverseRepeatableWidgetItemsContent;
|
|
153
8
|
const RepeatableWidgetsLegacy = (ctx) => {
|
|
154
|
-
return t.array(
|
|
9
|
+
return t.array((0, GroupContent_1.GroupItemLegacy)(ctx));
|
|
155
10
|
};
|
|
156
11
|
exports.RepeatableWidgetsLegacy = RepeatableWidgetsLegacy;
|
|
157
|
-
const RepeatableWidget = t.tuple([
|
|
12
|
+
const RepeatableWidget = t.tuple([
|
|
13
|
+
t.string,
|
|
14
|
+
t.union([nestable_1.NestableContent, GroupContent_1.GroupContent]),
|
|
15
|
+
]);
|
|
158
16
|
const RepeatableWidgetsBlock = t.strict({
|
|
159
17
|
__TYPE__: t.literal(GroupContent_1.GroupItemContentType),
|
|
160
18
|
value: t.array(RepeatableWidget),
|
|
@@ -636,7 +636,7 @@ export declare const isSharedSliceContent: (u: unknown) => u is {
|
|
|
636
636
|
}))[];
|
|
637
637
|
} | {
|
|
638
638
|
__TYPE__: "SeparatorContent";
|
|
639
|
-
}][];
|
|
639
|
+
} | import("../../GroupContent").GroupContent][];
|
|
640
640
|
}[];
|
|
641
641
|
};
|
|
642
642
|
export declare const SharedSliceLegacy: (ctx: LegacyContentCtx) => t.Type<{
|
|
@@ -1271,7 +1271,7 @@ export declare const SharedSliceLegacy: (ctx: LegacyContentCtx) => t.Type<{
|
|
|
1271
1271
|
}))[];
|
|
1272
1272
|
} | {
|
|
1273
1273
|
__TYPE__: "SeparatorContent";
|
|
1274
|
-
}][];
|
|
1274
|
+
} | import("../../GroupContent").GroupContent][];
|
|
1275
1275
|
}[];
|
|
1276
1276
|
}, WithTypes<{
|
|
1277
1277
|
variation: string;
|
|
@@ -1688,7 +1688,7 @@ export declare const SharedSliceContent: t.ExactC<t.TypeC<{
|
|
|
1688
1688
|
}>>]>, t.Type<import("../../GroupContent").GroupContent, import("../../GroupContent").GroupContent, unknown>]>>;
|
|
1689
1689
|
items: t.ArrayC<t.ExactC<t.TypeC<{
|
|
1690
1690
|
__TYPE__: t.LiteralC<"GroupItemContent">;
|
|
1691
|
-
value: t.ArrayC<t.TupleC<[t.StringC, t.UnionC<[t.ExactC<t.TypeC<{
|
|
1691
|
+
value: t.ArrayC<t.TupleC<[t.StringC, t.UnionC<[t.UnionC<[t.ExactC<t.TypeC<{
|
|
1692
1692
|
type: t.StringC;
|
|
1693
1693
|
__TYPE__: t.LiteralC<"EmptyContent">;
|
|
1694
1694
|
}>>, t.ExactC<t.TypeC<{
|
|
@@ -2090,7 +2090,7 @@ export declare const SharedSliceContent: t.ExactC<t.TypeC<{
|
|
|
2090
2090
|
}>]>>]>>;
|
|
2091
2091
|
}>>, t.ExactC<t.TypeC<{
|
|
2092
2092
|
__TYPE__: t.LiteralC<"SeparatorContent">;
|
|
2093
|
-
}>>]>]>>;
|
|
2093
|
+
}>>]>, t.Type<import("../../GroupContent").GroupContent, import("../../GroupContent").GroupContent, unknown>]>]>>;
|
|
2094
2094
|
}>>>;
|
|
2095
2095
|
}>>;
|
|
2096
2096
|
export declare type SharedSliceContent = t.TypeOf<typeof SharedSliceContent>;
|
|
@@ -159,7 +159,7 @@ function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content,
|
|
|
159
159
|
[fieldKey]: transformedField,
|
|
160
160
|
};
|
|
161
161
|
}, {});
|
|
162
|
-
const items = (0,
|
|
162
|
+
const items = (0, GroupContent_1.traverseGroupItemsContent)({
|
|
163
163
|
path: path.concat([{ key: "items", type: "items" }]),
|
|
164
164
|
model: model === null || model === void 0 ? void 0 : model.fields.items,
|
|
165
165
|
content: content.widget.items,
|