@prismicio/types-internal 2.2.1-alpha.0 → 2.2.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/UUID.d.ts +1 -2
- package/package.json +1 -1
- package/src/common/UUID.ts +1 -1
- package/lib/import/converters/Document.d.ts +0 -4
- package/lib/import/converters/Document.js +0 -21
- package/lib/import/converters/fields/Group.d.ts +0 -4
- package/lib/import/converters/fields/Group.js +0 -14
- package/lib/import/converters/fields/RepeatableZone.d.ts +0 -317
- package/lib/import/converters/fields/RepeatableZone.js +0 -15
- package/lib/import/converters/fields/RepeatableZoneItem.d.ts +0 -11
- package/lib/import/converters/fields/RepeatableZoneItem.js +0 -19
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +0 -4
- package/lib/import/converters/fields/Slices/SharedSlice.js +0 -19
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +0 -10
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +0 -23
- package/lib/import/converters/fields/Slices/Slices.d.ts +0 -4
- package/lib/import/converters/fields/Slices/Slices.js +0 -16
- package/lib/import/converters/fields/Slices/index.d.ts +0 -1
- package/lib/import/converters/fields/Slices/index.js +0 -4
- package/lib/import/converters/fields/UID.d.ts +0 -3
- package/lib/import/converters/fields/UID.js +0 -10
- package/lib/import/converters/fields/index.d.ts +0 -4
- package/lib/import/converters/fields/index.js +0 -7
- package/lib/import/converters/fields/nestable/Boolean.d.ts +0 -3
- package/lib/import/converters/fields/nestable/Boolean.js +0 -12
- package/lib/import/converters/fields/nestable/Color.d.ts +0 -3
- package/lib/import/converters/fields/nestable/Color.js +0 -13
- package/lib/import/converters/fields/nestable/Date.d.ts +0 -3
- package/lib/import/converters/fields/nestable/Date.js +0 -15
- package/lib/import/converters/fields/nestable/Embed.d.ts +0 -4
- package/lib/import/converters/fields/nestable/Embed.js +0 -32
- package/lib/import/converters/fields/nestable/GeoPoint.d.ts +0 -3
- package/lib/import/converters/fields/nestable/GeoPoint.js +0 -15
- package/lib/import/converters/fields/nestable/Image.d.ts +0 -28
- package/lib/import/converters/fields/nestable/Image.js +0 -67
- package/lib/import/converters/fields/nestable/Link.d.ts +0 -4
- package/lib/import/converters/fields/nestable/Link.js +0 -70
- package/lib/import/converters/fields/nestable/Nestable.d.ts +0 -5
- package/lib/import/converters/fields/nestable/Nestable.js +0 -35
- package/lib/import/converters/fields/nestable/Number.d.ts +0 -3
- package/lib/import/converters/fields/nestable/Number.js +0 -13
- package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +0 -4
- package/lib/import/converters/fields/nestable/RichText/embedBlock.js +0 -14
- package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +0 -4
- package/lib/import/converters/fields/nestable/RichText/imageBlock.js +0 -12
- package/lib/import/converters/fields/nestable/RichText/index.d.ts +0 -4
- package/lib/import/converters/fields/nestable/RichText/index.js +0 -22
- package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +0 -4
- package/lib/import/converters/fields/nestable/RichText/textBlock.js +0 -54
- package/lib/import/converters/fields/nestable/Select.d.ts +0 -3
- package/lib/import/converters/fields/nestable/Select.js +0 -13
- package/lib/import/converters/fields/nestable/Text.d.ts +0 -3
- package/lib/import/converters/fields/nestable/Text.js +0 -13
- package/lib/import/converters/fields/nestable/Timestamp.d.ts +0 -3
- package/lib/import/converters/fields/nestable/Timestamp.js +0 -13
- package/lib/import/converters/fields/nestable/index.d.ts +0 -13
- package/lib/import/converters/fields/nestable/index.js +0 -16
- package/lib/import/converters/index.d.ts +0 -2
- package/lib/import/converters/index.js +0 -5
- package/lib/import/index.d.ts +0 -2
- package/lib/import/index.js +0 -5
- package/lib/import/validators/Document.d.ts +0 -6
- package/lib/import/validators/Document.js +0 -64
- package/lib/import/validators/fields/ImportContent.d.ts +0 -5
- package/lib/import/validators/fields/ImportContent.js +0 -21
- package/lib/import/validators/fields/ImportField.d.ts +0 -141
- package/lib/import/validators/fields/ImportField.js +0 -33
- package/lib/import/validators/fields/ImportGroup.d.ts +0 -345
- package/lib/import/validators/fields/ImportGroup.js +0 -27
- package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +0 -8
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +0 -30
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +0 -16
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +0 -61
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +0 -4
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +0 -7
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +0 -2
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +0 -15
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +0 -9
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +0 -39
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +0 -11
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +0 -24
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +0 -11
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +0 -24
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +0 -4
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +0 -7
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +0 -3
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +0 -6
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +0 -342
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +0 -11
- package/lib/import/validators/fields/ImportSlices/index.d.ts +0 -1
- package/lib/import/validators/fields/ImportSlices/index.js +0 -4
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +0 -4
- package/lib/import/validators/fields/ImportSlices/utils.js +0 -35
- package/lib/import/validators/fields/RepeatableZone.d.ts +0 -11
- package/lib/import/validators/fields/RepeatableZone.js +0 -14
- package/lib/import/validators/fields/RepeatableZoneItem.d.ts +0 -11
- package/lib/import/validators/fields/RepeatableZoneItem.js +0 -39
- package/lib/import/validators/fields/UID.d.ts +0 -6
- package/lib/import/validators/fields/UID.js +0 -15
- package/lib/import/validators/fields/index.d.ts +0 -4
- package/lib/import/validators/fields/index.js +0 -7
- package/lib/import/validators/fields/nestable/Boolean.d.ts +0 -6
- package/lib/import/validators/fields/nestable/Boolean.js +0 -6
- package/lib/import/validators/fields/nestable/Color.d.ts +0 -6
- package/lib/import/validators/fields/nestable/Color.js +0 -15
- package/lib/import/validators/fields/nestable/Date.d.ts +0 -6
- package/lib/import/validators/fields/nestable/Date.js +0 -19
- package/lib/import/validators/fields/nestable/Embed.d.ts +0 -13
- package/lib/import/validators/fields/nestable/Embed.js +0 -31
- package/lib/import/validators/fields/nestable/GeoPoint.d.ts +0 -13
- package/lib/import/validators/fields/nestable/GeoPoint.js +0 -13
- package/lib/import/validators/fields/nestable/Image/default.d.ts +0 -22
- package/lib/import/validators/fields/nestable/Image/default.js +0 -19
- package/lib/import/validators/fields/nestable/Image/index.d.ts +0 -26
- package/lib/import/validators/fields/nestable/Image/index.js +0 -32
- package/lib/import/validators/fields/nestable/Image/merge.d.ts +0 -23
- package/lib/import/validators/fields/nestable/Image/merge.js +0 -44
- package/lib/import/validators/fields/nestable/Image/model.d.ts +0 -18
- package/lib/import/validators/fields/nestable/Image/model.js +0 -2
- package/lib/import/validators/fields/nestable/Image/validators.d.ts +0 -132
- package/lib/import/validators/fields/nestable/Image/validators.js +0 -43
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +0 -6
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +0 -25
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +0 -24
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +0 -32
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +0 -6
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +0 -18
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +0 -10
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +0 -11
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +0 -22
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +0 -13
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +0 -78
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +0 -43
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +0 -79
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +0 -27
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +0 -4
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +0 -7
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +0 -24
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +0 -18
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.d.ts +0 -12
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.js +0 -16
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +0 -5
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +0 -10
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +0 -15
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +0 -20
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +0 -2
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +0 -5
- package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +0 -2
- package/lib/import/validators/fields/nestable/ImportRichText/index.js +0 -7
- package/lib/import/validators/fields/nestable/Link.d.ts +0 -53
- package/lib/import/validators/fields/nestable/Link.js +0 -35
- package/lib/import/validators/fields/nestable/Nestable.d.ts +0 -192
- package/lib/import/validators/fields/nestable/Nestable.js +0 -71
- package/lib/import/validators/fields/nestable/Number.d.ts +0 -17
- package/lib/import/validators/fields/nestable/Number.js +0 -17
- package/lib/import/validators/fields/nestable/Select.d.ts +0 -16
- package/lib/import/validators/fields/nestable/Select.js +0 -19
- package/lib/import/validators/fields/nestable/Text.d.ts +0 -6
- package/lib/import/validators/fields/nestable/Text.js +0 -6
- package/lib/import/validators/fields/nestable/Timestamp.d.ts +0 -7
- package/lib/import/validators/fields/nestable/Timestamp.js +0 -19
- package/lib/import/validators/fields/nestable/index.d.ts +0 -14
- package/lib/import/validators/fields/nestable/index.js +0 -19
- package/lib/import/validators/index.d.ts +0 -2
- package/lib/import/validators/index.js +0 -5
- package/src/import/converters/Document.ts +0 -38
- package/src/import/converters/fields/Group.ts +0 -18
- package/src/import/converters/fields/RepeatableZone.ts +0 -19
- package/src/import/converters/fields/RepeatableZoneItem.ts +0 -32
- package/src/import/converters/fields/Slices/SharedSlice.ts +0 -24
- package/src/import/converters/fields/Slices/SharedSliceContent.ts +0 -27
- package/src/import/converters/fields/Slices/Slices.ts +0 -20
- package/src/import/converters/fields/Slices/index.ts +0 -1
- package/src/import/converters/fields/UID.ts +0 -9
- package/src/import/converters/fields/index.ts +0 -4
- package/src/import/converters/fields/nestable/Boolean.ts +0 -13
- package/src/import/converters/fields/nestable/Color.ts +0 -14
- package/src/import/converters/fields/nestable/Date.ts +0 -17
- package/src/import/converters/fields/nestable/Embed.ts +0 -37
- package/src/import/converters/fields/nestable/GeoPoint.ts +0 -16
- package/src/import/converters/fields/nestable/Image.ts +0 -91
- package/src/import/converters/fields/nestable/Link.ts +0 -77
- package/src/import/converters/fields/nestable/Nestable.ts +0 -55
- package/src/import/converters/fields/nestable/Number.ts +0 -14
- package/src/import/converters/fields/nestable/RichText/embedBlock.ts +0 -17
- package/src/import/converters/fields/nestable/RichText/imageBlock.ts +0 -17
- package/src/import/converters/fields/nestable/RichText/index.ts +0 -23
- package/src/import/converters/fields/nestable/RichText/textBlock.ts +0 -62
- package/src/import/converters/fields/nestable/Select.ts +0 -14
- package/src/import/converters/fields/nestable/Text.ts +0 -14
- package/src/import/converters/fields/nestable/Timestamp.ts +0 -14
- package/src/import/converters/fields/nestable/index.ts +0 -13
- package/src/import/converters/index.ts +0 -2
- package/src/import/index.ts +0 -2
- package/src/import/validators/Document.ts +0 -103
- package/src/import/validators/fields/ImportContent.ts +0 -30
- package/src/import/validators/fields/ImportField.ts +0 -36
- package/src/import/validators/fields/ImportGroup.ts +0 -45
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +0 -56
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +0 -104
- package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +0 -6
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +0 -20
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +0 -65
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +0 -45
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +0 -45
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +0 -4
- package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +0 -3
- package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +0 -21
- package/src/import/validators/fields/ImportSlices/index.ts +0 -1
- package/src/import/validators/fields/ImportSlices/utils.ts +0 -43
- package/src/import/validators/fields/RepeatableZone.ts +0 -21
- package/src/import/validators/fields/RepeatableZoneItem.ts +0 -64
- package/src/import/validators/fields/UID.ts +0 -27
- package/src/import/validators/fields/index.ts +0 -4
- package/src/import/validators/fields/nestable/Boolean.ts +0 -7
- package/src/import/validators/fields/nestable/Color.ts +0 -28
- package/src/import/validators/fields/nestable/Date.ts +0 -34
- package/src/import/validators/fields/nestable/Embed.ts +0 -41
- package/src/import/validators/fields/nestable/GeoPoint.ts +0 -21
- package/src/import/validators/fields/nestable/Image/default.ts +0 -22
- package/src/import/validators/fields/nestable/Image/index.ts +0 -66
- package/src/import/validators/fields/nestable/Image/merge.ts +0 -64
- package/src/import/validators/fields/nestable/Image/model.ts +0 -18
- package/src/import/validators/fields/nestable/Image/validators.ts +0 -70
- package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +0 -39
- package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +0 -54
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +0 -44
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +0 -13
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +0 -17
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +0 -56
- package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +0 -48
- package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +0 -4
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +0 -24
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.ts +0 -19
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +0 -8
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +0 -24
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +0 -2
- package/src/import/validators/fields/nestable/ImportRichText/index.ts +0 -2
- package/src/import/validators/fields/nestable/Link.ts +0 -59
- package/src/import/validators/fields/nestable/Nestable.ts +0 -88
- package/src/import/validators/fields/nestable/Number.ts +0 -38
- package/src/import/validators/fields/nestable/Select.ts +0 -38
- package/src/import/validators/fields/nestable/Text.ts +0 -7
- package/src/import/validators/fields/nestable/Timestamp.ts +0 -39
- package/src/import/validators/fields/nestable/index.ts +0 -14
- package/src/import/validators/index.ts +0 -2
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ColorContent } from "../../../../content"
|
|
2
|
-
import type { ImportColor } from "../../../validators"
|
|
3
|
-
|
|
4
|
-
export const colorConverter = (
|
|
5
|
-
field: ImportColor["value"],
|
|
6
|
-
): ColorContent | undefined => {
|
|
7
|
-
if (field === null) return
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
type: "Color",
|
|
11
|
-
value: field,
|
|
12
|
-
__TYPE__: "FieldContent",
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { DateContent } from "../../../../content"
|
|
2
|
-
import type { ImportDate } from "../../../validators"
|
|
3
|
-
|
|
4
|
-
export const dateConverter = (
|
|
5
|
-
field: ImportDate["value"],
|
|
6
|
-
): DateContent | undefined => {
|
|
7
|
-
if (field === null) return
|
|
8
|
-
|
|
9
|
-
const isoDate = field.toISOString()
|
|
10
|
-
const [withoutTime] = isoDate.split("T")
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
type: "Date",
|
|
14
|
-
value: withoutTime || isoDate,
|
|
15
|
-
__TYPE__: "FieldContent",
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Embed } from "../../../../common"
|
|
2
|
-
import { getEmbedOrThrow } from "../../../../common"
|
|
3
|
-
import type { EmbedContent } from "../../../../content"
|
|
4
|
-
import { withOptionals } from "../../../../utils/Objects"
|
|
5
|
-
import type { ImportEmbed } from "../../../validators"
|
|
6
|
-
|
|
7
|
-
export const embedConverter = (
|
|
8
|
-
field: ImportEmbed["value"],
|
|
9
|
-
embeds: Record<string, Embed | undefined>,
|
|
10
|
-
): EmbedContent | undefined => {
|
|
11
|
-
if (field === null) return
|
|
12
|
-
const embed = getEmbedOrThrow(embeds)(field.embed_url)
|
|
13
|
-
return withOptionals<EmbedContent>(
|
|
14
|
-
{
|
|
15
|
-
embed_url: field.embed_url,
|
|
16
|
-
type: embed.type,
|
|
17
|
-
all: {
|
|
18
|
-
embed_url: field.embed_url,
|
|
19
|
-
...embed,
|
|
20
|
-
},
|
|
21
|
-
__TYPE__: "EmbedContent",
|
|
22
|
-
},
|
|
23
|
-
[
|
|
24
|
-
["version", embed.version],
|
|
25
|
-
["title", embed.title],
|
|
26
|
-
["author_name", embed.author_name],
|
|
27
|
-
["author_url", embed.author_url],
|
|
28
|
-
["provider_name", embed.provider_name],
|
|
29
|
-
["provider_url", embed.provider_url],
|
|
30
|
-
["cache_age", embed.cache_age],
|
|
31
|
-
["thumbnail_url", embed.thumbnail_url],
|
|
32
|
-
["thumbnail_width", embed.thumbnail_width],
|
|
33
|
-
["thumbnail_height", embed.thumbnail_height],
|
|
34
|
-
["html", embed.html],
|
|
35
|
-
],
|
|
36
|
-
)
|
|
37
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { GeoPointContent } from "../../../../content"
|
|
2
|
-
import type { ImportGeoPoint } from "../../../validators"
|
|
3
|
-
|
|
4
|
-
export const geopointConverter = (
|
|
5
|
-
field: ImportGeoPoint["value"],
|
|
6
|
-
): GeoPointContent | undefined => {
|
|
7
|
-
if (field === null) return
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
position: {
|
|
11
|
-
lat: field.latitude,
|
|
12
|
-
lng: field.longitude,
|
|
13
|
-
},
|
|
14
|
-
__TYPE__: "GeoPointContent",
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { Asset } from "../../../../common"
|
|
2
|
-
import { getAssetOrThrow } from "../../../../common"
|
|
3
|
-
import type { ImageContent, ImageContentView } from "../../../../content"
|
|
4
|
-
import { withOptionals } from "../../../../utils/Objects"
|
|
5
|
-
import type { ImageField, ImportImage } from "../../../validators"
|
|
6
|
-
import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks"
|
|
7
|
-
|
|
8
|
-
export function convertImageView<Input extends ImageField | ImportImageBlock>(
|
|
9
|
-
inputImage: Input,
|
|
10
|
-
image: Asset,
|
|
11
|
-
) {
|
|
12
|
-
// We can do that because anyway all properties being read
|
|
13
|
-
const imageField: ImageField = {
|
|
14
|
-
...inputImage,
|
|
15
|
-
edit: {
|
|
16
|
-
x: 0,
|
|
17
|
-
y: 0,
|
|
18
|
-
zoom: 1,
|
|
19
|
-
...inputImage.edit,
|
|
20
|
-
},
|
|
21
|
-
dimensions: inputImage.dimensions ?? {},
|
|
22
|
-
}
|
|
23
|
-
return withOptionals<ImageContentView>(
|
|
24
|
-
{
|
|
25
|
-
origin: {
|
|
26
|
-
id: image.id,
|
|
27
|
-
url: image.origin_url,
|
|
28
|
-
// All images returned form Asset API should have width and height properties.
|
|
29
|
-
width: image.width ?? 0,
|
|
30
|
-
height: image.height ?? 0,
|
|
31
|
-
},
|
|
32
|
-
// All images returned form Asset API should have width and height properties.
|
|
33
|
-
// Image width and height will be only applied if there are no constraints and user didn't overwrite it
|
|
34
|
-
width: imageField?.dimensions?.width ?? image.width ?? 0,
|
|
35
|
-
height: imageField?.dimensions?.height ?? image.height ?? 0,
|
|
36
|
-
// If edit is not provided, we crop constraint width and height from the left upper corner.
|
|
37
|
-
// WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
|
|
38
|
-
edit: {
|
|
39
|
-
zoom: imageField.edit?.zoom ?? 1,
|
|
40
|
-
crop: {
|
|
41
|
-
x: imageField.edit?.x ?? 0,
|
|
42
|
-
y: imageField.edit?.y ?? 0,
|
|
43
|
-
},
|
|
44
|
-
background:
|
|
45
|
-
imageField.edit?.background ??
|
|
46
|
-
(image.extension === "png" ? "transparent" : "#ffffff"),
|
|
47
|
-
},
|
|
48
|
-
url: image.url,
|
|
49
|
-
},
|
|
50
|
-
[
|
|
51
|
-
["alt", imageField?.alt || image.alt],
|
|
52
|
-
["credits", imageField?.copyright || image.credits],
|
|
53
|
-
],
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function convertThumbnails(
|
|
58
|
-
imageField: Exclude<ImportImage["value"], null>,
|
|
59
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
60
|
-
) {
|
|
61
|
-
return Object.entries(imageField.thumbnails).reduce(
|
|
62
|
-
(acc, [thumbnailName, thumbnail]) => {
|
|
63
|
-
return {
|
|
64
|
-
...acc,
|
|
65
|
-
[thumbnailName]: convertImageView(
|
|
66
|
-
thumbnail,
|
|
67
|
-
getAssetOrThrow(assets)(thumbnail.id),
|
|
68
|
-
),
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
{},
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// All assets from `imageField` must be present in `assets`
|
|
76
|
-
// If not then function will throw an error
|
|
77
|
-
export const imageConverter = (
|
|
78
|
-
imageField: ImportImage["value"],
|
|
79
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
80
|
-
): ImageContent | undefined => {
|
|
81
|
-
if (!imageField) return
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
...convertImageView<ImageField>(
|
|
85
|
-
imageField,
|
|
86
|
-
getAssetOrThrow(assets)(imageField.id),
|
|
87
|
-
),
|
|
88
|
-
thumbnails: convertThumbnails(imageField, assets),
|
|
89
|
-
__TYPE__: "ImageContent" as const,
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { Asset } from "../../../../common"
|
|
2
|
-
import { getAssetOrThrow } from "../../../../common"
|
|
3
|
-
import type { LinkContent } from "../../../../content"
|
|
4
|
-
import type {
|
|
5
|
-
DocumentLink,
|
|
6
|
-
ImportLink,
|
|
7
|
-
MediaLink,
|
|
8
|
-
WebLink,
|
|
9
|
-
} from "../../../validators"
|
|
10
|
-
|
|
11
|
-
const webLinkConverter = (field: WebLink): LinkContent => ({
|
|
12
|
-
value: {
|
|
13
|
-
url: field.url,
|
|
14
|
-
target: field.target,
|
|
15
|
-
__TYPE__: "ExternalLink",
|
|
16
|
-
},
|
|
17
|
-
__TYPE__: "LinkContent",
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const documentLinkConverter = (field: DocumentLink): LinkContent => ({
|
|
21
|
-
value: {
|
|
22
|
-
id: field.id,
|
|
23
|
-
__TYPE__: "DocumentLink",
|
|
24
|
-
},
|
|
25
|
-
__TYPE__: "LinkContent",
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const fileLinkConverter = (field: MediaLink, asset: Asset): LinkContent => ({
|
|
29
|
-
value: {
|
|
30
|
-
id: field.id,
|
|
31
|
-
url: asset.origin_url,
|
|
32
|
-
name: asset.filename ?? "unknown.jpg",
|
|
33
|
-
kind: asset.kind,
|
|
34
|
-
size: asset.size ? String(asset.size) : "0",
|
|
35
|
-
__TYPE__: "FileLink",
|
|
36
|
-
},
|
|
37
|
-
__TYPE__: "LinkContent",
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
const imageLinkConverter = (field: MediaLink, asset: Asset): LinkContent => ({
|
|
41
|
-
value: {
|
|
42
|
-
id: field.id,
|
|
43
|
-
url: asset.origin_url,
|
|
44
|
-
height: String(asset.height ?? 1),
|
|
45
|
-
width: String(asset.width ?? 1),
|
|
46
|
-
name: asset.filename ?? "unknown.jpg",
|
|
47
|
-
kind: asset.kind,
|
|
48
|
-
size: asset.size ? String(asset.size) : "0",
|
|
49
|
-
__TYPE__: "ImageLink",
|
|
50
|
-
},
|
|
51
|
-
__TYPE__: "LinkContent",
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
export const linkConverter = (
|
|
55
|
-
field: ImportLink["value"],
|
|
56
|
-
assets: Record<string, Asset | undefined>,
|
|
57
|
-
): LinkContent | undefined => {
|
|
58
|
-
if (field === null) {
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
switch (field.link_type) {
|
|
63
|
-
case "Web":
|
|
64
|
-
return webLinkConverter(field)
|
|
65
|
-
case "Document":
|
|
66
|
-
return documentLinkConverter(field)
|
|
67
|
-
case "Media": {
|
|
68
|
-
const asset = getAssetOrThrow(assets)(field.id)
|
|
69
|
-
switch (asset.kind) {
|
|
70
|
-
case "all":
|
|
71
|
-
return fileLinkConverter(field, asset)
|
|
72
|
-
case "image":
|
|
73
|
-
return imageLinkConverter(field, asset)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { Asset } from "../../../../common"
|
|
2
|
-
import type { Embed } from "../../../../common/Embed"
|
|
3
|
-
import type { NestableContent } from "../../../../content"
|
|
4
|
-
import type { ImportNestable } from "../../../validators"
|
|
5
|
-
import {
|
|
6
|
-
booleanConverter,
|
|
7
|
-
colorConverter,
|
|
8
|
-
dateConverter,
|
|
9
|
-
embedConverter,
|
|
10
|
-
geopointConverter,
|
|
11
|
-
imageConverter,
|
|
12
|
-
linkConverter,
|
|
13
|
-
numberConverter,
|
|
14
|
-
richTextConverter,
|
|
15
|
-
selectConverter,
|
|
16
|
-
textConverter,
|
|
17
|
-
timestampConverter,
|
|
18
|
-
} from "."
|
|
19
|
-
|
|
20
|
-
export function convertNestableWidget(
|
|
21
|
-
field: ImportNestable,
|
|
22
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
23
|
-
embeds: Record<string, Embed | undefined>,
|
|
24
|
-
): NestableContent | undefined {
|
|
25
|
-
switch (field.type) {
|
|
26
|
-
case "Boolean":
|
|
27
|
-
return booleanConverter(field.value)
|
|
28
|
-
case "Color":
|
|
29
|
-
return colorConverter(field.value)
|
|
30
|
-
case "Select":
|
|
31
|
-
return selectConverter(field.value)
|
|
32
|
-
case "Number":
|
|
33
|
-
return numberConverter(field.value)
|
|
34
|
-
case "Text":
|
|
35
|
-
return textConverter(field.value)
|
|
36
|
-
case "Date":
|
|
37
|
-
return dateConverter(field.value)
|
|
38
|
-
case "Timestamp":
|
|
39
|
-
return timestampConverter(field.value)
|
|
40
|
-
case "Embed":
|
|
41
|
-
return embedConverter(field.value, embeds)
|
|
42
|
-
case "GeoPoint":
|
|
43
|
-
return geopointConverter(field.value)
|
|
44
|
-
case "Link":
|
|
45
|
-
return linkConverter(field.value, assets)
|
|
46
|
-
case "Image":
|
|
47
|
-
return imageConverter(field.value, assets)
|
|
48
|
-
case "StructuredText":
|
|
49
|
-
return richTextConverter(field.value, assets, embeds)
|
|
50
|
-
default:
|
|
51
|
-
throw new Error(
|
|
52
|
-
`Unsupported type of nestable converter ${JSON.stringify(field)}`,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { NumberContent } from "../../../../content"
|
|
2
|
-
import type { ImportNumber } from "../../../validators"
|
|
3
|
-
|
|
4
|
-
export const numberConverter = (
|
|
5
|
-
field: ImportNumber["value"],
|
|
6
|
-
): NumberContent | undefined => {
|
|
7
|
-
if (field === null) return
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
type: "Number",
|
|
11
|
-
value: field.toString(),
|
|
12
|
-
__TYPE__: "FieldContent",
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Embed } from "../../../../../common"
|
|
2
|
-
import type { EmbedBlock } from "../../../../../content"
|
|
3
|
-
import type { ImportEmbedBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
|
|
4
|
-
import { embedConverter } from "../Embed"
|
|
5
|
-
|
|
6
|
-
export function embedBlockConverter(
|
|
7
|
-
block: ImportEmbedBlock,
|
|
8
|
-
embeds: Record<string, Embed | undefined>,
|
|
9
|
-
): EmbedBlock {
|
|
10
|
-
const embedData = embedConverter(block.oembed, embeds)
|
|
11
|
-
|
|
12
|
-
if (!embedData) throw new Error("Failed to convert embed data")
|
|
13
|
-
return {
|
|
14
|
-
type: block.type,
|
|
15
|
-
data: embedData,
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Asset, getAssetOrThrow } from "../../../../../common"
|
|
2
|
-
import type { ImageBlock } from "../../../../../content"
|
|
3
|
-
import type { ImportImageBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
|
|
4
|
-
import { convertImageView } from "../Image"
|
|
5
|
-
|
|
6
|
-
export function imageBlockConverter(
|
|
7
|
-
block: ImportImageBlock,
|
|
8
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
9
|
-
): ImageBlock {
|
|
10
|
-
return {
|
|
11
|
-
type: block.type,
|
|
12
|
-
data: convertImageView<ImportImageBlock>(
|
|
13
|
-
block,
|
|
14
|
-
getAssetOrThrow(assets)(block.id),
|
|
15
|
-
),
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Asset, Embed } from "../../../../../common"
|
|
2
|
-
import type { RichTextContent } from "../../../../../content"
|
|
3
|
-
import { RichTextContentType } from "../../../../../content"
|
|
4
|
-
import type { ImportRichText } from "../../../../validators"
|
|
5
|
-
import { embedBlockConverter } from "./embedBlock"
|
|
6
|
-
import { imageBlockConverter } from "./imageBlock"
|
|
7
|
-
import { textBlockConverter } from "./textBlock"
|
|
8
|
-
|
|
9
|
-
export const richTextConverter = (
|
|
10
|
-
richTextField: ImportRichText["value"],
|
|
11
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
12
|
-
embeds: Record<string, Embed | undefined>,
|
|
13
|
-
): RichTextContent | undefined => {
|
|
14
|
-
if (richTextField === null) return
|
|
15
|
-
return {
|
|
16
|
-
__TYPE__: RichTextContentType,
|
|
17
|
-
value: richTextField.map((block) => {
|
|
18
|
-
if (block.type === "image") return imageBlockConverter(block, assets)
|
|
19
|
-
else if (block.type === "embed") return embedBlockConverter(block, embeds)
|
|
20
|
-
return textBlockConverter(block, assets)
|
|
21
|
-
}),
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { Asset } from "../../../../../common"
|
|
2
|
-
import type { Span, TextBlock } from "../../../../../content"
|
|
3
|
-
import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
|
|
4
|
-
import { linkConverter } from "../Link"
|
|
5
|
-
|
|
6
|
-
export function textBlockConverter(
|
|
7
|
-
block: ImportTextBlock,
|
|
8
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
9
|
-
): TextBlock {
|
|
10
|
-
return {
|
|
11
|
-
type: block.type,
|
|
12
|
-
content: {
|
|
13
|
-
text: block.text,
|
|
14
|
-
...(() => {
|
|
15
|
-
if (block.spans) {
|
|
16
|
-
const convertedSpans = spansConverter(block.spans, assets)
|
|
17
|
-
if (!convertedSpans) return {}
|
|
18
|
-
|
|
19
|
-
return { spans: convertedSpans }
|
|
20
|
-
}
|
|
21
|
-
return {}
|
|
22
|
-
})(),
|
|
23
|
-
},
|
|
24
|
-
...(block.direction ? { direction: block.direction } : {}),
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function spansConverter(
|
|
29
|
-
spans: NonNullable<ImportTextBlock["spans"]>,
|
|
30
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
31
|
-
): Span[] {
|
|
32
|
-
return spans.reduce<Span[]>((acc, span) => {
|
|
33
|
-
switch (span.type) {
|
|
34
|
-
case "em":
|
|
35
|
-
case "strong":
|
|
36
|
-
return [...acc, span]
|
|
37
|
-
case "label":
|
|
38
|
-
return [
|
|
39
|
-
...acc,
|
|
40
|
-
{
|
|
41
|
-
...span,
|
|
42
|
-
data: span.data.label,
|
|
43
|
-
},
|
|
44
|
-
]
|
|
45
|
-
|
|
46
|
-
case "hyperlink": {
|
|
47
|
-
const convertedLink = linkConverter(span.data, assets)
|
|
48
|
-
if (!convertedLink) return acc
|
|
49
|
-
|
|
50
|
-
return [
|
|
51
|
-
...acc,
|
|
52
|
-
{
|
|
53
|
-
type: span.type,
|
|
54
|
-
start: span.start,
|
|
55
|
-
end: span.end,
|
|
56
|
-
data: convertedLink.value,
|
|
57
|
-
},
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, [])
|
|
62
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SelectContent } from "../../../../content"
|
|
2
|
-
import type { ImportSelect } from "../../../validators"
|
|
3
|
-
|
|
4
|
-
export const selectConverter = (
|
|
5
|
-
field: ImportSelect["value"],
|
|
6
|
-
): SelectContent | undefined => {
|
|
7
|
-
if (field === null) return
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
type: "Select",
|
|
11
|
-
value: field,
|
|
12
|
-
__TYPE__: "FieldContent",
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { TextContent } from "../../../../content"
|
|
2
|
-
import type { ImportText } from "../../../validators"
|
|
3
|
-
|
|
4
|
-
export const textConverter = (
|
|
5
|
-
field: ImportText["value"],
|
|
6
|
-
): TextContent | undefined => {
|
|
7
|
-
if (field === null) return
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
type: "Text",
|
|
11
|
-
value: field,
|
|
12
|
-
__TYPE__: "FieldContent",
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { TimestampContent } from "../../../../content"
|
|
2
|
-
import type { ImportTimestamp } from "../../../validators"
|
|
3
|
-
|
|
4
|
-
export const timestampConverter = (
|
|
5
|
-
field: ImportTimestamp["value"],
|
|
6
|
-
): TimestampContent | undefined => {
|
|
7
|
-
if (field === null) return
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
type: "Timestamp",
|
|
11
|
-
value: field.toISOString(),
|
|
12
|
-
__TYPE__: "FieldContent",
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from "./Boolean"
|
|
2
|
-
export * from "./Color"
|
|
3
|
-
export * from "./Date"
|
|
4
|
-
export * from "./Embed"
|
|
5
|
-
export * from "./GeoPoint"
|
|
6
|
-
export * from "./Image"
|
|
7
|
-
export * from "./Link"
|
|
8
|
-
export * from "./Nestable"
|
|
9
|
-
export * from "./Number"
|
|
10
|
-
export * from "./RichText"
|
|
11
|
-
export * from "./Select"
|
|
12
|
-
export * from "./Text"
|
|
13
|
-
export * from "./Timestamp"
|
package/src/import/index.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { either } from "fp-ts"
|
|
2
|
-
import { Either, isLeft } from "fp-ts/Either"
|
|
3
|
-
import { pipe } from "fp-ts/lib/function"
|
|
4
|
-
import * as t from "io-ts"
|
|
5
|
-
|
|
6
|
-
import type { WidgetKey } from "../../common"
|
|
7
|
-
import type { StaticCustomType, StaticWidget } from "../../customtypes"
|
|
8
|
-
import { flattenCustomTypeFields } from "../../customtypes"
|
|
9
|
-
import { isObject } from "../../utils/Objects"
|
|
10
|
-
import { withCustomError } from "../../validators/function"
|
|
11
|
-
import { ImportField } from "./fields/ImportField"
|
|
12
|
-
|
|
13
|
-
const rawImportDocument = withCustomError(
|
|
14
|
-
t.UnknownRecord,
|
|
15
|
-
() => "document is not an object",
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
function validateField(
|
|
19
|
-
document: Record<string, unknown>,
|
|
20
|
-
customType: StaticCustomType,
|
|
21
|
-
) {
|
|
22
|
-
return (
|
|
23
|
-
key: string,
|
|
24
|
-
content: unknown,
|
|
25
|
-
model?: StaticWidget,
|
|
26
|
-
): Either<t.Errors, ImportField> => {
|
|
27
|
-
// the field is not defined in the custom type -> extra field or typo
|
|
28
|
-
if (!model) {
|
|
29
|
-
const error: t.ValidationError = {
|
|
30
|
-
value: content,
|
|
31
|
-
context: [{ key: key, type: t.unknown }],
|
|
32
|
-
message: `The field ${key} is not part of the Custom type`,
|
|
33
|
-
}
|
|
34
|
-
return either.left([error])
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// retrieving the right codec then testing out fieldValue with it.
|
|
38
|
-
const { result, codec } = ImportField.decode(model)(content)
|
|
39
|
-
|
|
40
|
-
// error.context is pointing at root when it should point to a `fieldKey`.
|
|
41
|
-
// We need to override the context to make it right.
|
|
42
|
-
if (isLeft(result)) {
|
|
43
|
-
const errors: t.Errors = result.left.map((error) => {
|
|
44
|
-
const contextHead = error.context[0]
|
|
45
|
-
const context = [
|
|
46
|
-
{ key: "", actual: document, type: ImportDocument(customType) },
|
|
47
|
-
contextHead
|
|
48
|
-
? { ...contextHead, key: key }
|
|
49
|
-
: { key: key, actual: content, type: codec },
|
|
50
|
-
...error.context.slice(1),
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
return { ...error, context }
|
|
54
|
-
})
|
|
55
|
-
return either.left(errors)
|
|
56
|
-
}
|
|
57
|
-
return either.right(result.right)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function validateDocument(
|
|
62
|
-
customType: StaticCustomType,
|
|
63
|
-
rawDoc: Record<string, unknown>,
|
|
64
|
-
) {
|
|
65
|
-
const fieldModels = flattenCustomTypeFields(customType)
|
|
66
|
-
const { document, errors } = Object.entries(rawDoc).reduce<{
|
|
67
|
-
document: ImportDocument
|
|
68
|
-
errors: t.Errors
|
|
69
|
-
}>(
|
|
70
|
-
(acc, [fieldKey, fieldValue]) => {
|
|
71
|
-
const parsedField = validateField(rawDoc, customType)(
|
|
72
|
-
fieldKey,
|
|
73
|
-
fieldValue,
|
|
74
|
-
fieldModels[fieldKey],
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
if (isLeft(parsedField))
|
|
78
|
-
return { ...acc, errors: [...acc.errors, ...parsedField.left] }
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
...acc,
|
|
82
|
-
document: { ...acc.document, [fieldKey]: parsedField.right },
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
{ document: {}, errors: [] },
|
|
86
|
-
)
|
|
87
|
-
if (errors.length > 0) return either.left(errors)
|
|
88
|
-
return either.right(document)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export type ImportDocument = Record<WidgetKey, ImportField>
|
|
92
|
-
export const ImportDocument = (customType: StaticCustomType) =>
|
|
93
|
-
new t.Type<ImportDocument, ImportDocument, unknown>(
|
|
94
|
-
"ImportDocument",
|
|
95
|
-
(u): u is ImportDocument => isObject(u),
|
|
96
|
-
(raw: unknown) => {
|
|
97
|
-
return pipe(
|
|
98
|
-
rawImportDocument.decode(raw),
|
|
99
|
-
either.chain((doc) => validateDocument(customType, doc)),
|
|
100
|
-
)
|
|
101
|
-
},
|
|
102
|
-
t.identity,
|
|
103
|
-
)
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { either } from "fp-ts"
|
|
2
|
-
import { pipe } from "fp-ts/lib/function"
|
|
3
|
-
import * as t from "io-ts"
|
|
4
|
-
|
|
5
|
-
import type { FieldType } from "../../../customtypes"
|
|
6
|
-
import { isObject } from "../../../utils/Objects"
|
|
7
|
-
|
|
8
|
-
export const ImportContent = <T extends FieldType, A, O = A>(
|
|
9
|
-
type: T,
|
|
10
|
-
valueCodec: t.Type<A, O>,
|
|
11
|
-
) =>
|
|
12
|
-
new t.Type<{ type: T; value: A }, O>(
|
|
13
|
-
`ImportField: ${valueCodec.name}`,
|
|
14
|
-
(u: unknown): u is { type: T; value: A } => {
|
|
15
|
-
if (!isObject(u)) return false
|
|
16
|
-
return type === u["type"] && valueCodec.is(u["value"])
|
|
17
|
-
},
|
|
18
|
-
(u: unknown, c) => {
|
|
19
|
-
return pipe(
|
|
20
|
-
valueCodec.validate(u, c),
|
|
21
|
-
either.map((decodedValue) => {
|
|
22
|
-
return {
|
|
23
|
-
type,
|
|
24
|
-
value: decodedValue,
|
|
25
|
-
}
|
|
26
|
-
}),
|
|
27
|
-
)
|
|
28
|
-
},
|
|
29
|
-
(field) => field.value as unknown as O,
|
|
30
|
-
)
|