@prismicio/types-internal 2.1.0-alpha.2 → 2.1.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 +1 -1
- package/lib/content/Document.js +1 -6
- package/lib/customtypes/CustomType.d.ts +1046 -1180
- package/lib/customtypes/CustomType.js +13 -74
- package/lib/customtypes/Section.d.ts +1047 -1171
- package/lib/customtypes/Section.js +23 -1
- package/lib/customtypes/_internal/utils.d.ts +3 -0
- package/lib/customtypes/_internal/utils.js +20 -0
- package/lib/customtypes/diff/SharedSlice.d.ts +184 -220
- package/lib/customtypes/diff/Variation.d.ts +183 -219
- package/lib/customtypes/widgets/Group.d.ts +6 -40
- package/lib/customtypes/widgets/Group.js +20 -1
- package/lib/customtypes/widgets/Widget.d.ts +778 -976
- package/lib/customtypes/widgets/nestable/Link/ContentRelationshipResolver.d.ts +4 -22
- package/lib/customtypes/widgets/nestable/Link/ContentRelationshipResolver.js +5 -34
- package/lib/customtypes/widgets/nestable/Link/index.d.ts +4 -40
- package/lib/customtypes/widgets/nestable/Link/index.js +1 -1
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +2 -20
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +6 -40
- package/lib/customtypes/widgets/slices/CompositeSlice.js +26 -1
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +4 -40
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +10 -80
- package/lib/customtypes/widgets/slices/SharedSlice.js +35 -1
- package/lib/customtypes/widgets/slices/Slices.d.ts +924 -1246
- package/lib/customtypes/widgets/slices/Slices.js +34 -1
- package/lib/validators/StringOrT.d.ts +3 -0
- package/lib/validators/StringOrT.js +15 -0
- package/package.json +1 -1
- package/src/content/Document.ts +2 -6
- package/src/customtypes/CustomType.ts +24 -97
- package/src/customtypes/Section.ts +28 -1
- package/src/customtypes/_internal/utils.ts +25 -0
- package/src/customtypes/widgets/Group.ts +24 -0
- package/src/customtypes/widgets/nestable/Link/ContentRelationshipResolver.ts +5 -54
- package/src/customtypes/widgets/nestable/Link/index.ts +2 -2
- package/src/customtypes/widgets/slices/CompositeSlice.ts +33 -0
- package/src/customtypes/widgets/slices/SharedSlice.ts +47 -0
- package/src/customtypes/widgets/slices/Slices.ts +44 -1
- package/src/validators/StringOrT.ts +21 -0
|
@@ -1,41 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.traverseCustomType = exports.filterMissingSharedSlices = exports.toStatic = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const Either_1 = require("fp-ts/lib/Either");
|
|
6
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
6
|
const withFallback_1 = require("io-ts-types/lib/withFallback");
|
|
8
7
|
const validators_1 = require("../validators");
|
|
8
|
+
const utils_1 = require("./_internal/utils");
|
|
9
9
|
const Section_1 = require("./Section");
|
|
10
10
|
exports.CustomTypeFormat = {
|
|
11
11
|
page: "page",
|
|
12
12
|
custom: "custom",
|
|
13
13
|
};
|
|
14
|
-
class CustomTypeSlicesError extends Error {
|
|
15
|
-
constructor(slices) {
|
|
16
|
-
super();
|
|
17
|
-
Object.defineProperty(this, "slices", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: void 0
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(this, "message", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: void 0
|
|
28
|
-
});
|
|
29
|
-
this.slices = slices;
|
|
30
|
-
this.message = this._formatError(slices);
|
|
31
|
-
}
|
|
32
|
-
_formatError(slicesRefs) {
|
|
33
|
-
const slicesMsg = slicesRefs.map((ref) => `\t - ${ref}`);
|
|
34
|
-
return `The following slices doesn't exists in your Prismic repository:
|
|
35
|
-
${slicesMsg.join("\n")}
|
|
36
|
-
`;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
14
|
function customTypeReader(codec) {
|
|
40
15
|
return t.exact(t.intersection([
|
|
41
16
|
t.type({
|
|
@@ -60,24 +35,6 @@ function flattenWidgets(customType) {
|
|
|
60
35
|
}, []);
|
|
61
36
|
}
|
|
62
37
|
exports.flattenWidgets = flattenWidgets;
|
|
63
|
-
function _retrieveSharedSlicesRef(customType) {
|
|
64
|
-
const slicezones = flattenWidgets(customType).filter(([, widget]) => widget.type === "Slices");
|
|
65
|
-
const allSharedRefs = slicezones.reduce((acc, [, slicezone]) => {
|
|
66
|
-
const sharedRefs = Object.entries(slicezone.config && slicezone.config.choices
|
|
67
|
-
? slicezone.config.choices
|
|
68
|
-
: {})
|
|
69
|
-
.filter(([, slice]) => slice.type === "SharedSlice")
|
|
70
|
-
.map(([key]) => key);
|
|
71
|
-
return acc.concat(sharedRefs);
|
|
72
|
-
}, []);
|
|
73
|
-
return allSharedRefs;
|
|
74
|
-
}
|
|
75
|
-
function _mapSharedSlicesRefs(customType) {
|
|
76
|
-
const refs = _retrieveSharedSlicesRef(customType);
|
|
77
|
-
return function (mapFn) {
|
|
78
|
-
return refs.map(mapFn);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
38
|
function toStatic(customType, sharedSlices) {
|
|
82
39
|
const json = Object.entries(customType.json).reduce((acc, [sectionKey, dynSection]) => {
|
|
83
40
|
return {
|
|
@@ -88,36 +45,8 @@ function toStatic(customType, sharedSlices) {
|
|
|
88
45
|
return { ...customType, json };
|
|
89
46
|
}
|
|
90
47
|
exports.toStatic = toStatic;
|
|
91
|
-
function validateSlices(customType, sharedSlices) {
|
|
92
|
-
const missingSlices = _mapSharedSlicesRefs(customType)((ref) => {
|
|
93
|
-
const slice = sharedSlices.get(ref);
|
|
94
|
-
const isMissing = !slice;
|
|
95
|
-
if (isMissing)
|
|
96
|
-
return ref;
|
|
97
|
-
return;
|
|
98
|
-
}).filter(Boolean);
|
|
99
|
-
if (missingSlices.length > 0)
|
|
100
|
-
return (0, Either_1.left)(new CustomTypeSlicesError(missingSlices));
|
|
101
|
-
else
|
|
102
|
-
return (0, Either_1.right)(customType);
|
|
103
|
-
}
|
|
104
|
-
exports.validateSlices = validateSlices;
|
|
105
|
-
function collectWidgets(customType, f) {
|
|
106
|
-
const json = Object.entries(customType.json).reduce((acc, [sectionId, section]) => {
|
|
107
|
-
const updatedSection = Object.entries(section).reduce((acc, [ref, widget]) => {
|
|
108
|
-
const updatedWidget = f(ref, widget);
|
|
109
|
-
if (updatedWidget) {
|
|
110
|
-
return { ...acc, [ref]: updatedWidget };
|
|
111
|
-
}
|
|
112
|
-
return acc;
|
|
113
|
-
}, {});
|
|
114
|
-
return { ...acc, [sectionId]: updatedSection };
|
|
115
|
-
}, {});
|
|
116
|
-
return { ...customType, json };
|
|
117
|
-
}
|
|
118
|
-
exports.collectWidgets = collectWidgets;
|
|
119
48
|
function filterMissingSharedSlices(customType, sharedSlices) {
|
|
120
|
-
return
|
|
49
|
+
return traverseCustomType(customType, (widget) => {
|
|
121
50
|
if (widget.type === "Slices") {
|
|
122
51
|
if (!widget.config || !widget.config.choices)
|
|
123
52
|
return widget;
|
|
@@ -133,3 +62,13 @@ function filterMissingSharedSlices(customType, sharedSlices) {
|
|
|
133
62
|
});
|
|
134
63
|
}
|
|
135
64
|
exports.filterMissingSharedSlices = filterMissingSharedSlices;
|
|
65
|
+
function traverseCustomType(customType, f) {
|
|
66
|
+
const ctEntries = Object.entries(customType.json).map(([sectionId, section]) => {
|
|
67
|
+
return [sectionId, (0, Section_1.traverseSection)([sectionId], section, f)];
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
...customType,
|
|
71
|
+
json: (0, utils_1.fromEntriesWithValue)(ctEntries),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.traverseCustomType = traverseCustomType;
|