@prismicio/types-internal 2.2.0-traverse.alpha-11 → 2.2.0
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/content/Document.d.ts +32 -32
- package/lib/content/fields/GroupContent.d.ts +7 -7
- package/lib/content/fields/WidgetContent.d.ts +32 -32
- package/lib/content/fields/nestable/NestableContent.d.ts +4 -4
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +9 -6
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +1 -0
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +5 -5
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +8 -8
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +3 -3
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -8
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +8 -8
- package/lib/content/fields/slices/Slice/index.d.ts +18 -18
- package/lib/content/fields/slices/SliceItem.d.ts +18 -18
- package/lib/content/fields/slices/SlicesContent.d.ts +24 -24
- package/lib/import/converters/Document.js +2 -0
- package/lib/import/converters/fields/Group.d.ts +4 -0
- package/lib/import/converters/fields/Group.js +14 -0
- package/lib/import/converters/fields/RepeatableZone.d.ts +317 -0
- package/lib/import/converters/fields/RepeatableZone.js +15 -0
- package/lib/import/converters/fields/RepeatableZoneItem.d.ts +11 -0
- package/lib/import/converters/fields/RepeatableZoneItem.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +6 -41
- package/lib/import/converters/fields/index.d.ts +1 -0
- package/lib/import/converters/fields/index.js +1 -0
- package/lib/import/validators/fields/ImportField.d.ts +11 -1
- package/lib/import/validators/fields/ImportField.js +6 -1
- package/lib/import/validators/fields/ImportGroup.d.ts +345 -0
- package/lib/import/validators/fields/ImportGroup.js +27 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +5 -3
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +4 -4
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +0 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +0 -1
- package/lib/import/validators/fields/RepeatableZone.d.ts +11 -0
- package/lib/import/validators/fields/RepeatableZone.js +14 -0
- package/lib/import/validators/fields/RepeatableZoneItem.d.ts +11 -0
- package/lib/import/validators/fields/RepeatableZoneItem.js +39 -0
- package/lib/import/validators/fields/index.d.ts +2 -0
- package/lib/import/validators/fields/index.js +2 -0
- package/lib/import/validators/fields/nestable/Nestable.d.ts +60 -0
- package/lib/import/validators/fields/nestable/Nestable.js +32 -30
- package/package.json +1 -1
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +1 -0
- package/src/import/converters/Document.ts +7 -1
- package/src/import/converters/fields/Group.ts +18 -0
- package/src/import/converters/fields/RepeatableZone.ts +19 -0
- package/src/import/converters/fields/RepeatableZoneItem.ts +32 -0
- package/src/import/converters/fields/Slices/SharedSliceContent.ts +9 -76
- package/src/import/converters/fields/index.ts +1 -0
- package/src/import/validators/fields/ImportField.ts +7 -2
- package/src/import/validators/fields/ImportGroup.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +6 -18
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +0 -1
- package/src/import/validators/fields/RepeatableZone.ts +21 -0
- package/src/import/validators/fields/RepeatableZoneItem.ts +64 -0
- package/src/import/validators/fields/index.ts +2 -0
- package/src/import/validators/fields/nestable/Nestable.ts +34 -31
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +0 -64
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +0 -100
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +0 -10
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +0 -2
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +0 -1
- package/src/utils/io-ts.ts +0 -29
|
@@ -1,100 +0,0 @@
|
|
|
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 { WidgetKey } from "../../../../../../../common"
|
|
6
|
-
import type { NestableWidget } from "../../../../../../../customtypes"
|
|
7
|
-
import { ImportNestable } from "../../../../nestable"
|
|
8
|
-
import { SharedSliceContentErrors } from "./errors"
|
|
9
|
-
|
|
10
|
-
export type SharedSliceContentEntry = [WidgetKey, ImportNestable]
|
|
11
|
-
/**
|
|
12
|
-
* Represents a single entry in the 'primary' field or a single entry in an item in the 'items' array in the SharedSlice. It is used to build the SharedSliceContent type from entries of the import object.
|
|
13
|
-
*
|
|
14
|
-
* For example, given the following slice:
|
|
15
|
-
* {
|
|
16
|
-
* "slice_type": "my_slice",
|
|
17
|
-
* "variation": "default",
|
|
18
|
-
* "primary": {
|
|
19
|
-
* "slice_text": "abc", // This is one entry
|
|
20
|
-
* "slice_text2": "def: // This is another entry
|
|
21
|
-
* },
|
|
22
|
-
* "items": [
|
|
23
|
-
* {
|
|
24
|
-
* "slice_number1": 0, // This is one entry
|
|
25
|
-
* "slice_number2": 1 // And this is yet another entry
|
|
26
|
-
* }
|
|
27
|
-
* ]
|
|
28
|
-
* }
|
|
29
|
-
*
|
|
30
|
-
* The 'primary' object is converted to following entries to be decoded:
|
|
31
|
-
* [
|
|
32
|
-
* ["slice_text", "abc"],
|
|
33
|
-
* ["slice_text2", "def"]
|
|
34
|
-
* ]
|
|
35
|
-
* and the first item in the 'items' array is converted to following entries to be decoded:
|
|
36
|
-
* [
|
|
37
|
-
* ["slice_number1", 0],
|
|
38
|
-
* ["slice_number2", 1]
|
|
39
|
-
* ]
|
|
40
|
-
*
|
|
41
|
-
* We decode them as separate entries because each of the values might require a different codec as per what is specified in the SharedSlice custom type.
|
|
42
|
-
* In this way we save on the decoding performance in comparison to a scenario where we would decode the whole content object as a record with a union type decoder for each value.
|
|
43
|
-
*
|
|
44
|
-
* @param sliceName name of the slice - used for error reporting in order to know which slice is being decoded
|
|
45
|
-
* @param sliceContentField 'primary' or 'items' - used for error reporting in order to know which field of the slice is being decoded
|
|
46
|
-
* @param sliceFieldModels models of the fields of the slice from custom type - used to know which codec to use for decoding each value of the object
|
|
47
|
-
*/
|
|
48
|
-
export const SharedSliceContentEntry = (
|
|
49
|
-
sliceName: string,
|
|
50
|
-
sliceContentField: "primary" | "items",
|
|
51
|
-
sliceFieldModels: Record<WidgetKey, NestableWidget>,
|
|
52
|
-
) =>
|
|
53
|
-
new t.Type<SharedSliceContentEntry, SharedSliceContentEntry, unknown>(
|
|
54
|
-
"SharedSliceContentEntry",
|
|
55
|
-
(u): u is SharedSliceContentEntry =>
|
|
56
|
-
t.tuple([WidgetKey, t.unknown]).is(u) && ImportNestable.is(u[1]),
|
|
57
|
-
(u, c) => {
|
|
58
|
-
return pipe(
|
|
59
|
-
t.tuple([WidgetKey, t.unknown]).validate(u, c),
|
|
60
|
-
E.chain(([key, content]) => {
|
|
61
|
-
const model: NestableWidget | undefined = sliceFieldModels[key]
|
|
62
|
-
if (!model) {
|
|
63
|
-
return t.failure(
|
|
64
|
-
[key, content],
|
|
65
|
-
[...c, { key, actual: content, type: t.unknown }],
|
|
66
|
-
SharedSliceContentErrors.UnknownField(
|
|
67
|
-
sliceName,
|
|
68
|
-
sliceContentField,
|
|
69
|
-
key,
|
|
70
|
-
),
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
const { codec, result } = ImportNestable.decode(model)(content)
|
|
74
|
-
|
|
75
|
-
return pipe(
|
|
76
|
-
result,
|
|
77
|
-
E.map<ImportNestable, SharedSliceContentEntry>((decodedContent) => [
|
|
78
|
-
key,
|
|
79
|
-
decodedContent,
|
|
80
|
-
]),
|
|
81
|
-
E.mapLeft(
|
|
82
|
-
(errors): t.Errors =>
|
|
83
|
-
errors.map((error) => {
|
|
84
|
-
const context = [
|
|
85
|
-
...c,
|
|
86
|
-
{ key, actual: content, type: codec },
|
|
87
|
-
...error.context.slice(1), // We ignore the first context element with "" key coming from ImportNestable decoder
|
|
88
|
-
]
|
|
89
|
-
|
|
90
|
-
const updatedError: t.ValidationError = { ...error, context }
|
|
91
|
-
|
|
92
|
-
return updatedError
|
|
93
|
-
}),
|
|
94
|
-
),
|
|
95
|
-
)
|
|
96
|
-
}),
|
|
97
|
-
)
|
|
98
|
-
},
|
|
99
|
-
t.identity,
|
|
100
|
-
)
|
package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { SharedSliceContentField } from "./types"
|
|
2
|
-
|
|
3
|
-
export const SharedSliceContentErrors = {
|
|
4
|
-
UnknownField: (
|
|
5
|
-
sliceName: string,
|
|
6
|
-
contentField: SharedSliceContentField,
|
|
7
|
-
fieldName: string,
|
|
8
|
-
) =>
|
|
9
|
-
`Unsupported field '${fieldName}'for '${contentField}' content in Shared Slice '${sliceName}'`,
|
|
10
|
-
} as const
|
package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type SharedSliceContentField = "primary" | "items"
|
package/src/utils/io-ts.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
)
|