@prismicio/types-internal 0.1.1 → 0.2.3
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/README.md +13 -13
- package/{dist → lib}/customtypes/CustomType.d.ts +697 -715
- package/{dist → lib}/customtypes/CustomType.js +42 -52
- package/{dist → lib}/customtypes/Format.d.ts +0 -0
- package/{dist → lib}/customtypes/Format.js +0 -0
- package/{dist → lib}/customtypes/Section.d.ts +1035 -1062
- package/lib/customtypes/Section.js +21 -0
- package/lib/customtypes/index.d.ts +4 -0
- package/lib/customtypes/index.js +9 -0
- package/{dist → lib}/customtypes/widgets/Group.d.ts +45 -45
- package/lib/customtypes/widgets/Group.js +24 -0
- package/{dist → lib}/customtypes/widgets/UID.d.ts +4 -4
- package/lib/customtypes/widgets/UID.js +21 -0
- package/{dist → lib}/customtypes/widgets/Widget.d.ts +1036 -1063
- package/lib/customtypes/widgets/Widget.js +27 -0
- package/{dist → lib}/customtypes/widgets/WidgetTypes.d.ts +0 -0
- package/{dist → lib}/customtypes/widgets/WidgetTypes.js +0 -0
- package/lib/customtypes/widgets/index.d.ts +7 -0
- package/lib/customtypes/widgets/index.js +14 -0
- package/{dist → lib}/customtypes/widgets/nestable/BooleanField.d.ts +3 -3
- package/lib/customtypes/widgets/nestable/BooleanField.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Color.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Color.js +20 -0
- package/{dist → lib}/customtypes/widgets/nestable/Date.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Date.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Embed.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Embed.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/GeoPoint.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/GeoPoint.js +19 -0
- package/lib/customtypes/widgets/nestable/Image.d.ts +23 -0
- package/lib/customtypes/widgets/nestable/Image.js +29 -0
- package/{dist → lib}/customtypes/widgets/nestable/IntegrationField.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/IntegrationField.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Link.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Link.js +54 -0
- package/{dist → lib}/customtypes/widgets/nestable/NestableWidget.d.ts +42 -42
- package/lib/customtypes/widgets/nestable/NestableWidget.js +37 -0
- package/{dist → lib}/customtypes/widgets/nestable/Number.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Number.js +24 -0
- package/{dist → lib}/customtypes/widgets/nestable/Range.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Range.js +24 -0
- package/{dist → lib}/customtypes/widgets/nestable/RichText.d.ts +6 -6
- package/lib/customtypes/widgets/nestable/RichText.js +111 -0
- package/lib/customtypes/widgets/nestable/Select.d.ts +15 -0
- package/lib/customtypes/widgets/nestable/Select.js +22 -0
- package/{dist → lib}/customtypes/widgets/nestable/Separator.d.ts +3 -3
- package/lib/customtypes/widgets/nestable/Separator.js +18 -0
- package/{dist → lib}/customtypes/widgets/nestable/Text.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Text.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Timestamp.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Timestamp.js +21 -0
- package/lib/customtypes/widgets/nestable/index.d.ts +15 -0
- package/{dist → lib}/customtypes/widgets/nestable/index.js +0 -0
- package/{dist → lib}/customtypes/widgets/shared/ImageConstraint.d.ts +3 -3
- package/lib/customtypes/widgets/shared/ImageConstraint.js +31 -0
- package/lib/customtypes/widgets/shared/index.d.ts +1 -0
- package/{dist → lib}/customtypes/widgets/shared/index.js +0 -0
- package/{dist → lib}/customtypes/widgets/slices/CompositeSlice.d.ts +87 -87
- package/lib/customtypes/widgets/slices/CompositeSlice.js +25 -0
- package/{dist → lib}/customtypes/widgets/slices/LegacySlice.d.ts +86 -95
- package/lib/customtypes/widgets/slices/LegacySlice.js +8 -0
- package/{dist → lib}/customtypes/widgets/slices/SharedSlice.d.ts +84 -84
- package/lib/customtypes/widgets/slices/SharedSlice.js +35 -0
- package/{dist → lib}/customtypes/widgets/slices/SharedSliceRef.d.ts +2 -2
- package/lib/customtypes/widgets/slices/SharedSliceRef.js +9 -0
- package/lib/customtypes/widgets/slices/Slice.d.ts +6 -0
- package/{dist → lib}/customtypes/widgets/slices/Slice.js +0 -0
- package/{dist → lib}/customtypes/widgets/slices/Slices.d.ts +1550 -1604
- package/lib/customtypes/widgets/slices/Slices.js +93 -0
- package/{dist → lib}/customtypes/widgets/slices/SlicesTypes.d.ts +0 -0
- package/{dist → lib}/customtypes/widgets/slices/SlicesTypes.js +0 -0
- package/lib/customtypes/widgets/slices/index.d.ts +7 -0
- package/lib/customtypes/widgets/slices/index.js +16 -0
- package/lib/documents/DocumentData.d.ts +8 -0
- package/lib/documents/DocumentData.js +28 -0
- package/lib/documents/index.d.ts +2 -0
- package/lib/documents/index.js +7 -0
- package/lib/documents/widgets/EmptyContent.d.ts +8 -0
- package/lib/documents/widgets/EmptyContent.js +9 -0
- package/lib/documents/widgets/GroupContent.d.ts +16 -0
- package/lib/documents/widgets/GroupContent.js +59 -0
- package/lib/documents/widgets/SimpleWidgetContent.d.ts +20 -0
- package/lib/documents/widgets/SimpleWidgetContent.js +75 -0
- package/lib/documents/widgets/StaticWidgetContent.d.ts +10 -0
- package/lib/documents/widgets/StaticWidgetContent.js +26 -0
- package/lib/documents/widgets/UIDContent.d.ts +7 -0
- package/lib/documents/widgets/UIDContent.js +10 -0
- package/lib/documents/widgets/index.d.ts +35 -0
- package/lib/documents/widgets/index.js +36 -0
- package/lib/documents/widgets/nestable/BooleanContent.d.ts +8 -0
- package/lib/documents/widgets/nestable/BooleanContent.js +11 -0
- package/lib/documents/widgets/nestable/EmbedContent.d.ts +40 -0
- package/lib/documents/widgets/nestable/EmbedContent.js +36 -0
- package/lib/documents/widgets/nestable/FieldContent.d.ts +12 -0
- package/lib/documents/widgets/nestable/FieldContent.js +37 -0
- package/lib/documents/widgets/nestable/GeoPointContent.d.ts +17 -0
- package/lib/documents/widgets/nestable/GeoPointContent.js +13 -0
- package/lib/documents/widgets/nestable/ImageContent.d.ts +127 -0
- package/lib/documents/widgets/nestable/ImageContent.js +41 -0
- package/lib/documents/widgets/nestable/IntegrationFieldsContent.d.ts +8 -0
- package/lib/documents/widgets/nestable/IntegrationFieldsContent.js +16 -0
- package/lib/documents/widgets/nestable/Link/DocumentLink.d.ts +12 -0
- package/lib/documents/widgets/nestable/Link/DocumentLink.js +13 -0
- package/lib/documents/widgets/nestable/Link/ExternalLink.d.ts +24 -0
- package/lib/documents/widgets/nestable/Link/ExternalLink.js +24 -0
- package/lib/documents/widgets/nestable/Link/FileLink.d.ts +22 -0
- package/lib/documents/widgets/nestable/Link/FileLink.js +24 -0
- package/lib/documents/widgets/nestable/Link/ImageLink.d.ts +28 -0
- package/lib/documents/widgets/nestable/Link/ImageLink.js +26 -0
- package/lib/documents/widgets/nestable/Link/LinkContent.d.ts +36 -0
- package/lib/documents/widgets/nestable/Link/LinkContent.js +13 -0
- package/lib/documents/widgets/nestable/Link/index.d.ts +89 -0
- package/lib/documents/widgets/nestable/Link/index.js +35 -0
- package/lib/documents/widgets/nestable/SeparatorContent.d.ts +7 -0
- package/lib/documents/widgets/nestable/SeparatorContent.js +10 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +274 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +97 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/index.d.ts +9 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/index.js +14 -0
- package/lib/documents/widgets/nestable/index.d.ts +26 -0
- package/lib/documents/widgets/nestable/index.js +40 -0
- package/lib/documents/widgets/slices/CompositeSliceContent.d.ts +14 -0
- package/lib/documents/widgets/slices/CompositeSliceContent.js +50 -0
- package/lib/documents/widgets/slices/SharedSliceContent.d.ts +15 -0
- package/lib/documents/widgets/slices/SharedSliceContent.js +62 -0
- package/lib/documents/widgets/slices/SimpleSliceContent.d.ts +6 -0
- package/lib/documents/widgets/slices/SimpleSliceContent.js +6 -0
- package/lib/documents/widgets/slices/SliceWidgetContent.d.ts +8 -0
- package/lib/documents/widgets/slices/SliceWidgetContent.js +26 -0
- package/lib/documents/widgets/slices/SlicesContent.d.ts +17 -0
- package/lib/documents/widgets/slices/SlicesContent.js +51 -0
- package/lib/documents/widgets/slices/index.d.ts +5 -0
- package/lib/documents/widgets/slices/index.js +8 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +7 -0
- package/lib/validators/DateFromString.d.ts +3 -0
- package/lib/validators/DateFromString.js +10 -0
- package/lib/validators/DateFromStringOrNumber.d.ts +3 -0
- package/lib/validators/DateFromStringOrNumber.js +10 -0
- package/lib/validators/DateFromTsMs.d.ts +3 -0
- package/lib/validators/DateFromTsMs.js +10 -0
- package/lib/validators/IntFromNumber.d.ts +5 -0
- package/lib/validators/IntFromNumber.js +14 -0
- package/lib/validators/IntFromPixels.d.ts +8 -0
- package/lib/validators/IntFromPixels.js +24 -0
- package/lib/validators/NonEmptyString.d.ts +3 -0
- package/lib/validators/NonEmptyString.js +6 -0
- package/lib/validators/NonEmptyStringOrNull.d.ts +3 -0
- package/lib/validators/NonEmptyStringOrNull.js +15 -0
- package/lib/validators/NumberOrNull.d.ts +3 -0
- package/lib/validators/NumberOrNull.js +6 -0
- package/lib/validators/StringFromBoolean.d.ts +5 -0
- package/lib/validators/StringFromBoolean.js +10 -0
- package/lib/validators/StringFromNumber.d.ts +5 -0
- package/lib/validators/StringFromNumber.js +10 -0
- package/lib/validators/StringOrNull.d.ts +3 -0
- package/lib/validators/StringOrNull.js +6 -0
- package/lib/validators/function.d.ts +14 -0
- package/lib/validators/function.js +60 -0
- package/lib/validators/index.d.ts +12 -0
- package/lib/validators/index.js +27 -0
- package/package.json +30 -18
- package/src/customtypes/CustomType.ts +173 -116
- package/src/customtypes/Format.ts +3 -3
- package/src/customtypes/Section.ts +26 -13
- package/src/customtypes/index.ts +4 -4
- package/src/customtypes/widgets/Group.ts +21 -20
- package/src/customtypes/widgets/UID.ts +18 -17
- package/src/customtypes/widgets/Widget.ts +22 -23
- package/src/customtypes/widgets/WidgetTypes.ts +21 -21
- package/src/customtypes/widgets/index.ts +7 -7
- package/src/customtypes/widgets/nestable/BooleanField.ts +19 -19
- package/src/customtypes/widgets/nestable/Color.ts +17 -16
- package/src/customtypes/widgets/nestable/Date.ts +19 -18
- package/src/customtypes/widgets/nestable/Embed.ts +19 -18
- package/src/customtypes/widgets/nestable/GeoPoint.ts +17 -16
- package/src/customtypes/widgets/nestable/Image.ts +26 -26
- package/src/customtypes/widgets/nestable/IntegrationField.ts +18 -17
- package/src/customtypes/widgets/nestable/Link.ts +80 -68
- package/src/customtypes/widgets/nestable/NestableWidget.ts +32 -32
- package/src/customtypes/widgets/nestable/Number.ts +22 -21
- package/src/customtypes/widgets/nestable/Range.ts +22 -21
- package/src/customtypes/widgets/nestable/RichText.ts +164 -134
- package/src/customtypes/widgets/nestable/Select.ts +22 -21
- package/src/customtypes/widgets/nestable/Separator.ts +15 -14
- package/src/customtypes/widgets/nestable/Text.ts +18 -17
- package/src/customtypes/widgets/nestable/Timestamp.ts +19 -18
- package/src/customtypes/widgets/nestable/index.ts +15 -15
- package/src/customtypes/widgets/shared/ImageConstraint.ts +31 -29
- package/src/customtypes/widgets/shared/index.ts +1 -1
- package/src/customtypes/widgets/slices/CompositeSlice.ts +21 -21
- package/src/customtypes/widgets/slices/LegacySlice.ts +5 -10
- package/src/customtypes/widgets/slices/SharedSlice.ts +33 -31
- package/src/customtypes/widgets/slices/SharedSliceRef.ts +6 -6
- package/src/customtypes/widgets/slices/Slice.ts +4 -4
- package/src/customtypes/widgets/slices/Slices.ts +95 -73
- package/src/customtypes/widgets/slices/SlicesTypes.ts +3 -3
- package/src/customtypes/widgets/slices/index.ts +7 -7
- package/src/documents/DocumentData.ts +54 -0
- package/src/documents/index.ts +2 -0
- package/src/documents/widgets/EmptyContent.ts +8 -0
- package/src/documents/widgets/GroupContent.ts +91 -0
- package/src/documents/widgets/SimpleWidgetContent.ts +96 -0
- package/src/documents/widgets/StaticWidgetContent.ts +46 -0
- package/src/documents/widgets/UIDContent.ts +18 -0
- package/src/documents/widgets/index.ts +56 -0
- package/src/documents/widgets/nestable/BooleanContent.ts +21 -0
- package/src/documents/widgets/nestable/EmbedContent.ts +54 -0
- package/src/documents/widgets/nestable/FieldContent.ts +45 -0
- package/src/documents/widgets/nestable/GeoPointContent.ts +18 -0
- package/src/documents/widgets/nestable/ImageContent.ts +51 -0
- package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +26 -0
- package/src/documents/widgets/nestable/Link/DocumentLink.ts +18 -0
- package/src/documents/widgets/nestable/Link/ExternalLink.ts +31 -0
- package/src/documents/widgets/nestable/Link/FileLink.ts +29 -0
- package/src/documents/widgets/nestable/Link/ImageLink.ts +31 -0
- package/src/documents/widgets/nestable/Link/LinkContent.ts +22 -0
- package/src/documents/widgets/nestable/Link/index.ts +33 -0
- package/src/documents/widgets/nestable/SeparatorContent.ts +8 -0
- package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +122 -0
- package/src/documents/widgets/nestable/StructuredTextContent/index.ts +25 -0
- package/src/documents/widgets/nestable/index.ts +35 -0
- package/src/documents/widgets/slices/CompositeSliceContent.ts +77 -0
- package/src/documents/widgets/slices/SharedSliceContent.ts +94 -0
- package/src/documents/widgets/slices/SimpleSliceContent.ts +4 -0
- package/src/documents/widgets/slices/SliceWidgetContent.ts +51 -0
- package/src/documents/widgets/slices/SlicesContent.ts +91 -0
- package/src/documents/widgets/slices/index.ts +5 -0
- package/src/index.ts +3 -1
- package/src/validators/DateFromString.ts +17 -0
- package/src/validators/DateFromStringOrNumber.ts +17 -0
- package/src/validators/DateFromTsMs.ts +17 -0
- package/src/validators/IntFromNumber.ts +22 -24
- package/src/validators/IntFromPixels.ts +27 -26
- package/src/validators/NonEmptyString.ts +9 -0
- package/src/validators/NonEmptyStringOrNull.ts +22 -0
- package/src/validators/NumberOrNull.ts +5 -0
- package/src/validators/StringFromBoolean.ts +17 -19
- package/src/validators/StringFromNumber.ts +17 -19
- package/src/validators/StringOrNull.ts +4 -2
- package/src/validators/function.ts +71 -0
- package/src/validators/index.ts +12 -0
- package/dist/customtypes/Section.js +0 -40
- package/dist/customtypes/index.d.ts +0 -4
- package/dist/customtypes/index.js +0 -30
- package/dist/customtypes/widgets/Group.js +0 -45
- package/dist/customtypes/widgets/UID.js +0 -42
- package/dist/customtypes/widgets/Widget.js +0 -51
- package/dist/customtypes/widgets/index.d.ts +0 -7
- package/dist/customtypes/widgets/index.js +0 -35
- package/dist/customtypes/widgets/nestable/BooleanField.js +0 -42
- package/dist/customtypes/widgets/nestable/Color.js +0 -41
- package/dist/customtypes/widgets/nestable/Date.js +0 -42
- package/dist/customtypes/widgets/nestable/Embed.js +0 -42
- package/dist/customtypes/widgets/nestable/GeoPoint.js +0 -40
- package/dist/customtypes/widgets/nestable/Image.d.ts +0 -23
- package/dist/customtypes/widgets/nestable/Image.js +0 -50
- package/dist/customtypes/widgets/nestable/IntegrationField.js +0 -42
- package/dist/customtypes/widgets/nestable/Link.js +0 -78
- package/dist/customtypes/widgets/nestable/NestableWidget.js +0 -58
- package/dist/customtypes/widgets/nestable/Number.js +0 -45
- package/dist/customtypes/widgets/nestable/Range.js +0 -45
- package/dist/customtypes/widgets/nestable/RichText.js +0 -134
- package/dist/customtypes/widgets/nestable/Select.d.ts +0 -15
- package/dist/customtypes/widgets/nestable/Select.js +0 -45
- package/dist/customtypes/widgets/nestable/Separator.js +0 -39
- package/dist/customtypes/widgets/nestable/Text.js +0 -42
- package/dist/customtypes/widgets/nestable/Timestamp.js +0 -42
- package/dist/customtypes/widgets/nestable/index.d.ts +0 -15
- package/dist/customtypes/widgets/shared/ImageConstraint.js +0 -48
- package/dist/customtypes/widgets/shared/index.d.ts +0 -1
- package/dist/customtypes/widgets/slices/CompositeSlice.js +0 -46
- package/dist/customtypes/widgets/slices/LegacySlice.js +0 -34
- package/dist/customtypes/widgets/slices/SharedSlice.js +0 -56
- package/dist/customtypes/widgets/slices/SharedSliceRef.js +0 -30
- package/dist/customtypes/widgets/slices/Slice.d.ts +0 -6
- package/dist/customtypes/widgets/slices/Slices.js +0 -106
- package/dist/customtypes/widgets/slices/index.d.ts +0 -7
- package/dist/customtypes/widgets/slices/index.js +0 -37
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/dist/validators/IntFromNumber.d.ts +0 -7
- package/dist/validators/IntFromNumber.js +0 -35
- package/dist/validators/IntFromPixels.d.ts +0 -7
- package/dist/validators/IntFromPixels.js +0 -43
- package/dist/validators/StringFromBoolean.d.ts +0 -7
- package/dist/validators/StringFromBoolean.js +0 -31
- package/dist/validators/StringFromNumber.d.ts +0 -7
- package/dist/validators/StringFromNumber.js +0 -31
- package/dist/validators/StringOrNull.d.ts +0 -2
- package/dist/validators/StringOrNull.js +0 -24
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BooleanContentType } from "./BooleanContent"
|
|
2
|
+
import { EmbedContentType } from "./EmbedContent"
|
|
3
|
+
import { FieldContentType } from "./FieldContent"
|
|
4
|
+
import { GeoPointContentType } from "./GeoPointContent"
|
|
5
|
+
import { ImageContentType } from "./ImageContent"
|
|
6
|
+
import { IntegrationFieldsContentType } from "./IntegrationFieldsContent"
|
|
7
|
+
import { LinksTypes } from "./Link"
|
|
8
|
+
import { SeparatorContentType } from "./SeparatorContent"
|
|
9
|
+
import { StructuredTextContentType } from "./StructuredTextContent"
|
|
10
|
+
|
|
11
|
+
export { default as BooleanContent } from "./BooleanContent"
|
|
12
|
+
export { default as EmbedContent } from "./EmbedContent"
|
|
13
|
+
export { default as FieldContent } from "./FieldContent"
|
|
14
|
+
export { type GeoPointContentO, GeoPointContent } from "./GeoPointContent"
|
|
15
|
+
export {
|
|
16
|
+
type ImageContentO,
|
|
17
|
+
ImageContent,
|
|
18
|
+
ImageContentView,
|
|
19
|
+
} from "./ImageContent"
|
|
20
|
+
export { default as IntegrationFieldsContent } from "./IntegrationFieldsContent"
|
|
21
|
+
export * as Links from "./Link"
|
|
22
|
+
export * from "./SeparatorContent"
|
|
23
|
+
export * from "./StructuredTextContent"
|
|
24
|
+
|
|
25
|
+
export const NestableTypes = {
|
|
26
|
+
Links: LinksTypes,
|
|
27
|
+
StructuredText: StructuredTextContentType,
|
|
28
|
+
Boolean: BooleanContentType,
|
|
29
|
+
Embed: EmbedContentType,
|
|
30
|
+
Field: FieldContentType,
|
|
31
|
+
GeoPoint: GeoPointContentType,
|
|
32
|
+
Image: ImageContentType,
|
|
33
|
+
IntegrationFields: IntegrationFieldsContentType,
|
|
34
|
+
Separator: SeparatorContentType,
|
|
35
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isRight } from "fp-ts/Either"
|
|
2
|
+
import * as O from "fp-ts/Option"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
import type { GroupItemContent } from "../GroupContent"
|
|
6
|
+
import { GroupContent, SimpleWidgetContent } from "../index"
|
|
7
|
+
|
|
8
|
+
export const CompositeSliceContentType = "CompositeSliceContent"
|
|
9
|
+
export type CompositeSliceContent = {
|
|
10
|
+
repeat: GroupItemContent[]
|
|
11
|
+
nonRepeat: { [key: string]: SimpleWidgetContent }
|
|
12
|
+
__TYPE__: typeof CompositeSliceContentType
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const codec = t.exact(
|
|
16
|
+
t.partial({
|
|
17
|
+
repeat: t.array(t.unknown),
|
|
18
|
+
"non-repeat": t.UnknownRecord,
|
|
19
|
+
}),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
export const CompositeSliceContent = {
|
|
23
|
+
fromJson: (
|
|
24
|
+
prefixes: Array<string>,
|
|
25
|
+
key: string,
|
|
26
|
+
value: unknown,
|
|
27
|
+
fieldTypes: Map<string, string>,
|
|
28
|
+
fieldPositions: Map<string, number>,
|
|
29
|
+
): O.Option<CompositeSliceContent> => {
|
|
30
|
+
const prefixedRepeatKey = Array.of(prefixes, [key, "repeat"])
|
|
31
|
+
.flat()
|
|
32
|
+
.join(".")
|
|
33
|
+
|
|
34
|
+
const decodedValue = codec.decode(value)
|
|
35
|
+
if (isRight(decodedValue)) {
|
|
36
|
+
const repeatObj = decodedValue.right.repeat
|
|
37
|
+
const nonRepeatObj = decodedValue.right["non-repeat"] ?? {}
|
|
38
|
+
const groupItemsContentsRepeat = GroupContent.itemsContentsFromJson(
|
|
39
|
+
prefixedRepeatKey,
|
|
40
|
+
repeatObj,
|
|
41
|
+
fieldTypes,
|
|
42
|
+
fieldPositions,
|
|
43
|
+
)
|
|
44
|
+
const sortedFields = Object.entries(nonRepeatObj).sort(([k1], [k2]) => {
|
|
45
|
+
const p1 =
|
|
46
|
+
fieldPositions.get(
|
|
47
|
+
`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`,
|
|
48
|
+
) ?? 10000
|
|
49
|
+
const p2 =
|
|
50
|
+
fieldPositions.get(
|
|
51
|
+
`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`,
|
|
52
|
+
) ?? 10000
|
|
53
|
+
return p1 - p2
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const nonRepeat = sortedFields.reduce((acc, [k, v]) => {
|
|
57
|
+
const kp = Array.of(prefixes, [key, "non-repeat", k]).flat().join(".")
|
|
58
|
+
const kind = fieldTypes.get(kp)
|
|
59
|
+
if (kind) {
|
|
60
|
+
const mWidgetContent = SimpleWidgetContent.from(kind, v)
|
|
61
|
+
if (O.isSome(mWidgetContent)) {
|
|
62
|
+
acc[k] = mWidgetContent.value
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return acc
|
|
66
|
+
}, {} as Record<string, SimpleWidgetContent>)
|
|
67
|
+
|
|
68
|
+
return O.some({
|
|
69
|
+
repeat: groupItemsContentsRepeat,
|
|
70
|
+
nonRepeat,
|
|
71
|
+
__TYPE__: "CompositeSliceContent",
|
|
72
|
+
})
|
|
73
|
+
} else {
|
|
74
|
+
return O.none
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { map } from "fp-ts/Either"
|
|
2
|
+
import * as O from "fp-ts/Option"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
import { withFallback } from "io-ts-types"
|
|
5
|
+
|
|
6
|
+
import type { GroupItemContent } from "../GroupContent"
|
|
7
|
+
import { GroupContent, SimpleWidgetContent } from "../index"
|
|
8
|
+
|
|
9
|
+
export const SharedSliceContentType = "SharedSliceContent"
|
|
10
|
+
export type SharedSliceContent = {
|
|
11
|
+
variation: string
|
|
12
|
+
primary: { [key: string]: SimpleWidgetContent }
|
|
13
|
+
items: GroupItemContent[]
|
|
14
|
+
__TYPE__: typeof SharedSliceContentType
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const codec = t.exact(
|
|
18
|
+
t.type({
|
|
19
|
+
variation: t.string,
|
|
20
|
+
items: withFallback(t.array(t.unknown), []),
|
|
21
|
+
primary: withFallback(t.UnknownRecord, {}),
|
|
22
|
+
}),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
export const SharedSliceContent = {
|
|
26
|
+
fromJson: (
|
|
27
|
+
prefixes: Array<string>,
|
|
28
|
+
key: string,
|
|
29
|
+
value: unknown,
|
|
30
|
+
fieldTypes: Map<string, string>,
|
|
31
|
+
fieldPositions: Map<string, number>,
|
|
32
|
+
): O.Option<SharedSliceContent> => {
|
|
33
|
+
type SharedSliceContentC = t.TypeOf<typeof codec>
|
|
34
|
+
|
|
35
|
+
const r = map((v: SharedSliceContentC) => {
|
|
36
|
+
const prefixedItemsKey = Array.of(prefixes, [
|
|
37
|
+
key,
|
|
38
|
+
"variations",
|
|
39
|
+
v.variation,
|
|
40
|
+
"items",
|
|
41
|
+
])
|
|
42
|
+
.flat()
|
|
43
|
+
.join(".")
|
|
44
|
+
const groupItemsContents = GroupContent.itemsContentsFromJson(
|
|
45
|
+
prefixedItemsKey,
|
|
46
|
+
v.items,
|
|
47
|
+
fieldTypes,
|
|
48
|
+
fieldPositions,
|
|
49
|
+
)
|
|
50
|
+
const sortedFields = Object.entries(v.primary).sort(([k1], [k2]) => {
|
|
51
|
+
const p1 =
|
|
52
|
+
fieldPositions.get(
|
|
53
|
+
`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`,
|
|
54
|
+
) ?? 10000
|
|
55
|
+
const p2 =
|
|
56
|
+
fieldPositions.get(
|
|
57
|
+
`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`,
|
|
58
|
+
) ?? 10000
|
|
59
|
+
return p1 - p2
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const primary = sortedFields.reduce((acc, [k, w]) => {
|
|
63
|
+
const kp = Array.of(prefixes, [
|
|
64
|
+
key,
|
|
65
|
+
"variations",
|
|
66
|
+
v.variation,
|
|
67
|
+
"primary",
|
|
68
|
+
k,
|
|
69
|
+
])
|
|
70
|
+
.flat()
|
|
71
|
+
.join(".")
|
|
72
|
+
const kind = fieldTypes.get(kp)
|
|
73
|
+
if (kind) {
|
|
74
|
+
const maybeWidgetContent = SimpleWidgetContent.from(kind, w)
|
|
75
|
+
if (O.isSome(maybeWidgetContent)) {
|
|
76
|
+
acc[k] = maybeWidgetContent.value
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return acc
|
|
80
|
+
}, {} as Record<string, SimpleWidgetContent>)
|
|
81
|
+
|
|
82
|
+
const result: SharedSliceContent = {
|
|
83
|
+
variation: v.variation,
|
|
84
|
+
primary,
|
|
85
|
+
items: groupItemsContents,
|
|
86
|
+
__TYPE__: "SharedSliceContent",
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return result
|
|
90
|
+
})(codec.decode(value))
|
|
91
|
+
|
|
92
|
+
return O.fromEither(r)
|
|
93
|
+
},
|
|
94
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as O from "fp-ts/Option"
|
|
2
|
+
|
|
3
|
+
import StaticWidgetContent from "../StaticWidgetContent"
|
|
4
|
+
import { CompositeSliceContent } from "./CompositeSliceContent"
|
|
5
|
+
import { SharedSliceContent } from "./SharedSliceContent"
|
|
6
|
+
import type { SimpleSliceContent } from "./SimpleSliceContent"
|
|
7
|
+
|
|
8
|
+
export type SliceWidgetContent =
|
|
9
|
+
| SimpleSliceContent
|
|
10
|
+
| CompositeSliceContent
|
|
11
|
+
| SharedSliceContent
|
|
12
|
+
export const SliceWidgetContent = {
|
|
13
|
+
fromJson: (
|
|
14
|
+
prefixes: Array<string>,
|
|
15
|
+
key: string,
|
|
16
|
+
value: unknown,
|
|
17
|
+
fieldTypes: Map<string, string>,
|
|
18
|
+
fieldPositions: Map<string, number>,
|
|
19
|
+
): O.Option<SliceWidgetContent> => {
|
|
20
|
+
const prefixedKey = Array.of(prefixes, [key]).flat().join(".")
|
|
21
|
+
|
|
22
|
+
const fieldType = fieldTypes.get(prefixedKey)
|
|
23
|
+
if (fieldType === "SharedSlice") {
|
|
24
|
+
return SharedSliceContent.fromJson(
|
|
25
|
+
prefixes,
|
|
26
|
+
key,
|
|
27
|
+
value,
|
|
28
|
+
fieldTypes,
|
|
29
|
+
fieldPositions,
|
|
30
|
+
)
|
|
31
|
+
} else if (fieldType === "Slice") {
|
|
32
|
+
return CompositeSliceContent.fromJson(
|
|
33
|
+
prefixes,
|
|
34
|
+
key,
|
|
35
|
+
value,
|
|
36
|
+
fieldTypes,
|
|
37
|
+
fieldPositions,
|
|
38
|
+
)
|
|
39
|
+
} else if (fieldType) {
|
|
40
|
+
return StaticWidgetContent.fromJson(
|
|
41
|
+
prefixes,
|
|
42
|
+
key,
|
|
43
|
+
value,
|
|
44
|
+
fieldTypes,
|
|
45
|
+
fieldPositions,
|
|
46
|
+
)
|
|
47
|
+
} else {
|
|
48
|
+
return O.none
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as A from "fp-ts/Array"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as O from "fp-ts/Option"
|
|
4
|
+
import * as t from "io-ts"
|
|
5
|
+
|
|
6
|
+
import { nullable } from "../../../validators/function"
|
|
7
|
+
import { SliceWidgetContent } from "./SliceWidgetContent"
|
|
8
|
+
|
|
9
|
+
export type SlicesContentItem = {
|
|
10
|
+
key: string
|
|
11
|
+
name: string
|
|
12
|
+
maybeLabel: string | undefined
|
|
13
|
+
widget: SliceWidgetContent
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const SlicesContentType = "SliceContentType"
|
|
17
|
+
export type SlicesContent = {
|
|
18
|
+
__TYPE__: typeof SlicesContentType
|
|
19
|
+
value: SlicesContentItem[]
|
|
20
|
+
}
|
|
21
|
+
const codec = t.exact(
|
|
22
|
+
t.intersection([
|
|
23
|
+
t.type({
|
|
24
|
+
key: t.string,
|
|
25
|
+
value: t.unknown,
|
|
26
|
+
}),
|
|
27
|
+
t.partial({
|
|
28
|
+
label: nullable(t.string),
|
|
29
|
+
}),
|
|
30
|
+
]),
|
|
31
|
+
)
|
|
32
|
+
export const SlicesContent = {
|
|
33
|
+
itemsCodec: (
|
|
34
|
+
value: unknown,
|
|
35
|
+
codecWidget: (n: string, v: unknown) => O.Option<SliceWidgetContent>,
|
|
36
|
+
): O.Option<SlicesContentItem> => {
|
|
37
|
+
return pipe(
|
|
38
|
+
codec.decode(value),
|
|
39
|
+
O.fromEither,
|
|
40
|
+
O.chain((r) => {
|
|
41
|
+
const stopIdx = r.key.indexOf("$")
|
|
42
|
+
const name = r.key.substring(0, stopIdx > 0 ? stopIdx : undefined)
|
|
43
|
+
const maybeWidget = codecWidget(name, r.value)
|
|
44
|
+
return O.map((widget) => {
|
|
45
|
+
return {
|
|
46
|
+
key: r.key,
|
|
47
|
+
name,
|
|
48
|
+
maybeLabel: r.label ?? undefined,
|
|
49
|
+
widget: widget,
|
|
50
|
+
} as SlicesContentItem
|
|
51
|
+
})(maybeWidget)
|
|
52
|
+
}),
|
|
53
|
+
)
|
|
54
|
+
},
|
|
55
|
+
fromJson: (
|
|
56
|
+
key: string,
|
|
57
|
+
value: unknown,
|
|
58
|
+
fieldTypes: Map<string, string>,
|
|
59
|
+
fieldPositions: Map<string, number>,
|
|
60
|
+
): O.Option<SlicesContent> => {
|
|
61
|
+
if (fieldTypes.get(key) === "Slices") {
|
|
62
|
+
const jsItems = O.getOrElse(() => new Array<unknown>())(
|
|
63
|
+
O.fromEither(t.array(t.unknown).decode(value)),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
const widgetCodec = (
|
|
67
|
+
name: string,
|
|
68
|
+
wValue: unknown,
|
|
69
|
+
): O.Option<SliceWidgetContent> =>
|
|
70
|
+
SliceWidgetContent.fromJson(
|
|
71
|
+
[key],
|
|
72
|
+
name,
|
|
73
|
+
wValue,
|
|
74
|
+
fieldTypes,
|
|
75
|
+
fieldPositions,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return O.some({
|
|
79
|
+
value: A.compact(
|
|
80
|
+
jsItems.map((jsItem: unknown) =>
|
|
81
|
+
SlicesContent.itemsCodec(jsItem, widgetCodec),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
__TYPE__: SlicesContentType,
|
|
85
|
+
} as const)
|
|
86
|
+
} else {
|
|
87
|
+
console.error("fieldTypes.get(key) !== 'Slices'")
|
|
88
|
+
return O.none
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { chain } from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
export default new t.Type<Date, string, unknown>(
|
|
6
|
+
"dateFromString",
|
|
7
|
+
(u): u is Date => u instanceof Date,
|
|
8
|
+
(u, c) =>
|
|
9
|
+
pipe(
|
|
10
|
+
t.string.validate(u, c),
|
|
11
|
+
chain((s) => {
|
|
12
|
+
const d = new Date(s)
|
|
13
|
+
return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d)
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
(date) => date.toISOString(),
|
|
17
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { chain } from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
export default new t.Type<Date, Date, unknown>(
|
|
6
|
+
"dateFromStringOrNumber",
|
|
7
|
+
(u): u is Date => u instanceof Date,
|
|
8
|
+
(u, c) =>
|
|
9
|
+
pipe(
|
|
10
|
+
t.union([t.number, t.string]).validate(u, c),
|
|
11
|
+
chain((s) => {
|
|
12
|
+
const d = new Date(s)
|
|
13
|
+
return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d)
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
(date) => date,
|
|
17
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { chain } from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
export default new t.Type<Date, number, unknown>(
|
|
6
|
+
"dateFromTsMs",
|
|
7
|
+
(u): u is Date => u instanceof Date,
|
|
8
|
+
(u, c) =>
|
|
9
|
+
pipe(
|
|
10
|
+
t.number.validate(u, c),
|
|
11
|
+
chain((s) => {
|
|
12
|
+
const d = new Date(s)
|
|
13
|
+
return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d)
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
(date) => date.getTime(),
|
|
17
|
+
)
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
t.Int.encode
|
|
24
|
-
)
|
|
1
|
+
import { chain } from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
export type IntFromNumberC = t.Type<t.Int, number, unknown>
|
|
6
|
+
|
|
7
|
+
/** A codec that succeeds if a number can be parsed to an integer */
|
|
8
|
+
export default new t.Type<t.Int, number, unknown>(
|
|
9
|
+
"IntFromNumber",
|
|
10
|
+
t.Int.is,
|
|
11
|
+
(u, c) =>
|
|
12
|
+
pipe(
|
|
13
|
+
t.number.validate(u, c),
|
|
14
|
+
chain((n) => {
|
|
15
|
+
if (t.Int.is(n)) return t.success(n)
|
|
16
|
+
else {
|
|
17
|
+
return t.success(Math.round(n) as t.Int)
|
|
18
|
+
}
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
t.Int.encode,
|
|
22
|
+
)
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { pipe } from
|
|
3
|
-
import
|
|
1
|
+
import { chain } from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export type IntFromPixelsC = t.Type<t.Int, string, unknown>
|
|
6
6
|
|
|
7
7
|
const PixelsRegex = /^([0-9]+)px$/
|
|
8
8
|
/**
|
|
9
|
-
* A codec that succeeds if a string representing pixels (eg: "200px") can be
|
|
9
|
+
* A codec that succeeds if a string representing pixels (eg: "200px") can be
|
|
10
|
+
* parsed to an integer
|
|
10
11
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
12
|
+
export default new t.Type<t.Int, string, unknown>(
|
|
13
|
+
"IntFromPixels",
|
|
14
|
+
t.Int.is,
|
|
15
|
+
(u, c) =>
|
|
16
|
+
pipe(
|
|
17
|
+
t.string.validate(u, c),
|
|
18
|
+
chain((strPixels) => {
|
|
19
|
+
try {
|
|
20
|
+
const matched = strPixels.match(PixelsRegex)
|
|
21
|
+
if (!matched) return t.failure(u, c)
|
|
22
|
+
|
|
23
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
24
|
+
const parsed = parseInt(matched[1]!) as t.Int
|
|
25
|
+
return t.success(parsed)
|
|
26
|
+
} catch {
|
|
27
|
+
return t.failure(u, c)
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
String,
|
|
32
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { chain } from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import { success, Type } from "io-ts"
|
|
4
|
+
|
|
5
|
+
import StringOrNull from "./StringOrNull"
|
|
6
|
+
|
|
7
|
+
export default new Type<string | null, string | null, unknown>(
|
|
8
|
+
"nonEmptyStringOrNull",
|
|
9
|
+
(u): u is string => typeof u === "string" || u === null,
|
|
10
|
+
(u, c) =>
|
|
11
|
+
pipe(
|
|
12
|
+
StringOrNull.validate(u, c),
|
|
13
|
+
chain((s) => {
|
|
14
|
+
if (typeof s === "string" && s.length > 0) {
|
|
15
|
+
return success(s)
|
|
16
|
+
} else {
|
|
17
|
+
return success(null)
|
|
18
|
+
}
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
(s) => s,
|
|
22
|
+
)
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { pipe } from
|
|
3
|
-
import
|
|
1
|
+
import { chain } from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export type StringFromBooleanC = t.Type<string, string, unknown>
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
i => i
|
|
21
|
-
)
|
|
7
|
+
/** A codec that validates a Boolean and convert it as a string */
|
|
8
|
+
export default new t.Type<string, string, unknown>(
|
|
9
|
+
"StringFromInt",
|
|
10
|
+
t.string.is,
|
|
11
|
+
(u, c) =>
|
|
12
|
+
pipe(
|
|
13
|
+
t.boolean.validate(u, c),
|
|
14
|
+
chain((i) => {
|
|
15
|
+
return t.success(i.toString())
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
(i) => i,
|
|
19
|
+
)
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { pipe } from
|
|
3
|
-
import
|
|
1
|
+
import { chain } from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export type StringFromNumberC = t.Type<string, string, unknown>
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
i => i
|
|
21
|
-
)
|
|
7
|
+
/** A codec that validates a number and convert it as a string */
|
|
8
|
+
export default new t.Type<string, string, unknown>(
|
|
9
|
+
"StringFromInt",
|
|
10
|
+
t.string.is,
|
|
11
|
+
(u, c) =>
|
|
12
|
+
pipe(
|
|
13
|
+
t.number.validate(u, c),
|
|
14
|
+
chain((i) => {
|
|
15
|
+
return t.success(i.toString())
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
(i) => i,
|
|
19
|
+
)
|