@prismicio/types-internal 2.2.0-alpha.2 → 2.2.0-alpha.21
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/Asset.d.ts +16 -0
- package/lib/common/Asset.js +11 -0
- package/lib/common/Embed.d.ts +15 -0
- package/lib/common/Embed.js +10 -0
- package/lib/common/UUID.d.ts +7 -0
- package/lib/common/UUID.js +8 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/content/Document.d.ts +40 -40
- package/lib/content/fields/GroupContent.d.ts +12 -12
- package/lib/content/fields/WidgetContent.d.ts +56 -56
- package/lib/content/fields/nestable/NestableContent.d.ts +7 -7
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +35 -12
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +5 -5
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +9 -9
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +14 -14
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -5
- package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +14 -14
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +14 -14
- package/lib/content/fields/slices/Slice/index.d.ts +30 -30
- package/lib/content/fields/slices/SliceItem.d.ts +30 -30
- package/lib/content/fields/slices/SlicesContent.d.ts +42 -42
- package/lib/customtypes/CustomType.d.ts +2 -0
- package/lib/customtypes/CustomType.js +8 -1
- package/lib/import/converters/Document.d.ts +2 -2
- package/lib/import/converters/Document.js +6 -6
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
- package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
- package/lib/import/converters/fields/Slices/Slices.js +16 -0
- package/lib/import/converters/fields/Slices/index.d.ts +1 -0
- package/lib/import/converters/fields/Slices/index.js +4 -0
- package/lib/import/converters/fields/UID.d.ts +1 -1
- package/lib/import/converters/fields/UID.js +0 -2
- package/lib/import/converters/fields/index.d.ts +1 -0
- package/lib/import/converters/fields/index.js +1 -0
- package/lib/import/converters/fields/nestable/Embed.d.ts +2 -1
- package/lib/import/converters/fields/nestable/Embed.js +24 -5
- package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
- package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
- package/lib/import/converters/fields/nestable/GeooPoint.d.ts +3 -0
- package/lib/import/converters/fields/nestable/GeooPoint.js +15 -0
- package/lib/import/converters/fields/nestable/Image.d.ts +6 -18
- package/lib/import/converters/fields/nestable/Image.js +47 -24
- package/lib/import/converters/fields/nestable/Link.d.ts +3 -2
- package/lib/import/converters/fields/nestable/Link.js +62 -11
- package/lib/import/converters/fields/nestable/Nestable.d.ts +4 -3
- package/lib/import/converters/fields/nestable/Nestable.js +9 -3
- package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
- package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.js +34 -0
- package/lib/import/converters/fields/nestable/RichText.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText.js +55 -0
- package/lib/import/converters/fields/nestable/index.d.ts +3 -0
- package/lib/import/converters/fields/nestable/index.js +3 -0
- package/lib/import/validators/Document.js +4 -9
- package/lib/import/validators/fields/ImportField.d.ts +68 -68
- package/lib/import/validators/fields/ImportField.js +8 -4
- package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +29 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +14 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/index.js +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
- package/lib/import/validators/fields/UID.d.ts +2 -2
- package/lib/import/validators/fields/UID.js +1 -1
- package/lib/import/validators/fields/nestable/Embed.d.ts +8 -22
- package/lib/import/validators/fields/nestable/Embed.js +5 -28
- package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
- package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
- package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
- package/lib/import/validators/fields/nestable/Image/default.js +19 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +45 -0
- package/lib/import/validators/fields/nestable/Image/index.js +41 -0
- package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
- package/lib/import/validators/fields/nestable/Image/merge.js +44 -0
- package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Image/model.js +2 -0
- package/lib/import/validators/fields/nestable/Image/validators.d.ts +35 -0
- package/lib/import/validators/fields/nestable/Image/validators.js +31 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +26 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +8 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +70 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +65 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +20 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +17 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +22 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +33 -0
- package/lib/import/validators/fields/nestable/Link.js +16 -11
- package/lib/import/validators/fields/nestable/Nestable.d.ts +65 -62
- package/lib/import/validators/fields/nestable/Nestable.js +18 -6
- package/lib/import/validators/fields/nestable/index.d.ts +5 -1
- package/lib/import/validators/fields/nestable/index.js +7 -1
- package/lib/utils/DocumentId.d.ts +2 -0
- package/lib/utils/DocumentId.js +7 -0
- package/lib/utils/Objects.d.ts +1 -1
- package/lib/utils/Objects.js +1 -1
- package/lib/utils/io-ts.d.ts +2 -0
- package/lib/utils/io-ts.js +22 -0
- package/lib/validators/BasicTypes.d.ts +0 -1
- package/lib/validators/BasicTypes.js +7 -8
- package/lib/validators/DefaultOrElse.js +1 -1
- package/lib/validators/NonEmptyString.js +1 -1
- package/lib/validators/NumberRange.d.ts +32 -0
- package/lib/validators/NumberRange.js +40 -0
- package/lib/validators/function.d.ts +20 -0
- package/lib/validators/function.js +41 -1
- package/lib/validators/index.d.ts +1 -0
- package/lib/validators/index.js +3 -1
- package/package.json +4 -2
- package/src/common/Asset.ts +25 -0
- package/src/common/Embed.ts +22 -0
- package/src/common/UUID.ts +19 -0
- package/src/common/index.ts +2 -0
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +1 -1
- package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
- package/src/customtypes/CustomType.ts +13 -0
- package/src/import/converters/Document.ts +10 -7
- package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
- package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
- package/src/import/converters/fields/Slices/Slices.ts +20 -0
- package/src/import/converters/fields/Slices/index.ts +1 -0
- package/src/import/converters/fields/UID.ts +1 -5
- package/src/import/converters/fields/index.ts +1 -0
- package/src/import/converters/fields/nestable/Embed.ts +29 -7
- package/src/import/converters/fields/nestable/GeoPoint.ts +16 -0
- package/src/import/converters/fields/nestable/Image.ts +69 -44
- package/src/import/converters/fields/nestable/Link.ts +77 -0
- package/src/import/converters/fields/nestable/Nestable.ts +17 -6
- package/src/import/converters/fields/nestable/RichText/embedBlock.ts +14 -0
- package/src/import/converters/fields/nestable/RichText/imageBlock.ts +14 -0
- package/src/import/converters/fields/nestable/RichText/index.ts +23 -0
- package/src/import/converters/fields/nestable/RichText/textBlock.ts +35 -0
- package/src/import/converters/fields/nestable/index.ts +3 -0
- package/src/import/validators/Document.ts +4 -12
- package/src/import/validators/fields/ImportField.ts +12 -6
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +116 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +6 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +20 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +64 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
- package/src/import/validators/fields/ImportSlices/index.ts +1 -0
- package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
- package/src/import/validators/fields/UID.ts +2 -2
- package/src/import/validators/fields/nestable/Embed.ts +6 -51
- package/src/import/validators/fields/nestable/GeoPoint.ts +21 -0
- package/src/import/validators/fields/nestable/Image/default.ts +25 -0
- package/src/import/validators/fields/nestable/Image/index.ts +73 -0
- package/src/import/validators/fields/nestable/Image/merge.ts +64 -0
- package/src/import/validators/fields/nestable/Image/model.ts +18 -0
- package/src/import/validators/fields/nestable/Image/validators.ts +45 -0
- package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +39 -0
- package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +41 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +44 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +13 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +13 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +56 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +44 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +4 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +24 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +8 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +26 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +2 -0
- package/src/import/validators/fields/nestable/ImportRichText/index.ts +2 -0
- package/src/import/validators/fields/nestable/Link.ts +59 -0
- package/src/import/validators/fields/nestable/Nestable.ts +19 -4
- package/src/import/validators/fields/nestable/index.ts +5 -1
- package/src/utils/DocumentId.ts +8 -0
- package/src/utils/Objects.ts +2 -2
- package/src/utils/io-ts.ts +29 -0
- package/src/validators/BasicTypes.ts +13 -11
- package/src/validators/DefaultOrElse.ts +1 -1
- package/src/validators/NonEmptyString.ts +4 -5
- package/src/validators/NumberRange.ts +51 -0
- package/src/validators/function.ts +44 -0
- package/src/validators/index.ts +1 -0
- package/lib/import/validators/fields/nestable/Image.d.ts +0 -24
- package/lib/import/validators/fields/nestable/Image.js +0 -45
- package/src/import/validators/fields/nestable/Image.ts +0 -90
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as E from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
import { withCustomError } from "../../../../../../validators/function"
|
|
6
|
+
import { ImportEmbedBlockType } from "./ImportEmbedBlock"
|
|
7
|
+
import { ImportImageBlockType } from "./ImportImageBlock"
|
|
8
|
+
import { ImportTextBlockType } from "./ImportTextBlock"
|
|
9
|
+
|
|
10
|
+
export type ImportBlockType =
|
|
11
|
+
| ImportTextBlockType
|
|
12
|
+
| ImportImageBlockType
|
|
13
|
+
| ImportEmbedBlockType
|
|
14
|
+
|
|
15
|
+
const ImportBlockTypeValidator = withCustomError(
|
|
16
|
+
t.union([ImportTextBlockType, ImportImageBlockType, ImportEmbedBlockType]),
|
|
17
|
+
() =>
|
|
18
|
+
`Invalid block type. Supported block types are: ${Object.keys(
|
|
19
|
+
ImportTextBlockType.keys,
|
|
20
|
+
).join(", ")}, ${ImportImageBlockType.value}, ${
|
|
21
|
+
ImportEmbedBlockType.value
|
|
22
|
+
}`,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
export const ImportBlockType = (allowedBlockTypes: string[]) =>
|
|
26
|
+
new t.Type<ImportBlockType>(
|
|
27
|
+
"ImportBlockType",
|
|
28
|
+
(u): u is ImportBlockType => ImportBlockTypeValidator.is(u),
|
|
29
|
+
(u, c) => {
|
|
30
|
+
return pipe(
|
|
31
|
+
ImportBlockTypeValidator.validate(u, c),
|
|
32
|
+
E.chain((validBlockType) =>
|
|
33
|
+
allowedBlockTypes.includes(validBlockType)
|
|
34
|
+
? t.success(validBlockType)
|
|
35
|
+
: t.failure(
|
|
36
|
+
u,
|
|
37
|
+
c,
|
|
38
|
+
`The block type '${validBlockType}' is not allowed in your document type. Enable the type for this rich text field to create the document.`,
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
},
|
|
43
|
+
t.identity,
|
|
44
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { ImportEmbedValue } from "../../Embed"
|
|
4
|
+
|
|
5
|
+
export const ImportEmbedBlockType = t.literal("embed")
|
|
6
|
+
export type ImportEmbedBlockType = t.TypeOf<typeof ImportEmbedBlockType>
|
|
7
|
+
|
|
8
|
+
export const ImportEmbedBlock = t.strict({
|
|
9
|
+
type: ImportEmbedBlockType,
|
|
10
|
+
oembed: ImportEmbedValue,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export type ImportEmbedBlock = t.TypeOf<typeof ImportEmbedBlock>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { String } from "../../../../../../validators"
|
|
4
|
+
|
|
5
|
+
export const ImportImageBlockType = t.literal("image")
|
|
6
|
+
export type ImportImageBlockType = t.TypeOf<typeof ImportImageBlockType>
|
|
7
|
+
|
|
8
|
+
export const ImportImageBlock = t.strict({
|
|
9
|
+
type: ImportImageBlockType,
|
|
10
|
+
id: String,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export type ImportImageBlock = t.TypeOf<typeof ImportImageBlock>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { String } from "../../../../../../validators"
|
|
4
|
+
import { withCustomError } from "../../../../../../validators/function"
|
|
5
|
+
import { Span } from "./Span"
|
|
6
|
+
|
|
7
|
+
export const ImportTextBlockTypes = {
|
|
8
|
+
Paragraph: "paragraph",
|
|
9
|
+
OListItem: "o-list-item",
|
|
10
|
+
ListItem: "list-item",
|
|
11
|
+
Heading1: "heading1",
|
|
12
|
+
Heading2: "heading2",
|
|
13
|
+
Heading3: "heading3",
|
|
14
|
+
Heading4: "heading4",
|
|
15
|
+
Heading5: "heading5",
|
|
16
|
+
Heading6: "heading6",
|
|
17
|
+
Preformatted: "preformatted",
|
|
18
|
+
} as const
|
|
19
|
+
|
|
20
|
+
export const ImportTextBlockType = t.keyof({
|
|
21
|
+
[ImportTextBlockTypes.Paragraph]: null,
|
|
22
|
+
[ImportTextBlockTypes.OListItem]: null,
|
|
23
|
+
[ImportTextBlockTypes.ListItem]: null,
|
|
24
|
+
[ImportTextBlockTypes.Heading1]: null,
|
|
25
|
+
[ImportTextBlockTypes.Heading2]: null,
|
|
26
|
+
[ImportTextBlockTypes.Heading3]: null,
|
|
27
|
+
[ImportTextBlockTypes.Heading4]: null,
|
|
28
|
+
[ImportTextBlockTypes.Heading5]: null,
|
|
29
|
+
[ImportTextBlockTypes.Heading6]: null,
|
|
30
|
+
[ImportTextBlockTypes.Preformatted]: null,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export type ImportTextBlockType = t.TypeOf<typeof ImportTextBlockType>
|
|
34
|
+
|
|
35
|
+
const TextDirection = withCustomError(
|
|
36
|
+
t.union([t.literal("ltr"), t.literal("rtl")]),
|
|
37
|
+
() => "The 'direction' property must be one of the following: ltr, rtl",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
export const ImportTextBlock = t.exact(
|
|
41
|
+
t.intersection([
|
|
42
|
+
t.type({
|
|
43
|
+
type: ImportTextBlockType,
|
|
44
|
+
text: String,
|
|
45
|
+
}),
|
|
46
|
+
t.partial({
|
|
47
|
+
spans: withCustomError(
|
|
48
|
+
t.array(Span),
|
|
49
|
+
() => "The 'spans' field must be an array",
|
|
50
|
+
),
|
|
51
|
+
direction: TextDirection,
|
|
52
|
+
}),
|
|
53
|
+
]),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
export type ImportTextBlock = t.TypeOf<typeof ImportTextBlock>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { withCustomError } from "../../../../../../validators/function"
|
|
4
|
+
import {
|
|
5
|
+
HyperlinkSpan,
|
|
6
|
+
HyperlinkSpanType,
|
|
7
|
+
TextSpan,
|
|
8
|
+
TextSpanType,
|
|
9
|
+
} from "./spans"
|
|
10
|
+
|
|
11
|
+
const SpanType = withCustomError(
|
|
12
|
+
t.union([HyperlinkSpanType, TextSpanType]),
|
|
13
|
+
() =>
|
|
14
|
+
`Span 'type' field must be specified and have one of the following values: ${Object.keys(
|
|
15
|
+
TextSpanType.keys,
|
|
16
|
+
).join(", ")} or ${HyperlinkSpanType.value}`,
|
|
17
|
+
)
|
|
18
|
+
export type SpanType = t.TypeOf<typeof SpanType>
|
|
19
|
+
|
|
20
|
+
const SpanTypeValidator = withCustomError(
|
|
21
|
+
t.type({
|
|
22
|
+
type: SpanType,
|
|
23
|
+
}),
|
|
24
|
+
() => "Span must be an object",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const SpanShape = t.union([HyperlinkSpan, TextSpan])
|
|
28
|
+
|
|
29
|
+
export type Span = t.TypeOf<typeof SpanShape>
|
|
30
|
+
|
|
31
|
+
export const Span = SpanTypeValidator.pipe(
|
|
32
|
+
new t.Type<Span, Span, { type: SpanType }>(
|
|
33
|
+
"Span",
|
|
34
|
+
(u): u is Span => SpanShape.is(u),
|
|
35
|
+
(u, c) => {
|
|
36
|
+
if (HyperlinkSpanType.is(u.type)) {
|
|
37
|
+
return HyperlinkSpan.validate(u, c)
|
|
38
|
+
} else {
|
|
39
|
+
return TextSpan.validate(u, c)
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
t.identity,
|
|
43
|
+
),
|
|
44
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { withCustomError } from "../../../../../../../validators/function"
|
|
4
|
+
import { Link } from "../../../Link"
|
|
5
|
+
import { SpanLocation } from "./SpanLocation"
|
|
6
|
+
|
|
7
|
+
export const HyperlinkSpanType = t.literal("hyperlink")
|
|
8
|
+
|
|
9
|
+
export type HyperlinkSpanType = t.TypeOf<typeof HyperlinkSpanType>
|
|
10
|
+
|
|
11
|
+
export const HyperlinkSpan = t.exact(
|
|
12
|
+
t.intersection([
|
|
13
|
+
t.type({
|
|
14
|
+
type: HyperlinkSpanType,
|
|
15
|
+
}),
|
|
16
|
+
SpanLocation,
|
|
17
|
+
withCustomError(
|
|
18
|
+
t.type({
|
|
19
|
+
data: Link,
|
|
20
|
+
}),
|
|
21
|
+
() => "Hyperlink span must contain a 'data' field with link data",
|
|
22
|
+
),
|
|
23
|
+
]),
|
|
24
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { SpanLocation } from "./SpanLocation"
|
|
4
|
+
|
|
5
|
+
const TextSpanTypes = {
|
|
6
|
+
Strong: "strong",
|
|
7
|
+
Em: "em",
|
|
8
|
+
Label: "label",
|
|
9
|
+
} as const
|
|
10
|
+
|
|
11
|
+
export const TextSpanType = t.keyof({
|
|
12
|
+
[TextSpanTypes.Strong]: null,
|
|
13
|
+
[TextSpanTypes.Em]: null,
|
|
14
|
+
[TextSpanTypes.Label]: null,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const TextSpan = t.exact(
|
|
18
|
+
t.intersection([
|
|
19
|
+
t.type({
|
|
20
|
+
type: TextSpanType,
|
|
21
|
+
}),
|
|
22
|
+
SpanLocation,
|
|
23
|
+
]),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export type TextSpan = t.TypeOf<typeof TextSpan>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { OutputOf, TypeOf } from "io-ts"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
|
|
4
|
+
import { DocumentId } from "../../../../utils/DocumentId"
|
|
5
|
+
import { DefaultOrElse, String } from "../../../../validators"
|
|
6
|
+
import { withCustomError } from "../../../../validators/function"
|
|
7
|
+
import { ImportContent } from "../ImportContent"
|
|
8
|
+
|
|
9
|
+
const LinkTypeValidator = t.type({
|
|
10
|
+
link_type: withCustomError(
|
|
11
|
+
t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]),
|
|
12
|
+
() => "The value must be `Web`, `Document` or `Media`",
|
|
13
|
+
),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const WebLink = t.exact(
|
|
17
|
+
t.intersection([
|
|
18
|
+
t.type({
|
|
19
|
+
link_type: t.literal("Web"),
|
|
20
|
+
url: String,
|
|
21
|
+
}),
|
|
22
|
+
t.partial({
|
|
23
|
+
target: String,
|
|
24
|
+
}),
|
|
25
|
+
]),
|
|
26
|
+
)
|
|
27
|
+
export type WebLink = t.TypeOf<typeof WebLink>
|
|
28
|
+
|
|
29
|
+
const DocumentLink = t.strict({
|
|
30
|
+
link_type: t.literal("Document"),
|
|
31
|
+
id: DocumentId,
|
|
32
|
+
})
|
|
33
|
+
export type DocumentLink = t.TypeOf<typeof DocumentLink>
|
|
34
|
+
|
|
35
|
+
const MediaLink = t.strict({
|
|
36
|
+
link_type: t.literal("Media"),
|
|
37
|
+
id: String,
|
|
38
|
+
})
|
|
39
|
+
export type MediaLink = t.TypeOf<typeof MediaLink>
|
|
40
|
+
|
|
41
|
+
export const Link = LinkTypeValidator.pipe(
|
|
42
|
+
t.union([WebLink, DocumentLink, MediaLink]),
|
|
43
|
+
)
|
|
44
|
+
export type Link = TypeOf<typeof Link>
|
|
45
|
+
|
|
46
|
+
// This is the default value for the link
|
|
47
|
+
const AnyLink = t.strict({
|
|
48
|
+
link_type: t.literal("Any"),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
export const ImportLink = ImportContent(
|
|
52
|
+
"Link",
|
|
53
|
+
DefaultOrElse<
|
|
54
|
+
TypeOf<typeof AnyLink>,
|
|
55
|
+
TypeOf<typeof Link>,
|
|
56
|
+
OutputOf<typeof Link>
|
|
57
|
+
>(AnyLink)(Link),
|
|
58
|
+
)
|
|
59
|
+
export type ImportLink = TypeOf<typeof ImportLink>
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { NestableWidget } from "../../../../customtypes"
|
|
2
|
-
import { ImportBoolean } from "
|
|
2
|
+
import { ImportBoolean } from "./Boolean"
|
|
3
3
|
import { ImportColor } from "./Color"
|
|
4
4
|
import { ImportDate } from "./Date"
|
|
5
5
|
import { ImportEmbed } from "./Embed"
|
|
6
|
+
import { ImportGeoPoint } from "./GeoPoint"
|
|
6
7
|
import { ImportImage } from "./Image"
|
|
8
|
+
import { ImportRichText } from "./ImportRichText"
|
|
9
|
+
import { ImportLink } from "./Link"
|
|
7
10
|
import { ImportNumber } from "./Number"
|
|
8
11
|
import { ImportSelect } from "./Select"
|
|
9
12
|
import { ImportText } from "./Text"
|
|
@@ -18,7 +21,10 @@ export type ImportNestable =
|
|
|
18
21
|
| ImportDate
|
|
19
22
|
| ImportTimestamp
|
|
20
23
|
| ImportEmbed
|
|
24
|
+
| ImportLink
|
|
25
|
+
| ImportGeoPoint
|
|
21
26
|
| ImportImage
|
|
27
|
+
| ImportRichText
|
|
22
28
|
|
|
23
29
|
export const ImportNestable = {
|
|
24
30
|
is(u: unknown): u is ImportNestable {
|
|
@@ -31,7 +37,10 @@ export const ImportNestable = {
|
|
|
31
37
|
ImportDate.is(u) ||
|
|
32
38
|
ImportTimestamp.is(u) ||
|
|
33
39
|
ImportEmbed.is(u) ||
|
|
34
|
-
|
|
40
|
+
ImportLink.is(u) ||
|
|
41
|
+
ImportGeoPoint.is(u) ||
|
|
42
|
+
ImportImage().is(u) ||
|
|
43
|
+
ImportRichText().is(u)
|
|
35
44
|
)
|
|
36
45
|
},
|
|
37
46
|
decode: (field: NestableWidget) => {
|
|
@@ -52,10 +61,16 @@ export const ImportNestable = {
|
|
|
52
61
|
return ImportDate
|
|
53
62
|
case "Timestamp":
|
|
54
63
|
return ImportTimestamp
|
|
55
|
-
case "Image":
|
|
56
|
-
return ImportImage
|
|
57
64
|
case "Embed":
|
|
58
65
|
return ImportEmbed
|
|
66
|
+
case "Link":
|
|
67
|
+
return ImportLink
|
|
68
|
+
case "Image":
|
|
69
|
+
return ImportImage(field)
|
|
70
|
+
case "GeoPoint":
|
|
71
|
+
return ImportGeoPoint
|
|
72
|
+
case "StructuredText":
|
|
73
|
+
return ImportRichText(field)
|
|
59
74
|
default:
|
|
60
75
|
throw new Error(`Unsupported type of nestable field ${field.type}`)
|
|
61
76
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export * from "./Boolean"
|
|
2
2
|
export * from "./Color"
|
|
3
3
|
export * from "./Date"
|
|
4
|
-
export
|
|
4
|
+
export { ImportEmbed } from "./Embed"
|
|
5
|
+
export * from "./GeoPoint"
|
|
5
6
|
export * from "./Image"
|
|
7
|
+
export * from "./Image/index"
|
|
8
|
+
export * from "./ImportRichText"
|
|
9
|
+
export * from "./Link"
|
|
6
10
|
export * from "./Nestable"
|
|
7
11
|
export * from "./Number"
|
|
8
12
|
export * from "./Select"
|
package/src/utils/Objects.ts
CHANGED
|
@@ -44,10 +44,10 @@ export function isObject(value: unknown): value is Record<string, unknown> {
|
|
|
44
44
|
|
|
45
45
|
export function mapValues<T, O>(
|
|
46
46
|
record: Record<string, T>,
|
|
47
|
-
fn: (value: T) => O,
|
|
47
|
+
fn: (value: T, key: string) => O,
|
|
48
48
|
): Record<string, O> {
|
|
49
49
|
return Object.entries<T>(record).reduce<Record<string, O>>(
|
|
50
|
-
(acc, [key, value]) => ({ ...acc, [key]: fn(value) }),
|
|
50
|
+
(acc, [key, value]) => ({ ...acc, [key]: fn(value, key) }),
|
|
51
51
|
{},
|
|
52
52
|
)
|
|
53
53
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as E from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as RA from "fp-ts/ReadonlyArray"
|
|
4
|
+
import type { Semigroup } from "fp-ts/Semigroup"
|
|
5
|
+
import type { Errors, Validation } from "io-ts"
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Semigroup simply defines how to concatenate two values of the same type.
|
|
9
|
+
* In this instance, Errors from io-ts are arrays already, so we just need to concatenate them.
|
|
10
|
+
*/
|
|
11
|
+
const validationErrorsSemigroup: Semigroup<Errors> = {
|
|
12
|
+
concat: (a: Errors, b: Errors) => [...a, ...b],
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* This is a helper function to combine multiple io-ts validations into one.
|
|
17
|
+
* t.array(...) works in the same way - it collects all the errors when decoding an array of values.
|
|
18
|
+
* However, it requires you to pass in a single io-ts validator as a parameter, which is not always convenient.
|
|
19
|
+
* Sometimes we have arrays of validation results received from function calls that don't have a validator instance.
|
|
20
|
+
*/
|
|
21
|
+
export const combineValidationResults = <T>(
|
|
22
|
+
validationResults: readonly Validation<T>[],
|
|
23
|
+
): Validation<readonly T[]> =>
|
|
24
|
+
pipe(
|
|
25
|
+
validationResults,
|
|
26
|
+
RA.traverse(E.getApplicativeValidation(validationErrorsSemigroup))(
|
|
27
|
+
(validation) => validation,
|
|
28
|
+
),
|
|
29
|
+
)
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
2
|
import { pipe } from "fp-ts/lib/function"
|
|
3
3
|
import * as t from "io-ts"
|
|
4
|
-
import { withMessage } from "io-ts-types"
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { withCustomError } from "./function"
|
|
6
|
+
|
|
7
|
+
export const String = withCustomError(
|
|
8
|
+
t.string,
|
|
9
|
+
() => "The value must be a string",
|
|
10
|
+
)
|
|
11
|
+
export const StringOrNull = withCustomError(
|
|
8
12
|
t.union([t.string, t.null]),
|
|
9
13
|
() => "The value must be a string or null",
|
|
10
14
|
)
|
|
11
|
-
export const Number =
|
|
12
|
-
|
|
15
|
+
export const Number = withCustomError(
|
|
16
|
+
t.number,
|
|
17
|
+
() => "The value must be a number",
|
|
18
|
+
)
|
|
19
|
+
export const NumberOrNull = withCustomError(
|
|
13
20
|
t.union([t.number, t.null]),
|
|
14
21
|
() => "The value must be a number or null",
|
|
15
22
|
)
|
|
16
|
-
export const Boolean =
|
|
23
|
+
export const Boolean = withCustomError(
|
|
17
24
|
t.boolean,
|
|
18
25
|
() => "The value must be a boolean",
|
|
19
26
|
)
|
|
@@ -46,8 +53,3 @@ export const EmptyArray = new t.Type<never[], never[], unknown>(
|
|
|
46
53
|
},
|
|
47
54
|
() => [],
|
|
48
55
|
)
|
|
49
|
-
|
|
50
|
-
export const AnyObject = withMessage(
|
|
51
|
-
t.record(t.string, t.unknown),
|
|
52
|
-
() => "The value must be an object",
|
|
53
|
-
)
|
|
@@ -6,7 +6,7 @@ import { EmptyArray, EmptyObject } from "./BasicTypes"
|
|
|
6
6
|
export const DefaultOrElse = <I, A, O = A>(inputValidator: t.Type<I>) => {
|
|
7
7
|
return (codec: t.Type<A, O>) =>
|
|
8
8
|
new t.Type<A | null, O | undefined>(
|
|
9
|
-
"
|
|
9
|
+
"DefaultOrElse",
|
|
10
10
|
(u: unknown): u is A | null => null === u || codec.is(u),
|
|
11
11
|
(u: unknown) => {
|
|
12
12
|
if (isRight(inputValidator.decode(u))) return t.success(null)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import { refineType } from "./function"
|
|
3
|
+
import { refineType, withCustomError } from "./function"
|
|
4
4
|
|
|
5
|
-
export default
|
|
6
|
-
t.string,
|
|
7
|
-
"
|
|
8
|
-
(s) => s.trim().length > 0,
|
|
5
|
+
export default withCustomError(
|
|
6
|
+
refineType(t.string, "nonEmptyString", (s) => s.trim().length > 0),
|
|
7
|
+
() => "The value must be a non-empty string",
|
|
9
8
|
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { Number } from "./BasicTypes"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a custom runtime type for validating that a number falls within a specified range.
|
|
7
|
+
*
|
|
8
|
+
* @param min - The minimum value of the range.
|
|
9
|
+
* @param max - The maximum value of the range.
|
|
10
|
+
* @param fieldName - The name of the field being validated (used in error messages).
|
|
11
|
+
* @returns A runtime type representing the number range validation.
|
|
12
|
+
*
|
|
13
|
+
* * @example
|
|
14
|
+
* // Creating a custom runtime type for age validation
|
|
15
|
+
* const AgeType = numberInRange(18, 99, 'Age');
|
|
16
|
+
*
|
|
17
|
+
* // Valid age
|
|
18
|
+
* const validAgeResult = AgeType.decode(25);
|
|
19
|
+
* if (t.isRight(validAgeResult)) {
|
|
20
|
+
* console.log('Valid age:', validAgeResult.right); // Output: Valid age: 25
|
|
21
|
+
* } else {
|
|
22
|
+
* console.error('Invalid age:', t.left(validAgeResult).map(t.reporter.report));
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Invalid age
|
|
27
|
+
* const invalidAgeResult = AgeType.decode(15);
|
|
28
|
+
* if (t.isRight(invalidAgeResult)) {
|
|
29
|
+
* console.log('Valid age:', invalidAgeResult.right);
|
|
30
|
+
* } else {
|
|
31
|
+
* console.error('Invalid age:', t.left(invalidAgeResult).map(t.reporter.report));
|
|
32
|
+
* }
|
|
33
|
+
*/
|
|
34
|
+
export default (min: number, max: number, fieldName: string) =>
|
|
35
|
+
Number.pipe(
|
|
36
|
+
new t.Type<number, number, number>(
|
|
37
|
+
"numberInRange",
|
|
38
|
+
(u: unknown): u is number => Number.is(u),
|
|
39
|
+
(u: number, context) => {
|
|
40
|
+
if (u > max || u < min) {
|
|
41
|
+
return t.failure(
|
|
42
|
+
u,
|
|
43
|
+
context,
|
|
44
|
+
`${fieldName} must be a number between ${min} and ${max}`,
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
return t.success(u)
|
|
48
|
+
},
|
|
49
|
+
t.identity,
|
|
50
|
+
),
|
|
51
|
+
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
2
|
import { pipe } from "fp-ts/function"
|
|
3
3
|
import * as t from "io-ts"
|
|
4
|
+
import { withValidate } from "io-ts-types"
|
|
4
5
|
import { mapOutput } from "io-ts-types/mapOutput"
|
|
5
6
|
|
|
6
7
|
export function nullable<A, O>(c: t.Type<A, O>) {
|
|
@@ -69,3 +70,46 @@ export function addType<A, O extends object, I, T extends string>(
|
|
|
69
70
|
): t.Type<A, O & { __TYPE__: T }, I> {
|
|
70
71
|
return mapOutput(codec, (o) => ({ ...o, __TYPE__: t } as const))
|
|
71
72
|
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns a clone of the given codec that tries to find sub-error with message already set.
|
|
76
|
+
* If there is such error it just returns sub-errors array.
|
|
77
|
+
* If there is no such error it generates new error with given message.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* expect(
|
|
81
|
+
* withCustomError(
|
|
82
|
+
* t.type({age: withCustomError(t.number, () => 'Invalid child')}),
|
|
83
|
+
* () => "Invalid parent"
|
|
84
|
+
* )
|
|
85
|
+
* ).toSubsetEqualLeft([{message: "Invalid child"}])
|
|
86
|
+
* expect(
|
|
87
|
+
* withCustomError(
|
|
88
|
+
* t.type({age: t.number}),
|
|
89
|
+
* () => "Invalid parent"
|
|
90
|
+
* )
|
|
91
|
+
* ).toSubsetEqualLeft([{message: "Invalid parent"}])
|
|
92
|
+
*/
|
|
93
|
+
export function withCustomError<C extends t.Any>(
|
|
94
|
+
codec: C,
|
|
95
|
+
message: (i: t.InputOf<C>, c: t.Context) => string,
|
|
96
|
+
): C {
|
|
97
|
+
return withValidate(codec, (i, c) => {
|
|
98
|
+
return either.mapLeft((errors: t.Errors) => {
|
|
99
|
+
if (errors.find((error) => error.message)) {
|
|
100
|
+
return errors
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
value: i,
|
|
106
|
+
context: c,
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
108
|
+
message: message(i, c),
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
110
|
+
actual: i,
|
|
111
|
+
},
|
|
112
|
+
]
|
|
113
|
+
})(codec.validate(i, c))
|
|
114
|
+
})
|
|
115
|
+
}
|
package/src/validators/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { default as IntFromPixels } from "./IntFromPixels"
|
|
|
9
9
|
export { default as NonEmptyString } from "./NonEmptyString"
|
|
10
10
|
export { default as NonEmptyStringOrNull } from "./NonEmptyStringOrNull"
|
|
11
11
|
export { default as NumberOrNull } from "./NumberOrNull"
|
|
12
|
+
export { default as NumberRange } from "./NumberRange"
|
|
12
13
|
export { default as StringFromBoolean } from "./StringFromBoolean"
|
|
13
14
|
export { default as StringFromNumber } from "./StringFromNumber"
|
|
14
15
|
export { default as StringOrNull } from "./StringOrNull"
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
export declare type ImageField = {
|
|
3
|
-
id: string;
|
|
4
|
-
edit?: {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
width: number;
|
|
8
|
-
height: number;
|
|
9
|
-
zoom: number;
|
|
10
|
-
background: string;
|
|
11
|
-
};
|
|
12
|
-
alt?: string | null;
|
|
13
|
-
credit?: string | null;
|
|
14
|
-
};
|
|
15
|
-
declare type ImageFieldWithThumbnails = ImageField & {
|
|
16
|
-
thumbnails: Record<string, ImageField>;
|
|
17
|
-
};
|
|
18
|
-
declare const ImageFieldWithThumbnails: t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
|
|
19
|
-
export declare const ImportImage: t.Type<{
|
|
20
|
-
type: "Image";
|
|
21
|
-
value: ImageFieldWithThumbnails | null;
|
|
22
|
-
}, ImageFieldWithThumbnails | undefined, unknown>;
|
|
23
|
-
export declare type ImportImage = t.TypeOf<typeof ImportImage>;
|
|
24
|
-
export {};
|