@prismicio/types-internal 3.16.0 → 3.16.1-alpha.0
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/fields/RepeatableContent.d.ts +51 -123
- package/lib/content/fields/RepeatableContent.js +10 -14
- package/lib/content/fields/nestable/RichTextContent/Block.d.ts +1036 -0
- package/lib/content/fields/nestable/RichTextContent/Block.js +31 -0
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.d.ts +60 -0
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.js +53 -0
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.d.ts +203 -0
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.js +36 -0
- package/lib/content/fields/nestable/RichTextContent/TableBlock.d.ts +500 -0
- package/lib/content/fields/nestable/RichTextContent/TableBlock.js +21 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +590 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +80 -0
- package/lib/scripts/release.d.ts +1 -0
- package/lib/scripts/release.js +34 -0
- package/lib/src/_internal/utils.d.ts +36 -0
- package/lib/src/_internal/utils.js +20 -0
- package/lib/src/common/Asset.d.ts +16 -0
- package/lib/src/common/Asset.js +11 -0
- package/lib/src/common/Embed.d.ts +15 -0
- package/lib/src/common/Embed.js +10 -0
- package/lib/src/common/HexaColorCode.d.ts +4 -0
- package/lib/src/common/HexaColorCode.js +7 -0
- package/lib/src/common/UUID.d.ts +6 -0
- package/lib/src/common/UUID.js +8 -0
- package/lib/src/common/WidgetKey.d.ts +3 -0
- package/lib/src/common/WidgetKey.js +8 -0
- package/lib/src/common/index.d.ts +3 -0
- package/lib/src/common/index.js +6 -0
- package/lib/src/content/Document.d.ts +11803 -0
- package/lib/src/content/Document.js +266 -0
- package/lib/src/content/LegacyContentCtx.d.ts +64 -0
- package/lib/src/content/LegacyContentCtx.js +130 -0
- package/lib/src/content/fields/EmptyContent.d.ts +16 -0
- package/lib/src/content/fields/EmptyContent.js +30 -0
- package/lib/src/content/fields/GroupContent.d.ts +42 -0
- package/lib/src/content/fields/GroupContent.js +208 -0
- package/lib/src/content/fields/UIDContent.d.ts +16 -0
- package/lib/src/content/fields/UIDContent.js +25 -0
- package/lib/src/content/fields/WidgetContent.d.ts +11749 -0
- package/lib/src/content/fields/WidgetContent.js +57 -0
- package/lib/src/content/fields/index.d.ts +6 -0
- package/lib/src/content/fields/index.js +9 -0
- package/lib/src/content/fields/nestable/BooleanContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/BooleanContent.js +35 -0
- package/lib/src/content/fields/nestable/EmbedContent.d.ts +78 -0
- package/lib/src/content/fields/nestable/EmbedContent.js +56 -0
- package/lib/src/content/fields/nestable/FieldContent/ColorContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/ColorContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/DateContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/DateContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/NumberContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/NumberContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/RangeContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/RangeContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/SelectContent.d.ts +20 -0
- package/lib/src/content/fields/nestable/FieldContent/SelectContent.js +46 -0
- package/lib/src/content/fields/nestable/FieldContent/TextContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/TextContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/TimestampContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/TimestampContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/common.d.ts +1 -0
- package/lib/src/content/fields/nestable/FieldContent/common.js +4 -0
- package/lib/src/content/fields/nestable/FieldContent/index.d.ts +49 -0
- package/lib/src/content/fields/nestable/FieldContent/index.js +38 -0
- package/lib/src/content/fields/nestable/GeoPointContent.d.ts +33 -0
- package/lib/src/content/fields/nestable/GeoPointContent.js +31 -0
- package/lib/src/content/fields/nestable/ImageContent.d.ts +227 -0
- package/lib/src/content/fields/nestable/ImageContent.js +73 -0
- package/lib/src/content/fields/nestable/IntegrationFieldContent.d.ts +16 -0
- package/lib/src/content/fields/nestable/IntegrationFieldContent.js +28 -0
- package/lib/src/content/fields/nestable/LinkContent.d.ts +919 -0
- package/lib/src/content/fields/nestable/LinkContent.js +399 -0
- package/lib/src/content/fields/nestable/NestableContent.d.ts +1953 -0
- package/lib/src/content/fields/nestable/NestableContent.js +167 -0
- package/lib/src/content/fields/nestable/RepeatableContent.d.ts +176 -0
- package/lib/src/content/fields/nestable/RepeatableContent.js +104 -0
- package/lib/src/content/fields/nestable/RichTextContent/Blocks.d.ts +1261 -0
- package/lib/src/content/fields/nestable/RichTextContent/Blocks.js +170 -0
- package/lib/src/content/fields/nestable/RichTextContent/index.d.ts +1004 -0
- package/lib/src/content/fields/nestable/RichTextContent/index.js +28 -0
- package/lib/src/content/fields/nestable/SeparatorContent.d.ts +13 -0
- package/lib/src/content/fields/nestable/SeparatorContent.js +22 -0
- package/lib/src/content/fields/nestable/TableContent.d.ts +770 -0
- package/lib/src/content/fields/nestable/TableContent.js +121 -0
- package/lib/src/content/fields/nestable/index.d.ts +12 -0
- package/lib/src/content/fields/nestable/index.js +15 -0
- package/lib/src/content/fields/slices/Slice/CompositeSliceContent.d.ts +3934 -0
- package/lib/src/content/fields/slices/Slice/CompositeSliceContent.js +195 -0
- package/lib/src/content/fields/slices/Slice/RepeatableContent.d.ts +774 -0
- package/lib/src/content/fields/slices/Slice/RepeatableContent.js +21 -0
- package/lib/src/content/fields/slices/Slice/SharedSliceContent.d.ts +3937 -0
- package/lib/src/content/fields/slices/Slice/SharedSliceContent.js +215 -0
- package/lib/src/content/fields/slices/Slice/SimpleSliceContent.d.ts +1962 -0
- package/lib/src/content/fields/slices/Slice/SimpleSliceContent.js +130 -0
- package/lib/src/content/fields/slices/Slice/SlicePrimaryContent.d.ts +1952 -0
- package/lib/src/content/fields/slices/Slice/SlicePrimaryContent.js +30 -0
- package/lib/src/content/fields/slices/Slice/index.d.ts +6810 -0
- package/lib/src/content/fields/slices/Slice/index.js +45 -0
- package/lib/src/content/fields/slices/SliceItem.d.ts +6846 -0
- package/lib/src/content/fields/slices/SliceItem.js +116 -0
- package/lib/src/content/fields/slices/SlicesContent.d.ts +9809 -0
- package/lib/src/content/fields/slices/SlicesContent.js +187 -0
- package/lib/src/content/fields/slices/index.d.ts +3 -0
- package/lib/src/content/fields/slices/index.js +6 -0
- package/lib/src/content/fields/withDefaultValues.d.ts +9 -0
- package/lib/src/content/fields/withDefaultValues.js +79 -0
- package/lib/src/content/index.d.ts +3 -0
- package/lib/src/content/index.js +6 -0
- package/lib/src/content/utils.d.ts +14 -0
- package/lib/src/content/utils.js +33 -0
- package/lib/src/customtypes/CustomType.d.ts +3680 -0
- package/lib/src/customtypes/CustomType.js +184 -0
- package/lib/src/customtypes/Section.d.ts +3635 -0
- package/lib/src/customtypes/Section.js +66 -0
- package/lib/src/customtypes/diff/Changes.d.ts +17 -0
- package/lib/src/customtypes/diff/Changes.js +9 -0
- package/lib/src/customtypes/diff/SharedSlice.d.ts +1624 -0
- package/lib/src/customtypes/diff/SharedSlice.js +55 -0
- package/lib/src/customtypes/diff/Variation.d.ts +1605 -0
- package/lib/src/customtypes/diff/Variation.js +113 -0
- package/lib/src/customtypes/diff/Widgets.d.ts +11 -0
- package/lib/src/customtypes/diff/Widgets.js +2 -0
- package/lib/src/customtypes/diff/index.d.ts +4 -0
- package/lib/src/customtypes/diff/index.js +7 -0
- package/lib/src/customtypes/index.d.ts +4 -0
- package/lib/src/customtypes/index.js +7 -0
- package/lib/src/customtypes/widgets/Group.d.ts +1352 -0
- package/lib/src/customtypes/widgets/Group.js +92 -0
- package/lib/src/customtypes/widgets/UID.d.ts +19 -0
- package/lib/src/customtypes/widgets/UID.js +21 -0
- package/lib/src/customtypes/widgets/Widget.d.ts +4457 -0
- package/lib/src/customtypes/widgets/Widget.js +49 -0
- package/lib/src/customtypes/widgets/index.d.ts +6 -0
- package/lib/src/customtypes/widgets/index.js +9 -0
- package/lib/src/customtypes/widgets/nestable/BooleanField.d.ts +20 -0
- package/lib/src/customtypes/widgets/nestable/BooleanField.js +21 -0
- package/lib/src/customtypes/widgets/nestable/Color.d.ts +17 -0
- package/lib/src/customtypes/widgets/nestable/Color.js +20 -0
- package/lib/src/customtypes/widgets/nestable/Date.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/Date.js +21 -0
- package/lib/src/customtypes/widgets/nestable/Embed.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/Embed.js +21 -0
- package/lib/src/customtypes/widgets/nestable/GeoPoint.d.ts +15 -0
- package/lib/src/customtypes/widgets/nestable/GeoPoint.js +19 -0
- package/lib/src/customtypes/widgets/nestable/Image.d.ts +44 -0
- package/lib/src/customtypes/widgets/nestable/Image.js +29 -0
- package/lib/src/customtypes/widgets/nestable/IntegrationField.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/IntegrationField.js +21 -0
- package/lib/src/customtypes/widgets/nestable/Link.d.ts +196 -0
- package/lib/src/customtypes/widgets/nestable/Link.js +167 -0
- package/lib/src/customtypes/widgets/nestable/NestableWidget.d.ts +217 -0
- package/lib/src/customtypes/widgets/nestable/NestableWidget.js +39 -0
- package/lib/src/customtypes/widgets/nestable/Number.d.ts +23 -0
- package/lib/src/customtypes/widgets/nestable/Number.js +24 -0
- package/lib/src/customtypes/widgets/nestable/Range.d.ts +23 -0
- package/lib/src/customtypes/widgets/nestable/Range.js +24 -0
- package/lib/src/customtypes/widgets/nestable/RichText.d.ts +73 -0
- package/lib/src/customtypes/widgets/nestable/RichText.js +131 -0
- package/lib/src/customtypes/widgets/nestable/Select.d.ts +21 -0
- package/lib/src/customtypes/widgets/nestable/Select.js +22 -0
- package/lib/src/customtypes/widgets/nestable/Separator.d.ts +14 -0
- package/lib/src/customtypes/widgets/nestable/Separator.js +18 -0
- package/lib/src/customtypes/widgets/nestable/Table.d.ts +21 -0
- package/lib/src/customtypes/widgets/nestable/Table.js +30 -0
- package/lib/src/customtypes/widgets/nestable/Text.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/Text.js +21 -0
- package/lib/src/customtypes/widgets/nestable/Timestamp.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/Timestamp.js +21 -0
- package/lib/src/customtypes/widgets/nestable/index.d.ts +17 -0
- package/lib/src/customtypes/widgets/nestable/index.js +20 -0
- package/lib/src/customtypes/widgets/shared/ImageConstraint.d.ts +7 -0
- package/lib/src/customtypes/widgets/shared/ImageConstraint.js +31 -0
- package/lib/src/customtypes/widgets/shared/index.d.ts +1 -0
- package/lib/src/customtypes/widgets/shared/index.js +8 -0
- package/lib/src/customtypes/widgets/slices/CompositeSlice.d.ts +455 -0
- package/lib/src/customtypes/widgets/slices/CompositeSlice.js +63 -0
- package/lib/src/customtypes/widgets/slices/LegacySlice.d.ts +442 -0
- package/lib/src/customtypes/widgets/slices/LegacySlice.js +12 -0
- package/lib/src/customtypes/widgets/slices/SharedSlice.d.ts +1807 -0
- package/lib/src/customtypes/widgets/slices/SharedSlice.js +118 -0
- package/lib/src/customtypes/widgets/slices/SharedSliceRef.d.ts +5 -0
- package/lib/src/customtypes/widgets/slices/SharedSliceRef.js +9 -0
- package/lib/src/customtypes/widgets/slices/Slice.d.ts +6 -0
- package/lib/src/customtypes/widgets/slices/Slice.js +2 -0
- package/lib/src/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +1259 -0
- package/lib/src/customtypes/widgets/slices/SlicePrimaryWidget.js +10 -0
- package/lib/src/customtypes/widgets/slices/Slices.d.ts +5917 -0
- package/lib/src/customtypes/widgets/slices/Slices.js +146 -0
- package/lib/src/customtypes/widgets/slices/SlicesTypes.d.ts +6 -0
- package/lib/src/customtypes/widgets/slices/SlicesTypes.js +11 -0
- package/lib/src/customtypes/widgets/slices/index.d.ts +8 -0
- package/lib/src/customtypes/widgets/slices/index.js +11 -0
- package/lib/src/utils/Arrays.d.ts +1 -0
- package/lib/src/utils/Arrays.js +13 -0
- package/lib/src/utils/DocumentId.d.ts +2 -0
- package/lib/src/utils/DocumentId.js +7 -0
- package/lib/src/utils/Objects.d.ts +8 -0
- package/lib/src/utils/Objects.js +42 -0
- package/lib/src/utils/index.d.ts +3 -0
- package/lib/src/utils/index.js +7 -0
- package/lib/src/validators/BasicTypes.d.ts +10 -0
- package/lib/src/validators/BasicTypes.js +25 -0
- package/lib/src/validators/DateFromString.d.ts +3 -0
- package/lib/src/validators/DateFromString.js +11 -0
- package/lib/src/validators/DateFromStringOrNumber.d.ts +3 -0
- package/lib/src/validators/DateFromStringOrNumber.js +10 -0
- package/lib/src/validators/DateFromTsMs.d.ts +3 -0
- package/lib/src/validators/DateFromTsMs.js +10 -0
- package/lib/src/validators/DefaultOrElse.d.ts +5 -0
- package/lib/src/validators/DefaultOrElse.js +21 -0
- package/lib/src/validators/IntFromNumber.d.ts +5 -0
- package/lib/src/validators/IntFromNumber.js +14 -0
- package/lib/src/validators/IntFromPixels.d.ts +8 -0
- package/lib/src/validators/IntFromPixels.js +24 -0
- package/lib/src/validators/NonEmptyString.d.ts +3 -0
- package/lib/src/validators/NonEmptyString.js +6 -0
- package/lib/src/validators/NonEmptyStringOrNull.d.ts +3 -0
- package/lib/src/validators/NonEmptyStringOrNull.js +15 -0
- package/lib/src/validators/NumberOrNull.d.ts +3 -0
- package/lib/src/validators/NumberOrNull.js +6 -0
- package/lib/src/validators/NumberRange.d.ts +32 -0
- package/lib/src/validators/NumberRange.js +40 -0
- package/lib/src/validators/StringFromBoolean.d.ts +5 -0
- package/lib/src/validators/StringFromBoolean.js +10 -0
- package/lib/src/validators/StringFromNumber.d.ts +5 -0
- package/lib/src/validators/StringFromNumber.js +10 -0
- package/lib/src/validators/StringOrNull.d.ts +3 -0
- package/lib/src/validators/StringOrNull.js +6 -0
- package/lib/src/validators/TrimmedString.d.ts +5 -0
- package/lib/src/validators/TrimmedString.js +23 -0
- package/lib/src/validators/function.d.ts +34 -0
- package/lib/src/validators/function.js +100 -0
- package/lib/src/validators/index.d.ts +15 -0
- package/lib/src/validators/index.js +31 -0
- package/package.json +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traverseSlices = exports.Slices = exports.DynamicSlices = exports.StaticSlices = exports.slicesReader = exports.DynamicSlicesConfig = exports.StaticSlicesConfig = exports.slicesConfigReader = exports.SlicesLabels = exports.SlicesFieldType = exports.LegacySlicesFieldType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const common_1 = require("../../../common");
|
|
7
|
+
const validators_1 = require("../../../validators");
|
|
8
|
+
const Group_1 = require("../Group");
|
|
9
|
+
const CompositeSlice_1 = require("./CompositeSlice");
|
|
10
|
+
const LegacySlice_1 = require("./LegacySlice");
|
|
11
|
+
const SharedSlice_1 = require("./SharedSlice");
|
|
12
|
+
const SharedSliceRef_1 = require("./SharedSliceRef");
|
|
13
|
+
exports.LegacySlicesFieldType = "Choice";
|
|
14
|
+
exports.SlicesFieldType = "Slices";
|
|
15
|
+
exports.SlicesLabels = t.union([
|
|
16
|
+
t.record(t.string, t.readonlyArray(t.exact(t.intersection([
|
|
17
|
+
t.type({
|
|
18
|
+
name: t.string,
|
|
19
|
+
}),
|
|
20
|
+
t.partial({
|
|
21
|
+
display: t.string,
|
|
22
|
+
}),
|
|
23
|
+
])))),
|
|
24
|
+
t.null,
|
|
25
|
+
]);
|
|
26
|
+
function slicesConfigReader(codec) {
|
|
27
|
+
return t.exact(t.partial({
|
|
28
|
+
label: validators_1.StringOrNull,
|
|
29
|
+
labels: exports.SlicesLabels,
|
|
30
|
+
choices: t.record(common_1.WidgetKey, t.union([LegacySlice_1.LegacySlice, CompositeSlice_1.CompositeSlice, codec])),
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
exports.slicesConfigReader = slicesConfigReader;
|
|
34
|
+
exports.StaticSlicesConfig = slicesConfigReader(SharedSlice_1.SharedSlice);
|
|
35
|
+
exports.DynamicSlicesConfig = slicesConfigReader(SharedSliceRef_1.SharedSliceRef);
|
|
36
|
+
const SlicesConfig = {
|
|
37
|
+
toStatic(config, sharedSlices) {
|
|
38
|
+
const choices = Object.entries(config.choices || {}).reduce((acc, [ref, slice]) => {
|
|
39
|
+
if (slice.type === "SharedSlice") {
|
|
40
|
+
const sharedSlice = sharedSlices.get(ref);
|
|
41
|
+
if (sharedSlice)
|
|
42
|
+
return { ...acc, [ref]: sharedSlice };
|
|
43
|
+
else
|
|
44
|
+
return acc;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return { ...acc, [ref]: slice };
|
|
48
|
+
}
|
|
49
|
+
}, {});
|
|
50
|
+
return { ...config, choices };
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
function slicesReader(codec) {
|
|
54
|
+
return t.exact(t.intersection([
|
|
55
|
+
t.type({
|
|
56
|
+
type: t.keyof({
|
|
57
|
+
[exports.SlicesFieldType]: null,
|
|
58
|
+
[exports.LegacySlicesFieldType]: null,
|
|
59
|
+
}),
|
|
60
|
+
}),
|
|
61
|
+
t.partial({
|
|
62
|
+
fieldset: validators_1.StringOrNull,
|
|
63
|
+
config: codec,
|
|
64
|
+
}),
|
|
65
|
+
]));
|
|
66
|
+
}
|
|
67
|
+
exports.slicesReader = slicesReader;
|
|
68
|
+
exports.StaticSlices = slicesReader(exports.StaticSlicesConfig);
|
|
69
|
+
exports.DynamicSlices = slicesReader(exports.DynamicSlicesConfig);
|
|
70
|
+
exports.Slices = {
|
|
71
|
+
toStatic(slices, sharedSlices) {
|
|
72
|
+
if (!slices.config)
|
|
73
|
+
return slices;
|
|
74
|
+
else {
|
|
75
|
+
return {
|
|
76
|
+
...slices,
|
|
77
|
+
config: SlicesConfig.toStatic(slices.config, sharedSlices),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
function traverseSlices(args) {
|
|
83
|
+
var _a;
|
|
84
|
+
const { path: prevPath, slices, onField } = args;
|
|
85
|
+
if (!((_a = slices.config) === null || _a === void 0 ? void 0 : _a.choices))
|
|
86
|
+
return slices;
|
|
87
|
+
let choices;
|
|
88
|
+
for (const [key, prevModel] of Object.entries(slices.config.choices)) {
|
|
89
|
+
const path = [...prevPath, key];
|
|
90
|
+
let model;
|
|
91
|
+
switch (prevModel.type) {
|
|
92
|
+
case "Slice":
|
|
93
|
+
model = (0, CompositeSlice_1.traverseCompositeSlice)({
|
|
94
|
+
path,
|
|
95
|
+
slice: prevModel,
|
|
96
|
+
onField: onField,
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
case "SharedSlice":
|
|
100
|
+
if ("variations" in prevModel)
|
|
101
|
+
model = (0, SharedSlice_1.traverseSharedSlice)({
|
|
102
|
+
path,
|
|
103
|
+
slice: prevModel,
|
|
104
|
+
onField,
|
|
105
|
+
});
|
|
106
|
+
else
|
|
107
|
+
model = prevModel;
|
|
108
|
+
break;
|
|
109
|
+
// Group and other fields are technically possible because of legacy slices.
|
|
110
|
+
case "Group":
|
|
111
|
+
model = onField({
|
|
112
|
+
path,
|
|
113
|
+
key,
|
|
114
|
+
field: (0, Group_1.traverseNestedGroup)({
|
|
115
|
+
path,
|
|
116
|
+
group: prevModel,
|
|
117
|
+
onField: onField,
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
model = onField({
|
|
123
|
+
path,
|
|
124
|
+
key,
|
|
125
|
+
field: prevModel,
|
|
126
|
+
});
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
if (model !== prevModel) {
|
|
130
|
+
if (!choices)
|
|
131
|
+
choices = { ...slices.config.choices };
|
|
132
|
+
choices[key] = model;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// returns the traversed model instead of a new one if it didn't change
|
|
136
|
+
return choices
|
|
137
|
+
? {
|
|
138
|
+
...slices,
|
|
139
|
+
config: {
|
|
140
|
+
...slices.config,
|
|
141
|
+
choices,
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
: slices;
|
|
145
|
+
}
|
|
146
|
+
exports.traverseSlices = traverseSlices;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SlicesTypes = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const CompositeSlice_1 = require("./CompositeSlice");
|
|
7
|
+
const SharedSlice_1 = require("./SharedSlice");
|
|
8
|
+
exports.SlicesTypes = t.keyof({
|
|
9
|
+
[CompositeSlice_1.CompositeSliceType]: null,
|
|
10
|
+
[SharedSlice_1.SharedSliceType]: null,
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./CompositeSlice"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./LegacySlice"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./SharedSlice"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./SharedSliceRef"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./Slice"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./SlicePrimaryWidget"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./Slices"), exports);
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./SlicesTypes"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toRecord<A extends object>(arr: ReadonlyArray<A>, key: (obj: A) => string): {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRecord = void 0;
|
|
4
|
+
function toRecord(arr, key) {
|
|
5
|
+
return arr.reduce((acc, entry) => {
|
|
6
|
+
const k = key(entry);
|
|
7
|
+
return {
|
|
8
|
+
...acc,
|
|
9
|
+
[k]: entry,
|
|
10
|
+
};
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
exports.toRecord = toRecord;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentId = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const function_1 = require("../validators/function");
|
|
7
|
+
exports.DocumentId = (0, function_1.withCustomError)((0, function_1.refineType)(t.string, "DocumentId", (s) => s.length === 16), () => "DocumentId must be a 16 character string");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function zipObjects<A, B = A>(objLeft?: Partial<Record<string, A>> | undefined, objRight?: Partial<Record<string, B>> | undefined): Partial<Record<string, {
|
|
2
|
+
left?: A | undefined;
|
|
3
|
+
right?: B | undefined;
|
|
4
|
+
}>>;
|
|
5
|
+
export declare function isNotEmpty<A extends object>(obj: A): boolean;
|
|
6
|
+
export declare function withOptionals<T extends object>(object: T, optionals: Array<[keyof T, T[keyof T] | null | undefined]>): T;
|
|
7
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
8
|
+
export declare function mapValues<T, O>(record: Record<string, T>, fn: (value: T, key: string) => O): Record<string, O>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapValues = exports.isObject = exports.withOptionals = exports.isNotEmpty = exports.zipObjects = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
function zipObjects(objLeft, objRight) {
|
|
8
|
+
const allKeys = [
|
|
9
|
+
...new Set(Object.keys(objLeft || {}).concat(Object.keys(objRight || {}))),
|
|
10
|
+
];
|
|
11
|
+
return allKeys.reduce((acc, key) => {
|
|
12
|
+
const left = objLeft === null || objLeft === void 0 ? void 0 : objLeft[key];
|
|
13
|
+
const right = objRight === null || objRight === void 0 ? void 0 : objRight[key];
|
|
14
|
+
return {
|
|
15
|
+
...acc,
|
|
16
|
+
[key]: { left, right },
|
|
17
|
+
};
|
|
18
|
+
}, {});
|
|
19
|
+
}
|
|
20
|
+
exports.zipObjects = zipObjects;
|
|
21
|
+
function isNotEmpty(obj) {
|
|
22
|
+
return Boolean(Object.keys(obj).length);
|
|
23
|
+
}
|
|
24
|
+
exports.isNotEmpty = isNotEmpty;
|
|
25
|
+
function withOptionals(object, optionals) {
|
|
26
|
+
return {
|
|
27
|
+
...object,
|
|
28
|
+
...optionals.reduce((acc, [key, value]) => {
|
|
29
|
+
return value ? { ...acc, [key]: value } : acc;
|
|
30
|
+
}, {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.withOptionals = withOptionals;
|
|
34
|
+
const recordCodec = t.record(t.string, t.unknown);
|
|
35
|
+
function isObject(value) {
|
|
36
|
+
return (0, Either_1.isRight)(recordCodec.decode(value));
|
|
37
|
+
}
|
|
38
|
+
exports.isObject = isObject;
|
|
39
|
+
function mapValues(record, fn) {
|
|
40
|
+
return Object.entries(record).reduce((acc, [key, value]) => ({ ...acc, [key]: fn(value, key) }), {});
|
|
41
|
+
}
|
|
42
|
+
exports.mapValues = mapValues;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Objects = exports.Arrays = exports.HexaColorCode = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
exports.HexaColorCode = (0, tslib_1.__importStar)(require("../common/HexaColorCode"));
|
|
6
|
+
exports.Arrays = (0, tslib_1.__importStar)(require("./Arrays"));
|
|
7
|
+
exports.Objects = (0, tslib_1.__importStar)(require("./Objects"));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const String: t.StringC;
|
|
3
|
+
export declare const StringOrNull: t.UnionC<[t.StringC, t.NullC]>;
|
|
4
|
+
export declare const Number: t.NumberC;
|
|
5
|
+
export declare const NumberOrNull: t.UnionC<[t.NumberC, t.NullC]>;
|
|
6
|
+
export declare const Boolean: t.BooleanC;
|
|
7
|
+
export declare const EmptyObject: t.Type<Record<never, never>, {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}, unknown>;
|
|
10
|
+
export declare const EmptyArray: t.Type<never[], never[], unknown>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmptyArray = exports.EmptyObject = exports.Boolean = exports.NumberOrNull = exports.Number = exports.StringOrNull = exports.String = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fp_ts_1 = require("fp-ts");
|
|
6
|
+
const function_1 = require("fp-ts/lib/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const function_2 = require("./function");
|
|
9
|
+
exports.String = (0, function_2.withCustomError)(t.string, () => "The value must be a string");
|
|
10
|
+
exports.StringOrNull = (0, function_2.withCustomError)(t.union([t.string, t.null]), () => "The value must be a string or null");
|
|
11
|
+
exports.Number = (0, function_2.withCustomError)(t.number, () => "The value must be a number");
|
|
12
|
+
exports.NumberOrNull = (0, function_2.withCustomError)(t.union([t.number, t.null]), () => "The value must be a number or null");
|
|
13
|
+
exports.Boolean = (0, function_2.withCustomError)(t.boolean, () => "The value must be a boolean");
|
|
14
|
+
exports.EmptyObject = t.UnknownRecord.pipe(new t.Type("emptyObject", (u) => t.UnknownRecord.is(u), (u, c) => {
|
|
15
|
+
if (Object.keys(u).length > 0)
|
|
16
|
+
return t.failure(u, c, "The object is not empty.");
|
|
17
|
+
return t.success({});
|
|
18
|
+
}, t.identity));
|
|
19
|
+
exports.EmptyArray = new t.Type("emptyArray", (u) => t.UnknownArray.is(u) && u.length === 0, (u, c) => {
|
|
20
|
+
return (0, function_1.pipe)(t.UnknownArray.decode(u), fp_ts_1.either.chain((parsedArray) => {
|
|
21
|
+
if (parsedArray.length > 0)
|
|
22
|
+
return t.failure(u, c, "The array is not empty.");
|
|
23
|
+
return t.success(new Array());
|
|
24
|
+
}));
|
|
25
|
+
}, () => []);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Either_1 = require("fp-ts/Either");
|
|
5
|
+
const function_1 = require("fp-ts/function");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
exports.default = new t.Type("dateFromString", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(_1.String.validate(u, c), (0, Either_1.chain)((s) => {
|
|
9
|
+
const d = new Date(s);
|
|
10
|
+
return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d);
|
|
11
|
+
})), (date) => date.toISOString());
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Either_1 = require("fp-ts/Either");
|
|
5
|
+
const function_1 = require("fp-ts/function");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
exports.default = new t.Type("dateFromStringOrNumber", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(t.union([t.number, t.string]).validate(u, c), (0, Either_1.chain)((s) => {
|
|
8
|
+
const d = new Date(s);
|
|
9
|
+
return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d);
|
|
10
|
+
})), (date) => date);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Either_1 = require("fp-ts/Either");
|
|
5
|
+
const function_1 = require("fp-ts/function");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
exports.default = new t.Type("dateFromTsMs", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(t.number.validate(u, c), (0, Either_1.chain)((s) => {
|
|
8
|
+
const d = new Date(s);
|
|
9
|
+
return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d);
|
|
10
|
+
})), (date) => date.getTime());
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const DefaultOrElse: <I, A, O = A>(inputValidator: t.Type<I, I, unknown>) => (codec: t.Type<A, O, unknown>) => t.Type<A | null, O | undefined, unknown>;
|
|
3
|
+
export declare const NullOrElse: <A, O = A>(codec: t.Type<A, O, unknown>) => t.Type<A | null, O | undefined, unknown>;
|
|
4
|
+
export declare const EmptyObjectOrElse: <A, O = A>(codec: t.Type<A, O, unknown>) => t.Type<A | null, O | undefined, unknown>;
|
|
5
|
+
export declare const EmptyArrayOrElse: <A, O = A>(codec: t.Type<A, O, unknown>) => t.Type<A | null, O | undefined, unknown>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmptyArrayOrElse = exports.EmptyObjectOrElse = exports.NullOrElse = exports.DefaultOrElse = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
const BasicTypes_1 = require("./BasicTypes");
|
|
8
|
+
const DefaultOrElse = (inputValidator) => {
|
|
9
|
+
return (codec) => new t.Type(`DefaultOrElse<${inputValidator.name}, ${codec.name}>`, (u) => null === u || codec.is(u), (u, c) => {
|
|
10
|
+
if ((0, Either_1.isRight)(inputValidator.validate(u, c)))
|
|
11
|
+
return t.success(null);
|
|
12
|
+
return codec.validate(u, c);
|
|
13
|
+
}, (chunk) => (chunk ? codec.encode(chunk) : undefined));
|
|
14
|
+
};
|
|
15
|
+
exports.DefaultOrElse = DefaultOrElse;
|
|
16
|
+
const NullOrElse = (codec) => (0, exports.DefaultOrElse)(t.null)(codec);
|
|
17
|
+
exports.NullOrElse = NullOrElse;
|
|
18
|
+
const EmptyObjectOrElse = (codec) => (0, exports.DefaultOrElse)(BasicTypes_1.EmptyObject)(codec);
|
|
19
|
+
exports.EmptyObjectOrElse = EmptyObjectOrElse;
|
|
20
|
+
const EmptyArrayOrElse = (codec) => (0, exports.DefaultOrElse)(BasicTypes_1.EmptyArray)(codec);
|
|
21
|
+
exports.EmptyArrayOrElse = EmptyArrayOrElse;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Either_1 = require("fp-ts/Either");
|
|
5
|
+
const function_1 = require("fp-ts/function");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
/** A codec that succeeds if a number can be parsed to an integer */
|
|
8
|
+
exports.default = new t.Type("IntFromNumber", t.Int.is, (u, c) => (0, function_1.pipe)(t.number.validate(u, c), (0, Either_1.chain)((n) => {
|
|
9
|
+
if (t.Int.is(n))
|
|
10
|
+
return t.success(n);
|
|
11
|
+
else {
|
|
12
|
+
return t.success(Math.round(n));
|
|
13
|
+
}
|
|
14
|
+
})), t.Int.encode);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare type IntFromPixelsC = t.Type<t.Int, string, unknown>;
|
|
3
|
+
declare const _default: t.Type<t.Int, string, unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* A codec that succeeds if a string representing pixels (eg: "200px") can be
|
|
6
|
+
* parsed to an integer
|
|
7
|
+
*/
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Either_1 = require("fp-ts/Either");
|
|
5
|
+
const function_1 = require("fp-ts/function");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
const PixelsRegex = /^([0-9]+)px$/;
|
|
8
|
+
/**
|
|
9
|
+
* A codec that succeeds if a string representing pixels (eg: "200px") can be
|
|
10
|
+
* parsed to an integer
|
|
11
|
+
*/
|
|
12
|
+
exports.default = new t.Type("IntFromPixels", t.Int.is, (u, c) => (0, function_1.pipe)(t.string.validate(u, c), (0, Either_1.chain)((strPixels) => {
|
|
13
|
+
try {
|
|
14
|
+
const matched = strPixels.match(PixelsRegex);
|
|
15
|
+
if (!matched)
|
|
16
|
+
return t.failure(u, c);
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
18
|
+
const parsed = parseInt(matched[1]);
|
|
19
|
+
return t.success(parsed);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return t.failure(u, c);
|
|
23
|
+
}
|
|
24
|
+
})), String);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
5
|
+
const function_1 = require("./function");
|
|
6
|
+
exports.default = (0, function_1.withCustomError)((0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0), () => "The value must be a non-empty string");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Either_1 = require("fp-ts/Either");
|
|
5
|
+
const function_1 = require("fp-ts/function");
|
|
6
|
+
const io_ts_1 = require("io-ts");
|
|
7
|
+
const StringOrNull_1 = (0, tslib_1.__importDefault)(require("./StringOrNull"));
|
|
8
|
+
exports.default = new io_ts_1.Type("nonEmptyStringOrNull", (u) => typeof u === "string" || u === null, (u, c) => (0, function_1.pipe)(StringOrNull_1.default.validate(u, c), (0, Either_1.chain)((s) => {
|
|
9
|
+
if (typeof s === "string" && s.length > 0) {
|
|
10
|
+
return (0, io_ts_1.success)(s);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return (0, io_ts_1.success)(null);
|
|
14
|
+
}
|
|
15
|
+
})), (s) => s);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
5
|
+
const function_1 = require("./function");
|
|
6
|
+
exports.default = (0, function_1.nullable)(t.number);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
declare const _default: (min: number, max: number, fieldName: string) => t.Type<number, number, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Creates a custom runtime type for validating that a number falls within a specified range.
|
|
5
|
+
*
|
|
6
|
+
* @param min - The minimum value of the range.
|
|
7
|
+
* @param max - The maximum value of the range.
|
|
8
|
+
* @param fieldName - The name of the field being validated (used in error messages).
|
|
9
|
+
* @returns A runtime type representing the number range validation.
|
|
10
|
+
*
|
|
11
|
+
* * @example
|
|
12
|
+
* // Creating a custom runtime type for age validation
|
|
13
|
+
* const AgeType = numberInRange(18, 99, 'Age');
|
|
14
|
+
*
|
|
15
|
+
* // Valid age
|
|
16
|
+
* const validAgeResult = AgeType.decode(25);
|
|
17
|
+
* if (t.isRight(validAgeResult)) {
|
|
18
|
+
* console.log('Valid age:', validAgeResult.right); // Output: Valid age: 25
|
|
19
|
+
* } else {
|
|
20
|
+
* console.error('Invalid age:', t.left(validAgeResult).map(t.reporter.report));
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Invalid age
|
|
25
|
+
* const invalidAgeResult = AgeType.decode(15);
|
|
26
|
+
* if (t.isRight(invalidAgeResult)) {
|
|
27
|
+
* console.log('Valid age:', invalidAgeResult.right);
|
|
28
|
+
* } else {
|
|
29
|
+
* console.error('Invalid age:', t.left(invalidAgeResult).map(t.reporter.report));
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
5
|
+
const BasicTypes_1 = require("./BasicTypes");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a custom runtime type for validating that a number falls within a specified range.
|
|
8
|
+
*
|
|
9
|
+
* @param min - The minimum value of the range.
|
|
10
|
+
* @param max - The maximum value of the range.
|
|
11
|
+
* @param fieldName - The name of the field being validated (used in error messages).
|
|
12
|
+
* @returns A runtime type representing the number range validation.
|
|
13
|
+
*
|
|
14
|
+
* * @example
|
|
15
|
+
* // Creating a custom runtime type for age validation
|
|
16
|
+
* const AgeType = numberInRange(18, 99, 'Age');
|
|
17
|
+
*
|
|
18
|
+
* // Valid age
|
|
19
|
+
* const validAgeResult = AgeType.decode(25);
|
|
20
|
+
* if (t.isRight(validAgeResult)) {
|
|
21
|
+
* console.log('Valid age:', validAgeResult.right); // Output: Valid age: 25
|
|
22
|
+
* } else {
|
|
23
|
+
* console.error('Invalid age:', t.left(validAgeResult).map(t.reporter.report));
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Invalid age
|
|
28
|
+
* const invalidAgeResult = AgeType.decode(15);
|
|
29
|
+
* if (t.isRight(invalidAgeResult)) {
|
|
30
|
+
* console.log('Valid age:', invalidAgeResult.right);
|
|
31
|
+
* } else {
|
|
32
|
+
* console.error('Invalid age:', t.left(invalidAgeResult).map(t.reporter.report));
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
35
|
+
exports.default = (min, max, fieldName) => BasicTypes_1.Number.pipe(new t.Type("numberInRange", (u) => BasicTypes_1.Number.is(u), (u, context) => {
|
|
36
|
+
if (u > max || u < min) {
|
|
37
|
+
return t.failure(u, context, `${fieldName} must be a number between ${min} and ${max}`);
|
|
38
|
+
}
|
|
39
|
+
return t.success(u);
|
|
40
|
+
}, t.identity));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Either_1 = require("fp-ts/Either");
|
|
5
|
+
const function_1 = require("fp-ts/function");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
/** A codec that validates a Boolean and convert it as a string */
|
|
8
|
+
exports.default = new t.Type("StringFromInt", t.string.is, (u, c) => (0, function_1.pipe)(t.boolean.validate(u, c), (0, Either_1.chain)((i) => {
|
|
9
|
+
return t.success(i.toString());
|
|
10
|
+
})), (i) => i);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const Either_1 = require("fp-ts/Either");
|
|
5
|
+
const function_1 = require("fp-ts/function");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
/** A codec that validates a number and convert it as a string */
|
|
8
|
+
exports.default = new t.Type("StringFromInt", t.string.is, (u, c) => (0, function_1.pipe)(t.number.validate(u, c), (0, Either_1.chain)((i) => {
|
|
9
|
+
return t.success(i.toString());
|
|
10
|
+
})), (i) => i);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
5
|
+
const function_1 = require("./function");
|
|
6
|
+
exports.default = (0, function_1.nullable)(t.string);
|