@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,46 @@
|
|
|
1
|
+
import * as O from "fp-ts/Option"
|
|
2
|
+
|
|
3
|
+
import { GroupContent, GroupContentType } from "./GroupContent"
|
|
4
|
+
import {
|
|
5
|
+
NonEmptySimpleWidgetContent,
|
|
6
|
+
SimpleWidgetContent,
|
|
7
|
+
} from "./SimpleWidgetContent"
|
|
8
|
+
|
|
9
|
+
type StaticWidgetContent = SimpleWidgetContent | GroupContent
|
|
10
|
+
export type NonEmptyStaticWidgetContent =
|
|
11
|
+
| NonEmptySimpleWidgetContent
|
|
12
|
+
| GroupContent
|
|
13
|
+
|
|
14
|
+
const StaticWidgetContent = {
|
|
15
|
+
fromJson: (
|
|
16
|
+
prefixes: Array<string>,
|
|
17
|
+
key: string,
|
|
18
|
+
value: unknown,
|
|
19
|
+
fieldTypes: Map<string, string>,
|
|
20
|
+
fieldPositions: Map<string, number>,
|
|
21
|
+
): O.Option<StaticWidgetContent> => {
|
|
22
|
+
const prefixedKey = Array.of(prefixes, [key]).flat().join(".")
|
|
23
|
+
const type = fieldTypes.get(prefixedKey)
|
|
24
|
+
if (type === "Group") {
|
|
25
|
+
return GroupContent.fromJson(
|
|
26
|
+
prefixes,
|
|
27
|
+
key,
|
|
28
|
+
value,
|
|
29
|
+
fieldTypes,
|
|
30
|
+
fieldPositions,
|
|
31
|
+
)
|
|
32
|
+
} else if (type) {
|
|
33
|
+
return SimpleWidgetContent.from(type, value)
|
|
34
|
+
} else {
|
|
35
|
+
return O.none
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
is: (value: unknown): value is StaticWidgetContent => {
|
|
39
|
+
return (
|
|
40
|
+
SimpleWidgetContent.is(value) ||
|
|
41
|
+
GroupContentType === (value as StaticWidgetContent).__TYPE__
|
|
42
|
+
)
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default StaticWidgetContent
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Chain } from "fp-ts/Either"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
|
|
4
|
+
export type UIDContent = {
|
|
5
|
+
__TYPE__: "UIDContent"
|
|
6
|
+
value: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const UIDContentType = "UIDContent"
|
|
10
|
+
export const UIDContent = new t.Type<UIDContent, string>(
|
|
11
|
+
"UIDContent",
|
|
12
|
+
(u): u is UIDContent => (u as UIDContent)?.__TYPE__ === UIDContentType,
|
|
13
|
+
(u, c) =>
|
|
14
|
+
Chain.chain(t.string.validate(u, c), (u) => {
|
|
15
|
+
return t.success({ value: u, __TYPE__: "UIDContent" } as const)
|
|
16
|
+
}),
|
|
17
|
+
(uidContent) => uidContent.value,
|
|
18
|
+
)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EmptyContentType } from "./EmptyContent"
|
|
2
|
+
import { GroupContentType } from "./GroupContent"
|
|
3
|
+
import { NestableTypes } from "./nestable"
|
|
4
|
+
import { SlicesContent, SlicesContentType } from "./slices/SlicesContent"
|
|
5
|
+
import StaticWidgetContent from "./StaticWidgetContent"
|
|
6
|
+
import { UIDContentType } from "./UIDContent"
|
|
7
|
+
|
|
8
|
+
export * from "./EmptyContent"
|
|
9
|
+
export * from "./GroupContent"
|
|
10
|
+
export * as Nestable from "./nestable"
|
|
11
|
+
export * from "./SimpleWidgetContent"
|
|
12
|
+
export * as Slices from "./slices"
|
|
13
|
+
export {
|
|
14
|
+
type NonEmptyStaticWidgetContent,
|
|
15
|
+
default as StaticWidgetContent,
|
|
16
|
+
} from "./StaticWidgetContent"
|
|
17
|
+
export * from "./UIDContent"
|
|
18
|
+
|
|
19
|
+
export const WidgetTypes = {
|
|
20
|
+
...NestableTypes,
|
|
21
|
+
Empty: EmptyContentType,
|
|
22
|
+
UID: UIDContentType,
|
|
23
|
+
Group: GroupContentType,
|
|
24
|
+
slices: SlicesContentType,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type WidgetKey = string
|
|
28
|
+
export type WidgetContent = SlicesContent | StaticWidgetContent
|
|
29
|
+
|
|
30
|
+
export const Widget = {
|
|
31
|
+
fromJson(
|
|
32
|
+
widgetKey: WidgetKey,
|
|
33
|
+
widgetValue: unknown,
|
|
34
|
+
widgetTypes: Map<WidgetKey, string>,
|
|
35
|
+
widgetPositions: Map<WidgetKey, number>,
|
|
36
|
+
) {
|
|
37
|
+
const fieldType = widgetTypes.get(widgetKey)
|
|
38
|
+
|
|
39
|
+
if (fieldType === "Slices") {
|
|
40
|
+
return SlicesContent.fromJson(
|
|
41
|
+
widgetKey,
|
|
42
|
+
widgetValue,
|
|
43
|
+
widgetTypes,
|
|
44
|
+
widgetPositions,
|
|
45
|
+
)
|
|
46
|
+
} else {
|
|
47
|
+
return StaticWidgetContent.fromJson(
|
|
48
|
+
[],
|
|
49
|
+
widgetKey,
|
|
50
|
+
widgetValue,
|
|
51
|
+
widgetTypes,
|
|
52
|
+
widgetPositions,
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Chain } from "fp-ts/Either"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
|
|
4
|
+
type BooleanContent = {
|
|
5
|
+
__TYPE__: "BooleanContent"
|
|
6
|
+
value: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const BooleanContentType = "BooleanContent"
|
|
10
|
+
const BooleanContent = new t.Type<BooleanContent, boolean>(
|
|
11
|
+
"BooleanContent",
|
|
12
|
+
(u): u is BooleanContent =>
|
|
13
|
+
(u as BooleanContent)?.__TYPE__ === BooleanContentType,
|
|
14
|
+
(u, c) =>
|
|
15
|
+
Chain.chain(t.boolean.validate(u, c), (u) => {
|
|
16
|
+
return t.success({ value: u, __TYPE__: BooleanContentType } as const)
|
|
17
|
+
}),
|
|
18
|
+
(booleanContent) => t.boolean.encode(booleanContent.value),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
export default BooleanContent
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { either } from "fp-ts"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
import { NumberOrNull, StringOrNull } from "../../../validators"
|
|
6
|
+
import { addType } from "../../../validators/function"
|
|
7
|
+
|
|
8
|
+
export const EmbedContentType = "EmbedContent"
|
|
9
|
+
|
|
10
|
+
type EmbedContent = t.OutputOf<typeof EmbedContentC> & {
|
|
11
|
+
all: unknown
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const EmbedContent = new t.Type<EmbedContent, unknown, unknown>(
|
|
15
|
+
"EmbedContent",
|
|
16
|
+
(u): u is EmbedContent => (u as EmbedContent).__TYPE__ === EmbedContentType,
|
|
17
|
+
(u) => {
|
|
18
|
+
return pipe(
|
|
19
|
+
EmbedContentC.decode(u),
|
|
20
|
+
either.map((s) => ({
|
|
21
|
+
...EmbedContentC.encode(s),
|
|
22
|
+
all: u,
|
|
23
|
+
})),
|
|
24
|
+
)
|
|
25
|
+
},
|
|
26
|
+
(ec: EmbedContent) => EmbedContentC.encode(ec),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const EmbedContentC = addType(
|
|
30
|
+
t.exact(
|
|
31
|
+
t.intersection([
|
|
32
|
+
t.type({
|
|
33
|
+
embed_url: t.string,
|
|
34
|
+
type: t.string,
|
|
35
|
+
}),
|
|
36
|
+
t.partial({
|
|
37
|
+
version: t.union([t.string, t.number, t.null]),
|
|
38
|
+
title: StringOrNull,
|
|
39
|
+
author_name: StringOrNull,
|
|
40
|
+
author_url: StringOrNull,
|
|
41
|
+
provider_name: StringOrNull,
|
|
42
|
+
provider_url: StringOrNull,
|
|
43
|
+
cache_age: t.union([t.string, t.number, t.null]),
|
|
44
|
+
thumbnail_url: StringOrNull,
|
|
45
|
+
thumbnail_width: NumberOrNull,
|
|
46
|
+
thumbnail_height: NumberOrNull,
|
|
47
|
+
html: StringOrNull,
|
|
48
|
+
}),
|
|
49
|
+
]),
|
|
50
|
+
),
|
|
51
|
+
EmbedContentType,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
export default EmbedContent
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { pipe } from "fp-ts/function"
|
|
2
|
+
import * as O from "fp-ts/Option"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
export const FieldContentType = "FieldContent"
|
|
6
|
+
type FieldContent = {
|
|
7
|
+
value: string
|
|
8
|
+
type: string
|
|
9
|
+
__TYPE__: typeof FieldContentType
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//we do that instead of idiomatic .trim()
|
|
13
|
+
//because we need to have the exact same behaviour than scala/java .trim()
|
|
14
|
+
//in other world only trim space and not non-breaking space or tab
|
|
15
|
+
function trimScalaStyle(s: string): string {
|
|
16
|
+
let startAt = 0
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
18
|
+
while (startAt < s.length && s[startAt]! <= " ") {
|
|
19
|
+
startAt++
|
|
20
|
+
}
|
|
21
|
+
let endAt = s.length
|
|
22
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
23
|
+
while (startAt < endAt && s[endAt - 1]! <= " ") {
|
|
24
|
+
endAt--
|
|
25
|
+
}
|
|
26
|
+
return s.substring(startAt, endAt)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const FieldContent = {
|
|
30
|
+
types: ["Text", "Date", "Timestamp", "Color", "Number", "Range", "Select"],
|
|
31
|
+
forType: (type: string, value: unknown): O.Option<FieldContent> => {
|
|
32
|
+
return pipe(
|
|
33
|
+
O.fromEither(t.string.decode(value)),
|
|
34
|
+
O.map((r) => {
|
|
35
|
+
return {
|
|
36
|
+
value: trimScalaStyle(r),
|
|
37
|
+
type,
|
|
38
|
+
__TYPE__: "FieldContent",
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
)
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default FieldContent
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { addType } from "../../../validators/function"
|
|
4
|
+
|
|
5
|
+
export const GeoPointContentType = "GeoPointContent"
|
|
6
|
+
|
|
7
|
+
export const GeoPointContent = addType(
|
|
8
|
+
t.strict({
|
|
9
|
+
position: t.strict({
|
|
10
|
+
lat: t.number,
|
|
11
|
+
lng: t.number,
|
|
12
|
+
}),
|
|
13
|
+
}),
|
|
14
|
+
GeoPointContentType,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
export type GeoPointContent = t.TypeOf<typeof GeoPointContent>
|
|
18
|
+
export type GeoPointContentO = t.OutputOf<typeof GeoPointContent>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { NonEmptyStringOrNull, StringOrNull } from "../../../validators"
|
|
4
|
+
import { addType } from "../../../validators/function"
|
|
5
|
+
|
|
6
|
+
const Origin = t.exact(
|
|
7
|
+
t.type({
|
|
8
|
+
id: t.string,
|
|
9
|
+
url: t.string,
|
|
10
|
+
width: t.number,
|
|
11
|
+
height: t.number,
|
|
12
|
+
}),
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
export const ImageContentView = t.exact(
|
|
16
|
+
t.intersection([
|
|
17
|
+
t.type({
|
|
18
|
+
origin: Origin,
|
|
19
|
+
width: t.number,
|
|
20
|
+
height: t.number,
|
|
21
|
+
edit: t.type({
|
|
22
|
+
zoom: t.number,
|
|
23
|
+
crop: t.type({
|
|
24
|
+
x: t.number,
|
|
25
|
+
y: t.number,
|
|
26
|
+
}),
|
|
27
|
+
background: t.string,
|
|
28
|
+
}),
|
|
29
|
+
}),
|
|
30
|
+
t.partial({
|
|
31
|
+
url: t.string,
|
|
32
|
+
credits: NonEmptyStringOrNull,
|
|
33
|
+
alt: NonEmptyStringOrNull,
|
|
34
|
+
provider: StringOrNull,
|
|
35
|
+
}),
|
|
36
|
+
]),
|
|
37
|
+
)
|
|
38
|
+
export type ImageContentView = t.TypeOf<typeof ImageContentView>
|
|
39
|
+
|
|
40
|
+
export const ImageContentType = "ImageContent"
|
|
41
|
+
export const ImageContent = addType(
|
|
42
|
+
t.intersection([
|
|
43
|
+
ImageContentView,
|
|
44
|
+
t.partial({
|
|
45
|
+
thumbnails: t.record(t.string, ImageContentView),
|
|
46
|
+
}),
|
|
47
|
+
]),
|
|
48
|
+
ImageContentType,
|
|
49
|
+
)
|
|
50
|
+
export type ImageContent = t.TypeOf<typeof ImageContent>
|
|
51
|
+
export type ImageContentO = t.OutputOf<typeof ImageContent>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Chain } from "fp-ts/Either"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
|
|
4
|
+
type IntegrationFieldsContent = {
|
|
5
|
+
__TYPE__: "IntegrationFieldsContent"
|
|
6
|
+
value: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const IntegrationFieldsContentType = "IntegrationFieldsContent"
|
|
10
|
+
const IntegrationFieldsContent = new t.Type<IntegrationFieldsContent>(
|
|
11
|
+
"IntegrationFieldsContent",
|
|
12
|
+
(u): u is IntegrationFieldsContent =>
|
|
13
|
+
(u as IntegrationFieldsContent)?.__TYPE__ === IntegrationFieldsContentType,
|
|
14
|
+
(u, c) =>
|
|
15
|
+
Chain.chain(t.string.validate(u, c), (u) => {
|
|
16
|
+
return t.success({
|
|
17
|
+
value: u,
|
|
18
|
+
__TYPE__: IntegrationFieldsContentType,
|
|
19
|
+
} as const)
|
|
20
|
+
}),
|
|
21
|
+
() => {
|
|
22
|
+
throw new Error("Not implemented - Not used - Not relevant")
|
|
23
|
+
},
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export default IntegrationFieldsContent
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { NonEmptyString } from "../../../../validators"
|
|
4
|
+
import { addType } from "../../../../validators/function"
|
|
5
|
+
|
|
6
|
+
export const DocumentLinkType = "DocumentLink"
|
|
7
|
+
|
|
8
|
+
export const DocumentLink = addType(
|
|
9
|
+
t.strict({ id: NonEmptyString }),
|
|
10
|
+
DocumentLinkType,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
export type DocumentLink = t.TypeOf<typeof DocumentLink>
|
|
14
|
+
export type DocumentLinkO = t.OutputOf<typeof DocumentLink>
|
|
15
|
+
|
|
16
|
+
export function isDocumentLink(u: unknown): u is DocumentLinkO {
|
|
17
|
+
return (u as DocumentLinkO).__TYPE__ === DocumentLinkType
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { StringOrNull } from "../../../../validators"
|
|
4
|
+
import { addType, nullable } from "../../../../validators/function"
|
|
5
|
+
|
|
6
|
+
export const ExternalLinkType = "ExternalLink"
|
|
7
|
+
export const ExternalLink = addType(
|
|
8
|
+
t.exact(
|
|
9
|
+
t.intersection([
|
|
10
|
+
t.type({
|
|
11
|
+
url: t.string,
|
|
12
|
+
}),
|
|
13
|
+
t.partial({
|
|
14
|
+
kind: t.literal("web"),
|
|
15
|
+
target: StringOrNull,
|
|
16
|
+
preview: nullable(
|
|
17
|
+
t.partial({
|
|
18
|
+
title: t.string,
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
}),
|
|
22
|
+
]),
|
|
23
|
+
),
|
|
24
|
+
ExternalLinkType,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
export type ExternalLink = t.TypeOf<typeof ExternalLink>
|
|
28
|
+
export type ExternalLinkO = t.OutputOf<typeof ExternalLink>
|
|
29
|
+
export function isExternalLink(u: unknown): u is ExternalLinkO {
|
|
30
|
+
return (u as ExternalLinkO).__TYPE__ === ExternalLinkType
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
import { mapOutput } from "io-ts-types/lib/mapOutput"
|
|
3
|
+
|
|
4
|
+
import { nullable } from "../../../../validators/function"
|
|
5
|
+
|
|
6
|
+
export const FileLinkType = "FileLink"
|
|
7
|
+
export const FileLink = mapOutput(
|
|
8
|
+
t.exact(
|
|
9
|
+
t.intersection([
|
|
10
|
+
t.type({
|
|
11
|
+
id: t.string,
|
|
12
|
+
url: t.string,
|
|
13
|
+
name: t.string,
|
|
14
|
+
kind: t.string,
|
|
15
|
+
}),
|
|
16
|
+
t.partial({
|
|
17
|
+
date: nullable(t.string),
|
|
18
|
+
size: nullable(t.string),
|
|
19
|
+
}),
|
|
20
|
+
]),
|
|
21
|
+
),
|
|
22
|
+
(o) => ({ ...o, size: o.size || "0", __TYPE__: FileLinkType } as const),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
export type FileLink = t.TypeOf<typeof FileLink>
|
|
26
|
+
export type FileLinkO = t.OutputOf<typeof FileLink>
|
|
27
|
+
export function isFileLink(u: unknown): u is FileLinkO {
|
|
28
|
+
return (u as FileLinkO).__TYPE__ === FileLinkType
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { StringOrNull } from "../../../../validators"
|
|
4
|
+
import { addType } from "../../../../validators/function"
|
|
5
|
+
|
|
6
|
+
export const ImageLinkType = "ImageLink"
|
|
7
|
+
export const ImageLink = addType(
|
|
8
|
+
t.exact(
|
|
9
|
+
t.intersection([
|
|
10
|
+
t.type({
|
|
11
|
+
id: t.string,
|
|
12
|
+
url: t.string,
|
|
13
|
+
height: t.string,
|
|
14
|
+
width: t.string,
|
|
15
|
+
size: t.string,
|
|
16
|
+
name: t.string,
|
|
17
|
+
kind: t.string,
|
|
18
|
+
}),
|
|
19
|
+
t.partial({
|
|
20
|
+
date: StringOrNull,
|
|
21
|
+
}),
|
|
22
|
+
]),
|
|
23
|
+
),
|
|
24
|
+
ImageLinkType,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
export type ImageLink = t.TypeOf<typeof ImageLink>
|
|
28
|
+
export type ImageLinkO = t.OutputOf<typeof ImageLink>
|
|
29
|
+
export function isImageLink(u: unknown): u is ImageLinkO {
|
|
30
|
+
return (u as ImageLinkO).__TYPE__ === ImageLinkType
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Chain } from "fp-ts/Either"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
|
|
4
|
+
import { Link } from "./index"
|
|
5
|
+
|
|
6
|
+
export type LinkContent = {
|
|
7
|
+
__TYPE__: "LinkContent"
|
|
8
|
+
value: Link
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const LinkContentType = "LinkContent"
|
|
12
|
+
export const LinkContent = new t.Type<LinkContent, Link>(
|
|
13
|
+
"LinkContent",
|
|
14
|
+
(u): u is LinkContent => {
|
|
15
|
+
return Link.is((u as LinkContent)?.value)
|
|
16
|
+
},
|
|
17
|
+
(u, c) =>
|
|
18
|
+
Chain.chain(Link.validate(u, c), (u) => {
|
|
19
|
+
return t.success({ value: u, __TYPE__: LinkContentType } as const)
|
|
20
|
+
}),
|
|
21
|
+
(linkContent) => Link.encode(linkContent.value),
|
|
22
|
+
)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { DocumentLink, DocumentLinkType, isDocumentLink } from "./DocumentLink"
|
|
4
|
+
import { ExternalLink, ExternalLinkType, isExternalLink } from "./ExternalLink"
|
|
5
|
+
import { FileLink, FileLinkType, isFileLink } from "./FileLink"
|
|
6
|
+
import { ImageLink, ImageLinkType, isImageLink } from "./ImageLink"
|
|
7
|
+
import { LinkContentType } from "./LinkContent"
|
|
8
|
+
|
|
9
|
+
export const Link = t.union([ImageLink, FileLink, DocumentLink, ExternalLink])
|
|
10
|
+
export type Link = t.TypeOf<typeof Link>
|
|
11
|
+
export type LinkO = t.OutputOf<typeof Link>
|
|
12
|
+
|
|
13
|
+
export { type DocumentLinkO, DocumentLink } from "./DocumentLink"
|
|
14
|
+
export { type ExternalLinkO, ExternalLink } from "./ExternalLink"
|
|
15
|
+
export { type FileLinkO, FileLink } from "./FileLink"
|
|
16
|
+
export { type ImageLinkO, ImageLink } from "./ImageLink"
|
|
17
|
+
export { LinkContent } from "./LinkContent"
|
|
18
|
+
|
|
19
|
+
export const BROKEN_CUSTOM_TYPE = "broken_type"
|
|
20
|
+
|
|
21
|
+
export const is = {
|
|
22
|
+
documentLink: isDocumentLink,
|
|
23
|
+
fileLink: isFileLink,
|
|
24
|
+
externalLink: isExternalLink,
|
|
25
|
+
imageLink: isImageLink,
|
|
26
|
+
}
|
|
27
|
+
export const LinksTypes = {
|
|
28
|
+
DocumentLink: DocumentLinkType,
|
|
29
|
+
FileLink: FileLinkType,
|
|
30
|
+
ExternalLink: ExternalLinkType,
|
|
31
|
+
ImageLink: ImageLinkType,
|
|
32
|
+
LinkContent: LinkContentType,
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const SeparatorContentType = "SeparatorContent"
|
|
2
|
+
export type SeparatorContent = { __TYPE__: typeof SeparatorContentType }
|
|
3
|
+
export const SeparatorContent = {
|
|
4
|
+
is(value: unknown): value is SeparatorContent {
|
|
5
|
+
const asFieldContent = value as SeparatorContent
|
|
6
|
+
return asFieldContent.__TYPE__ === "SeparatorContent"
|
|
7
|
+
},
|
|
8
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as E from "fp-ts/lib/Either"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
|
|
4
|
+
import { StringOrNull } from "../../../../validators"
|
|
5
|
+
import { nullable, refineType } from "../../../../validators/function"
|
|
6
|
+
import EmbedContent from "../EmbedContent"
|
|
7
|
+
import { ImageContentView } from "../ImageContent"
|
|
8
|
+
import { Link } from "../Link"
|
|
9
|
+
|
|
10
|
+
export const Meta = t.exact(
|
|
11
|
+
t.intersection([
|
|
12
|
+
t.partial({
|
|
13
|
+
data: t.unknown,
|
|
14
|
+
}),
|
|
15
|
+
t.type({
|
|
16
|
+
start: t.number,
|
|
17
|
+
end: t.number,
|
|
18
|
+
type: t.string,
|
|
19
|
+
}),
|
|
20
|
+
]),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
type Meta = t.TypeOf<typeof Meta>
|
|
24
|
+
|
|
25
|
+
export const ValidatedMetas = new t.Type<Meta[], Meta[], unknown>(
|
|
26
|
+
"ValidatedMetas",
|
|
27
|
+
(metas): metas is Meta[] => Array.isArray(metas) && metas.every(Meta.is),
|
|
28
|
+
(metas: unknown, c) => {
|
|
29
|
+
if (Array.isArray(metas)) {
|
|
30
|
+
const res = metas
|
|
31
|
+
.reduce<Array<Meta>>((acc, maybeMeta) => {
|
|
32
|
+
const maybeDecodedMeta = Meta.decode(maybeMeta)
|
|
33
|
+
if (E.isRight(maybeDecodedMeta)) {
|
|
34
|
+
const meta = maybeDecodedMeta.right
|
|
35
|
+
// if it's an hyperlink it should have data validated as link otherwise we don't care and keep the meta
|
|
36
|
+
if (
|
|
37
|
+
(meta.data &&
|
|
38
|
+
meta.type === "hyperlink" &&
|
|
39
|
+
E.isRight(Link.validate(meta.data, c))) ||
|
|
40
|
+
meta.type !== "hyperlink"
|
|
41
|
+
) {
|
|
42
|
+
return [...acc, meta]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return acc
|
|
46
|
+
}, [])
|
|
47
|
+
.sort((m1: Meta, m2: Meta) => m1.start - m2.start)
|
|
48
|
+
return t.success(res)
|
|
49
|
+
} else return t.failure(metas, c)
|
|
50
|
+
},
|
|
51
|
+
(m) => t.array(Meta).encode(m),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
export const ImageBlockType = "image"
|
|
55
|
+
|
|
56
|
+
export const ImageBlock = t.exact(
|
|
57
|
+
t.intersection([
|
|
58
|
+
t.type({
|
|
59
|
+
type: t.literal(ImageBlockType),
|
|
60
|
+
data: t.intersection([
|
|
61
|
+
ImageContentView,
|
|
62
|
+
t.partial({
|
|
63
|
+
linkTo: nullable(Link),
|
|
64
|
+
}),
|
|
65
|
+
]),
|
|
66
|
+
}),
|
|
67
|
+
t.partial({
|
|
68
|
+
label: StringOrNull,
|
|
69
|
+
direction: StringOrNull,
|
|
70
|
+
}),
|
|
71
|
+
]),
|
|
72
|
+
)
|
|
73
|
+
export type ImageBlock = t.TypeOf<typeof ImageBlock>
|
|
74
|
+
export function checkImageBlock(block: Block): block is ImageBlock {
|
|
75
|
+
return block.type === ImageBlockType
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const EmbedBlockType = "embed"
|
|
79
|
+
export const EmbedBlock = t.exact(
|
|
80
|
+
t.intersection([
|
|
81
|
+
t.type({
|
|
82
|
+
type: t.literal(EmbedBlockType),
|
|
83
|
+
data: EmbedContent,
|
|
84
|
+
}),
|
|
85
|
+
t.partial({
|
|
86
|
+
label: StringOrNull,
|
|
87
|
+
direction: StringOrNull,
|
|
88
|
+
}),
|
|
89
|
+
]),
|
|
90
|
+
)
|
|
91
|
+
export type EmbedBlock = t.TypeOf<typeof EmbedBlock>
|
|
92
|
+
export function checkEmbedBlock(block: Block): block is EmbedBlock {
|
|
93
|
+
return block.type === EmbedBlockType
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const TextBlock = t.exact(
|
|
97
|
+
t.intersection([
|
|
98
|
+
t.type({
|
|
99
|
+
type: refineType(
|
|
100
|
+
t.string,
|
|
101
|
+
`string which isn't ${ImageBlockType} ${EmbedBlockType}`,
|
|
102
|
+
(s) => s !== ImageBlockType && s !== EmbedBlockType,
|
|
103
|
+
),
|
|
104
|
+
content: t.intersection([
|
|
105
|
+
t.type({
|
|
106
|
+
text: t.string,
|
|
107
|
+
}),
|
|
108
|
+
t.partial({
|
|
109
|
+
spans: ValidatedMetas,
|
|
110
|
+
}),
|
|
111
|
+
]),
|
|
112
|
+
}),
|
|
113
|
+
t.partial({
|
|
114
|
+
label: t.string,
|
|
115
|
+
direction: t.string,
|
|
116
|
+
}),
|
|
117
|
+
]),
|
|
118
|
+
)
|
|
119
|
+
export type TextBlock = t.TypeOf<typeof TextBlock>
|
|
120
|
+
|
|
121
|
+
export const Block = t.union([ImageBlock, EmbedBlock, TextBlock])
|
|
122
|
+
export type Block = t.TypeOf<typeof Block>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Chain } from "fp-ts/Either"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
|
|
4
|
+
import { Block } from "./Block"
|
|
5
|
+
|
|
6
|
+
export const StructuredTextContentType = "StructuredTextContent"
|
|
7
|
+
export type StructuredTextContent = {
|
|
8
|
+
value: Block[]
|
|
9
|
+
__TYPE__: typeof StructuredTextContentType
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const StructuredTextContent = new t.Type<StructuredTextContent, string>(
|
|
13
|
+
StructuredTextContentType,
|
|
14
|
+
(u): u is StructuredTextContent =>
|
|
15
|
+
(u as StructuredTextContent)?.__TYPE__ === StructuredTextContentType,
|
|
16
|
+
(u, c) =>
|
|
17
|
+
Chain.chain(t.array(Block).validate(u, c), (u) => {
|
|
18
|
+
return t.success({ value: u, __TYPE__: StructuredTextContentType })
|
|
19
|
+
}),
|
|
20
|
+
() => {
|
|
21
|
+
throw new Error("NotImplementedError: Not relevant method")
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
export * as Blocks from "./Block"
|