@prismicio/types-internal 2.2.0-alpha.1 → 2.2.0-alpha.11
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/GroupContent.js +11 -4
- 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 +12 -12
- 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/customtypes/widgets/nestable/NestableWidget.d.ts +0 -157
- package/lib/customtypes/widgets/nestable/NestableWidget.js +1 -17
- package/lib/import/converters/Document.d.ts +3 -2
- package/lib/import/converters/Document.js +11 -7
- 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/SliceItem.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SliceItem.js +24 -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 +3 -0
- package/lib/import/converters/fields/UID.js +12 -0
- package/lib/import/converters/fields/index.d.ts +2 -0
- package/lib/import/converters/fields/index.js +2 -0
- package/lib/import/converters/fields/nestable/Boolean.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Boolean.js +12 -0
- package/lib/import/converters/fields/nestable/Color.js +9 -6
- package/lib/import/converters/fields/nestable/Date.d.ts +1 -1
- package/lib/import/converters/fields/nestable/Date.js +5 -5
- package/lib/import/converters/fields/nestable/Embed.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Embed.js +32 -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 +4 -0
- package/lib/import/converters/fields/nestable/Image.js +55 -0
- package/lib/import/converters/fields/nestable/Link.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Link.js +70 -0
- package/lib/import/converters/fields/nestable/Nestable.d.ts +4 -2
- package/lib/import/converters/fields/nestable/Nestable.js +11 -1
- package/lib/import/converters/fields/nestable/Number.js +9 -6
- package/lib/import/converters/fields/nestable/Select.js +9 -6
- package/lib/import/converters/fields/nestable/Text.js +9 -6
- package/lib/import/converters/fields/nestable/Timestamp.d.ts +1 -1
- package/lib/import/converters/fields/nestable/Timestamp.js +9 -6
- package/lib/import/converters/fields/nestable/index.d.ts +5 -0
- package/lib/import/converters/fields/nestable/index.js +5 -0
- package/lib/import/validators/Document.d.ts +4 -4
- package/lib/import/validators/Document.js +38 -46
- package/lib/import/validators/fields/ImportContent.d.ts +5 -0
- package/lib/import/validators/fields/ImportContent.js +21 -0
- package/lib/import/validators/fields/ImportField.d.ts +135 -0
- package/lib/import/validators/fields/ImportField.js +29 -0
- package/lib/import/validators/fields/ImportSlices/ImportSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/ImportSliceId.js +43 -0
- package/lib/import/validators/fields/ImportSlices/ImportSliceItem.d.ts +24 -0
- package/lib/import/validators/fields/ImportSlices/ImportSliceItem.js +87 -0
- package/lib/import/validators/fields/ImportSlices/ImportSliceItemContent.d.ts +12 -0
- package/lib/import/validators/fields/ImportSlices/ImportSliceItemContent.js +41 -0
- 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 +60 -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/Slices/SharedSlice/SharedSlice.d.ts +14 -0
- package/lib/import/validators/fields/Slices/SharedSlice/SharedSlice.js +60 -0
- package/lib/import/validators/fields/Slices/SharedSlice/errors.d.ts +5 -0
- package/lib/import/validators/fields/Slices/SharedSlice/errors.js +8 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +38 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/errors.d.ts +5 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/errors.js +9 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceItems.d.ts +11 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceItems.js +25 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/index.d.ts +6 -0
- package/lib/import/validators/fields/Slices/SharedSlice/fields/index.js +9 -0
- package/lib/import/validators/fields/Slices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/Slices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/Slices/SharedSlice/utils.d.ts +339 -0
- package/lib/import/validators/fields/Slices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/Slices/Slices.d.ts +8 -0
- package/lib/import/validators/fields/Slices/Slices.js +29 -0
- package/lib/import/validators/fields/Slices/index.d.ts +1 -0
- package/lib/import/validators/fields/Slices/index.js +4 -0
- package/lib/import/validators/fields/Slices/utils.d.ts +4 -0
- package/lib/import/validators/fields/Slices/utils.js +35 -0
- package/lib/import/validators/fields/Slices.d.ts +4 -0
- package/lib/import/validators/fields/Slices.js +12 -0
- package/lib/import/validators/fields/UID.d.ts +6 -0
- package/lib/import/validators/fields/UID.js +15 -0
- package/lib/import/validators/fields/index.d.ts +1 -5
- package/lib/import/validators/fields/index.js +1 -0
- package/lib/import/validators/fields/nestable/Boolean.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Boolean.js +6 -0
- package/lib/import/validators/fields/nestable/Color.d.ts +5 -4
- package/lib/import/validators/fields/nestable/Color.js +4 -4
- package/lib/import/validators/fields/nestable/Date.d.ts +5 -3
- package/lib/import/validators/fields/nestable/Date.js +4 -2
- package/lib/import/validators/fields/nestable/Embed.d.ts +10 -0
- package/lib/import/validators/fields/nestable/Embed.js +36 -0
- 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/Decoder.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/Decoder.js +40 -0
- package/lib/import/validators/fields/nestable/Image/Validator.d.ts +37 -0
- package/lib/import/validators/fields/nestable/Image/Validator.js +26 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/index.js +28 -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.d.ts +45 -0
- package/lib/import/validators/fields/nestable/Image.js +45 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +38 -0
- package/lib/import/validators/fields/nestable/Link.js +35 -0
- package/lib/import/validators/fields/nestable/Nestable.d.ts +120 -4
- package/lib/import/validators/fields/nestable/Nestable.js +59 -28
- package/lib/import/validators/fields/nestable/Number.d.ts +16 -9
- package/lib/import/validators/fields/nestable/Number.js +5 -4
- package/lib/import/validators/fields/nestable/Select.d.ts +15 -8
- package/lib/import/validators/fields/nestable/Select.js +4 -2
- package/lib/import/validators/fields/nestable/Text.d.ts +6 -3
- package/lib/import/validators/fields/nestable/Text.js +2 -1
- package/lib/import/validators/fields/nestable/Timestamp.d.ts +5 -3
- package/lib/import/validators/fields/nestable/Timestamp.js +4 -2
- package/lib/import/validators/fields/nestable/index.d.ts +6 -0
- package/lib/import/validators/fields/nestable/index.js +6 -0
- package/lib/utils/DocumentId.d.ts +1 -0
- package/lib/utils/DocumentId.js +7 -0
- package/lib/utils/Objects.d.ts +1 -0
- package/lib/utils/Objects.js +5 -1
- package/lib/utils/io-ts.d.ts +2 -0
- package/lib/utils/io-ts.js +22 -0
- package/lib/validators/BasicTypes.d.ts +9 -0
- package/lib/validators/BasicTypes.js +20 -1
- package/lib/validators/DefaultOrElse.d.ts +5 -0
- package/lib/validators/DefaultOrElse.js +21 -0
- package/lib/validators/NonEmptyString.js +2 -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 +2 -1
- package/lib/validators/index.js +4 -2
- package/package.json +6 -3
- package/src/common/Asset.ts +25 -0
- package/src/common/Embed.ts +22 -0
- package/src/common/UUID.ts +18 -0
- package/src/common/index.ts +2 -0
- package/src/content/fields/GroupContent.ts +9 -5
- package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
- package/src/customtypes/CustomType.ts +13 -0
- package/src/customtypes/widgets/nestable/NestableWidget.ts +0 -17
- package/src/import/converters/Document.ts +26 -10
- 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 +13 -0
- package/src/import/converters/fields/index.ts +2 -0
- package/src/import/converters/fields/nestable/Boolean.ts +13 -0
- package/src/import/converters/fields/nestable/Color.ts +7 -5
- package/src/import/converters/fields/nestable/Date.ts +12 -13
- package/src/import/converters/fields/nestable/Embed.ts +37 -0
- package/src/import/converters/fields/nestable/GeooPoint.ts +16 -0
- package/src/import/converters/fields/nestable/Image.ts +73 -0
- package/src/import/converters/fields/nestable/Link.ts +77 -0
- package/src/import/converters/fields/nestable/Nestable.ts +21 -2
- package/src/import/converters/fields/nestable/Number.ts +7 -5
- package/src/import/converters/fields/nestable/Select.ts +7 -5
- package/src/import/converters/fields/nestable/Text.ts +7 -5
- package/src/import/converters/fields/nestable/Timestamp.ts +8 -6
- package/src/import/converters/fields/nestable/index.ts +5 -0
- package/src/import/validators/Document.ts +86 -79
- package/src/import/validators/fields/ImportContent.ts +30 -0
- package/src/import/validators/fields/ImportField.ts +30 -0
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +114 -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 +61 -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 +27 -0
- package/src/import/validators/fields/index.ts +1 -7
- package/src/import/validators/fields/nestable/Boolean.ts +7 -0
- package/src/import/validators/fields/nestable/Color.ts +23 -23
- package/src/import/validators/fields/nestable/Date.ts +26 -27
- package/src/import/validators/fields/nestable/Embed.ts +54 -0
- package/src/import/validators/fields/nestable/GeoPoint.ts +21 -0
- package/src/import/validators/fields/nestable/Image/Decoder.ts +61 -0
- package/src/import/validators/fields/nestable/Image/Validator.ts +35 -0
- package/src/import/validators/fields/nestable/Image/index.ts +45 -0
- package/src/import/validators/fields/nestable/Image/model.ts +18 -0
- package/src/import/validators/fields/nestable/Link.ts +54 -0
- package/src/import/validators/fields/nestable/Nestable.ts +65 -26
- package/src/import/validators/fields/nestable/Number.ts +32 -30
- package/src/import/validators/fields/nestable/Select.ts +32 -30
- package/src/import/validators/fields/nestable/Text.ts +6 -6
- package/src/import/validators/fields/nestable/Timestamp.ts +29 -26
- package/src/import/validators/fields/nestable/index.ts +6 -0
- package/src/utils/DocumentId.ts +9 -0
- package/src/utils/Objects.ts +10 -0
- package/src/utils/io-ts.ts +29 -0
- package/src/validators/BasicTypes.ts +53 -0
- package/src/validators/DefaultOrElse.ts +24 -0
- package/src/validators/NonEmptyString.ts +4 -4
- package/src/validators/NumberRange.ts +51 -0
- package/src/validators/function.ts +44 -0
- package/src/validators/index.ts +2 -1
- package/lib/import/converters/fields/utils.d.ts +0 -1
- package/lib/import/converters/fields/utils.js +0 -10
- package/lib/validators/NullOrT.d.ts +0 -2
- package/lib/validators/NullOrT.js +0 -13
- package/src/import/converters/fields/utils.ts +0 -7
- package/src/validators/NullOrT.ts +0 -18
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TypeOf } from "io-ts";
|
|
2
|
+
import * as t from "io-ts";
|
|
3
|
+
declare const WebLink: t.IntersectionC<[t.TypeC<{
|
|
4
|
+
link_type: t.LiteralC<"Web">;
|
|
5
|
+
url: t.StringC;
|
|
6
|
+
}>, t.PartialC<{
|
|
7
|
+
target: t.StringC;
|
|
8
|
+
}>]>;
|
|
9
|
+
export declare type WebLink = t.TypeOf<typeof WebLink>;
|
|
10
|
+
declare const DocumentLink: t.TypeC<{
|
|
11
|
+
link_type: t.LiteralC<"Document">;
|
|
12
|
+
id: t.Type<string, string, unknown>;
|
|
13
|
+
}>;
|
|
14
|
+
export declare type DocumentLink = t.TypeOf<typeof DocumentLink>;
|
|
15
|
+
declare const MediaLink: t.TypeC<{
|
|
16
|
+
link_type: t.LiteralC<"Media">;
|
|
17
|
+
id: t.StringC;
|
|
18
|
+
}>;
|
|
19
|
+
export declare type MediaLink = t.TypeOf<typeof MediaLink>;
|
|
20
|
+
export declare const ImportLink: t.Type<{
|
|
21
|
+
type: "Link";
|
|
22
|
+
value: ({
|
|
23
|
+
link_type: "Web";
|
|
24
|
+
url: string;
|
|
25
|
+
} & {
|
|
26
|
+
target?: string;
|
|
27
|
+
}) | {
|
|
28
|
+
link_type: "Document";
|
|
29
|
+
id: string;
|
|
30
|
+
} | {
|
|
31
|
+
link_type: "Media";
|
|
32
|
+
id: string;
|
|
33
|
+
} | null;
|
|
34
|
+
}, {
|
|
35
|
+
link_type: "Document" | "Web" | "Media";
|
|
36
|
+
} | undefined, unknown>;
|
|
37
|
+
export declare type ImportLink = TypeOf<typeof ImportLink>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportLink = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
7
|
+
const DocumentId_1 = require("../../../../utils/DocumentId");
|
|
8
|
+
const validators_1 = require("../../../../validators");
|
|
9
|
+
const ImportContent_1 = require("../ImportContent");
|
|
10
|
+
const LinkTypeValidator = t.type({
|
|
11
|
+
link_type: (0, io_ts_types_1.withMessage)(t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]), () => "The value must be `Web`, `Document` or `Media`"),
|
|
12
|
+
});
|
|
13
|
+
const WebLink = t.intersection([
|
|
14
|
+
t.type({
|
|
15
|
+
link_type: t.literal("Web"),
|
|
16
|
+
url: validators_1.String,
|
|
17
|
+
}),
|
|
18
|
+
t.partial({
|
|
19
|
+
target: validators_1.String,
|
|
20
|
+
}),
|
|
21
|
+
]);
|
|
22
|
+
const DocumentLink = t.type({
|
|
23
|
+
link_type: t.literal("Document"),
|
|
24
|
+
id: DocumentId_1.DocumentId,
|
|
25
|
+
});
|
|
26
|
+
const MediaLink = t.type({
|
|
27
|
+
link_type: t.literal("Media"),
|
|
28
|
+
id: validators_1.String,
|
|
29
|
+
});
|
|
30
|
+
const Link = LinkTypeValidator.pipe(t.union([WebLink, DocumentLink, MediaLink]));
|
|
31
|
+
// This is the default value for the link
|
|
32
|
+
const AnyLink = t.type({
|
|
33
|
+
link_type: t.literal("Any"),
|
|
34
|
+
});
|
|
35
|
+
exports.ImportLink = (0, ImportContent_1.ImportContent)("Link", (0, validators_1.DefaultOrElse)(AnyLink)(Link));
|
|
@@ -1,9 +1,125 @@
|
|
|
1
1
|
import type { NestableWidget } from "../../../../customtypes";
|
|
2
|
-
import {
|
|
2
|
+
import { ImportBoolean } from "./Boolean";
|
|
3
3
|
import { ImportColor } from "./Color";
|
|
4
|
+
import { ImportDate } from "./Date";
|
|
5
|
+
import { ImportEmbed } from "./Embed";
|
|
6
|
+
import { ImportGeoPoint } from "./GeoPoint";
|
|
7
|
+
import { ImportImage } from "./Image";
|
|
8
|
+
import { ImportLink } from "./Link";
|
|
4
9
|
import { ImportNumber } from "./Number";
|
|
5
10
|
import { ImportSelect } from "./Select";
|
|
6
11
|
import { ImportText } from "./Text";
|
|
7
|
-
|
|
8
|
-
export declare
|
|
9
|
-
export declare
|
|
12
|
+
import { ImportTimestamp } from "./Timestamp";
|
|
13
|
+
export declare type ImportNestable = ImportBoolean | ImportColor | ImportNumber | ImportSelect | ImportText | ImportDate | ImportTimestamp | ImportEmbed | ImportLink | ImportGeoPoint | ImportImage;
|
|
14
|
+
export declare const ImportNestable: {
|
|
15
|
+
is(u: unknown): u is ImportNestable;
|
|
16
|
+
decode: (field: NestableWidget) => (content: unknown) => {
|
|
17
|
+
codec: import("io-ts").Type<{
|
|
18
|
+
type: "Boolean";
|
|
19
|
+
value: boolean | null;
|
|
20
|
+
}, boolean | undefined, unknown> | import("io-ts").Type<{
|
|
21
|
+
type: "Color";
|
|
22
|
+
value: `#${string}` | null;
|
|
23
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
24
|
+
type: "Date";
|
|
25
|
+
value: Date | null;
|
|
26
|
+
}, Date | undefined, unknown> | import("io-ts").Type<{
|
|
27
|
+
type: "Embed";
|
|
28
|
+
value: {
|
|
29
|
+
embed_url: string;
|
|
30
|
+
} | null;
|
|
31
|
+
}, {
|
|
32
|
+
embed_url: string;
|
|
33
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
34
|
+
type: "GeoPoint";
|
|
35
|
+
value: {
|
|
36
|
+
latitude: number;
|
|
37
|
+
longitude: number;
|
|
38
|
+
} | null;
|
|
39
|
+
}, {
|
|
40
|
+
latitude: number;
|
|
41
|
+
longitude: number;
|
|
42
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
43
|
+
type: "Image";
|
|
44
|
+
value: import("./Image").ImageFieldWithThumbnails | null;
|
|
45
|
+
}, import("./Image").ImageFieldWithThumbnails | undefined, unknown> | import("io-ts").Type<{
|
|
46
|
+
type: "Link";
|
|
47
|
+
value: ({
|
|
48
|
+
link_type: "Web";
|
|
49
|
+
url: string;
|
|
50
|
+
} & {
|
|
51
|
+
target?: string;
|
|
52
|
+
}) | {
|
|
53
|
+
link_type: "Document";
|
|
54
|
+
id: string;
|
|
55
|
+
} | {
|
|
56
|
+
link_type: "Media";
|
|
57
|
+
id: string;
|
|
58
|
+
} | null;
|
|
59
|
+
}, {
|
|
60
|
+
link_type: "Document" | "Web" | "Media";
|
|
61
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
62
|
+
type: "Number";
|
|
63
|
+
value: number | null;
|
|
64
|
+
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
65
|
+
type: "Select";
|
|
66
|
+
value: string | null;
|
|
67
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
68
|
+
type: "Text";
|
|
69
|
+
value: string | null;
|
|
70
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
71
|
+
type: "Timestamp";
|
|
72
|
+
value: Date | null;
|
|
73
|
+
}, Date | undefined, unknown>;
|
|
74
|
+
result: import("fp-ts/lib/Either").Left<import("io-ts").Errors> | import("fp-ts/lib/Either").Right<{
|
|
75
|
+
type: "Timestamp";
|
|
76
|
+
value: Date | null;
|
|
77
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
78
|
+
type: "Text";
|
|
79
|
+
value: string | null;
|
|
80
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
81
|
+
type: "Select";
|
|
82
|
+
value: string | null;
|
|
83
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
84
|
+
type: "Number";
|
|
85
|
+
value: number | null;
|
|
86
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
87
|
+
type: "Link";
|
|
88
|
+
value: ({
|
|
89
|
+
link_type: "Web";
|
|
90
|
+
url: string;
|
|
91
|
+
} & {
|
|
92
|
+
target?: string;
|
|
93
|
+
}) | {
|
|
94
|
+
link_type: "Document";
|
|
95
|
+
id: string;
|
|
96
|
+
} | {
|
|
97
|
+
link_type: "Media";
|
|
98
|
+
id: string;
|
|
99
|
+
} | null;
|
|
100
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
101
|
+
type: "Image";
|
|
102
|
+
value: import("./Image").ImageFieldWithThumbnails | null;
|
|
103
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
104
|
+
type: "GeoPoint";
|
|
105
|
+
value: {
|
|
106
|
+
latitude: number;
|
|
107
|
+
longitude: number;
|
|
108
|
+
} | null;
|
|
109
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
110
|
+
type: "Embed";
|
|
111
|
+
value: {
|
|
112
|
+
embed_url: string;
|
|
113
|
+
} | null;
|
|
114
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
115
|
+
type: "Date";
|
|
116
|
+
value: Date | null;
|
|
117
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
118
|
+
type: "Color";
|
|
119
|
+
value: `#${string}` | null;
|
|
120
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
121
|
+
type: "Boolean";
|
|
122
|
+
value: boolean | null;
|
|
123
|
+
}>;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
@@ -1,34 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.ImportNestable = void 0;
|
|
4
|
+
const Boolean_1 = require("./Boolean");
|
|
5
5
|
const Color_1 = require("./Color");
|
|
6
|
+
const Date_1 = require("./Date");
|
|
7
|
+
const Embed_1 = require("./Embed");
|
|
8
|
+
const GeoPoint_1 = require("./GeoPoint");
|
|
9
|
+
const Image_1 = require("./Image");
|
|
10
|
+
const Link_1 = require("./Link");
|
|
6
11
|
const Number_1 = require("./Number");
|
|
7
12
|
const Select_1 = require("./Select");
|
|
8
13
|
const Text_1 = require("./Text");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
const Timestamp_1 = require("./Timestamp");
|
|
15
|
+
exports.ImportNestable = {
|
|
16
|
+
is(u) {
|
|
17
|
+
return (Boolean_1.ImportBoolean.is(u) ||
|
|
18
|
+
Color_1.ImportColor.is(u) ||
|
|
19
|
+
(0, Number_1.ImportNumber)().is(u) ||
|
|
20
|
+
(0, Select_1.ImportSelect)().is(u) ||
|
|
21
|
+
Text_1.ImportText.is(u) ||
|
|
22
|
+
Date_1.ImportDate.is(u) ||
|
|
23
|
+
Timestamp_1.ImportTimestamp.is(u) ||
|
|
24
|
+
Embed_1.ImportEmbed.is(u) ||
|
|
25
|
+
Link_1.ImportLink.is(u) ||
|
|
26
|
+
GeoPoint_1.ImportGeoPoint.is(u) ||
|
|
27
|
+
(0, Image_1.ImportImage)().is(u));
|
|
28
|
+
},
|
|
29
|
+
decode: (field) => {
|
|
30
|
+
return (content) => {
|
|
31
|
+
const codec = (() => {
|
|
32
|
+
switch (field.type) {
|
|
33
|
+
case "Boolean":
|
|
34
|
+
return Boolean_1.ImportBoolean;
|
|
35
|
+
case "Color":
|
|
36
|
+
return Color_1.ImportColor;
|
|
37
|
+
case "Number":
|
|
38
|
+
return (0, Number_1.ImportNumber)(field);
|
|
39
|
+
case "Select":
|
|
40
|
+
return (0, Select_1.ImportSelect)(field);
|
|
41
|
+
case "Text":
|
|
42
|
+
return Text_1.ImportText;
|
|
43
|
+
case "Date":
|
|
44
|
+
return Date_1.ImportDate;
|
|
45
|
+
case "Timestamp":
|
|
46
|
+
return Timestamp_1.ImportTimestamp;
|
|
47
|
+
case "Embed":
|
|
48
|
+
return Embed_1.ImportEmbed;
|
|
49
|
+
case "Link":
|
|
50
|
+
return Link_1.ImportLink;
|
|
51
|
+
case "Image":
|
|
52
|
+
return (0, Image_1.ImportImage)(field);
|
|
53
|
+
case "GeoPoint":
|
|
54
|
+
return GeoPoint_1.ImportGeoPoint;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unsupported type of nestable field ${field.type}`);
|
|
57
|
+
}
|
|
58
|
+
})();
|
|
59
|
+
return {
|
|
60
|
+
codec,
|
|
61
|
+
result: codec.decode(content),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
export declare const ImportNumber: (field?: ({
|
|
3
|
+
type: "Number";
|
|
4
|
+
} & {
|
|
5
|
+
fieldset?: string | null | undefined;
|
|
6
|
+
config?: {
|
|
7
|
+
label?: string | null | undefined;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
step?: number;
|
|
12
|
+
};
|
|
13
|
+
}) | undefined) => t.Type<{
|
|
14
|
+
type: "Number";
|
|
15
|
+
value: number | null;
|
|
16
|
+
}, number | undefined, unknown>;
|
|
17
|
+
export declare type ImportNumber = t.TypeOf<ReturnType<typeof ImportNumber>>;
|
|
@@ -4,13 +4,14 @@ exports.ImportNumber = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const validators_1 = require("../../../../validators");
|
|
7
|
-
const
|
|
7
|
+
const ImportContent_1 = require("../ImportContent");
|
|
8
|
+
const numberValue = (config) => validators_1.Number.pipe(new t.Type("ImportNumberValue", (u) => validators_1.Number.is(u), (n, c) => {
|
|
8
9
|
const min = config === null || config === void 0 ? void 0 : config.min;
|
|
9
10
|
const max = config === null || config === void 0 ? void 0 : config.max;
|
|
10
|
-
if ((min !== undefined && n < min) ||
|
|
11
|
-
(max !== undefined && n > max)) {
|
|
11
|
+
if ((min !== undefined && n < min) || (max !== undefined && n > max)) {
|
|
12
12
|
return t.failure(n, c, `The value must be between [${min !== undefined ? min : ""}, ${max !== undefined ? max : ""}]`);
|
|
13
13
|
}
|
|
14
14
|
return t.success(n);
|
|
15
|
-
}, t.identity))
|
|
15
|
+
}, t.identity));
|
|
16
|
+
const ImportNumber = (field) => (0, ImportContent_1.ImportContent)("Number", (0, validators_1.NullOrElse)(numberValue(field === null || field === void 0 ? void 0 : field.config)));
|
|
16
17
|
exports.ImportNumber = ImportNumber;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export declare const ImportSelect: (field?: ({
|
|
3
|
+
type: "Select";
|
|
4
|
+
} & {
|
|
5
|
+
fieldset?: string | null | undefined;
|
|
6
|
+
config?: {
|
|
7
|
+
label?: string | null | undefined;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
default_value?: string;
|
|
10
|
+
options?: readonly string[];
|
|
11
|
+
};
|
|
12
|
+
}) | undefined) => t.Type<{
|
|
13
|
+
type: "Select";
|
|
14
|
+
value: string | null;
|
|
15
|
+
}, string | undefined, unknown>;
|
|
16
|
+
export declare type ImportSelect = t.TypeOf<ReturnType<typeof ImportSelect>>;
|
|
@@ -4,7 +4,8 @@ exports.ImportSelect = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const validators_1 = require("../../../../validators");
|
|
7
|
-
const
|
|
7
|
+
const ImportContent_1 = require("../ImportContent");
|
|
8
|
+
const selectValue = (config) => validators_1.String.pipe(new t.Type("ImportSelectValue", (u) => validators_1.String.is(u), (s, c) => {
|
|
8
9
|
var _a;
|
|
9
10
|
if (!(config === null || config === void 0 ? void 0 : config.options)) {
|
|
10
11
|
return t.failure(s, c, "The value must be defined in the custom type's configuration of the field");
|
|
@@ -13,5 +14,6 @@ const ImportSelect = (config) => (0, validators_1.NullOrT)(validators_1.String.p
|
|
|
13
14
|
return t.failure(s, c, `The value must be one of these: ${(_a = config.options) === null || _a === void 0 ? void 0 : _a.join(",")}`);
|
|
14
15
|
}
|
|
15
16
|
return t.success(s);
|
|
16
|
-
}, t.identity))
|
|
17
|
+
}, t.identity));
|
|
18
|
+
const ImportSelect = (field) => (0, ImportContent_1.ImportContent)("Select", (0, validators_1.NullOrElse)(selectValue(field === null || field === void 0 ? void 0 : field.config)));
|
|
17
19
|
exports.ImportSelect = ImportSelect;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare
|
|
3
|
-
|
|
1
|
+
import type { TypeOf } from "io-ts";
|
|
2
|
+
export declare const ImportText: import("io-ts").Type<{
|
|
3
|
+
type: "Text";
|
|
4
|
+
value: string | null;
|
|
5
|
+
}, string | undefined, unknown>;
|
|
6
|
+
export declare type ImportText = TypeOf<typeof ImportText>;
|
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImportText = void 0;
|
|
4
4
|
const validators_1 = require("../../../../validators");
|
|
5
|
-
|
|
5
|
+
const ImportContent_1 = require("../ImportContent");
|
|
6
|
+
exports.ImportText = (0, ImportContent_1.ImportContent)("Text", (0, validators_1.NullOrElse)(validators_1.String));
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
import type { ImportFieldOutput } from "..";
|
|
3
2
|
export declare const TIMESTAMP_INPUT_REGEX: RegExp;
|
|
4
|
-
export declare
|
|
5
|
-
|
|
3
|
+
export declare const ImportTimestamp: t.Type<{
|
|
4
|
+
type: "Timestamp";
|
|
5
|
+
value: Date | null;
|
|
6
|
+
}, Date | undefined, unknown>;
|
|
7
|
+
export declare type ImportTimestamp = t.TypeOf<typeof ImportTimestamp>;
|
|
@@ -6,12 +6,14 @@ const Either_1 = require("fp-ts/Either");
|
|
|
6
6
|
const function_1 = require("fp-ts/function");
|
|
7
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
8
|
const validators_1 = require("../../../../validators");
|
|
9
|
+
const ImportContent_1 = require("../ImportContent");
|
|
9
10
|
exports.TIMESTAMP_INPUT_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:(?:[+-]{1}\d{2}:?\d{2})|Z)$/;
|
|
10
|
-
|
|
11
|
+
const timestampValue = new t.Type("ImportTimestampValue", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(validators_1.String.validate(u, c), (0, Either_1.chain)((s) => {
|
|
11
12
|
const date = new Date(s);
|
|
12
13
|
const isInvalidDate = isNaN(date.getTime());
|
|
13
14
|
if (isInvalidDate || !exports.TIMESTAMP_INPUT_REGEX.test(s)) {
|
|
14
15
|
return t.failure(u, c, "The value must be a DateTime in the format YYYY-MM-DDTHH:MM:SS+0000");
|
|
15
16
|
}
|
|
16
17
|
return t.success(date);
|
|
17
|
-
})), t.identity)
|
|
18
|
+
})), t.identity);
|
|
19
|
+
exports.ImportTimestamp = (0, ImportContent_1.ImportContent)("Timestamp", (0, validators_1.NullOrElse)(timestampValue));
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
export * from "./Boolean";
|
|
1
2
|
export * from "./Color";
|
|
2
3
|
export * from "./Date";
|
|
4
|
+
export * from "./Embed";
|
|
5
|
+
export * from "./GeoPoint";
|
|
6
|
+
export * from "./Image";
|
|
7
|
+
export * from "./Image/index";
|
|
8
|
+
export * from "./Link";
|
|
3
9
|
export * from "./Nestable";
|
|
4
10
|
export * from "./Number";
|
|
5
11
|
export * from "./Select";
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./Boolean"), exports);
|
|
4
5
|
(0, tslib_1.__exportStar)(require("./Color"), exports);
|
|
5
6
|
(0, tslib_1.__exportStar)(require("./Date"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./Embed"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./Image"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./Image/index"), exports);
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./Link"), exports);
|
|
6
12
|
(0, tslib_1.__exportStar)(require("./Nestable"), exports);
|
|
7
13
|
(0, tslib_1.__exportStar)(require("./Number"), exports);
|
|
8
14
|
(0, tslib_1.__exportStar)(require("./Select"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DocumentId: import("io-ts").Type<string, string, unknown>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentId = void 0;
|
|
4
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
5
|
+
const validators_1 = require("../validators");
|
|
6
|
+
const function_1 = require("../validators/function");
|
|
7
|
+
exports.DocumentId = (0, io_ts_types_1.withMessage)((0, function_1.refineType)(validators_1.String, "DocumentId", (s) => s.length === 16), () => "DocumentId must be a 16 character string");
|
package/lib/utils/Objects.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare function zipObjects<A, B = A>(objLeft?: Partial<Record<string, A>
|
|
|
5
5
|
export declare function isNotEmpty<A extends object>(obj: A): boolean;
|
|
6
6
|
export declare function withOptionals<T extends object>(object: T, optionals: Array<[keyof T, T[keyof T] | null | undefined]>): T;
|
|
7
7
|
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
8
|
+
export declare function mapValues<T, O>(record: Record<string, T>, fn: (value: T, key: string) => O): Record<string, O>;
|
package/lib/utils/Objects.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject = exports.withOptionals = exports.isNotEmpty = exports.zipObjects = void 0;
|
|
3
|
+
exports.mapValues = exports.isObject = exports.withOptionals = exports.isNotEmpty = exports.zipObjects = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const Either_1 = require("fp-ts/lib/Either");
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
@@ -36,3 +36,7 @@ function isObject(value) {
|
|
|
36
36
|
return (0, Either_1.isRight)(recordCodec.decode(value));
|
|
37
37
|
}
|
|
38
38
|
exports.isObject = isObject;
|
|
39
|
+
function mapValues(record, fn) {
|
|
40
|
+
return Object.entries(record).reduce((acc, [key, value]) => ({ ...acc, [key]: fn(value, key) }), {});
|
|
41
|
+
}
|
|
42
|
+
exports.mapValues = mapValues;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combineValidationResults = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const RA = (0, tslib_1.__importStar)(require("fp-ts/ReadonlyArray"));
|
|
8
|
+
/*
|
|
9
|
+
* Semigroup simply defines how to concatenate two values of the same type.
|
|
10
|
+
* In this instance, Errors from io-ts are arrays already, so we just need to concatenate them.
|
|
11
|
+
*/
|
|
12
|
+
const validationErrorsSemigroup = {
|
|
13
|
+
concat: (a, b) => [...a, ...b],
|
|
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
|
+
const combineValidationResults = (validationResults) => (0, function_1.pipe)(validationResults, RA.traverse(E.getApplicativeValidation(validationErrorsSemigroup))((validation) => validation));
|
|
22
|
+
exports.combineValidationResults = combineValidationResults;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
export declare const String: t.StringC;
|
|
3
|
+
export declare const StringOrNull: t.UnionC<[t.StringC, t.NullC]>;
|
|
3
4
|
export declare const Number: t.NumberC;
|
|
5
|
+
export declare const NumberOrNull: t.UnionC<[t.NumberC, t.NullC]>;
|
|
6
|
+
export declare const Boolean: t.BooleanC;
|
|
7
|
+
export declare const EmptyObject: t.Type<Record<never, never>, {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}, unknown>;
|
|
10
|
+
export declare const EmptyArray: t.Type<never[], never[], unknown>;
|
|
11
|
+
export declare const AnyObject: t.RecordC<t.StringC, t.UnknownC>;
|
|
12
|
+
export declare const AnyArray: t.ArrayC<t.UnknownC>;
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Number = exports.String = void 0;
|
|
3
|
+
exports.AnyArray = exports.AnyObject = exports.EmptyArray = exports.EmptyObject = exports.Boolean = exports.NumberOrNull = exports.Number = exports.StringOrNull = exports.String = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const fp_ts_1 = require("fp-ts");
|
|
6
|
+
const function_1 = require("fp-ts/lib/function");
|
|
5
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
8
|
const io_ts_types_1 = require("io-ts-types");
|
|
7
9
|
exports.String = (0, io_ts_types_1.withMessage)(t.string, () => "The value must be a string");
|
|
10
|
+
exports.StringOrNull = (0, io_ts_types_1.withMessage)(t.union([t.string, t.null]), () => "The value must be a string or null");
|
|
8
11
|
exports.Number = (0, io_ts_types_1.withMessage)(t.number, () => "The value must be a number");
|
|
12
|
+
exports.NumberOrNull = (0, io_ts_types_1.withMessage)(t.union([t.number, t.null]), () => "The value must be a number or null");
|
|
13
|
+
exports.Boolean = (0, io_ts_types_1.withMessage)(t.boolean, () => "The value must be a boolean");
|
|
14
|
+
exports.EmptyObject = t.UnknownRecord.pipe(new t.Type("emptyObject", (u) => t.UnknownRecord.is(u), (u, c) => {
|
|
15
|
+
if (Object.keys(u).length > 0)
|
|
16
|
+
return t.failure(u, c, "The object is not empty.");
|
|
17
|
+
return t.success({});
|
|
18
|
+
}, t.identity));
|
|
19
|
+
exports.EmptyArray = new t.Type("emptyArray", (u) => t.UnknownArray.is(u) && u.length === 0, (u, c) => {
|
|
20
|
+
return (0, function_1.pipe)(t.UnknownArray.decode(u), fp_ts_1.either.chain((parsedArray) => {
|
|
21
|
+
if (parsedArray.length > 0)
|
|
22
|
+
return t.failure(u, c, "The array is not empty.");
|
|
23
|
+
return t.success(new Array());
|
|
24
|
+
}));
|
|
25
|
+
}, () => []);
|
|
26
|
+
exports.AnyObject = (0, io_ts_types_1.withMessage)(t.record(t.string, t.unknown), () => "The value must be an object");
|
|
27
|
+
exports.AnyArray = (0, io_ts_types_1.withMessage)(t.array(t.unknown), () => "The value must be an array");
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const DefaultOrElse: <I, A, O = A>(inputValidator: t.Type<I, I, unknown>) => (codec: t.Type<A, O, unknown>) => t.Type<A | null, O | undefined, unknown>;
|
|
3
|
+
export declare const NullOrElse: <A, O = A>(codec: t.Type<A, O, unknown>) => t.Type<A | null, O | undefined, unknown>;
|
|
4
|
+
export declare const EmptyObjectOrElse: <A, O = A>(codec: t.Type<A, O, unknown>) => t.Type<A | null, O | undefined, unknown>;
|
|
5
|
+
export declare const EmptyArrayOrElse: <A, O = A>(codec: t.Type<A, O, unknown>) => t.Type<A | null, O | undefined, unknown>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmptyArrayOrElse = exports.EmptyObjectOrElse = exports.NullOrElse = exports.DefaultOrElse = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
const BasicTypes_1 = require("./BasicTypes");
|
|
8
|
+
const DefaultOrElse = (inputValidator) => {
|
|
9
|
+
return (codec) => new t.Type("NullOrT", (u) => null === u || codec.is(u), (u) => {
|
|
10
|
+
if ((0, Either_1.isRight)(inputValidator.decode(u)))
|
|
11
|
+
return t.success(null);
|
|
12
|
+
return codec.decode(u);
|
|
13
|
+
}, (chunk) => (chunk ? codec.encode(chunk) : undefined));
|
|
14
|
+
};
|
|
15
|
+
exports.DefaultOrElse = DefaultOrElse;
|
|
16
|
+
const NullOrElse = (codec) => (0, exports.DefaultOrElse)(t.null)(codec);
|
|
17
|
+
exports.NullOrElse = NullOrElse;
|
|
18
|
+
const EmptyObjectOrElse = (codec) => (0, exports.DefaultOrElse)(BasicTypes_1.EmptyObject)(codec);
|
|
19
|
+
exports.EmptyObjectOrElse = EmptyObjectOrElse;
|
|
20
|
+
const EmptyArrayOrElse = (codec) => (0, exports.DefaultOrElse)(BasicTypes_1.EmptyArray)(codec);
|
|
21
|
+
exports.EmptyArrayOrElse = EmptyArrayOrElse;
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
5
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
5
6
|
const function_1 = require("./function");
|
|
6
|
-
exports.default = (0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0);
|
|
7
|
+
exports.default = (0, io_ts_types_1.withMessage)((0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0), () => "The value must be a non-empty string");
|