@prismicio/types-internal 0.1.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -13
- package/{dist → lib}/customtypes/CustomType.d.ts +697 -715
- package/{dist → lib}/customtypes/CustomType.js +42 -52
- package/{dist → lib}/customtypes/Format.d.ts +0 -0
- package/{dist → lib}/customtypes/Format.js +0 -0
- package/{dist → lib}/customtypes/Section.d.ts +1035 -1062
- package/lib/customtypes/Section.js +21 -0
- package/lib/customtypes/index.d.ts +4 -0
- package/lib/customtypes/index.js +9 -0
- package/{dist → lib}/customtypes/widgets/Group.d.ts +45 -45
- package/lib/customtypes/widgets/Group.js +24 -0
- package/{dist → lib}/customtypes/widgets/UID.d.ts +4 -4
- package/lib/customtypes/widgets/UID.js +21 -0
- package/{dist → lib}/customtypes/widgets/Widget.d.ts +1036 -1063
- package/lib/customtypes/widgets/Widget.js +27 -0
- package/{dist → lib}/customtypes/widgets/WidgetTypes.d.ts +0 -0
- package/{dist → lib}/customtypes/widgets/WidgetTypes.js +0 -0
- package/lib/customtypes/widgets/index.d.ts +7 -0
- package/lib/customtypes/widgets/index.js +14 -0
- package/{dist → lib}/customtypes/widgets/nestable/BooleanField.d.ts +3 -3
- package/lib/customtypes/widgets/nestable/BooleanField.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Color.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Color.js +20 -0
- package/{dist → lib}/customtypes/widgets/nestable/Date.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Date.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Embed.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Embed.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/GeoPoint.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/GeoPoint.js +19 -0
- package/lib/customtypes/widgets/nestable/Image.d.ts +23 -0
- package/lib/customtypes/widgets/nestable/Image.js +29 -0
- package/{dist → lib}/customtypes/widgets/nestable/IntegrationField.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/IntegrationField.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Link.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Link.js +54 -0
- package/{dist → lib}/customtypes/widgets/nestable/NestableWidget.d.ts +42 -42
- package/lib/customtypes/widgets/nestable/NestableWidget.js +37 -0
- package/{dist → lib}/customtypes/widgets/nestable/Number.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Number.js +24 -0
- package/{dist → lib}/customtypes/widgets/nestable/Range.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Range.js +24 -0
- package/{dist → lib}/customtypes/widgets/nestable/RichText.d.ts +6 -6
- package/lib/customtypes/widgets/nestable/RichText.js +111 -0
- package/lib/customtypes/widgets/nestable/Select.d.ts +15 -0
- package/lib/customtypes/widgets/nestable/Select.js +22 -0
- package/{dist → lib}/customtypes/widgets/nestable/Separator.d.ts +3 -3
- package/lib/customtypes/widgets/nestable/Separator.js +18 -0
- package/{dist → lib}/customtypes/widgets/nestable/Text.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Text.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Timestamp.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Timestamp.js +21 -0
- package/lib/customtypes/widgets/nestable/index.d.ts +15 -0
- package/{dist → lib}/customtypes/widgets/nestable/index.js +0 -0
- package/{dist → lib}/customtypes/widgets/shared/ImageConstraint.d.ts +3 -3
- package/lib/customtypes/widgets/shared/ImageConstraint.js +31 -0
- package/lib/customtypes/widgets/shared/index.d.ts +1 -0
- package/{dist → lib}/customtypes/widgets/shared/index.js +0 -0
- package/{dist → lib}/customtypes/widgets/slices/CompositeSlice.d.ts +87 -87
- package/lib/customtypes/widgets/slices/CompositeSlice.js +25 -0
- package/{dist → lib}/customtypes/widgets/slices/LegacySlice.d.ts +86 -95
- package/lib/customtypes/widgets/slices/LegacySlice.js +8 -0
- package/{dist → lib}/customtypes/widgets/slices/SharedSlice.d.ts +84 -84
- package/lib/customtypes/widgets/slices/SharedSlice.js +35 -0
- package/{dist → lib}/customtypes/widgets/slices/SharedSliceRef.d.ts +2 -2
- package/lib/customtypes/widgets/slices/SharedSliceRef.js +9 -0
- package/lib/customtypes/widgets/slices/Slice.d.ts +6 -0
- package/{dist → lib}/customtypes/widgets/slices/Slice.js +0 -0
- package/{dist → lib}/customtypes/widgets/slices/Slices.d.ts +1550 -1604
- package/lib/customtypes/widgets/slices/Slices.js +93 -0
- package/{dist → lib}/customtypes/widgets/slices/SlicesTypes.d.ts +0 -0
- package/{dist → lib}/customtypes/widgets/slices/SlicesTypes.js +0 -0
- package/lib/customtypes/widgets/slices/index.d.ts +7 -0
- package/lib/customtypes/widgets/slices/index.js +16 -0
- package/lib/documents/DocumentData.d.ts +8 -0
- package/lib/documents/DocumentData.js +28 -0
- package/lib/documents/index.d.ts +2 -0
- package/lib/documents/index.js +7 -0
- package/lib/documents/widgets/EmptyContent.d.ts +8 -0
- package/lib/documents/widgets/EmptyContent.js +9 -0
- package/lib/documents/widgets/GroupContent.d.ts +16 -0
- package/lib/documents/widgets/GroupContent.js +59 -0
- package/lib/documents/widgets/SimpleWidgetContent.d.ts +20 -0
- package/lib/documents/widgets/SimpleWidgetContent.js +75 -0
- package/lib/documents/widgets/StaticWidgetContent.d.ts +10 -0
- package/lib/documents/widgets/StaticWidgetContent.js +26 -0
- package/lib/documents/widgets/UIDContent.d.ts +7 -0
- package/lib/documents/widgets/UIDContent.js +10 -0
- package/lib/documents/widgets/index.d.ts +35 -0
- package/lib/documents/widgets/index.js +36 -0
- package/lib/documents/widgets/nestable/BooleanContent.d.ts +8 -0
- package/lib/documents/widgets/nestable/BooleanContent.js +11 -0
- package/lib/documents/widgets/nestable/EmbedContent.d.ts +40 -0
- package/lib/documents/widgets/nestable/EmbedContent.js +36 -0
- package/lib/documents/widgets/nestable/FieldContent.d.ts +12 -0
- package/lib/documents/widgets/nestable/FieldContent.js +37 -0
- package/lib/documents/widgets/nestable/GeoPointContent.d.ts +17 -0
- package/lib/documents/widgets/nestable/GeoPointContent.js +13 -0
- package/lib/documents/widgets/nestable/ImageContent.d.ts +127 -0
- package/lib/documents/widgets/nestable/ImageContent.js +41 -0
- package/lib/documents/widgets/nestable/IntegrationFieldsContent.d.ts +8 -0
- package/lib/documents/widgets/nestable/IntegrationFieldsContent.js +16 -0
- package/lib/documents/widgets/nestable/Link/DocumentLink.d.ts +12 -0
- package/lib/documents/widgets/nestable/Link/DocumentLink.js +13 -0
- package/lib/documents/widgets/nestable/Link/ExternalLink.d.ts +24 -0
- package/lib/documents/widgets/nestable/Link/ExternalLink.js +24 -0
- package/lib/documents/widgets/nestable/Link/FileLink.d.ts +22 -0
- package/lib/documents/widgets/nestable/Link/FileLink.js +24 -0
- package/lib/documents/widgets/nestable/Link/ImageLink.d.ts +28 -0
- package/lib/documents/widgets/nestable/Link/ImageLink.js +26 -0
- package/lib/documents/widgets/nestable/Link/LinkContent.d.ts +36 -0
- package/lib/documents/widgets/nestable/Link/LinkContent.js +13 -0
- package/lib/documents/widgets/nestable/Link/index.d.ts +89 -0
- package/lib/documents/widgets/nestable/Link/index.js +35 -0
- package/lib/documents/widgets/nestable/SeparatorContent.d.ts +7 -0
- package/lib/documents/widgets/nestable/SeparatorContent.js +10 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +274 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +97 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/index.d.ts +9 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/index.js +14 -0
- package/lib/documents/widgets/nestable/index.d.ts +26 -0
- package/lib/documents/widgets/nestable/index.js +40 -0
- package/lib/documents/widgets/slices/CompositeSliceContent.d.ts +14 -0
- package/lib/documents/widgets/slices/CompositeSliceContent.js +50 -0
- package/lib/documents/widgets/slices/SharedSliceContent.d.ts +15 -0
- package/lib/documents/widgets/slices/SharedSliceContent.js +62 -0
- package/lib/documents/widgets/slices/SimpleSliceContent.d.ts +6 -0
- package/lib/documents/widgets/slices/SimpleSliceContent.js +6 -0
- package/lib/documents/widgets/slices/SliceWidgetContent.d.ts +8 -0
- package/lib/documents/widgets/slices/SliceWidgetContent.js +26 -0
- package/lib/documents/widgets/slices/SlicesContent.d.ts +17 -0
- package/lib/documents/widgets/slices/SlicesContent.js +51 -0
- package/lib/documents/widgets/slices/index.d.ts +5 -0
- package/lib/documents/widgets/slices/index.js +8 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +7 -0
- package/lib/validators/DateFromString.d.ts +3 -0
- package/lib/validators/DateFromString.js +10 -0
- package/lib/validators/DateFromStringOrNumber.d.ts +3 -0
- package/lib/validators/DateFromStringOrNumber.js +10 -0
- package/lib/validators/DateFromTsMs.d.ts +3 -0
- package/lib/validators/DateFromTsMs.js +10 -0
- package/lib/validators/IntFromNumber.d.ts +5 -0
- package/lib/validators/IntFromNumber.js +14 -0
- package/lib/validators/IntFromPixels.d.ts +8 -0
- package/lib/validators/IntFromPixels.js +24 -0
- package/lib/validators/NonEmptyString.d.ts +3 -0
- package/lib/validators/NonEmptyString.js +6 -0
- package/lib/validators/NonEmptyStringOrNull.d.ts +3 -0
- package/lib/validators/NonEmptyStringOrNull.js +15 -0
- package/lib/validators/NumberOrNull.d.ts +3 -0
- package/lib/validators/NumberOrNull.js +6 -0
- package/lib/validators/StringFromBoolean.d.ts +5 -0
- package/lib/validators/StringFromBoolean.js +10 -0
- package/lib/validators/StringFromNumber.d.ts +5 -0
- package/lib/validators/StringFromNumber.js +10 -0
- package/lib/validators/StringOrNull.d.ts +3 -0
- package/lib/validators/StringOrNull.js +6 -0
- package/lib/validators/function.d.ts +14 -0
- package/lib/validators/function.js +60 -0
- package/lib/validators/index.d.ts +12 -0
- package/lib/validators/index.js +27 -0
- package/package.json +30 -18
- package/src/customtypes/CustomType.ts +173 -116
- package/src/customtypes/Format.ts +3 -3
- package/src/customtypes/Section.ts +26 -13
- package/src/customtypes/index.ts +4 -4
- package/src/customtypes/widgets/Group.ts +21 -20
- package/src/customtypes/widgets/UID.ts +18 -17
- package/src/customtypes/widgets/Widget.ts +22 -23
- package/src/customtypes/widgets/WidgetTypes.ts +21 -21
- package/src/customtypes/widgets/index.ts +7 -7
- package/src/customtypes/widgets/nestable/BooleanField.ts +19 -19
- package/src/customtypes/widgets/nestable/Color.ts +17 -16
- package/src/customtypes/widgets/nestable/Date.ts +19 -18
- package/src/customtypes/widgets/nestable/Embed.ts +19 -18
- package/src/customtypes/widgets/nestable/GeoPoint.ts +17 -16
- package/src/customtypes/widgets/nestable/Image.ts +26 -26
- package/src/customtypes/widgets/nestable/IntegrationField.ts +18 -17
- package/src/customtypes/widgets/nestable/Link.ts +80 -68
- package/src/customtypes/widgets/nestable/NestableWidget.ts +32 -32
- package/src/customtypes/widgets/nestable/Number.ts +22 -21
- package/src/customtypes/widgets/nestable/Range.ts +22 -21
- package/src/customtypes/widgets/nestable/RichText.ts +164 -134
- package/src/customtypes/widgets/nestable/Select.ts +22 -21
- package/src/customtypes/widgets/nestable/Separator.ts +15 -14
- package/src/customtypes/widgets/nestable/Text.ts +18 -17
- package/src/customtypes/widgets/nestable/Timestamp.ts +19 -18
- package/src/customtypes/widgets/nestable/index.ts +15 -15
- package/src/customtypes/widgets/shared/ImageConstraint.ts +31 -29
- package/src/customtypes/widgets/shared/index.ts +1 -1
- package/src/customtypes/widgets/slices/CompositeSlice.ts +21 -21
- package/src/customtypes/widgets/slices/LegacySlice.ts +5 -10
- package/src/customtypes/widgets/slices/SharedSlice.ts +33 -31
- package/src/customtypes/widgets/slices/SharedSliceRef.ts +6 -6
- package/src/customtypes/widgets/slices/Slice.ts +4 -4
- package/src/customtypes/widgets/slices/Slices.ts +95 -73
- package/src/customtypes/widgets/slices/SlicesTypes.ts +3 -3
- package/src/customtypes/widgets/slices/index.ts +7 -7
- package/src/documents/DocumentData.ts +54 -0
- package/src/documents/index.ts +2 -0
- package/src/documents/widgets/EmptyContent.ts +8 -0
- package/src/documents/widgets/GroupContent.ts +91 -0
- package/src/documents/widgets/SimpleWidgetContent.ts +96 -0
- package/src/documents/widgets/StaticWidgetContent.ts +46 -0
- package/src/documents/widgets/UIDContent.ts +18 -0
- package/src/documents/widgets/index.ts +56 -0
- package/src/documents/widgets/nestable/BooleanContent.ts +21 -0
- package/src/documents/widgets/nestable/EmbedContent.ts +54 -0
- package/src/documents/widgets/nestable/FieldContent.ts +45 -0
- package/src/documents/widgets/nestable/GeoPointContent.ts +18 -0
- package/src/documents/widgets/nestable/ImageContent.ts +51 -0
- package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +26 -0
- package/src/documents/widgets/nestable/Link/DocumentLink.ts +18 -0
- package/src/documents/widgets/nestable/Link/ExternalLink.ts +31 -0
- package/src/documents/widgets/nestable/Link/FileLink.ts +29 -0
- package/src/documents/widgets/nestable/Link/ImageLink.ts +31 -0
- package/src/documents/widgets/nestable/Link/LinkContent.ts +22 -0
- package/src/documents/widgets/nestable/Link/index.ts +33 -0
- package/src/documents/widgets/nestable/SeparatorContent.ts +8 -0
- package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +122 -0
- package/src/documents/widgets/nestable/StructuredTextContent/index.ts +25 -0
- package/src/documents/widgets/nestable/index.ts +35 -0
- package/src/documents/widgets/slices/CompositeSliceContent.ts +77 -0
- package/src/documents/widgets/slices/SharedSliceContent.ts +94 -0
- package/src/documents/widgets/slices/SimpleSliceContent.ts +4 -0
- package/src/documents/widgets/slices/SliceWidgetContent.ts +51 -0
- package/src/documents/widgets/slices/SlicesContent.ts +91 -0
- package/src/documents/widgets/slices/index.ts +5 -0
- package/src/index.ts +3 -1
- package/src/validators/DateFromString.ts +17 -0
- package/src/validators/DateFromStringOrNumber.ts +17 -0
- package/src/validators/DateFromTsMs.ts +17 -0
- package/src/validators/IntFromNumber.ts +22 -24
- package/src/validators/IntFromPixels.ts +27 -26
- package/src/validators/NonEmptyString.ts +9 -0
- package/src/validators/NonEmptyStringOrNull.ts +22 -0
- package/src/validators/NumberOrNull.ts +5 -0
- package/src/validators/StringFromBoolean.ts +17 -19
- package/src/validators/StringFromNumber.ts +17 -19
- package/src/validators/StringOrNull.ts +4 -2
- package/src/validators/function.ts +71 -0
- package/src/validators/index.ts +12 -0
- package/dist/customtypes/Section.js +0 -40
- package/dist/customtypes/index.d.ts +0 -4
- package/dist/customtypes/index.js +0 -30
- package/dist/customtypes/widgets/Group.js +0 -45
- package/dist/customtypes/widgets/UID.js +0 -42
- package/dist/customtypes/widgets/Widget.js +0 -51
- package/dist/customtypes/widgets/index.d.ts +0 -7
- package/dist/customtypes/widgets/index.js +0 -35
- package/dist/customtypes/widgets/nestable/BooleanField.js +0 -42
- package/dist/customtypes/widgets/nestable/Color.js +0 -41
- package/dist/customtypes/widgets/nestable/Date.js +0 -42
- package/dist/customtypes/widgets/nestable/Embed.js +0 -42
- package/dist/customtypes/widgets/nestable/GeoPoint.js +0 -40
- package/dist/customtypes/widgets/nestable/Image.d.ts +0 -23
- package/dist/customtypes/widgets/nestable/Image.js +0 -50
- package/dist/customtypes/widgets/nestable/IntegrationField.js +0 -42
- package/dist/customtypes/widgets/nestable/Link.js +0 -78
- package/dist/customtypes/widgets/nestable/NestableWidget.js +0 -58
- package/dist/customtypes/widgets/nestable/Number.js +0 -45
- package/dist/customtypes/widgets/nestable/Range.js +0 -45
- package/dist/customtypes/widgets/nestable/RichText.js +0 -134
- package/dist/customtypes/widgets/nestable/Select.d.ts +0 -15
- package/dist/customtypes/widgets/nestable/Select.js +0 -45
- package/dist/customtypes/widgets/nestable/Separator.js +0 -39
- package/dist/customtypes/widgets/nestable/Text.js +0 -42
- package/dist/customtypes/widgets/nestable/Timestamp.js +0 -42
- package/dist/customtypes/widgets/nestable/index.d.ts +0 -15
- package/dist/customtypes/widgets/shared/ImageConstraint.js +0 -48
- package/dist/customtypes/widgets/shared/index.d.ts +0 -1
- package/dist/customtypes/widgets/slices/CompositeSlice.js +0 -46
- package/dist/customtypes/widgets/slices/LegacySlice.js +0 -34
- package/dist/customtypes/widgets/slices/SharedSlice.js +0 -56
- package/dist/customtypes/widgets/slices/SharedSliceRef.js +0 -30
- package/dist/customtypes/widgets/slices/Slice.d.ts +0 -6
- package/dist/customtypes/widgets/slices/Slices.js +0 -106
- package/dist/customtypes/widgets/slices/index.d.ts +0 -7
- package/dist/customtypes/widgets/slices/index.js +0 -37
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/dist/validators/IntFromNumber.d.ts +0 -7
- package/dist/validators/IntFromNumber.js +0 -35
- package/dist/validators/IntFromPixels.d.ts +0 -7
- package/dist/validators/IntFromPixels.js +0 -43
- package/dist/validators/StringFromBoolean.d.ts +0 -7
- package/dist/validators/StringFromBoolean.js +0 -31
- package/dist/validators/StringFromNumber.d.ts +0 -7
- package/dist/validators/StringFromNumber.js +0 -31
- package/dist/validators/StringOrNull.d.ts +0 -2
- package/dist/validators/StringOrNull.js +0 -24
|
@@ -1,53 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { Format } from
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import {
|
|
1
|
+
import { Either, left, right } from "fp-ts/lib/Either"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
import { withFallback } from "io-ts-types/lib/withFallback"
|
|
4
|
+
|
|
5
|
+
import { StringOrNull } from "../validators"
|
|
6
|
+
import { Format } from "./Format"
|
|
7
|
+
import {
|
|
8
|
+
DynamicSection,
|
|
9
|
+
sectionReader,
|
|
10
|
+
Sections,
|
|
11
|
+
StaticSection,
|
|
12
|
+
} from "./Section"
|
|
13
|
+
import type SharedSlice from "./widgets/slices/SharedSlice"
|
|
14
|
+
import type { DynamicSlice } from "./widgets/slices/Slice"
|
|
15
|
+
import type { DynamicSlices } from "./widgets/slices/Slices"
|
|
16
|
+
import SlicesTypes from "./widgets/slices/SlicesTypes"
|
|
17
|
+
import type { DynamicWidget } from "./widgets/Widget"
|
|
18
|
+
import WidgetTypes from "./widgets/WidgetTypes"
|
|
15
19
|
|
|
16
20
|
class CustomTypeSlicesError extends Error {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
${slicesMsg.join('\n')}
|
|
21
|
+
slices: Array<string>
|
|
22
|
+
override message: string
|
|
23
|
+
|
|
24
|
+
constructor(slices: Array<string>) {
|
|
25
|
+
super()
|
|
26
|
+
this.slices = slices
|
|
27
|
+
this.message = this._formatError(slices)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
_formatError(slicesRefs: Array<string>) {
|
|
31
|
+
const slicesMsg = slicesRefs.map((ref) => `\t - ${ref}`)
|
|
32
|
+
return `The following slices doesn't exists in your Prismic repository:
|
|
33
|
+
${slicesMsg.join("\n")}
|
|
31
34
|
`
|
|
32
|
-
|
|
33
|
-
}
|
|
35
|
+
}
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
function customTypeReader<F extends Format>(format: F) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
return t.exact(
|
|
40
|
+
t.intersection([
|
|
41
|
+
t.type({
|
|
42
|
+
id: t.string,
|
|
43
|
+
label: StringOrNull,
|
|
44
|
+
repeatable: withFallback(t.boolean, true),
|
|
45
|
+
json: t.record(t.string, sectionReader(format)),
|
|
46
|
+
status: withFallback(t.boolean, true),
|
|
47
|
+
}),
|
|
48
|
+
t.partial({
|
|
49
|
+
hash: t.string,
|
|
50
|
+
}),
|
|
51
|
+
]),
|
|
52
|
+
)
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export const StaticCustomType = customTypeReader(Format.Static)
|
|
@@ -57,86 +59,141 @@ export const CustomType = customTypeReader(Format.Dynamic)
|
|
|
57
59
|
export type CustomType = t.TypeOf<typeof CustomType>
|
|
58
60
|
|
|
59
61
|
function _retrieveSharedSlicesRef(customType: CustomType): Array<string> {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
const flattenWidgets: Array<[string, DynamicWidget]> = Object.entries(
|
|
63
|
+
customType.json,
|
|
64
|
+
).reduce(
|
|
65
|
+
(
|
|
66
|
+
acc: Array<[string, DynamicWidget]>,
|
|
67
|
+
[, section]: [string, DynamicSection],
|
|
68
|
+
) => {
|
|
69
|
+
const sectionWidgets: Array<[string, DynamicWidget]> =
|
|
70
|
+
Object.entries(section)
|
|
71
|
+
return acc.concat(sectionWidgets)
|
|
72
|
+
},
|
|
73
|
+
[],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
const slicezones = flattenWidgets.filter(
|
|
77
|
+
([, widget]: [string, DynamicWidget]) => widget.type === WidgetTypes.Slices,
|
|
78
|
+
) as Array<[string, DynamicSlices]>
|
|
79
|
+
|
|
80
|
+
const allSharedRefs = slicezones.reduce(
|
|
81
|
+
(acc: Array<string>, [, slicezone]) => {
|
|
82
|
+
const sharedRefs = Object.entries(
|
|
83
|
+
slicezone.config && slicezone.config.choices
|
|
84
|
+
? slicezone.config.choices
|
|
85
|
+
: {},
|
|
86
|
+
)
|
|
87
|
+
.filter(
|
|
88
|
+
([, slice]: [string, DynamicSlice]) =>
|
|
89
|
+
slice.type === SlicesTypes.SharedSlice,
|
|
90
|
+
)
|
|
91
|
+
.map(([key]) => key)
|
|
92
|
+
return acc.concat(sharedRefs)
|
|
93
|
+
},
|
|
94
|
+
[],
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
return allSharedRefs
|
|
76
98
|
}
|
|
77
99
|
|
|
78
|
-
function _mapSharedSlicesRefs<A>(
|
|
79
|
-
|
|
100
|
+
function _mapSharedSlicesRefs<A>(
|
|
101
|
+
customType: CustomType,
|
|
102
|
+
): (mapFn: (ref: string) => A) => Array<A> {
|
|
103
|
+
const refs = _retrieveSharedSlicesRef(customType)
|
|
80
104
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
105
|
+
return function (mapFn: (ref: string) => A): Array<A> {
|
|
106
|
+
return refs.map(mapFn)
|
|
107
|
+
}
|
|
84
108
|
}
|
|
85
109
|
|
|
86
|
-
export function toStatic(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
110
|
+
export function toStatic(
|
|
111
|
+
customType: CustomType,
|
|
112
|
+
sharedSlices: Map<string, SharedSlice>,
|
|
113
|
+
): StaticCustomType {
|
|
114
|
+
const json = Object.entries(customType.json).reduce(
|
|
115
|
+
(
|
|
116
|
+
acc: { [key: string]: StaticSection },
|
|
117
|
+
[sectionKey, dynSection]: [string, DynamicSection],
|
|
118
|
+
) => {
|
|
119
|
+
return {
|
|
120
|
+
...acc,
|
|
121
|
+
[sectionKey]: Sections.toStatic(dynSection, sharedSlices),
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{},
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
return { ...customType, json } as StaticCustomType
|
|
93
128
|
}
|
|
94
129
|
|
|
95
|
-
export function validateSlices(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
130
|
+
export function validateSlices(
|
|
131
|
+
customType: CustomType,
|
|
132
|
+
sharedSlices: Map<string, SharedSlice>,
|
|
133
|
+
): Either<CustomTypeSlicesError, CustomType> {
|
|
134
|
+
const missingSlices = _mapSharedSlicesRefs<string | undefined>(customType)(
|
|
135
|
+
(ref: string) => {
|
|
136
|
+
const slice: SharedSlice | undefined = sharedSlices.get(ref)
|
|
137
|
+
const isMissing = !slice
|
|
138
|
+
if (isMissing) return ref
|
|
139
|
+
return
|
|
140
|
+
},
|
|
141
|
+
).filter(Boolean) as Array<string>
|
|
142
|
+
|
|
143
|
+
if (missingSlices.length > 0)
|
|
144
|
+
return left(new CustomTypeSlicesError(missingSlices))
|
|
145
|
+
else return right(customType)
|
|
104
146
|
}
|
|
105
147
|
|
|
106
|
-
export function collectWidgets(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
export function collectWidgets(
|
|
149
|
+
customType: CustomType,
|
|
150
|
+
f: (ref: string, widget: DynamicWidget) => DynamicWidget | undefined,
|
|
151
|
+
): CustomType {
|
|
152
|
+
const json = Object.entries(customType.json).reduce(
|
|
153
|
+
(acc, [sectionId, section]: [string, DynamicSection]) => {
|
|
154
|
+
const updatedSection = Object.entries(section).reduce(
|
|
155
|
+
(acc, [ref, widget]) => {
|
|
156
|
+
const updatedWidget = f(ref, widget)
|
|
157
|
+
if (updatedWidget) {
|
|
158
|
+
return { ...acc, [ref]: updatedWidget }
|
|
159
|
+
}
|
|
160
|
+
return acc
|
|
161
|
+
},
|
|
162
|
+
{},
|
|
163
|
+
)
|
|
164
|
+
return { ...acc, [sectionId]: updatedSection }
|
|
165
|
+
},
|
|
166
|
+
{},
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
return { ...customType, json }
|
|
122
170
|
}
|
|
123
171
|
|
|
124
|
-
export function filterMissingSharedSlices(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
172
|
+
export function filterMissingSharedSlices(
|
|
173
|
+
customType: CustomType,
|
|
174
|
+
sharedSlices: Map<string, SharedSlice>,
|
|
175
|
+
): CustomType {
|
|
176
|
+
return collectWidgets(customType, (_widgetId, widget) => {
|
|
177
|
+
if (widget.type === WidgetTypes.Slices) {
|
|
178
|
+
if (!widget.config || !widget.config.choices) return widget
|
|
179
|
+
|
|
180
|
+
const choices = Object.entries(widget.config.choices).reduce(
|
|
181
|
+
(acc, [sliceId, sliceValue]: [string, DynamicSlice]) => {
|
|
182
|
+
if (
|
|
183
|
+
sliceValue.type === SlicesTypes.SharedSlice &&
|
|
184
|
+
!sharedSlices.get(sliceId)
|
|
185
|
+
)
|
|
186
|
+
return acc
|
|
187
|
+
return { ...acc, [sliceId]: sliceValue }
|
|
188
|
+
},
|
|
189
|
+
{},
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
const config = { ...widget.config, choices }
|
|
193
|
+
|
|
194
|
+
return { ...widget, config }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return widget
|
|
198
|
+
})
|
|
199
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export enum Format {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
2
|
+
Static = "static",
|
|
3
|
+
Dynamic = "dynamic",
|
|
4
|
+
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import * as t from
|
|
1
|
+
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import { Format } from
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import { Format } from "./Format"
|
|
4
|
+
import type SharedSlice from "./widgets/slices/SharedSlice"
|
|
5
|
+
import {
|
|
6
|
+
DynamicWidget,
|
|
7
|
+
StaticWidget,
|
|
8
|
+
widgetReader,
|
|
9
|
+
Widgets,
|
|
10
|
+
} from "./widgets/Widget"
|
|
6
11
|
|
|
7
12
|
export function sectionReader<F extends Format>(format: F) {
|
|
8
|
-
|
|
13
|
+
return t.record(t.string, widgetReader(format))
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
export const StaticSection = sectionReader(Format.Static)
|
|
@@ -15,11 +20,19 @@ export const DynamicSection = sectionReader(Format.Dynamic)
|
|
|
15
20
|
export type DynamicSection = t.TypeOf<typeof DynamicSection>
|
|
16
21
|
|
|
17
22
|
export const Sections = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
toStatic(
|
|
24
|
+
dynamic: DynamicSection,
|
|
25
|
+
sharedSlices: Map<string, SharedSlice>,
|
|
26
|
+
): StaticSection {
|
|
27
|
+
const section = Object.entries(dynamic).reduce(
|
|
28
|
+
(
|
|
29
|
+
acc: { [key: string]: StaticWidget },
|
|
30
|
+
[widgetKey, widget]: [string, DynamicWidget],
|
|
31
|
+
) => {
|
|
32
|
+
return { ...acc, [widgetKey]: Widgets.toStatic(widget, sharedSlices) }
|
|
33
|
+
},
|
|
34
|
+
{},
|
|
35
|
+
)
|
|
36
|
+
return section as StaticSection
|
|
37
|
+
},
|
|
38
|
+
}
|
package/src/customtypes/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * as
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./CustomType"
|
|
2
|
+
export { Format } from "./Format"
|
|
3
|
+
export * as Section from "./Section"
|
|
4
|
+
export * as Widgets from "./widgets"
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import * as t from
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import NestableWidget from
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { StringOrNull } from "../../validators"
|
|
4
|
+
import NestableWidget from "./nestable/NestableWidget"
|
|
5
|
+
import WidgetTypes from "./WidgetTypes"
|
|
5
6
|
|
|
6
7
|
const GroupConfig = t.exact(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
t.partial({
|
|
9
|
+
label: StringOrNull,
|
|
10
|
+
repeat: t.boolean,
|
|
11
|
+
fields: t.record(t.string, NestableWidget),
|
|
12
|
+
}),
|
|
12
13
|
)
|
|
13
14
|
type GroupConfig = t.TypeOf<typeof GroupConfig>
|
|
14
15
|
|
|
15
16
|
const Group = t.exact(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
t.intersection([
|
|
18
|
+
t.type({
|
|
19
|
+
type: t.literal(WidgetTypes.Group),
|
|
20
|
+
}),
|
|
21
|
+
t.partial({
|
|
22
|
+
fieldset: StringOrNull,
|
|
23
|
+
icon: t.string,
|
|
24
|
+
description: t.string,
|
|
25
|
+
config: GroupConfig,
|
|
26
|
+
}),
|
|
27
|
+
]),
|
|
27
28
|
)
|
|
28
29
|
type Group = t.TypeOf<typeof Group>
|
|
29
30
|
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import * as t from
|
|
2
|
-
|
|
3
|
-
import
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { StringOrNull } from "../../validators"
|
|
4
|
+
import WidgetTypes from "./WidgetTypes"
|
|
4
5
|
|
|
5
6
|
const UIDConfig = t.exact(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
t.partial({
|
|
8
|
+
label: StringOrNull,
|
|
9
|
+
useAsTitle: t.boolean,
|
|
10
|
+
placeholder: t.string,
|
|
11
|
+
}),
|
|
11
12
|
)
|
|
12
13
|
type UIDConfig = t.TypeOf<typeof UIDConfig>
|
|
13
14
|
|
|
14
15
|
const UID = t.exact(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
t.intersection([
|
|
17
|
+
t.type({
|
|
18
|
+
type: t.literal(WidgetTypes.UID),
|
|
19
|
+
}),
|
|
20
|
+
t.partial({
|
|
21
|
+
fieldset: StringOrNull,
|
|
22
|
+
config: UIDConfig,
|
|
23
|
+
}),
|
|
24
|
+
]),
|
|
24
25
|
)
|
|
25
26
|
type UID = t.TypeOf<typeof UID>
|
|
26
27
|
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import * as t from
|
|
1
|
+
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import SharedSlice from
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import WidgetTypes from
|
|
3
|
+
import { Format } from "../Format"
|
|
4
|
+
import Group from "./Group"
|
|
5
|
+
import NestableWidget from "./nestable/NestableWidget"
|
|
6
|
+
import type SharedSlice from "./slices/SharedSlice"
|
|
7
|
+
import { Slices, slicesReader } from "./slices/Slices"
|
|
8
|
+
import UID from "./UID"
|
|
9
|
+
import WidgetTypes from "./WidgetTypes"
|
|
10
10
|
|
|
11
|
-
export function widgetReader<F extends Format>(format: F){
|
|
12
|
-
|
|
13
|
-
UID,
|
|
14
|
-
NestableWidget,
|
|
15
|
-
Group,
|
|
16
|
-
slicesReader(format)
|
|
17
|
-
])
|
|
11
|
+
export function widgetReader<F extends Format>(format: F) {
|
|
12
|
+
return t.union([UID, NestableWidget, Group, slicesReader(format)])
|
|
18
13
|
}
|
|
19
14
|
export const StaticWidget = widgetReader(Format.Static)
|
|
20
15
|
export type StaticWidget = t.TypeOf<typeof StaticWidget>
|
|
@@ -22,12 +17,16 @@ export type StaticWidget = t.TypeOf<typeof StaticWidget>
|
|
|
22
17
|
export const DynamicWidget = widgetReader(Format.Dynamic)
|
|
23
18
|
export type DynamicWidget = t.TypeOf<typeof DynamicWidget>
|
|
24
19
|
|
|
25
|
-
|
|
26
20
|
export const Widgets = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
toStatic(
|
|
22
|
+
widget: DynamicWidget,
|
|
23
|
+
sharedSlices: Map<string, SharedSlice>,
|
|
24
|
+
): StaticWidget {
|
|
25
|
+
switch (widget.type) {
|
|
26
|
+
case WidgetTypes.Slices:
|
|
27
|
+
return Slices.toStatic(widget, sharedSlices)
|
|
28
|
+
default:
|
|
29
|
+
return widget as StaticWidget
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
enum WidgetTypes {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
Text = "Text",
|
|
3
|
+
RichText = "StructuredText",
|
|
4
|
+
Color = "Color",
|
|
5
|
+
Image = "Image",
|
|
6
|
+
Date = "Date",
|
|
7
|
+
Timestamp = "Timestamp",
|
|
8
|
+
Number = "Number",
|
|
9
|
+
Range = "Range",
|
|
10
|
+
Select = "Select",
|
|
11
|
+
Link = "Link",
|
|
12
|
+
Embed = "Embed",
|
|
13
|
+
GeoPoint = "GeoPoint",
|
|
14
|
+
Separator = "Separator",
|
|
15
|
+
UID = "UID",
|
|
16
|
+
BooleanField = "Boolean",
|
|
17
|
+
IntegrationField = "IntegrationFields",
|
|
18
|
+
Group = "Group",
|
|
19
|
+
Slices = "Slices",
|
|
20
|
+
// Legacy type for slices
|
|
21
|
+
LegacySlices = "Choice",
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export default WidgetTypes
|
|
24
|
+
export default WidgetTypes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * as
|
|
3
|
-
export * as
|
|
4
|
-
export * as
|
|
5
|
-
export { default as
|
|
6
|
-
export
|
|
7
|
-
export { default as WidgetTypes } from
|
|
1
|
+
export { default as Group } from "./Group"
|
|
2
|
+
export * as Nestable from "./nestable"
|
|
3
|
+
export * as Shared from "./shared"
|
|
4
|
+
export * as Slices from "./slices"
|
|
5
|
+
export { default as UID } from "./UID"
|
|
6
|
+
export * as Widget from "./Widget"
|
|
7
|
+
export { default as WidgetTypes } from "./WidgetTypes"
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import * as t from
|
|
2
|
-
|
|
3
|
-
import
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { StringOrNull } from "../../../validators"
|
|
4
|
+
import WidgetTypes from "../WidgetTypes"
|
|
4
5
|
|
|
5
6
|
const BooleanConfig = t.exact(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
t.partial({
|
|
8
|
+
label: StringOrNull,
|
|
9
|
+
default_value: t.boolean,
|
|
10
|
+
placeholder_true: t.string,
|
|
11
|
+
placeholder_false: t.string,
|
|
12
|
+
}),
|
|
12
13
|
)
|
|
13
14
|
|
|
14
15
|
type BooleanConfig = t.TypeOf<typeof BooleanConfig>
|
|
15
16
|
|
|
16
17
|
const BooleanField = t.exact(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
t.intersection([
|
|
19
|
+
t.type({
|
|
20
|
+
type: t.literal(WidgetTypes.BooleanField),
|
|
21
|
+
}),
|
|
22
|
+
t.partial({
|
|
23
|
+
config: BooleanConfig,
|
|
24
|
+
}),
|
|
25
|
+
]),
|
|
25
26
|
)
|
|
26
27
|
|
|
27
28
|
type BooleanField = t.TypeOf<typeof BooleanField>
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
export default BooleanField
|
|
30
|
+
export default BooleanField
|