@prismicio/types-internal 2.2.0-alpha.10 → 2.2.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/UUID.d.ts +7 -0
- package/lib/common/UUID.js +8 -0
- package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
- package/lib/import/converters/Document.d.ts +1 -2
- package/lib/import/converters/Document.js +2 -0
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
- package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
- package/lib/import/converters/fields/Slices/Slices.js +16 -0
- package/lib/import/converters/fields/Slices/index.d.ts +1 -0
- package/lib/import/converters/fields/Slices/index.js +4 -0
- package/lib/import/converters/fields/index.d.ts +1 -0
- package/lib/import/converters/fields/index.js +1 -0
- package/lib/import/converters/fields/nestable/Nestable.d.ts +2 -2
- package/lib/import/validators/fields/ImportField.d.ts +11 -1
- package/lib/import/validators/fields/ImportField.js +6 -1
- 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/utils/io-ts.d.ts +2 -0
- package/lib/utils/io-ts.js +22 -0
- package/lib/validators/BasicTypes.d.ts +1 -0
- package/lib/validators/BasicTypes.js +2 -1
- package/lib/validators/NonEmptyString.js +2 -1
- package/package.json +4 -2
- package/src/common/UUID.ts +18 -0
- package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
- package/src/import/converters/Document.ts +8 -3
- 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/index.ts +1 -0
- package/src/import/converters/fields/nestable/Nestable.ts +2 -2
- package/src/import/validators/fields/ImportField.ts +7 -2
- 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/utils/io-ts.ts +29 -0
- package/src/validators/BasicTypes.ts +5 -0
- package/src/validators/NonEmptyString.ts +4 -4
- package/lib/import/validators/fields/nestable/Image.d.ts +0 -62
- package/lib/import/validators/fields/nestable/Image.js +0 -76
|
@@ -0,0 +1,45 @@
|
|
|
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 { SharedSlice as SharedSliceCustomType } from "../../../../../../customtypes"
|
|
6
|
+
import { NonEmptyString } from "../../../../../../validators"
|
|
7
|
+
import { findSlice } from "../utils"
|
|
8
|
+
|
|
9
|
+
export type SharedSliceType = {
|
|
10
|
+
slice_type: string
|
|
11
|
+
data: SharedSliceCustomType
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* slice_type - the validated slice_type
|
|
16
|
+
* slice - SharedSlice custom type data matching the slice_type. We return it alongside the validated slice_type, because it is needed to decode the 'variation' field in the SharedSlice (see SharedSliceVariation.ts)
|
|
17
|
+
*/
|
|
18
|
+
const SharedSliceTypeShape = t.type({
|
|
19
|
+
slice_type: NonEmptyString,
|
|
20
|
+
slice: SharedSliceCustomType,
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Builds the decoder for the 'slice_type' field in the SharedSlice. Alongside the decoded 'slice_type' it also returns the SharedSlice data matching the slice_type.
|
|
25
|
+
* @param slices all the SharedSlices from the custom type
|
|
26
|
+
*/
|
|
27
|
+
export const SharedSliceType = (slices: SharedSliceCustomType[]) =>
|
|
28
|
+
new t.Type<SharedSliceType, string, unknown>(
|
|
29
|
+
"slice_type",
|
|
30
|
+
(u): u is SharedSliceType => SharedSliceTypeShape.is(u),
|
|
31
|
+
(u, c) =>
|
|
32
|
+
pipe(
|
|
33
|
+
NonEmptyString.validate(u, c),
|
|
34
|
+
E.chain((slice_type) =>
|
|
35
|
+
pipe(
|
|
36
|
+
findSlice(slices)(slice_type),
|
|
37
|
+
E.fold(
|
|
38
|
+
(err) => t.failure(u, c, err),
|
|
39
|
+
(data) => t.success({ slice_type, data }),
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
({ slice_type }) => slice_type,
|
|
45
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
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 { SharedSlice, Variation } from "../../../../../../customtypes"
|
|
6
|
+
import { NonEmptyString } from "../../../../../../validators"
|
|
7
|
+
import { findSliceVariation } from "../utils"
|
|
8
|
+
|
|
9
|
+
export type SharedSliceVariation = {
|
|
10
|
+
variation: string
|
|
11
|
+
data: Variation
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* variation - the validated variation of the slice
|
|
16
|
+
* data - Variation data matching the variation. We return it alongside the validated variation, because it is needed to decode the 'primary' and 'items' fields in the SharedSlice.
|
|
17
|
+
*/
|
|
18
|
+
const SharedSliceVariationShape = t.type({
|
|
19
|
+
variation: NonEmptyString,
|
|
20
|
+
data: Variation,
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Builds the decoder for the 'variation' field in the SharedSlice. Alongside the decoded 'variation' it also returns the Variation data matching the variation custom type.
|
|
25
|
+
* @param slice SharedSlice from the custom type
|
|
26
|
+
*/
|
|
27
|
+
export const SharedSliceVariation = (slice: SharedSlice) =>
|
|
28
|
+
new t.Type<SharedSliceVariation, string, unknown>(
|
|
29
|
+
"variation",
|
|
30
|
+
(u): u is SharedSliceVariation => SharedSliceVariationShape.is(u),
|
|
31
|
+
(u, c) =>
|
|
32
|
+
pipe(
|
|
33
|
+
NonEmptyString.validate(u, c),
|
|
34
|
+
E.chain((variation) =>
|
|
35
|
+
pipe(
|
|
36
|
+
findSliceVariation(slice)(variation),
|
|
37
|
+
E.fold(
|
|
38
|
+
(err) => t.failure(u, c, err),
|
|
39
|
+
(data) => t.success({ variation, data }),
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
({ variation }) => variation,
|
|
45
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as E from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
|
|
4
|
+
import type { SharedSlice as SharedSliceCustomType } from "../../../../../customtypes"
|
|
5
|
+
import type { Variation } from "../../../../../customtypes"
|
|
6
|
+
import { SharedSliceErrors } from "./errors"
|
|
7
|
+
|
|
8
|
+
export const findSlice =
|
|
9
|
+
(slices: SharedSliceCustomType[]) => (sliceId: string) =>
|
|
10
|
+
pipe(
|
|
11
|
+
slices.find((slice) => slice.id === sliceId),
|
|
12
|
+
E.fromNullable(SharedSliceErrors.SliceTypeNotFound(sliceId)),
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
export const findSliceVariation =
|
|
16
|
+
(slice: SharedSliceCustomType) =>
|
|
17
|
+
(variation: string): E.Either<string, Variation> =>
|
|
18
|
+
pipe(
|
|
19
|
+
slice.variations.find((v) => v.id === variation),
|
|
20
|
+
E.fromNullable(SharedSliceErrors.VariationNotFound(variation, slice.id)),
|
|
21
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ImportSlices"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as A from "fp-ts/Array"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as O from "fp-ts/Option"
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
SharedSlice as SharedSliceCustomType,
|
|
7
|
+
StaticSlices,
|
|
8
|
+
} from "../../../../customtypes"
|
|
9
|
+
import type { SharedSlice, SharedSliceId } from "./SharedSlice"
|
|
10
|
+
|
|
11
|
+
// Extracts all supported slices from the static slices object
|
|
12
|
+
// For now we only support the SharedSlice, if we want to support other slices in the future, we have to add them here
|
|
13
|
+
export const extractSupportedSlices = (
|
|
14
|
+
staticSlices: StaticSlices,
|
|
15
|
+
): SharedSliceCustomType[] =>
|
|
16
|
+
pipe(
|
|
17
|
+
Object.values(staticSlices.config?.choices ?? {}).map((slice) =>
|
|
18
|
+
pipe(SharedSliceCustomType.decode(slice), O.fromEither),
|
|
19
|
+
),
|
|
20
|
+
A.compact,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
export const findImportSharedSliceDuplicateIds = (
|
|
24
|
+
slices: SharedSlice[],
|
|
25
|
+
): SharedSliceId[] => {
|
|
26
|
+
const duplicatesMap = slices.reduce((acc, { id }) => {
|
|
27
|
+
if (id) {
|
|
28
|
+
const currentNumOfDuplicates = acc[id] ?? 0
|
|
29
|
+
return {
|
|
30
|
+
...acc,
|
|
31
|
+
[id]: acc[id] === undefined ? 0 : currentNumOfDuplicates + 1,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return acc
|
|
35
|
+
}, {} as Record<SharedSliceId, number>)
|
|
36
|
+
|
|
37
|
+
return Object.entries(duplicatesMap).flatMap(([id, numOfDuplicates]) => {
|
|
38
|
+
if (numOfDuplicates > 0) {
|
|
39
|
+
return [id]
|
|
40
|
+
}
|
|
41
|
+
return []
|
|
42
|
+
})
|
|
43
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as E from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
3
|
+
import * as RA from "fp-ts/ReadonlyArray"
|
|
4
|
+
import type { Semigroup } from "fp-ts/Semigroup"
|
|
5
|
+
import type { Errors, Validation } from "io-ts"
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Semigroup simply defines how to concatenate two values of the same type.
|
|
9
|
+
* In this instance, Errors from io-ts are arrays already, so we just need to concatenate them.
|
|
10
|
+
*/
|
|
11
|
+
const validationErrorsSemigroup: Semigroup<Errors> = {
|
|
12
|
+
concat: (a: Errors, b: Errors) => [...a, ...b],
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* This is a helper function to combine multiple io-ts validations into one.
|
|
17
|
+
* t.array(...) works in the same way - it collects all the errors when decoding an array of values.
|
|
18
|
+
* However, it requires you to pass in a single io-ts validator as a parameter, which is not always convenient.
|
|
19
|
+
* Sometimes we have arrays of validation results received from function calls that don't have a validator instance.
|
|
20
|
+
*/
|
|
21
|
+
export const combineValidationResults = <T>(
|
|
22
|
+
validationResults: readonly Validation<T>[],
|
|
23
|
+
): Validation<readonly T[]> =>
|
|
24
|
+
pipe(
|
|
25
|
+
validationResults,
|
|
26
|
+
RA.traverse(E.getApplicativeValidation(validationErrorsSemigroup))(
|
|
27
|
+
(validation) => validation,
|
|
28
|
+
),
|
|
29
|
+
)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
|
+
import { withMessage } from "io-ts-types"
|
|
2
3
|
|
|
3
4
|
import { refineType } from "./function"
|
|
4
5
|
|
|
5
|
-
export default
|
|
6
|
-
t.string,
|
|
7
|
-
"
|
|
8
|
-
(s) => s.trim().length > 0,
|
|
6
|
+
export default withMessage(
|
|
7
|
+
refineType(t.string, "nonEmptyString", (s) => s.trim().length > 0),
|
|
8
|
+
() => "The value must be a non-empty string",
|
|
9
9
|
)
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
export declare type ImageField = {
|
|
3
|
-
id: string;
|
|
4
|
-
edit: {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
zoom: number;
|
|
8
|
-
background?: string;
|
|
9
|
-
};
|
|
10
|
-
dimensions: {
|
|
11
|
-
width?: number;
|
|
12
|
-
height?: number;
|
|
13
|
-
};
|
|
14
|
-
credit?: string | null;
|
|
15
|
-
alt?: string | null;
|
|
16
|
-
};
|
|
17
|
-
declare type ImageFieldWithThumbnails = ImageField & {
|
|
18
|
-
thumbnails: Record<string, ImageField>;
|
|
19
|
-
};
|
|
20
|
-
declare const ImageFieldWithThumbnails: (field?: ({
|
|
21
|
-
type: "Image";
|
|
22
|
-
} & {
|
|
23
|
-
fieldset?: string | null | undefined;
|
|
24
|
-
config?: {
|
|
25
|
-
label?: string | null | undefined;
|
|
26
|
-
placeholder?: string;
|
|
27
|
-
constraint?: {
|
|
28
|
-
width?: number | null;
|
|
29
|
-
height?: number | null;
|
|
30
|
-
};
|
|
31
|
-
thumbnails?: readonly ({
|
|
32
|
-
name: string;
|
|
33
|
-
} & {
|
|
34
|
-
width?: number | null;
|
|
35
|
-
height?: number | null;
|
|
36
|
-
})[];
|
|
37
|
-
};
|
|
38
|
-
}) | undefined) => t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
|
|
39
|
-
export declare const ImportImage: (field?: ({
|
|
40
|
-
type: "Image";
|
|
41
|
-
} & {
|
|
42
|
-
fieldset?: string | null | undefined;
|
|
43
|
-
config?: {
|
|
44
|
-
label?: string | null | undefined;
|
|
45
|
-
placeholder?: string;
|
|
46
|
-
constraint?: {
|
|
47
|
-
width?: number | null;
|
|
48
|
-
height?: number | null;
|
|
49
|
-
};
|
|
50
|
-
thumbnails?: readonly ({
|
|
51
|
-
name: string;
|
|
52
|
-
} & {
|
|
53
|
-
width?: number | null;
|
|
54
|
-
height?: number | null;
|
|
55
|
-
})[];
|
|
56
|
-
};
|
|
57
|
-
}) | undefined) => t.Type<{
|
|
58
|
-
type: "Image";
|
|
59
|
-
value: ImageFieldWithThumbnails | null;
|
|
60
|
-
}, ImageFieldWithThumbnails | undefined, unknown>;
|
|
61
|
-
export declare type ImportImage = t.TypeOf<ReturnType<typeof ImportImage>>;
|
|
62
|
-
export {};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportImage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Either_1 = require("fp-ts/Either");
|
|
6
|
-
const function_1 = require("fp-ts/lib/function");
|
|
7
|
-
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
-
const validators_1 = require("../../../../validators");
|
|
9
|
-
const BasicTypes_1 = require("../../../../validators/BasicTypes");
|
|
10
|
-
const ImportContent_1 = require("../ImportContent");
|
|
11
|
-
const ImageFieldValidator = BasicTypes_1.AnyObject.pipe(t.intersection([
|
|
12
|
-
t.type({
|
|
13
|
-
id: BasicTypes_1.String,
|
|
14
|
-
}),
|
|
15
|
-
t.partial({
|
|
16
|
-
dimensions: BasicTypes_1.AnyObject.pipe(t.partial({
|
|
17
|
-
width: BasicTypes_1.Number,
|
|
18
|
-
height: BasicTypes_1.Number,
|
|
19
|
-
})),
|
|
20
|
-
edit: BasicTypes_1.AnyObject.pipe(t.partial({
|
|
21
|
-
x: BasicTypes_1.Number,
|
|
22
|
-
y: BasicTypes_1.Number,
|
|
23
|
-
zoom: BasicTypes_1.Number,
|
|
24
|
-
background: BasicTypes_1.String,
|
|
25
|
-
})),
|
|
26
|
-
credit: BasicTypes_1.StringOrNull,
|
|
27
|
-
alt: BasicTypes_1.StringOrNull,
|
|
28
|
-
}),
|
|
29
|
-
]));
|
|
30
|
-
const ThumbnailsValidator = t.record(t.string, ImageFieldValidator);
|
|
31
|
-
const encodeImageField = (image, mainImage, constraints) => {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
33
|
-
const background = (_a = image === null || image === void 0 ? void 0 : image.edit) === null || _a === void 0 ? void 0 : _a.background;
|
|
34
|
-
const width = (_d = (_b = constraints === null || constraints === void 0 ? void 0 : constraints.width) !== null && _b !== void 0 ? _b : (_c = image === null || image === void 0 ? void 0 : image.dimensions) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : (_e = mainImage.dimensions) === null || _e === void 0 ? void 0 : _e.width;
|
|
35
|
-
const height = (_h = (_f = constraints === null || constraints === void 0 ? void 0 : constraints.height) !== null && _f !== void 0 ? _f : (_g = image === null || image === void 0 ? void 0 : image.dimensions) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : (_j = mainImage.dimensions) === null || _j === void 0 ? void 0 : _j.height;
|
|
36
|
-
const alt = image === null || image === void 0 ? void 0 : image.alt;
|
|
37
|
-
const credit = image === null || image === void 0 ? void 0 : image.credit;
|
|
38
|
-
return {
|
|
39
|
-
id: (_k = image === null || image === void 0 ? void 0 : image.id) !== null && _k !== void 0 ? _k : mainImage === null || mainImage === void 0 ? void 0 : mainImage.id,
|
|
40
|
-
edit: {
|
|
41
|
-
x: (_m = (_l = image === null || image === void 0 ? void 0 : image.edit) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
|
|
42
|
-
y: (_p = (_o = image === null || image === void 0 ? void 0 : image.edit) === null || _o === void 0 ? void 0 : _o.y) !== null && _p !== void 0 ? _p : 0,
|
|
43
|
-
zoom: (_r = (_q = image === null || image === void 0 ? void 0 : image.edit) === null || _q === void 0 ? void 0 : _q.zoom) !== null && _r !== void 0 ? _r : 1,
|
|
44
|
-
...(background !== undefined ? { background } : {}),
|
|
45
|
-
},
|
|
46
|
-
dimensions: {
|
|
47
|
-
...(width !== undefined ? { width } : {}),
|
|
48
|
-
...(height !== undefined ? { height } : {}),
|
|
49
|
-
},
|
|
50
|
-
...(alt !== undefined ? { alt } : {}),
|
|
51
|
-
...(credit !== undefined ? { credit } : {}),
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const encodeThumbnails = (mainImage, thumbnails, field) => {
|
|
55
|
-
var _a, _b, _c;
|
|
56
|
-
return (_c = (_b = (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.thumbnails) === null || _b === void 0 ? void 0 : _b.reduce((acc, thumbnail) => ({
|
|
57
|
-
...acc,
|
|
58
|
-
[thumbnail.name]: encodeImageField(thumbnails[thumbnail.name], mainImage, thumbnail),
|
|
59
|
-
}), {})) !== null && _c !== void 0 ? _c : {};
|
|
60
|
-
};
|
|
61
|
-
const ImageFieldWithThumbnails = (field) => new t.Type("ImageFieldWithThumbnails", (u) => ImageFieldValidator.is(u) &&
|
|
62
|
-
"thumbnails" in u &&
|
|
63
|
-
ThumbnailsValidator.is(u["thumbnails"]), (u, ctx) => {
|
|
64
|
-
return (0, function_1.pipe)(ImageFieldValidator.validate(u, ctx), (0, Either_1.chain)((mainImage) => {
|
|
65
|
-
const { id, dimensions, edit, credit, alt, ...maybeThumbnails } = mainImage;
|
|
66
|
-
return (0, function_1.pipe)(ThumbnailsValidator.validate(maybeThumbnails, ctx), (0, Either_1.map)((thumbnails) => {
|
|
67
|
-
var _a;
|
|
68
|
-
return ({
|
|
69
|
-
...encodeImageField(mainImage, mainImage, (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.constraint),
|
|
70
|
-
thumbnails: encodeThumbnails(mainImage, thumbnails, field),
|
|
71
|
-
});
|
|
72
|
-
}));
|
|
73
|
-
}));
|
|
74
|
-
}, t.identity);
|
|
75
|
-
const ImportImage = (field) => (0, ImportContent_1.ImportContent)("Image", (0, validators_1.NullOrElse)(ImageFieldWithThumbnails(field)));
|
|
76
|
-
exports.ImportImage = ImportImage;
|