@prismicio/types-internal 1.5.3 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/WidgetKey.d.ts +3 -0
- package/lib/common/WidgetKey.js +8 -0
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +4 -0
- package/lib/content/Document.d.ts +4285 -2573
- package/lib/content/Document.js +87 -10
- package/lib/content/LegacyContentCtx.d.ts +41 -0
- package/lib/content/LegacyContentCtx.js +65 -0
- package/lib/content/fields/EmptyContent.d.ts +16 -0
- package/lib/content/fields/EmptyContent.js +30 -0
- package/lib/content/fields/GroupContent.d.ts +1063 -364
- package/lib/content/fields/GroupContent.js +65 -6
- package/lib/content/fields/UIDContent.d.ts +10 -1
- package/lib/content/fields/UIDContent.js +17 -4
- package/lib/content/fields/WidgetContent.d.ts +6820 -0
- package/lib/content/fields/WidgetContent.js +57 -0
- package/lib/content/fields/index.d.ts +1 -2989
- package/lib/content/fields/index.js +1 -18
- package/lib/content/fields/nestable/BooleanContent.d.ts +10 -1
- package/lib/content/fields/nestable/BooleanContent.js +17 -4
- package/lib/content/fields/nestable/EmbedContent.d.ts +56 -5
- package/lib/content/fields/nestable/EmbedContent.js +57 -6
- package/lib/content/fields/nestable/FieldContent/ColorContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/ColorContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/DateContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/DateContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/NumberContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/NumberContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/RangeContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/RangeContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/TextContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/TextContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/TimestampContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/TimestampContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/common.d.ts +1 -0
- package/lib/content/fields/nestable/FieldContent/common.js +4 -0
- package/lib/content/fields/nestable/FieldContent/index.d.ts +49 -0
- package/lib/content/fields/nestable/FieldContent/index.js +38 -0
- package/lib/content/fields/nestable/FieldContent.d.ts +7 -1
- package/lib/content/fields/nestable/FieldContent.js +19 -4
- package/lib/content/fields/nestable/GeoPointContent.d.ts +19 -4
- package/lib/content/fields/nestable/GeoPointContent.js +22 -5
- package/lib/content/fields/nestable/ImageContent.d.ts +109 -11
- package/lib/content/fields/nestable/ImageContent.js +64 -6
- package/lib/content/fields/nestable/IntegrationFieldContent.d.ts +10 -1
- package/lib/content/fields/nestable/IntegrationFieldContent.js +20 -4
- package/lib/content/fields/nestable/LinkContent.d.ts +240 -87
- package/lib/content/fields/nestable/LinkContent.js +133 -36
- package/lib/content/fields/nestable/NestableContent.d.ts +711 -251
- package/lib/content/fields/nestable/NestableContent.js +116 -13
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +594 -0
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +151 -0
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +489 -0
- package/lib/content/fields/nestable/RichTextContent/index.js +27 -0
- package/lib/content/fields/nestable/SeparatorContent.d.ts +8 -1
- package/lib/content/fields/nestable/SeparatorContent.js +15 -4
- package/lib/content/fields/slices/CompositeSliceContent.d.ts +296 -362
- package/lib/content/fields/slices/RepeatableContent.d.ts +148 -181
- package/lib/content/fields/slices/SharedSliceContent.d.ts +296 -362
- package/lib/content/fields/slices/SimpleSliceContent.d.ts +296 -362
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1709 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +81 -0
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +582 -0
- package/lib/content/fields/slices/Slice/RepeatableContent.js +18 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +1713 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +98 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +1429 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +24 -0
- package/lib/content/fields/slices/Slice/index.d.ts +3216 -0
- package/lib/content/fields/slices/Slice/index.js +41 -0
- package/lib/content/fields/slices/SliceItem.d.ts +3498 -0
- package/lib/content/fields/slices/SliceItem.js +61 -0
- package/lib/content/fields/slices/SlicesContent.d.ts +4243 -3576
- package/lib/content/fields/slices/SlicesContent.js +28 -18
- package/lib/content/fields/slices/index.d.ts +4 -3
- package/lib/content/fields/slices/index.js +4 -3
- package/lib/content/index.d.ts +1 -0
- package/lib/content/index.js +1 -0
- package/lib/content/utils.d.ts +10 -0
- package/lib/content/utils.js +19 -0
- package/lib/customtypes/CustomType.d.ts +366 -366
- package/lib/customtypes/CustomType.js +4 -7
- package/lib/customtypes/Section.d.ts +366 -366
- package/lib/customtypes/Section.js +2 -2
- package/lib/customtypes/diff/SharedSlice.d.ts +4 -4
- package/lib/customtypes/diff/Variation.d.ts +4 -4
- package/lib/customtypes/index.d.ts +1 -1
- package/lib/customtypes/index.js +2 -2
- package/lib/customtypes/widgets/Group.d.ts +1 -0
- package/lib/customtypes/widgets/Group.js +6 -5
- package/lib/customtypes/widgets/UID.d.ts +1 -0
- package/lib/customtypes/widgets/UID.js +3 -2
- package/lib/customtypes/widgets/Widget.d.ts +384 -362
- package/lib/customtypes/widgets/Widget.js +29 -8
- package/lib/customtypes/widgets/index.d.ts +6 -7
- package/lib/customtypes/widgets/index.js +6 -11
- package/lib/customtypes/widgets/nestable/BooleanField.d.ts +10 -3
- package/lib/customtypes/widgets/nestable/BooleanField.js +6 -6
- package/lib/customtypes/widgets/nestable/Color.d.ts +8 -3
- package/lib/customtypes/widgets/nestable/Color.js +6 -6
- package/lib/customtypes/widgets/nestable/Date.d.ts +9 -3
- package/lib/customtypes/widgets/nestable/Date.js +6 -6
- package/lib/customtypes/widgets/nestable/Embed.d.ts +9 -3
- package/lib/customtypes/widgets/nestable/Embed.js +6 -6
- package/lib/customtypes/widgets/nestable/GeoPoint.d.ts +7 -3
- package/lib/customtypes/widgets/nestable/GeoPoint.js +6 -6
- package/lib/customtypes/widgets/nestable/Image.d.ts +25 -3
- package/lib/customtypes/widgets/nestable/Image.js +8 -8
- package/lib/customtypes/widgets/nestable/IntegrationField.d.ts +9 -3
- package/lib/customtypes/widgets/nestable/IntegrationField.js +6 -6
- package/lib/customtypes/widgets/nestable/Link.d.ts +14 -2
- package/lib/customtypes/widgets/nestable/Link.js +7 -6
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +3 -3
- package/lib/customtypes/widgets/nestable/NestableWidget.js +30 -30
- package/lib/customtypes/widgets/nestable/Number.d.ts +11 -3
- package/lib/customtypes/widgets/nestable/Number.js +6 -6
- package/lib/customtypes/widgets/nestable/Range.d.ts +11 -3
- package/lib/customtypes/widgets/nestable/Range.js +6 -6
- package/lib/customtypes/widgets/nestable/RichText.d.ts +1 -0
- package/lib/customtypes/widgets/nestable/RichText.js +3 -3
- package/lib/customtypes/widgets/nestable/Select.d.ts +10 -3
- package/lib/customtypes/widgets/nestable/Select.js +6 -6
- package/lib/customtypes/widgets/nestable/Separator.d.ts +7 -3
- package/lib/customtypes/widgets/nestable/Separator.js +6 -6
- package/lib/customtypes/widgets/nestable/Text.d.ts +9 -2
- package/lib/customtypes/widgets/nestable/Text.js +7 -6
- package/lib/customtypes/widgets/nestable/Timestamp.d.ts +9 -3
- package/lib/customtypes/widgets/nestable/Timestamp.js +6 -6
- package/lib/customtypes/widgets/nestable/index.d.ts +15 -15
- package/lib/customtypes/widgets/nestable/index.js +15 -31
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +1 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.js +7 -6
- package/lib/customtypes/widgets/slices/LegacySlice.js +2 -2
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +1 -0
- package/lib/customtypes/widgets/slices/SharedSlice.js +7 -7
- package/lib/customtypes/widgets/slices/SharedSliceRef.js +2 -2
- package/lib/customtypes/widgets/slices/Slices.d.ts +364 -362
- package/lib/customtypes/widgets/slices/Slices.js +8 -8
- package/lib/customtypes/widgets/slices/SlicesTypes.d.ts +6 -5
- package/lib/customtypes/widgets/slices/SlicesTypes.js +8 -4
- package/lib/documents/DocumentData.d.ts +3 -14
- package/lib/documents/DocumentData.js +5 -60
- package/lib/documents/widgets/nestable/ImageContent.d.ts +1 -1
- package/lib/documents/widgets/nestable/ImageContent.js +2 -2
- package/lib/utils/Objects.d.ts +1 -0
- package/lib/utils/Objects.js +10 -1
- package/package.json +1 -1
- package/src/common/WidgetKey.ts +13 -0
- package/src/common/index.ts +1 -0
- package/src/content/Document.ts +129 -16
- package/src/content/LegacyContentCtx.ts +57 -0
- package/src/content/fields/EmptyContent.ts +45 -0
- package/src/content/fields/GroupContent.ts +103 -8
- package/src/content/fields/UIDContent.ts +33 -3
- package/src/content/fields/WidgetContent.ts +76 -0
- package/src/content/fields/index.ts +1 -23
- package/src/content/fields/nestable/BooleanContent.ts +32 -3
- package/src/content/fields/nestable/EmbedContent.ts +79 -8
- package/src/content/fields/nestable/FieldContent/ColorContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/DateContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/NumberContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/RangeContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/SelectContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/TextContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/TimestampContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/common.ts +1 -0
- package/src/content/fields/nestable/FieldContent/index.ts +40 -0
- package/src/content/fields/nestable/GeoPointContent.ts +38 -7
- package/src/content/fields/nestable/ImageContent.ts +91 -11
- package/src/content/fields/nestable/IntegrationFieldContent.ts +42 -3
- package/src/content/fields/nestable/LinkContent.ts +208 -47
- package/src/content/fields/nestable/NestableContent.ts +180 -24
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +205 -0
- package/src/content/fields/nestable/RichTextContent/index.ts +43 -0
- package/src/content/fields/nestable/SeparatorContent.ts +26 -3
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +118 -0
- package/src/content/fields/slices/{RepeatableContent.ts → Slice/RepeatableContent.ts} +7 -4
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +129 -0
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +30 -0
- package/src/content/fields/slices/Slice/index.ts +47 -0
- package/src/content/fields/slices/SliceItem.ts +83 -0
- package/src/content/fields/slices/SlicesContent.ts +47 -19
- package/src/content/fields/slices/index.ts +4 -3
- package/src/content/index.ts +1 -0
- package/src/content/utils.ts +20 -0
- package/src/customtypes/CustomType.ts +4 -10
- package/src/customtypes/Section.ts +1 -1
- package/src/customtypes/index.ts +1 -1
- package/src/customtypes/widgets/Group.ts +4 -4
- package/src/customtypes/widgets/UID.ts +3 -2
- package/src/customtypes/widgets/Widget.ts +53 -7
- package/src/customtypes/widgets/index.ts +6 -7
- package/src/customtypes/widgets/nestable/BooleanField.ts +7 -8
- package/src/customtypes/widgets/nestable/Color.ts +6 -8
- package/src/customtypes/widgets/nestable/Date.ts +7 -8
- package/src/customtypes/widgets/nestable/Embed.ts +7 -8
- package/src/customtypes/widgets/nestable/GeoPoint.ts +7 -8
- package/src/customtypes/widgets/nestable/Image.ts +9 -10
- package/src/customtypes/widgets/nestable/IntegrationField.ts +6 -8
- package/src/customtypes/widgets/nestable/Link.ts +7 -6
- package/src/customtypes/widgets/nestable/NestableWidget.ts +17 -18
- package/src/customtypes/widgets/nestable/Number.ts +7 -8
- package/src/customtypes/widgets/nestable/Range.ts +7 -8
- package/src/customtypes/widgets/nestable/RichText.ts +3 -2
- package/src/customtypes/widgets/nestable/Select.ts +7 -8
- package/src/customtypes/widgets/nestable/Separator.ts +7 -8
- package/src/customtypes/widgets/nestable/Text.ts +7 -6
- package/src/customtypes/widgets/nestable/Timestamp.ts +7 -8
- package/src/customtypes/widgets/nestable/index.ts +15 -15
- package/src/customtypes/widgets/slices/CompositeSlice.ts +5 -4
- package/src/customtypes/widgets/slices/LegacySlice.ts +1 -1
- package/src/customtypes/widgets/slices/SharedSlice.ts +5 -4
- package/src/customtypes/widgets/slices/SharedSliceRef.ts +2 -2
- package/src/customtypes/widgets/slices/Slices.ts +7 -6
- package/src/customtypes/widgets/slices/SlicesTypes.ts +10 -5
- package/src/utils/Objects.ts +12 -0
- package/src/content/fields/nestable/FieldContent.ts +0 -25
- package/src/content/fields/nestable/RichTextContent.ts +0 -32
- package/src/content/fields/slices/CompositeSliceContent.ts +0 -14
- package/src/content/fields/slices/SharedSliceContent.ts +0 -14
- package/src/content/fields/slices/SimpleSliceContent.ts +0 -7
- package/src/customtypes/widgets/WidgetTypes.ts +0 -24
- package/src/documents/DocumentData.ts +0 -112
- package/src/documents/index.ts +0 -2
- package/src/documents/widgets/EmptyContent.ts +0 -8
- package/src/documents/widgets/GroupContent.ts +0 -91
- package/src/documents/widgets/SimpleWidgetContent.ts +0 -96
- package/src/documents/widgets/StaticWidgetContent.ts +0 -46
- package/src/documents/widgets/UIDContent.ts +0 -18
- package/src/documents/widgets/index.ts +0 -70
- package/src/documents/widgets/nestable/BooleanContent.ts +0 -21
- package/src/documents/widgets/nestable/EmbedContent.ts +0 -56
- package/src/documents/widgets/nestable/FieldContent.ts +0 -53
- package/src/documents/widgets/nestable/GeoPointContent.ts +0 -18
- package/src/documents/widgets/nestable/ImageContent.ts +0 -51
- package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +0 -26
- package/src/documents/widgets/nestable/Link/DocumentLink.ts +0 -18
- package/src/documents/widgets/nestable/Link/ExternalLink.ts +0 -31
- package/src/documents/widgets/nestable/Link/FileLink.ts +0 -30
- package/src/documents/widgets/nestable/Link/ImageLink.ts +0 -31
- package/src/documents/widgets/nestable/Link/LinkContent.ts +0 -25
- package/src/documents/widgets/nestable/Link/index.ts +0 -35
- package/src/documents/widgets/nestable/SeparatorContent.ts +0 -13
- package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +0 -126
- package/src/documents/widgets/nestable/StructuredTextContent/index.ts +0 -25
- package/src/documents/widgets/nestable/index.ts +0 -35
- package/src/documents/widgets/slices/CompositeSliceContent.ts +0 -77
- package/src/documents/widgets/slices/SharedSliceContent.ts +0 -94
- package/src/documents/widgets/slices/SimpleSliceContent.ts +0 -4
- package/src/documents/widgets/slices/SliceWidgetContent.ts +0 -51
- package/src/documents/widgets/slices/SlicesContent.ts +0 -91
- package/src/documents/widgets/slices/index.ts +0 -5
- package/src/index.ts +0 -3
|
@@ -1,16 +1,47 @@
|
|
|
1
|
+
import { either } from "fp-ts"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
1
3
|
import * as t from "io-ts"
|
|
2
4
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
|
|
6
|
+
import { hasContentType } from "../../utils"
|
|
7
|
+
|
|
8
|
+
export const GeoPointContentType = "GeoPointContent"
|
|
9
|
+
|
|
10
|
+
export const isGeoPointContent = (u: unknown): u is GeoPointContent =>
|
|
11
|
+
hasContentType(u) && u.__TYPE__ === GeoPointContentType
|
|
12
|
+
|
|
13
|
+
const legacyReader = t.strict({
|
|
14
|
+
position: t.strict({
|
|
15
|
+
lat: t.number,
|
|
16
|
+
lng: t.number,
|
|
17
|
+
}),
|
|
18
|
+
})
|
|
19
|
+
type GeoPointLegacy = t.TypeOf<typeof legacyReader>
|
|
20
|
+
|
|
21
|
+
export const GeoPointLegacy = (ctx: LegacyContentCtx) =>
|
|
22
|
+
new t.Type<GeoPointContent, WithTypes<GeoPointLegacy>, unknown>(
|
|
23
|
+
"GeoPointLegacy",
|
|
24
|
+
isGeoPointContent,
|
|
25
|
+
(u) => {
|
|
26
|
+
return pipe(
|
|
27
|
+
legacyReader.decode(u),
|
|
28
|
+
either.map((geo) =>
|
|
29
|
+
GeoPointContent.encode({ ...geo, __TYPE__: GeoPointContentType }),
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
(geo: GeoPointContent) => ({
|
|
35
|
+
content: { position: geo.position },
|
|
36
|
+
types: { [ctx.keyOfType]: "GeoPoint" },
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
7
39
|
|
|
8
40
|
export const GeoPointContent = t.intersection([
|
|
9
|
-
|
|
41
|
+
legacyReader,
|
|
10
42
|
t.strict({
|
|
11
|
-
__TYPE__: t.literal(
|
|
43
|
+
__TYPE__: t.literal(GeoPointContentType),
|
|
12
44
|
}),
|
|
13
45
|
])
|
|
14
46
|
|
|
15
47
|
export type GeoPointContent = t.TypeOf<typeof GeoPointContent>
|
|
16
|
-
export const GeoPointContentType = type
|
|
@@ -1,20 +1,100 @@
|
|
|
1
|
+
import { either } from "fp-ts"
|
|
2
|
+
import { pipe } from "fp-ts/lib/function"
|
|
1
3
|
import * as t from "io-ts"
|
|
2
4
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { withOptionals } from "../../../utils/Objects"
|
|
6
|
+
import { NonEmptyStringOrNull, StringOrNull } from "../../../validators"
|
|
7
|
+
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
|
|
8
|
+
import { hasContentType } from "../../utils"
|
|
9
|
+
|
|
10
|
+
export const ImageContentType = "ImageContent"
|
|
11
|
+
|
|
12
|
+
export const isImageContent = (u: unknown): u is ImageContent =>
|
|
13
|
+
hasContentType(u) && u.__TYPE__ === ImageContentType
|
|
14
|
+
|
|
15
|
+
const originReader = t.exact(
|
|
16
|
+
t.type({
|
|
17
|
+
id: t.string,
|
|
18
|
+
url: t.string,
|
|
19
|
+
width: t.number,
|
|
20
|
+
height: t.number,
|
|
21
|
+
}),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export const ImageContentView = t.exact(
|
|
25
|
+
t.intersection([
|
|
26
|
+
t.type({
|
|
27
|
+
origin: originReader,
|
|
28
|
+
width: t.number,
|
|
29
|
+
height: t.number,
|
|
30
|
+
edit: t.type({
|
|
31
|
+
zoom: t.number,
|
|
32
|
+
crop: t.type({
|
|
33
|
+
x: t.number,
|
|
34
|
+
y: t.number,
|
|
35
|
+
}),
|
|
36
|
+
background: t.string,
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
t.partial({
|
|
40
|
+
url: t.string,
|
|
41
|
+
credits: NonEmptyStringOrNull,
|
|
42
|
+
alt: NonEmptyStringOrNull,
|
|
43
|
+
provider: StringOrNull,
|
|
44
|
+
}),
|
|
45
|
+
]),
|
|
46
|
+
)
|
|
47
|
+
export type ImageContentView = t.TypeOf<typeof ImageContentView>
|
|
48
|
+
|
|
49
|
+
const legacyReader = t.intersection([
|
|
50
|
+
ImageContentView,
|
|
51
|
+
t.partial({
|
|
52
|
+
thumbnails: t.record(t.string, ImageContentView),
|
|
53
|
+
}),
|
|
54
|
+
])
|
|
55
|
+
|
|
56
|
+
type ImageLegacy = t.TypeOf<typeof legacyReader>
|
|
57
|
+
|
|
58
|
+
export const ImageLegacy = (ctx: LegacyContentCtx) =>
|
|
59
|
+
new t.Type<ImageContent, WithTypes<ImageLegacy>, unknown>(
|
|
60
|
+
"ImageLegacy",
|
|
61
|
+
isImageContent,
|
|
62
|
+
(u) => {
|
|
63
|
+
return pipe(
|
|
64
|
+
legacyReader.decode(u),
|
|
65
|
+
either.map((i) =>
|
|
66
|
+
ImageContent.encode({ ...i, __TYPE__: ImageContentType }),
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
(i: ImageContent) => {
|
|
72
|
+
return {
|
|
73
|
+
content: withOptionals<ImageLegacy>(
|
|
74
|
+
{
|
|
75
|
+
edit: i.edit,
|
|
76
|
+
height: i.height,
|
|
77
|
+
origin: i.origin,
|
|
78
|
+
width: i.width,
|
|
79
|
+
},
|
|
80
|
+
[
|
|
81
|
+
["alt", i.alt],
|
|
82
|
+
["credits", i.credits],
|
|
83
|
+
["provider", i.provider],
|
|
84
|
+
["thumbnails", i.thumbnails],
|
|
85
|
+
["url", i.url],
|
|
86
|
+
],
|
|
87
|
+
),
|
|
88
|
+
types: { [ctx.keyOfType]: "Image" },
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
)
|
|
8
92
|
|
|
9
93
|
export const ImageContent = t.intersection([
|
|
10
|
-
|
|
94
|
+
legacyReader,
|
|
11
95
|
t.strict({
|
|
12
|
-
__TYPE__: t.literal(
|
|
96
|
+
__TYPE__: t.literal(ImageContentType),
|
|
13
97
|
}),
|
|
14
98
|
])
|
|
15
99
|
|
|
16
100
|
export type ImageContent = t.TypeOf<typeof ImageContent>
|
|
17
|
-
export const ImageContentType = type
|
|
18
|
-
|
|
19
|
-
export const ImageContentView = view
|
|
20
|
-
export type ImageContentView = view
|
|
@@ -1,11 +1,50 @@
|
|
|
1
|
+
import { either } from "fp-ts"
|
|
2
|
+
import { pipe } from "fp-ts/lib/function"
|
|
1
3
|
import * as t from "io-ts"
|
|
2
4
|
|
|
3
|
-
import {
|
|
5
|
+
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
|
|
6
|
+
import { hasContentType } from "../../utils"
|
|
7
|
+
|
|
8
|
+
export const IntegrationFieldContentType = "IntegrationFieldsContent"
|
|
9
|
+
|
|
10
|
+
export const isIntegrationFieldContent = (
|
|
11
|
+
u: unknown,
|
|
12
|
+
): u is IntegrationFieldContent =>
|
|
13
|
+
hasContentType(u) && u.__TYPE__ === IntegrationFieldContentType
|
|
14
|
+
|
|
15
|
+
type IntegrationFieldLegacy = string
|
|
16
|
+
|
|
17
|
+
export const IntegrationFieldLegacy = (ctx: LegacyContentCtx) =>
|
|
18
|
+
new t.Type<
|
|
19
|
+
IntegrationFieldContent,
|
|
20
|
+
WithTypes<IntegrationFieldLegacy>,
|
|
21
|
+
unknown
|
|
22
|
+
>(
|
|
23
|
+
"IntegrationFieldLegacy",
|
|
24
|
+
isIntegrationFieldContent,
|
|
25
|
+
(u) => {
|
|
26
|
+
return pipe(
|
|
27
|
+
t.string.decode(u),
|
|
28
|
+
either.map((i) =>
|
|
29
|
+
IntegrationFieldContent.encode({
|
|
30
|
+
value: i,
|
|
31
|
+
__TYPE__: IntegrationFieldContentType,
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
)
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
(i: IntegrationFieldContent) => {
|
|
38
|
+
return {
|
|
39
|
+
content: i.value,
|
|
40
|
+
types: { [ctx.keyOfType]: "IntegrationFields" },
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
)
|
|
4
44
|
|
|
5
45
|
export const IntegrationFieldContent = t.strict({
|
|
6
|
-
__TYPE__: t.literal(
|
|
46
|
+
__TYPE__: t.literal(IntegrationFieldContentType),
|
|
7
47
|
value: t.string,
|
|
8
48
|
})
|
|
9
49
|
|
|
10
50
|
export type IntegrationFieldContent = t.TypeOf<typeof IntegrationFieldContent>
|
|
11
|
-
export const IntegrationFieldsContentType = type
|
|
@@ -1,80 +1,241 @@
|
|
|
1
|
+
import { either } from "fp-ts"
|
|
2
|
+
import { pipe } from "fp-ts/lib/function"
|
|
1
3
|
import * as t from "io-ts"
|
|
2
4
|
import { withFallback } from "io-ts-types"
|
|
3
5
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
import { NonEmptyString, StringOrNull } from "../../../validators"
|
|
7
|
+
import { nullable } from "../../../validators/function"
|
|
8
|
+
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
|
|
9
|
+
import { hasContentType } from "../../utils"
|
|
10
|
+
|
|
11
|
+
export const ImageLinkType = "ImageLink"
|
|
12
|
+
|
|
13
|
+
const imageLinkLegacyCodec = t.exact(
|
|
14
|
+
t.intersection([
|
|
15
|
+
t.type({
|
|
16
|
+
id: t.string,
|
|
17
|
+
url: t.string,
|
|
18
|
+
height: t.string,
|
|
19
|
+
width: t.string,
|
|
20
|
+
size: t.string,
|
|
21
|
+
name: t.string,
|
|
22
|
+
kind: t.string,
|
|
23
|
+
}),
|
|
24
|
+
t.partial({
|
|
25
|
+
date: StringOrNull,
|
|
26
|
+
}),
|
|
27
|
+
]),
|
|
28
|
+
)
|
|
29
|
+
type ImageLinkLegacy = t.TypeOf<typeof imageLinkLegacyCodec>
|
|
30
|
+
const ImageLinkLegacy = new t.Type<ImageLinkContent, ImageLinkLegacy, unknown>(
|
|
31
|
+
"ImageLink",
|
|
32
|
+
(u): u is ImageLinkContent =>
|
|
33
|
+
hasContentType(u) && u.__TYPE__ === ImageLinkType,
|
|
34
|
+
(image) => {
|
|
35
|
+
return pipe(
|
|
36
|
+
imageLinkLegacyCodec.decode(image),
|
|
37
|
+
either.map((parsedImage) => {
|
|
38
|
+
return ImageLinkContent.encode({
|
|
39
|
+
...parsedImage,
|
|
40
|
+
__TYPE__: ImageLinkType,
|
|
41
|
+
})
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
},
|
|
45
|
+
(image: ImageLinkContent): ImageLinkLegacy => {
|
|
46
|
+
return imageLinkLegacyCodec.encode(image)
|
|
47
|
+
},
|
|
48
|
+
)
|
|
21
49
|
|
|
22
50
|
export const ImageLinkContent = t.intersection([
|
|
23
51
|
t.strict({
|
|
24
|
-
__TYPE__: t.literal(
|
|
52
|
+
__TYPE__: t.literal(ImageLinkType),
|
|
25
53
|
}),
|
|
26
|
-
|
|
54
|
+
imageLinkLegacyCodec,
|
|
27
55
|
])
|
|
28
56
|
export type ImageLinkContent = t.TypeOf<typeof ImageLinkContent>
|
|
29
|
-
export const ImageLinkType = ilType
|
|
30
57
|
|
|
31
|
-
export const
|
|
32
|
-
|
|
33
|
-
|
|
58
|
+
export const FileLinkType = "FileLink"
|
|
59
|
+
|
|
60
|
+
const fileLinkLegacyCodec = t.exact(
|
|
61
|
+
t.intersection([
|
|
34
62
|
t.type({
|
|
35
|
-
|
|
63
|
+
id: t.string,
|
|
64
|
+
url: t.string,
|
|
65
|
+
name: t.string,
|
|
66
|
+
kind: t.string,
|
|
67
|
+
}),
|
|
68
|
+
t.partial({
|
|
69
|
+
date: nullable(t.string),
|
|
36
70
|
size: withFallback(t.string, "0"),
|
|
37
71
|
}),
|
|
72
|
+
]),
|
|
73
|
+
)
|
|
74
|
+
type FileLinkLegacy = t.TypeOf<typeof fileLinkLegacyCodec>
|
|
75
|
+
const FileLinkLegacy = new t.Type<FileLinkContent, FileLinkLegacy>(
|
|
76
|
+
"FileLink",
|
|
77
|
+
(u): u is FileLinkContent => hasContentType(u) && u.__TYPE__ === FileLinkType,
|
|
78
|
+
(file) => {
|
|
79
|
+
return pipe(
|
|
80
|
+
fileLinkLegacyCodec.decode(file),
|
|
81
|
+
either.map((parsedFile) => {
|
|
82
|
+
return FileLinkContent.encode({
|
|
83
|
+
...parsedFile,
|
|
84
|
+
__TYPE__: FileLinkType,
|
|
85
|
+
})
|
|
86
|
+
}),
|
|
87
|
+
)
|
|
88
|
+
},
|
|
89
|
+
(file: FileLinkContent): FileLinkLegacy => {
|
|
90
|
+
return fileLinkLegacyCodec.encode(file)
|
|
91
|
+
},
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
export const FileLinkContent = t.intersection([
|
|
95
|
+
fileLinkLegacyCodec,
|
|
96
|
+
t.exact(
|
|
97
|
+
t.intersection([
|
|
98
|
+
t.type({
|
|
99
|
+
__TYPE__: t.literal(FileLinkType),
|
|
100
|
+
}),
|
|
101
|
+
t.partial({
|
|
102
|
+
size: withFallback(t.string, "0"),
|
|
103
|
+
}),
|
|
104
|
+
]),
|
|
38
105
|
),
|
|
39
106
|
])
|
|
40
107
|
export type FileLinkContent = t.TypeOf<typeof FileLinkContent>
|
|
41
|
-
export const FileLinkType = flType
|
|
42
108
|
|
|
109
|
+
export const DocumentLinkType = "DocumentLink"
|
|
110
|
+
|
|
111
|
+
const documentLinkLegacyCodec = t.strict({ id: NonEmptyString })
|
|
112
|
+
type DocumentLinkLegacy = t.TypeOf<typeof documentLinkLegacyCodec>
|
|
113
|
+
const DocumentLinkLegacy = new t.Type<DocumentLinkContent, DocumentLinkLegacy>(
|
|
114
|
+
"DocumentLink",
|
|
115
|
+
(u): u is DocumentLinkContent =>
|
|
116
|
+
hasContentType(u) && u.__TYPE__ === DocumentLinkType,
|
|
117
|
+
(file) => {
|
|
118
|
+
return pipe(
|
|
119
|
+
documentLinkLegacyCodec.decode(file),
|
|
120
|
+
either.map((parsedDoc) => {
|
|
121
|
+
return DocumentLinkContent.encode({
|
|
122
|
+
...parsedDoc,
|
|
123
|
+
__TYPE__: DocumentLinkType,
|
|
124
|
+
})
|
|
125
|
+
}),
|
|
126
|
+
)
|
|
127
|
+
},
|
|
128
|
+
(doc: DocumentLinkContent): DocumentLinkLegacy => {
|
|
129
|
+
return documentLinkLegacyCodec.encode(doc)
|
|
130
|
+
},
|
|
131
|
+
)
|
|
43
132
|
export const DocumentLinkContent = t.intersection([
|
|
44
133
|
t.strict({
|
|
45
|
-
__TYPE__: t.literal(
|
|
134
|
+
__TYPE__: t.literal(DocumentLinkType),
|
|
46
135
|
}),
|
|
47
|
-
|
|
136
|
+
documentLinkLegacyCodec,
|
|
48
137
|
])
|
|
49
138
|
export type DocumentLinkContent = t.TypeOf<typeof DocumentLinkContent>
|
|
50
|
-
|
|
139
|
+
|
|
140
|
+
export const ExternalLinkType = "ExternalLink"
|
|
141
|
+
|
|
142
|
+
const externalLinkLegacyCodec = t.exact(
|
|
143
|
+
t.intersection([
|
|
144
|
+
t.type({
|
|
145
|
+
url: t.string,
|
|
146
|
+
}),
|
|
147
|
+
t.partial({
|
|
148
|
+
kind: t.literal("web"),
|
|
149
|
+
target: StringOrNull,
|
|
150
|
+
preview: nullable(
|
|
151
|
+
t.partial({
|
|
152
|
+
title: t.string,
|
|
153
|
+
}),
|
|
154
|
+
),
|
|
155
|
+
}),
|
|
156
|
+
]),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
type ExternalLinkLegacy = t.TypeOf<typeof externalLinkLegacyCodec>
|
|
160
|
+
const ExternalLinkLegacy = new t.Type<ExternalLinkContent, ExternalLinkLegacy>(
|
|
161
|
+
"ExternalLink",
|
|
162
|
+
(u): u is ExternalLinkContent =>
|
|
163
|
+
hasContentType(u) && u.__TYPE__ === ExternalLinkType,
|
|
164
|
+
(file) => {
|
|
165
|
+
return pipe(
|
|
166
|
+
externalLinkLegacyCodec.decode(file),
|
|
167
|
+
either.map((parsedLink) => {
|
|
168
|
+
return ExternalLinkContent.encode({
|
|
169
|
+
...parsedLink,
|
|
170
|
+
__TYPE__: ExternalLinkType,
|
|
171
|
+
})
|
|
172
|
+
}),
|
|
173
|
+
)
|
|
174
|
+
},
|
|
175
|
+
(link: ExternalLinkContent): ExternalLinkLegacy => {
|
|
176
|
+
return externalLinkLegacyCodec.encode(link)
|
|
177
|
+
},
|
|
178
|
+
)
|
|
51
179
|
|
|
52
180
|
export const ExternalLinkContent = t.intersection([
|
|
53
181
|
t.strict({
|
|
54
|
-
__TYPE__: t.literal(
|
|
182
|
+
__TYPE__: t.literal(ExternalLinkType),
|
|
55
183
|
}),
|
|
56
|
-
|
|
184
|
+
externalLinkLegacyCodec,
|
|
57
185
|
])
|
|
58
186
|
export type ExternalLinkContent = t.TypeOf<typeof ExternalLinkContent>
|
|
59
|
-
export const ExternalLinkType = elType
|
|
60
187
|
|
|
188
|
+
export const LinkContentType = "LinkContent"
|
|
189
|
+
|
|
190
|
+
export const isLinkContent = (u: unknown): u is LinkContent =>
|
|
191
|
+
hasContentType(u) && u.__TYPE__ === LinkContentType
|
|
192
|
+
|
|
193
|
+
export const LinkLegacy = t.union([
|
|
194
|
+
ImageLinkLegacy,
|
|
195
|
+
FileLinkLegacy,
|
|
196
|
+
DocumentLinkLegacy,
|
|
197
|
+
ExternalLinkLegacy,
|
|
198
|
+
])
|
|
199
|
+
|
|
200
|
+
type LinkLegacy = t.OutputOf<typeof LinkLegacy>
|
|
201
|
+
|
|
202
|
+
export const LinkContentLegacy = (ctx: LegacyContentCtx) =>
|
|
203
|
+
new t.Type<LinkContent, WithTypes<LinkLegacy>, unknown>(
|
|
204
|
+
"LinkLegacy",
|
|
205
|
+
isLinkContent,
|
|
206
|
+
(u) => {
|
|
207
|
+
return pipe(
|
|
208
|
+
LinkLegacy.decode(u),
|
|
209
|
+
either.map((link) =>
|
|
210
|
+
LinkContent.encode({
|
|
211
|
+
value: link,
|
|
212
|
+
__TYPE__: LinkContentType,
|
|
213
|
+
}),
|
|
214
|
+
),
|
|
215
|
+
)
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
(link: LinkContent): WithTypes<LinkLegacy> => {
|
|
219
|
+
return {
|
|
220
|
+
content: LinkLegacy.encode(link.value),
|
|
221
|
+
types: { [ctx.keyOfType]: "Link" },
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
export const Link = t.union([
|
|
227
|
+
ImageLinkContent,
|
|
228
|
+
FileLinkContent,
|
|
229
|
+
DocumentLinkContent,
|
|
230
|
+
ExternalLinkContent,
|
|
231
|
+
])
|
|
61
232
|
export const LinkContent = t.strict({
|
|
62
|
-
__TYPE__: t.literal(
|
|
63
|
-
value:
|
|
64
|
-
ImageLinkContent,
|
|
65
|
-
FileLinkContent,
|
|
66
|
-
DocumentLinkContent,
|
|
67
|
-
ExternalLinkContent,
|
|
68
|
-
]),
|
|
233
|
+
__TYPE__: t.literal(LinkContentType),
|
|
234
|
+
value: Link,
|
|
69
235
|
})
|
|
70
236
|
|
|
71
237
|
export type LinkContent = t.TypeOf<typeof LinkContent>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
FileLink: FileLinkType,
|
|
77
|
-
ExternalLink: ExternalLinkType,
|
|
78
|
-
ImageLink: ImageLinkType,
|
|
79
|
-
LinkContent: LinkContentType,
|
|
80
|
-
} as const
|
|
238
|
+
|
|
239
|
+
export type LinksTypes =
|
|
240
|
+
| LinkContent["__TYPE__"]
|
|
241
|
+
| LinkContent["value"]["__TYPE__"]
|