@prismicio/types-internal 2.1.0-alpha.4 → 2.2.0-alpha.1
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/common/HexaColorCode.d.ts +4 -0
- package/lib/common/HexaColorCode.js +7 -0
- package/lib/content/Document.d.ts +1 -1
- package/lib/customtypes/CustomType.d.ts +875 -923
- package/lib/customtypes/CustomType.js +74 -13
- package/lib/customtypes/Section.d.ts +866 -924
- package/lib/customtypes/Section.js +1 -23
- package/lib/customtypes/diff/SharedSlice.d.ts +168 -184
- package/lib/customtypes/diff/Variation.d.ts +167 -183
- package/lib/customtypes/widgets/Group.d.ts +2 -20
- package/lib/customtypes/widgets/Group.js +1 -20
- package/lib/customtypes/widgets/Widget.d.ts +733 -821
- package/lib/customtypes/widgets/nestable/{Link/index.d.ts → Link.d.ts} +2 -19
- package/lib/customtypes/widgets/nestable/{Link/index.js → Link.js} +2 -4
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +158 -9
- package/lib/customtypes/widgets/nestable/NestableWidget.js +17 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -20
- package/lib/customtypes/widgets/slices/CompositeSlice.js +1 -26
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -18
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +4 -38
- package/lib/customtypes/widgets/slices/SharedSlice.js +1 -35
- package/lib/customtypes/widgets/slices/Slices.d.ts +801 -947
- package/lib/customtypes/widgets/slices/Slices.js +1 -34
- package/lib/import/converters/Document.d.ts +3 -0
- package/lib/import/converters/Document.js +17 -0
- package/lib/import/converters/fields/index.d.ts +1 -0
- package/lib/import/converters/fields/index.js +4 -0
- package/lib/import/converters/fields/nestable/Color.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Color.js +10 -0
- package/lib/import/converters/fields/nestable/Date.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Date.js +15 -0
- package/lib/import/converters/fields/nestable/Nestable.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Nestable.js +23 -0
- package/lib/import/converters/fields/nestable/Number.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Number.js +10 -0
- package/lib/import/converters/fields/nestable/Select.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Select.js +10 -0
- package/lib/import/converters/fields/nestable/Text.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Text.js +10 -0
- package/lib/import/converters/fields/nestable/Timestamp.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Timestamp.js +10 -0
- package/lib/import/converters/fields/nestable/index.d.ts +7 -0
- package/lib/import/converters/fields/nestable/index.js +10 -0
- package/lib/import/converters/fields/utils.d.ts +1 -0
- package/lib/import/converters/fields/utils.js +10 -0
- package/lib/import/converters/index.d.ts +2 -0
- package/lib/import/converters/index.js +5 -0
- package/lib/import/index.d.ts +2 -0
- package/lib/import/index.js +5 -0
- package/lib/import/validators/Document.d.ts +6 -0
- package/lib/import/validators/Document.js +72 -0
- package/lib/import/validators/fields/index.d.ts +6 -0
- package/lib/import/validators/fields/index.js +4 -0
- package/lib/import/validators/fields/nestable/Color.d.ts +5 -0
- package/lib/import/validators/fields/nestable/Color.js +15 -0
- package/lib/import/validators/fields/nestable/Date.d.ts +4 -0
- package/lib/import/validators/fields/nestable/Date.js +17 -0
- package/lib/import/validators/fields/nestable/Nestable.d.ts +9 -0
- package/lib/import/validators/fields/nestable/Nestable.js +34 -0
- package/lib/import/validators/fields/nestable/Number.d.ts +10 -0
- package/lib/import/validators/fields/nestable/Number.js +16 -0
- package/lib/import/validators/fields/nestable/Select.d.ts +9 -0
- package/lib/import/validators/fields/nestable/Select.js +17 -0
- package/lib/import/validators/fields/nestable/Text.d.ts +3 -0
- package/lib/import/validators/fields/nestable/Text.js +5 -0
- package/lib/import/validators/fields/nestable/Timestamp.d.ts +5 -0
- package/lib/import/validators/fields/nestable/Timestamp.js +17 -0
- package/lib/import/validators/fields/nestable/index.d.ts +7 -0
- package/lib/import/validators/fields/nestable/index.js +10 -0
- package/lib/import/validators/index.d.ts +2 -0
- package/lib/import/validators/index.js +5 -0
- package/lib/utils/Objects.d.ts +1 -0
- package/lib/utils/Objects.js +9 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +2 -1
- package/lib/validators/BasicTypes.d.ts +3 -0
- package/lib/validators/BasicTypes.js +8 -0
- package/lib/validators/DateFromString.js +2 -1
- package/lib/validators/NullOrT.d.ts +2 -0
- package/lib/validators/NullOrT.js +13 -0
- package/lib/validators/index.d.ts +2 -0
- package/lib/validators/index.js +2 -0
- package/package.json +1 -1
- package/src/common/HexaColorCode.ts +11 -0
- package/src/customtypes/CustomType.ts +97 -24
- package/src/customtypes/Section.ts +1 -28
- package/src/customtypes/widgets/Group.ts +0 -24
- package/src/customtypes/widgets/nestable/{Link/index.ts → Link.ts} +2 -5
- package/src/customtypes/widgets/nestable/NestableWidget.ts +17 -0
- package/src/customtypes/widgets/slices/CompositeSlice.ts +0 -33
- package/src/customtypes/widgets/slices/SharedSlice.ts +0 -47
- package/src/customtypes/widgets/slices/Slices.ts +1 -44
- package/src/import/converters/Document.ts +22 -0
- package/src/import/converters/fields/index.ts +1 -0
- package/src/import/converters/fields/nestable/Color.ts +12 -0
- package/src/import/converters/fields/nestable/Date.ts +18 -0
- package/src/import/converters/fields/nestable/Nestable.ts +33 -0
- package/src/import/converters/fields/nestable/Number.ts +12 -0
- package/src/import/converters/fields/nestable/Select.ts +12 -0
- package/src/import/converters/fields/nestable/Text.ts +12 -0
- package/src/import/converters/fields/nestable/Timestamp.ts +12 -0
- package/src/import/converters/fields/nestable/index.ts +7 -0
- package/src/import/converters/fields/utils.ts +7 -0
- package/src/import/converters/index.ts +2 -0
- package/src/import/index.ts +2 -0
- package/src/import/validators/Document.ts +96 -0
- package/src/import/validators/fields/index.ts +8 -0
- package/src/import/validators/fields/nestable/Color.ts +28 -0
- package/src/import/validators/fields/nestable/Date.ts +35 -0
- package/src/import/validators/fields/nestable/Nestable.ts +41 -0
- package/src/import/validators/fields/nestable/Number.ts +36 -0
- package/src/import/validators/fields/nestable/Select.ts +36 -0
- package/src/import/validators/fields/nestable/Text.ts +7 -0
- package/src/import/validators/fields/nestable/Timestamp.ts +36 -0
- package/src/import/validators/fields/nestable/index.ts +7 -0
- package/src/import/validators/index.ts +2 -0
- package/src/utils/Objects.ts +8 -0
- package/src/utils/index.ts +1 -0
- package/src/validators/BasicTypes.ts +5 -0
- package/src/validators/DateFromString.ts +3 -1
- package/src/validators/NullOrT.ts +18 -0
- package/src/validators/index.ts +2 -0
- package/lib/customtypes/_internal/utils.d.ts +0 -3
- package/lib/customtypes/_internal/utils.js +0 -20
- package/lib/customtypes/widgets/nestable/Link/ContentRelationshipResolver.d.ts +0 -11
- package/lib/customtypes/widgets/nestable/Link/ContentRelationshipResolver.js +0 -15
- package/lib/validators/StringOrT.d.ts +0 -3
- package/lib/validators/StringOrT.js +0 -15
- package/src/customtypes/_internal/utils.ts +0 -25
- package/src/customtypes/widgets/nestable/Link/ContentRelationshipResolver.ts +0 -20
- package/src/validators/StringOrT.ts +0 -21
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = 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");
|
|
5
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
7
|
const withFallback_1 = require("io-ts-types/lib/withFallback");
|
|
7
8
|
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
|
+
}
|
|
14
39
|
function customTypeReader(codec) {
|
|
15
40
|
return t.exact(t.intersection([
|
|
16
41
|
t.type({
|
|
@@ -35,6 +60,24 @@ function flattenWidgets(customType) {
|
|
|
35
60
|
}, []);
|
|
36
61
|
}
|
|
37
62
|
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
|
+
}
|
|
38
81
|
function toStatic(customType, sharedSlices) {
|
|
39
82
|
const json = Object.entries(customType.json).reduce((acc, [sectionKey, dynSection]) => {
|
|
40
83
|
return {
|
|
@@ -45,8 +88,36 @@ function toStatic(customType, sharedSlices) {
|
|
|
45
88
|
return { ...customType, json };
|
|
46
89
|
}
|
|
47
90
|
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;
|
|
48
119
|
function filterMissingSharedSlices(customType, sharedSlices) {
|
|
49
|
-
return
|
|
120
|
+
return collectWidgets(customType, (_widgetId, widget) => {
|
|
50
121
|
if (widget.type === "Slices") {
|
|
51
122
|
if (!widget.config || !widget.config.choices)
|
|
52
123
|
return widget;
|
|
@@ -62,13 +133,3 @@ function filterMissingSharedSlices(customType, sharedSlices) {
|
|
|
62
133
|
});
|
|
63
134
|
}
|
|
64
135
|
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;
|