@prismicio/types-internal 2.5.0-alpha.0 → 2.5.0-alpha.2
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 +3972 -7926
- package/lib/content/fields/GroupContent.d.ts +17 -1754
- package/lib/content/fields/GroupContent.js +62 -22
- package/lib/content/fields/WidgetContent.d.ts +3371 -7324
- package/lib/content/fields/nestable/NestableContent.d.ts +3 -145
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +4 -212
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +2 -0
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +4 -184
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +6 -290
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +3 -0
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +2 -383
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +15 -1333
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +2 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +7 -1182
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +1 -0
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +7 -1182
- package/lib/content/fields/slices/Slice/index.d.ts +983 -2935
- package/lib/content/fields/slices/SliceItem.d.ts +148 -2100
- package/lib/content/fields/slices/SlicesContent.d.ts +866 -3644
- package/lib/content/fields/withDefaultValues.d.ts +4 -3
- package/lib/content/fields/withDefaultValues.js +17 -1
- package/lib/customtypes/CustomType.d.ts +70 -915
- package/lib/customtypes/Section.d.ts +70 -915
- package/lib/customtypes/diff/SharedSlice.d.ts +2 -340
- package/lib/customtypes/diff/Variation.d.ts +4 -351
- package/lib/customtypes/diff/Variation.js +4 -3
- package/lib/customtypes/diff/Widgets.d.ts +11 -0
- package/lib/customtypes/diff/Widgets.js +2 -0
- package/lib/customtypes/diff/index.d.ts +1 -0
- package/lib/customtypes/diff/index.js +1 -0
- package/lib/customtypes/widgets/Group.d.ts +15 -331
- package/lib/customtypes/widgets/Group.js +25 -5
- package/lib/customtypes/widgets/Widget.d.ts +7 -1014
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -168
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +2 -336
- package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +3 -338
- package/lib/customtypes/widgets/slices/Slices.d.ts +7 -1184
- package/lib/validators/function.js +8 -1
- package/package.json +5 -5
- package/src/content/fields/GroupContent.ts +107 -32
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +3 -1
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +7 -4
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +5 -3
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +3 -1
- package/src/content/fields/withDefaultValues.ts +27 -3
- package/src/customtypes/diff/Variation.ts +9 -20
- package/src/customtypes/diff/Widgets.ts +17 -0
- package/src/customtypes/diff/index.ts +1 -0
- package/src/customtypes/widgets/Group.ts +66 -20
- package/src/validators/function.ts +11 -1
|
@@ -1,27 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupContentDefaultValue = exports.
|
|
3
|
+
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupContentDefaultValue = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
7
7
|
const function_1 = require("fp-ts/lib/function");
|
|
8
8
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
9
|
+
const customtypes_1 = require("../../customtypes");
|
|
10
|
+
const function_2 = require("../../validators/function");
|
|
9
11
|
const LegacyContentCtx_1 = require("../LegacyContentCtx");
|
|
10
12
|
const utils_1 = require("../utils");
|
|
11
13
|
const nestable_1 = require("./nestable");
|
|
12
14
|
const withDefaultValues_1 = require("./withDefaultValues");
|
|
15
|
+
exports.GroupContentType = "GroupContentType";
|
|
16
|
+
const isGroupContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.GroupContentType;
|
|
17
|
+
exports.isGroupContent = isGroupContent;
|
|
18
|
+
const MAX_GROUP_DEPTH = 1;
|
|
19
|
+
const getGroupDepth = (group, depth = 0) => {
|
|
20
|
+
// Stop searching when we're over limit
|
|
21
|
+
if (depth > MAX_GROUP_DEPTH)
|
|
22
|
+
return depth;
|
|
23
|
+
for (const item of group.value) {
|
|
24
|
+
for (const [_key, widget] of item.value) {
|
|
25
|
+
if ((0, exports.isGroupContent)(widget)) {
|
|
26
|
+
depth = Math.max(depth, getGroupDepth(widget, depth + 1));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return depth;
|
|
31
|
+
};
|
|
32
|
+
exports.GroupContent = (0, function_2.refineType)(t.recursion("GroupContent", () => t.strict({
|
|
33
|
+
__TYPE__: t.literal(exports.GroupContentType),
|
|
34
|
+
value: t.array(exports.GroupItemContent),
|
|
35
|
+
})), "GroupContent", (g) => {
|
|
36
|
+
if (getGroupDepth(g) > MAX_GROUP_DEPTH) {
|
|
37
|
+
throw new Error(`GroupContent is nested too deeply (max ${MAX_GROUP_DEPTH} level)`);
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
});
|
|
13
41
|
exports.GroupItemContentType = "GroupItemContent";
|
|
14
|
-
exports.GroupItemContent = t.strict({
|
|
42
|
+
exports.GroupItemContent = t.recursion("GroupItemContent", () => t.strict({
|
|
15
43
|
__TYPE__: t.literal(exports.GroupItemContentType),
|
|
16
|
-
value: t.array(t.tuple([t.string, nestable_1.NestableContent])),
|
|
17
|
-
});
|
|
44
|
+
value: t.array(t.tuple([t.string, t.union([nestable_1.NestableContent, exports.GroupContent])])),
|
|
45
|
+
}));
|
|
18
46
|
const itemLegacyReader = t.record(t.string, t.unknown);
|
|
19
47
|
const GroupItemLegacy = (ctx) => {
|
|
20
48
|
return new t.Type("GroupItemLegacy", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.GroupItemContentType, (u) => {
|
|
21
49
|
const parsed = (0, function_1.pipe)(itemLegacyReader.decode(u), fp_ts_1.either.map((items) => {
|
|
22
50
|
const parsedItems = Object.entries(items).reduce((acc, [itemKey, itemValue]) => {
|
|
23
51
|
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(itemKey, ctx);
|
|
24
|
-
const result =
|
|
52
|
+
const result = itemCtx.fieldType === customtypes_1.GroupFieldType
|
|
53
|
+
? (0, exports.GroupLegacy)(itemCtx).decode(itemValue)
|
|
54
|
+
: (0, nestable_1.NestableLegacy)(itemCtx).decode(itemValue);
|
|
25
55
|
if (!result)
|
|
26
56
|
return acc;
|
|
27
57
|
if ((0, Either_1.isLeft)(result))
|
|
@@ -37,7 +67,9 @@ const GroupItemLegacy = (ctx) => {
|
|
|
37
67
|
}, (item) => {
|
|
38
68
|
return item.value.reduce((acc, [key, value]) => {
|
|
39
69
|
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(key, ctx);
|
|
40
|
-
const encoded = (0,
|
|
70
|
+
const encoded = (0, exports.isGroupContent)(value)
|
|
71
|
+
? (0, exports.GroupLegacy)(itemCtx).encode(value)
|
|
72
|
+
: (0, nestable_1.NestableLegacy)(itemCtx).encode(value);
|
|
41
73
|
if (!encoded)
|
|
42
74
|
return acc;
|
|
43
75
|
return {
|
|
@@ -70,18 +102,11 @@ const GroupLegacy = (ctx) => {
|
|
|
70
102
|
content: res.map((block) => block.content),
|
|
71
103
|
types: res.reduce((acc, block) => {
|
|
72
104
|
return { ...acc, ...block.types };
|
|
73
|
-
}, { [ctx.keyOfType]:
|
|
105
|
+
}, { [ctx.keyOfType]: customtypes_1.GroupFieldType }),
|
|
74
106
|
};
|
|
75
107
|
});
|
|
76
108
|
};
|
|
77
109
|
exports.GroupLegacy = GroupLegacy;
|
|
78
|
-
exports.GroupContentType = "GroupContentType";
|
|
79
|
-
const isGroupContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.GroupContentType;
|
|
80
|
-
exports.isGroupContent = isGroupContent;
|
|
81
|
-
exports.GroupContent = t.strict({
|
|
82
|
-
__TYPE__: t.literal(exports.GroupContentType),
|
|
83
|
-
value: t.array(exports.GroupItemContent),
|
|
84
|
-
});
|
|
85
110
|
exports.GroupContentDefaultValue = {
|
|
86
111
|
__TYPE__: exports.GroupContentType,
|
|
87
112
|
value: [],
|
|
@@ -126,15 +151,30 @@ function traverseGroupItemsContent({ path, model, content, }) {
|
|
|
126
151
|
]);
|
|
127
152
|
const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
128
153
|
const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
154
|
+
let transformedField;
|
|
155
|
+
if ((!fieldDef || (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) &&
|
|
156
|
+
fieldContent.__TYPE__ === exports.GroupContentType) {
|
|
157
|
+
transformedField = traverseGroupContent({
|
|
158
|
+
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
|
|
159
|
+
key: fieldKey,
|
|
160
|
+
apiId: fieldKey,
|
|
161
|
+
model: fieldDef,
|
|
162
|
+
content: fieldContent,
|
|
163
|
+
})(transform);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
transformedField = transform({
|
|
167
|
+
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
|
|
168
|
+
key: fieldKey,
|
|
169
|
+
apiId: fieldKey,
|
|
170
|
+
model: fieldDef,
|
|
171
|
+
content: fieldContent,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
136
174
|
// Can happen if the transform function returns undefined to filter out a field
|
|
137
|
-
if (!transformedField ||
|
|
175
|
+
if (!transformedField ||
|
|
176
|
+
!((0, nestable_1.isNestableContent)(transformedField) ||
|
|
177
|
+
(0, exports.isGroupContent)(transformedField)))
|
|
138
178
|
return acc;
|
|
139
179
|
return acc.concat([[fieldKey, transformedField]]);
|
|
140
180
|
}, []);
|