@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.
Files changed (100) hide show
  1. package/dist/customtypes/CustomType.d.ts +2703 -0
  2. package/dist/customtypes/CustomType.js +141 -0
  3. package/dist/customtypes/Format.d.ts +4 -0
  4. package/dist/customtypes/Format.js +8 -0
  5. package/dist/customtypes/Section.d.ts +4010 -0
  6. package/dist/customtypes/Section.js +40 -0
  7. package/dist/customtypes/index.d.ts +4 -18433
  8. package/dist/customtypes/index.js +30 -864
  9. package/dist/customtypes/widgets/Group.d.ts +172 -0
  10. package/dist/customtypes/widgets/Group.js +45 -0
  11. package/dist/customtypes/widgets/UID.d.ts +14 -0
  12. package/dist/customtypes/widgets/UID.js +42 -0
  13. package/dist/customtypes/widgets/Widget.d.ts +4011 -0
  14. package/dist/customtypes/widgets/Widget.js +51 -0
  15. package/dist/customtypes/widgets/WidgetTypes.d.ts +22 -0
  16. package/dist/customtypes/widgets/WidgetTypes.js +26 -0
  17. package/dist/customtypes/widgets/index.d.ts +7 -11697
  18. package/dist/customtypes/widgets/index.js +34 -734
  19. package/dist/customtypes/widgets/nestable/BooleanField.d.ts +14 -0
  20. package/dist/customtypes/widgets/nestable/BooleanField.js +42 -0
  21. package/dist/customtypes/widgets/nestable/Color.d.ts +13 -0
  22. package/dist/customtypes/widgets/nestable/Color.js +41 -0
  23. package/dist/customtypes/widgets/nestable/Date.d.ts +14 -0
  24. package/dist/customtypes/widgets/nestable/Date.js +42 -0
  25. package/dist/customtypes/widgets/nestable/Embed.d.ts +14 -0
  26. package/dist/customtypes/widgets/nestable/Embed.js +42 -0
  27. package/dist/customtypes/widgets/nestable/GeoPoint.d.ts +12 -0
  28. package/dist/customtypes/widgets/nestable/GeoPoint.js +40 -0
  29. package/dist/customtypes/widgets/nestable/Image.d.ts +23 -0
  30. package/dist/customtypes/widgets/nestable/Image.js +50 -0
  31. package/dist/customtypes/widgets/nestable/IntegrationField.d.ts +14 -0
  32. package/dist/customtypes/widgets/nestable/IntegrationField.js +42 -0
  33. package/dist/customtypes/widgets/nestable/Link.d.ts +19 -0
  34. package/dist/customtypes/widgets/nestable/Link.js +78 -0
  35. package/dist/customtypes/widgets/nestable/NestableWidget.d.ts +160 -0
  36. package/dist/customtypes/widgets/nestable/NestableWidget.js +58 -0
  37. package/dist/customtypes/widgets/nestable/Number.d.ts +16 -0
  38. package/dist/customtypes/widgets/nestable/Number.js +45 -0
  39. package/dist/customtypes/widgets/nestable/Range.d.ts +16 -0
  40. package/dist/customtypes/widgets/nestable/Range.js +45 -0
  41. package/dist/customtypes/widgets/nestable/RichText.d.ts +22 -0
  42. package/dist/customtypes/widgets/nestable/RichText.js +134 -0
  43. package/dist/customtypes/widgets/nestable/Select.d.ts +15 -0
  44. package/dist/customtypes/widgets/nestable/Select.js +45 -0
  45. package/dist/customtypes/widgets/nestable/Separator.d.ts +11 -0
  46. package/dist/customtypes/widgets/nestable/Separator.js +39 -0
  47. package/dist/customtypes/widgets/nestable/Text.d.ts +14 -0
  48. package/dist/customtypes/widgets/nestable/Text.js +42 -0
  49. package/dist/customtypes/widgets/nestable/Timestamp.d.ts +14 -0
  50. package/dist/customtypes/widgets/nestable/Timestamp.js +42 -0
  51. package/dist/customtypes/widgets/nestable/index.d.ts +15 -0
  52. package/dist/customtypes/widgets/nestable/index.js +36 -0
  53. package/dist/customtypes/widgets/shared/ImageConstraint.d.ts +7 -0
  54. package/dist/customtypes/widgets/shared/ImageConstraint.js +48 -0
  55. package/dist/customtypes/widgets/shared/index.d.ts +1 -0
  56. package/dist/customtypes/widgets/shared/index.js +8 -0
  57. package/dist/customtypes/widgets/slices/CompositeSlice.d.ts +329 -0
  58. package/dist/customtypes/widgets/slices/CompositeSlice.js +46 -0
  59. package/dist/customtypes/widgets/slices/LegacySlice.d.ts +336 -0
  60. package/dist/customtypes/widgets/slices/LegacySlice.js +34 -0
  61. package/dist/customtypes/widgets/slices/SharedSlice.d.ts +335 -0
  62. package/dist/customtypes/widgets/slices/SharedSlice.js +56 -0
  63. package/dist/customtypes/widgets/slices/SharedSliceRef.d.ts +7 -0
  64. package/dist/customtypes/widgets/slices/SharedSliceRef.js +30 -0
  65. package/dist/customtypes/widgets/slices/Slice.d.ts +6 -0
  66. package/dist/customtypes/widgets/slices/Slice.js +2 -0
  67. package/dist/customtypes/widgets/slices/Slices.d.ts +6009 -0
  68. package/dist/customtypes/widgets/slices/Slices.js +106 -0
  69. package/dist/customtypes/widgets/slices/SlicesTypes.d.ts +5 -0
  70. package/dist/customtypes/widgets/slices/SlicesTypes.js +8 -0
  71. package/dist/customtypes/widgets/slices/index.d.ts +7 -7079
  72. package/dist/customtypes/widgets/slices/index.js +36 -670
  73. package/dist/index.d.ts +1 -18455
  74. package/dist/index.js +23 -844
  75. package/dist/index.js.map +1 -1
  76. package/dist/validators/IntFromNumber.d.ts +7 -0
  77. package/dist/validators/IntFromNumber.js +35 -0
  78. package/dist/validators/IntFromPixels.d.ts +7 -0
  79. package/dist/validators/IntFromPixels.js +43 -0
  80. package/dist/validators/StringFromBoolean.d.ts +7 -0
  81. package/dist/validators/StringFromBoolean.js +31 -0
  82. package/dist/validators/StringFromNumber.d.ts +7 -0
  83. package/dist/validators/StringFromNumber.js +31 -0
  84. package/dist/validators/StringOrNull.d.ts +2 -0
  85. package/dist/validators/StringOrNull.js +24 -0
  86. package/package.json +4 -24
  87. package/dist/customtypes/index.cjs +0 -864
  88. package/dist/customtypes/index.cjs.map +0 -1
  89. package/dist/customtypes/index.d.ts.map +0 -1
  90. package/dist/customtypes/index.js.map +0 -1
  91. package/dist/customtypes/widgets/index.cjs +0 -735
  92. package/dist/customtypes/widgets/index.cjs.map +0 -1
  93. package/dist/customtypes/widgets/index.d.ts.map +0 -1
  94. package/dist/customtypes/widgets/index.js.map +0 -1
  95. package/dist/customtypes/widgets/slices/index.cjs +0 -671
  96. package/dist/customtypes/widgets/slices/index.cjs.map +0 -1
  97. package/dist/customtypes/widgets/slices/index.d.ts.map +0 -1
  98. package/dist/customtypes/widgets/slices/index.js.map +0 -1
  99. package/dist/index.cjs +0 -870
  100. 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;
@@ -0,0 +1,4 @@
1
+ export declare enum Format {
2
+ Static = "static",
3
+ Dynamic = "dynamic"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Format = void 0;
4
+ var Format;
5
+ (function (Format) {
6
+ Format["Static"] = "static";
7
+ Format["Dynamic"] = "dynamic";
8
+ })(Format = exports.Format || (exports.Format = {}));