@prismicio/types-internal 0.1.0 → 0.1.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/dist/customtypes/CustomType.d.ts +2703 -0
- package/dist/customtypes/CustomType.js +141 -0
- package/dist/customtypes/Format.d.ts +4 -0
- package/dist/customtypes/Format.js +8 -0
- package/dist/customtypes/Section.d.ts +4010 -0
- package/dist/customtypes/Section.js +40 -0
- package/dist/customtypes/index.d.ts +4 -18433
- package/dist/customtypes/index.js +30 -864
- package/dist/customtypes/widgets/Group.d.ts +172 -0
- package/dist/customtypes/widgets/Group.js +45 -0
- package/dist/customtypes/widgets/UID.d.ts +14 -0
- package/dist/customtypes/widgets/UID.js +42 -0
- package/dist/customtypes/widgets/Widget.d.ts +4011 -0
- package/dist/customtypes/widgets/Widget.js +51 -0
- package/dist/customtypes/widgets/WidgetTypes.d.ts +22 -0
- package/dist/customtypes/widgets/WidgetTypes.js +26 -0
- package/dist/customtypes/widgets/index.d.ts +7 -11697
- package/dist/customtypes/widgets/index.js +34 -734
- package/dist/customtypes/widgets/nestable/BooleanField.d.ts +14 -0
- package/dist/customtypes/widgets/nestable/BooleanField.js +42 -0
- package/dist/customtypes/widgets/nestable/Color.d.ts +13 -0
- package/dist/customtypes/widgets/nestable/Color.js +41 -0
- package/dist/customtypes/widgets/nestable/Date.d.ts +14 -0
- package/dist/customtypes/widgets/nestable/Date.js +42 -0
- package/dist/customtypes/widgets/nestable/Embed.d.ts +14 -0
- package/dist/customtypes/widgets/nestable/Embed.js +42 -0
- package/dist/customtypes/widgets/nestable/GeoPoint.d.ts +12 -0
- package/dist/customtypes/widgets/nestable/GeoPoint.js +40 -0
- package/dist/customtypes/widgets/nestable/Image.d.ts +23 -0
- package/dist/customtypes/widgets/nestable/Image.js +50 -0
- package/dist/customtypes/widgets/nestable/IntegrationField.d.ts +14 -0
- package/dist/customtypes/widgets/nestable/IntegrationField.js +42 -0
- package/dist/customtypes/widgets/nestable/Link.d.ts +19 -0
- package/dist/customtypes/widgets/nestable/Link.js +78 -0
- package/dist/customtypes/widgets/nestable/NestableWidget.d.ts +160 -0
- package/dist/customtypes/widgets/nestable/NestableWidget.js +58 -0
- package/dist/customtypes/widgets/nestable/Number.d.ts +16 -0
- package/dist/customtypes/widgets/nestable/Number.js +45 -0
- package/dist/customtypes/widgets/nestable/Range.d.ts +16 -0
- package/dist/customtypes/widgets/nestable/Range.js +45 -0
- package/dist/customtypes/widgets/nestable/RichText.d.ts +22 -0
- package/dist/customtypes/widgets/nestable/RichText.js +134 -0
- package/dist/customtypes/widgets/nestable/Select.d.ts +15 -0
- package/dist/customtypes/widgets/nestable/Select.js +45 -0
- package/dist/customtypes/widgets/nestable/Separator.d.ts +11 -0
- package/dist/customtypes/widgets/nestable/Separator.js +39 -0
- package/dist/customtypes/widgets/nestable/Text.d.ts +14 -0
- package/dist/customtypes/widgets/nestable/Text.js +42 -0
- package/dist/customtypes/widgets/nestable/Timestamp.d.ts +14 -0
- package/dist/customtypes/widgets/nestable/Timestamp.js +42 -0
- package/dist/customtypes/widgets/nestable/index.d.ts +15 -0
- package/dist/customtypes/widgets/nestable/index.js +36 -0
- package/dist/customtypes/widgets/shared/ImageConstraint.d.ts +7 -0
- package/dist/customtypes/widgets/shared/ImageConstraint.js +48 -0
- package/dist/customtypes/widgets/shared/index.d.ts +1 -0
- package/dist/customtypes/widgets/shared/index.js +8 -0
- package/dist/customtypes/widgets/slices/CompositeSlice.d.ts +329 -0
- package/dist/customtypes/widgets/slices/CompositeSlice.js +46 -0
- package/dist/customtypes/widgets/slices/LegacySlice.d.ts +336 -0
- package/dist/customtypes/widgets/slices/LegacySlice.js +34 -0
- package/dist/customtypes/widgets/slices/SharedSlice.d.ts +335 -0
- package/dist/customtypes/widgets/slices/SharedSlice.js +56 -0
- package/dist/customtypes/widgets/slices/SharedSliceRef.d.ts +7 -0
- package/dist/customtypes/widgets/slices/SharedSliceRef.js +30 -0
- package/dist/customtypes/widgets/slices/Slice.d.ts +6 -0
- package/dist/customtypes/widgets/slices/Slice.js +2 -0
- package/dist/customtypes/widgets/slices/Slices.d.ts +6009 -0
- package/dist/customtypes/widgets/slices/Slices.js +106 -0
- package/dist/customtypes/widgets/slices/SlicesTypes.d.ts +5 -0
- package/dist/customtypes/widgets/slices/SlicesTypes.js +8 -0
- package/dist/customtypes/widgets/slices/index.d.ts +7 -7079
- package/dist/customtypes/widgets/slices/index.js +36 -670
- package/dist/index.d.ts +1 -18455
- package/dist/index.js +23 -844
- package/dist/index.js.map +1 -1
- package/dist/validators/IntFromNumber.d.ts +7 -0
- package/dist/validators/IntFromNumber.js +35 -0
- package/dist/validators/IntFromPixels.d.ts +7 -0
- package/dist/validators/IntFromPixels.js +43 -0
- package/dist/validators/StringFromBoolean.d.ts +7 -0
- package/dist/validators/StringFromBoolean.js +31 -0
- package/dist/validators/StringFromNumber.d.ts +7 -0
- package/dist/validators/StringFromNumber.js +31 -0
- package/dist/validators/StringOrNull.d.ts +2 -0
- package/dist/validators/StringOrNull.js +24 -0
- package/package.json +4 -24
- package/dist/customtypes/index.cjs +0 -864
- package/dist/customtypes/index.cjs.map +0 -1
- package/dist/customtypes/index.d.ts.map +0 -1
- package/dist/customtypes/index.js.map +0 -1
- package/dist/customtypes/widgets/index.cjs +0 -735
- package/dist/customtypes/widgets/index.cjs.map +0 -1
- package/dist/customtypes/widgets/index.d.ts.map +0 -1
- package/dist/customtypes/widgets/index.js.map +0 -1
- package/dist/customtypes/widgets/slices/index.cjs +0 -671
- package/dist/customtypes/widgets/slices/index.cjs.map +0 -1
- package/dist/customtypes/widgets/slices/index.d.ts.map +0 -1
- package/dist/customtypes/widgets/slices/index.js.map +0 -1
- package/dist/index.cjs +0 -870
- package/dist/index.cjs.map +0 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.CustomType = exports.StaticCustomType = void 0;
|
|
26
|
+
const t = __importStar(require("io-ts"));
|
|
27
|
+
const StringOrNull_1 = require("../validators/StringOrNull");
|
|
28
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
29
|
+
const withFallback_1 = require("io-ts-types/lib/withFallback");
|
|
30
|
+
const Format_1 = require("./Format");
|
|
31
|
+
const WidgetTypes_1 = __importDefault(require("./widgets/WidgetTypes"));
|
|
32
|
+
const SlicesTypes_1 = __importDefault(require("./widgets/slices/SlicesTypes"));
|
|
33
|
+
const Section_1 = require("./Section");
|
|
34
|
+
class CustomTypeSlicesError extends Error {
|
|
35
|
+
slices;
|
|
36
|
+
message;
|
|
37
|
+
constructor(slices) {
|
|
38
|
+
super();
|
|
39
|
+
this.slices = slices;
|
|
40
|
+
this.message = this._formatError(slices);
|
|
41
|
+
}
|
|
42
|
+
_formatError(slicesRefs) {
|
|
43
|
+
const slicesMsg = slicesRefs.map(ref => `\t - ${ref}`);
|
|
44
|
+
return (`The following slices doesn't exists in your Prismic repository:
|
|
45
|
+
${slicesMsg.join('\n')}
|
|
46
|
+
`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function customTypeReader(format) {
|
|
50
|
+
return t.exact(t.intersection([
|
|
51
|
+
t.type({
|
|
52
|
+
id: t.string,
|
|
53
|
+
label: StringOrNull_1.StringOrNull,
|
|
54
|
+
repeatable: (0, withFallback_1.withFallback)(t.boolean, true),
|
|
55
|
+
json: t.record(t.string, (0, Section_1.sectionReader)(format)),
|
|
56
|
+
status: (0, withFallback_1.withFallback)(t.boolean, true)
|
|
57
|
+
}),
|
|
58
|
+
t.partial({
|
|
59
|
+
hash: t.string
|
|
60
|
+
})
|
|
61
|
+
]));
|
|
62
|
+
}
|
|
63
|
+
exports.StaticCustomType = customTypeReader(Format_1.Format.Static);
|
|
64
|
+
exports.CustomType = customTypeReader(Format_1.Format.Dynamic);
|
|
65
|
+
function _retrieveSharedSlicesRef(customType) {
|
|
66
|
+
const flattenWidgets = Object.entries(customType.json)
|
|
67
|
+
.reduce((acc, [, section]) => {
|
|
68
|
+
const sectionWidgets = Object.entries(section);
|
|
69
|
+
return acc.concat(sectionWidgets);
|
|
70
|
+
}, []);
|
|
71
|
+
const slicezones = flattenWidgets.filter(([, widget]) => widget.type === WidgetTypes_1.default.Slices);
|
|
72
|
+
const allSharedRefs = slicezones.reduce((acc, [, slicezone]) => {
|
|
73
|
+
const sharedRefs = Object.entries(slicezone.config && slicezone.config.choices ? slicezone.config.choices : {})
|
|
74
|
+
.filter(([, slice]) => slice.type === SlicesTypes_1.default.SharedSlice)
|
|
75
|
+
.map(([key]) => key);
|
|
76
|
+
return acc.concat(sharedRefs);
|
|
77
|
+
}, []);
|
|
78
|
+
return allSharedRefs;
|
|
79
|
+
}
|
|
80
|
+
function _mapSharedSlicesRefs(customType) {
|
|
81
|
+
const refs = _retrieveSharedSlicesRef(customType);
|
|
82
|
+
return function (mapFn) {
|
|
83
|
+
return refs.map(mapFn);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function toStatic(customType, sharedSlices) {
|
|
87
|
+
const json = Object.entries(customType.json)
|
|
88
|
+
.reduce((acc, [sectionKey, dynSection]) => {
|
|
89
|
+
return { ...acc, [sectionKey]: Section_1.Sections.toStatic(dynSection, sharedSlices) };
|
|
90
|
+
}, {});
|
|
91
|
+
return { ...customType, json };
|
|
92
|
+
}
|
|
93
|
+
exports.toStatic = toStatic;
|
|
94
|
+
function validateSlices(customType, sharedSlices) {
|
|
95
|
+
const missingSlices = _mapSharedSlicesRefs(customType)((ref) => {
|
|
96
|
+
const slice = sharedSlices.get(ref);
|
|
97
|
+
const isMissing = !Boolean(slice);
|
|
98
|
+
if (isMissing)
|
|
99
|
+
return ref;
|
|
100
|
+
}).filter(Boolean);
|
|
101
|
+
if (missingSlices.length > 0)
|
|
102
|
+
return (0, Either_1.left)(new CustomTypeSlicesError(missingSlices));
|
|
103
|
+
else
|
|
104
|
+
return (0, Either_1.right)(customType);
|
|
105
|
+
}
|
|
106
|
+
exports.validateSlices = validateSlices;
|
|
107
|
+
function collectWidgets(customType, f) {
|
|
108
|
+
const json = Object.entries(customType.json)
|
|
109
|
+
.reduce((acc, [sectionId, section]) => {
|
|
110
|
+
const updatedSection = Object
|
|
111
|
+
.entries(section)
|
|
112
|
+
.reduce((acc, [ref, widget]) => {
|
|
113
|
+
const updatedWidget = f(ref, widget);
|
|
114
|
+
if (!!updatedWidget) {
|
|
115
|
+
return { ...acc, [ref]: updatedWidget };
|
|
116
|
+
}
|
|
117
|
+
return acc;
|
|
118
|
+
}, {});
|
|
119
|
+
return { ...acc, [sectionId]: updatedSection };
|
|
120
|
+
}, {});
|
|
121
|
+
return { ...customType, json };
|
|
122
|
+
}
|
|
123
|
+
exports.collectWidgets = collectWidgets;
|
|
124
|
+
function filterMissingSharedSlices(customType, sharedSlices) {
|
|
125
|
+
return collectWidgets(customType, (_widgetId, widget) => {
|
|
126
|
+
if (widget.type === WidgetTypes_1.default.Slices) {
|
|
127
|
+
if (!widget.config || !widget.config.choices)
|
|
128
|
+
return widget;
|
|
129
|
+
const choices = Object.entries(widget.config.choices)
|
|
130
|
+
.reduce((acc, [sliceId, sliceValue]) => {
|
|
131
|
+
if (sliceValue.type === SlicesTypes_1.default.SharedSlice && !sharedSlices.get(sliceId))
|
|
132
|
+
return acc;
|
|
133
|
+
return { ...acc, [sliceId]: sliceValue };
|
|
134
|
+
}, {});
|
|
135
|
+
const config = { ...widget.config, choices };
|
|
136
|
+
return { ...widget, config };
|
|
137
|
+
}
|
|
138
|
+
return widget;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
exports.filterMissingSharedSlices = filterMissingSharedSlices;
|