@prismicio/types-internal 2.2.0 → 2.2.1-alpha.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/fields/slices/Slice/CompositeSliceContent.js +2 -1
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +4 -2
- package/lib/import/validators/fields/nestable/Image/default.js +4 -4
- package/lib/import/validators/fields/nestable/Image/index.d.ts +0 -19
- package/lib/import/validators/fields/nestable/Image/index.js +12 -21
- package/lib/import/validators/fields/nestable/Image/validators.d.ts +100 -3
- package/lib/import/validators/fields/nestable/Image/validators.js +16 -4
- package/package.json +1 -1
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +2 -1
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +5 -2
- package/src/import/validators/fields/nestable/Image/default.ts +9 -12
- package/src/import/validators/fields/nestable/Image/index.ts +33 -40
- package/src/import/validators/fields/nestable/Image/validators.ts +56 -31
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +0 -17
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +0 -30
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +0 -43
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +0 -69
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +0 -4
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +0 -6
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +0 -2
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +0 -5
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +0 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +0 -2
- package/lib/utils/io-ts.d.ts +0 -2
- package/lib/utils/io-ts.js +0 -22
|
@@ -134,8 +134,9 @@ function traverseCompositeSliceContent({ path, sliceKey, sliceName, model, conte
|
|
|
134
134
|
}
|
|
135
135
|
exports.traverseCompositeSliceContent = traverseCompositeSliceContent;
|
|
136
136
|
function migrateCompositeSlice(model, content) {
|
|
137
|
+
const [, sliceUUID] = content.key.split("$");
|
|
137
138
|
return {
|
|
138
|
-
key:
|
|
139
|
+
key: `${model.sliceName}$${sliceUUID}`,
|
|
139
140
|
name: model.sliceName,
|
|
140
141
|
maybeLabel: content.maybeLabel,
|
|
141
142
|
widget: {
|
|
@@ -87,9 +87,11 @@ function traverseSimpleSliceContent({ path, sliceKey, sliceName, model, content,
|
|
|
87
87
|
exports.traverseSimpleSliceContent = traverseSimpleSliceContent;
|
|
88
88
|
function migrateSimpleSlice(model, content) {
|
|
89
89
|
var _a;
|
|
90
|
+
const [, sliceUUID] = content.key.split("$");
|
|
91
|
+
const key = `${model.sliceName}$${sliceUUID}`;
|
|
90
92
|
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
91
93
|
return {
|
|
92
|
-
key
|
|
94
|
+
key,
|
|
93
95
|
name: model.sliceName,
|
|
94
96
|
maybeLabel: content.maybeLabel,
|
|
95
97
|
widget: {
|
|
@@ -111,7 +113,7 @@ function migrateSimpleSlice(model, content) {
|
|
|
111
113
|
};
|
|
112
114
|
}
|
|
113
115
|
return {
|
|
114
|
-
key
|
|
116
|
+
key,
|
|
115
117
|
name: model.sliceName,
|
|
116
118
|
maybeLabel: content.maybeLabel,
|
|
117
119
|
widget: {
|
|
@@ -4,16 +4,16 @@ exports.defaultImportImage = 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 function_1 = require("../../../../../validators/function");
|
|
8
7
|
const defaultImportImage = (field) => {
|
|
9
8
|
var _a;
|
|
10
9
|
// If there is not thumbnails we expect an empty object
|
|
11
10
|
if (!((_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.thumbnails) || !field.config.thumbnails.length)
|
|
12
11
|
return validators_1.EmptyObject;
|
|
13
|
-
// If there are thumbnails, we expect an object with thumbnails as empty objects
|
|
14
|
-
|
|
12
|
+
// If there are thumbnails, we can expect an object with thumbnails as empty objects,
|
|
13
|
+
// however we don't accept any other properties for the empty state
|
|
14
|
+
return t.strict(field.config.thumbnails.reduce((acc, thumbnail) => ({
|
|
15
15
|
...acc,
|
|
16
16
|
[thumbnail.name]: validators_1.EmptyObject,
|
|
17
|
-
}), {}))
|
|
17
|
+
}), {}));
|
|
18
18
|
};
|
|
19
19
|
exports.defaultImportImage = defaultImportImage;
|
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import type { ImageFieldWithThumbnails } from "./model";
|
|
3
|
-
export declare const ImageFieldCodec: (field?: ({
|
|
4
|
-
type: "Image";
|
|
5
|
-
} & {
|
|
6
|
-
fieldset?: string | null | undefined;
|
|
7
|
-
config?: {
|
|
8
|
-
label?: string | null | undefined;
|
|
9
|
-
placeholder?: string;
|
|
10
|
-
constraint?: {
|
|
11
|
-
width?: number | null;
|
|
12
|
-
height?: number | null;
|
|
13
|
-
};
|
|
14
|
-
thumbnails?: readonly ({
|
|
15
|
-
name: string;
|
|
16
|
-
} & {
|
|
17
|
-
width?: number | null;
|
|
18
|
-
height?: number | null;
|
|
19
|
-
})[];
|
|
20
|
-
};
|
|
21
|
-
}) | undefined) => t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
|
|
22
3
|
export declare const ImportImage: (field?: ({
|
|
23
4
|
type: "Image";
|
|
24
5
|
} & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportImage =
|
|
3
|
+
exports.ImportImage = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const Either_1 = require("fp-ts/Either");
|
|
6
6
|
const function_1 = require("fp-ts/function");
|
|
@@ -16,26 +16,17 @@ const validators_2 = require("./validators");
|
|
|
16
16
|
* Input -> type ImageAPIV2 = ImportImageView & ImportThumbnails
|
|
17
17
|
* Output -> type ImageWithThumbnails 👇
|
|
18
18
|
*/
|
|
19
|
-
const ImageFieldCodec = (field) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Validating the higher level image
|
|
24
|
-
validators_2.ImportImageView.validate(u, ctx), (0, Either_1.chain)((imageApiV2) => {
|
|
19
|
+
const ImageFieldCodec = (field) => {
|
|
20
|
+
const ImageCodec = (0, validators_2.ImportImageWithThumbnails)(field);
|
|
21
|
+
return new t.Type("ImageField", (u) => ImageCodec.is(u), (u, ctx) => (0, function_1.pipe)(ImageCodec.validate(u, ctx), (0, Either_1.map)((imageApiV2) => {
|
|
22
|
+
var _a;
|
|
25
23
|
const { id, dimensions, edit, copyright, alt, ...thumbnails } = imageApiV2;
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
}));
|
|
35
|
-
}));
|
|
36
|
-
}, t.identity);
|
|
37
|
-
exports.ImageFieldCodec = ImageFieldCodec;
|
|
38
|
-
const ImageCodec = (field) => (0, function_2.withCustomError)((0, validators_1.DefaultOrElse)((0, default_1.defaultImportImage)(field))((0, exports.ImageFieldCodec)(field)), () => "An image field must be an object");
|
|
39
|
-
const ImportImage = (field) => (0, ImportContent_1.ImportContent)("Image", ImageCodec(field));
|
|
24
|
+
return {
|
|
25
|
+
...(0, merge_1.mergeImageViewWithCtConstraints)(imageApiV2, imageApiV2, (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.constraint),
|
|
26
|
+
thumbnails: (0, merge_1.mergeThumbnailsWithCtConstraints)(thumbnails, imageApiV2, field),
|
|
27
|
+
};
|
|
28
|
+
})), t.identity);
|
|
29
|
+
};
|
|
30
|
+
const ImportImage = (field) => (0, ImportContent_1.ImportContent)("Image", (0, function_2.withCustomError)((0, validators_1.DefaultOrElse)((0, default_1.defaultImportImage)(field))(ImageFieldCodec(field)), () => "An image field must be an object"));
|
|
40
31
|
exports.ImportImage = ImportImage;
|
|
41
32
|
(0, tslib_1.__exportStar)(require("./model"), exports);
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { Thumbnail } from "../../../../../customtypes";
|
|
3
|
+
export declare const ImportImageViewShape: t.IntersectionC<[t.TypeC<{
|
|
4
|
+
id: t.StringC;
|
|
5
|
+
}>, t.PartialC<{
|
|
6
|
+
dimensions: t.PartialC<{
|
|
7
|
+
width: t.NumberC;
|
|
8
|
+
height: t.NumberC;
|
|
9
|
+
}>;
|
|
10
|
+
edit: t.PartialC<{
|
|
11
|
+
x: t.NumberC;
|
|
12
|
+
y: t.NumberC;
|
|
13
|
+
zoom: t.NumberC;
|
|
14
|
+
background: t.StringC;
|
|
15
|
+
}>;
|
|
16
|
+
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
17
|
+
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
18
|
+
}>]>;
|
|
2
19
|
export declare const ImportImageView: t.IntersectionC<[t.TypeC<{
|
|
3
20
|
id: t.StringC;
|
|
4
21
|
}>, t.PartialC<{
|
|
@@ -16,7 +33,57 @@ export declare const ImportImageView: t.IntersectionC<[t.TypeC<{
|
|
|
16
33
|
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
17
34
|
}>]>;
|
|
18
35
|
export declare type ImportImageView = t.TypeOf<typeof ImportImageView>;
|
|
19
|
-
|
|
36
|
+
declare const ImportThumbnails: (thumbnails: readonly Thumbnail[]) => t.Type<Record<string, {
|
|
37
|
+
id: string;
|
|
38
|
+
} & {
|
|
39
|
+
dimensions?: {
|
|
40
|
+
width?: number;
|
|
41
|
+
height?: number;
|
|
42
|
+
};
|
|
43
|
+
edit?: {
|
|
44
|
+
x?: number;
|
|
45
|
+
y?: number;
|
|
46
|
+
zoom?: number;
|
|
47
|
+
background?: string;
|
|
48
|
+
};
|
|
49
|
+
copyright?: string | null;
|
|
50
|
+
alt?: string | null;
|
|
51
|
+
}>, Record<string, {
|
|
52
|
+
id: string;
|
|
53
|
+
} & {
|
|
54
|
+
dimensions?: {
|
|
55
|
+
width?: number;
|
|
56
|
+
height?: number;
|
|
57
|
+
};
|
|
58
|
+
edit?: {
|
|
59
|
+
x?: number;
|
|
60
|
+
y?: number;
|
|
61
|
+
zoom?: number;
|
|
62
|
+
background?: string;
|
|
63
|
+
};
|
|
64
|
+
copyright?: string | null;
|
|
65
|
+
alt?: string | null;
|
|
66
|
+
}>, unknown>;
|
|
67
|
+
export declare type ImportThumbnails = t.TypeOf<ReturnType<typeof ImportThumbnails>>;
|
|
68
|
+
export declare const ImportImageWithThumbnails: (def?: ({
|
|
69
|
+
type: "Image";
|
|
70
|
+
} & {
|
|
71
|
+
fieldset?: string | null | undefined;
|
|
72
|
+
config?: {
|
|
73
|
+
label?: string | null | undefined;
|
|
74
|
+
placeholder?: string;
|
|
75
|
+
constraint?: {
|
|
76
|
+
width?: number | null;
|
|
77
|
+
height?: number | null;
|
|
78
|
+
};
|
|
79
|
+
thumbnails?: readonly ({
|
|
80
|
+
name: string;
|
|
81
|
+
} & {
|
|
82
|
+
width?: number | null;
|
|
83
|
+
height?: number | null;
|
|
84
|
+
})[];
|
|
85
|
+
};
|
|
86
|
+
}) | undefined) => t.IntersectionC<[t.IntersectionC<[t.TypeC<{
|
|
20
87
|
id: t.StringC;
|
|
21
88
|
}>, t.PartialC<{
|
|
22
89
|
dimensions: t.PartialC<{
|
|
@@ -31,5 +98,35 @@ export declare const ImportThumbnails: t.RecordC<t.StringC, t.IntersectionC<[t.T
|
|
|
31
98
|
}>;
|
|
32
99
|
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
33
100
|
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
34
|
-
}>]
|
|
35
|
-
|
|
101
|
+
}>]>, t.Type<Record<string, {
|
|
102
|
+
id: string;
|
|
103
|
+
} & {
|
|
104
|
+
dimensions?: {
|
|
105
|
+
width?: number;
|
|
106
|
+
height?: number;
|
|
107
|
+
};
|
|
108
|
+
edit?: {
|
|
109
|
+
x?: number;
|
|
110
|
+
y?: number;
|
|
111
|
+
zoom?: number;
|
|
112
|
+
background?: string;
|
|
113
|
+
};
|
|
114
|
+
copyright?: string | null;
|
|
115
|
+
alt?: string | null;
|
|
116
|
+
}>, Record<string, {
|
|
117
|
+
id: string;
|
|
118
|
+
} & {
|
|
119
|
+
dimensions?: {
|
|
120
|
+
width?: number;
|
|
121
|
+
height?: number;
|
|
122
|
+
};
|
|
123
|
+
edit?: {
|
|
124
|
+
x?: number;
|
|
125
|
+
y?: number;
|
|
126
|
+
zoom?: number;
|
|
127
|
+
background?: string;
|
|
128
|
+
};
|
|
129
|
+
copyright?: string | null;
|
|
130
|
+
alt?: string | null;
|
|
131
|
+
}>, unknown>]>;
|
|
132
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ImportImageWithThumbnails = exports.ImportImageView = exports.ImportImageViewShape = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const BasicTypes_1 = require("../../../../../validators/BasicTypes");
|
|
7
7
|
const function_1 = require("../../../../../validators/function");
|
|
8
|
-
exports.
|
|
8
|
+
exports.ImportImageViewShape = t.intersection([
|
|
9
9
|
t.type({
|
|
10
10
|
// Image Id
|
|
11
11
|
id: BasicTypes_1.String,
|
|
@@ -27,5 +27,17 @@ exports.ImportImageView = (0, function_1.withCustomError)(t.intersection([
|
|
|
27
27
|
copyright: BasicTypes_1.StringOrNull,
|
|
28
28
|
alt: BasicTypes_1.StringOrNull,
|
|
29
29
|
}),
|
|
30
|
-
])
|
|
31
|
-
exports.
|
|
30
|
+
]);
|
|
31
|
+
exports.ImportImageView = (0, function_1.withCustomError)(exports.ImportImageViewShape, () => "The value must be an object");
|
|
32
|
+
const ImportThumbnails = (thumbnails) => t.partial(thumbnails.reduce((acc, thumbnail) => ({
|
|
33
|
+
...acc,
|
|
34
|
+
[thumbnail.name]: exports.ImportImageView,
|
|
35
|
+
}), {}));
|
|
36
|
+
const ImportImageWithThumbnails = (def) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
return (0, function_1.withCustomError)(t.intersection([
|
|
39
|
+
exports.ImportImageViewShape,
|
|
40
|
+
ImportThumbnails((_b = (_a = def === null || def === void 0 ? void 0 : def.config) === null || _a === void 0 ? void 0 : _a.thumbnails) !== null && _b !== void 0 ? _b : []),
|
|
41
|
+
]), () => "The value must be an object");
|
|
42
|
+
};
|
|
43
|
+
exports.ImportImageWithThumbnails = ImportImageWithThumbnails;
|
package/package.json
CHANGED
|
@@ -211,8 +211,9 @@ export function migrateCompositeSlice(
|
|
|
211
211
|
model: VariationFields,
|
|
212
212
|
content: CompositeSliceItemContent,
|
|
213
213
|
): SharedSliceItemContent {
|
|
214
|
+
const [, sliceUUID] = content.key.split("$")
|
|
214
215
|
return {
|
|
215
|
-
key:
|
|
216
|
+
key: `${model.sliceName}$${sliceUUID}`,
|
|
216
217
|
name: model.sliceName,
|
|
217
218
|
maybeLabel: content.maybeLabel,
|
|
218
219
|
widget: {
|
|
@@ -135,9 +135,12 @@ export function migrateSimpleSlice(
|
|
|
135
135
|
model: VariationFields,
|
|
136
136
|
content: SimpleSliceItemContent,
|
|
137
137
|
): SharedSliceItemContent {
|
|
138
|
+
const [, sliceUUID] = content.key.split("$")
|
|
139
|
+
const key = `${model.sliceName}$${sliceUUID}`
|
|
140
|
+
|
|
138
141
|
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
139
142
|
return {
|
|
140
|
-
key
|
|
143
|
+
key,
|
|
141
144
|
name: model.sliceName,
|
|
142
145
|
maybeLabel: content.maybeLabel,
|
|
143
146
|
widget: {
|
|
@@ -161,7 +164,7 @@ export function migrateSimpleSlice(
|
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
return {
|
|
164
|
-
key
|
|
167
|
+
key,
|
|
165
168
|
name: model.sliceName,
|
|
166
169
|
maybeLabel: content.maybeLabel,
|
|
167
170
|
widget: {
|
|
@@ -2,24 +2,21 @@ import * as t from "io-ts"
|
|
|
2
2
|
|
|
3
3
|
import type { Image as ImageDefinition } from "../../../../../customtypes"
|
|
4
4
|
import { EmptyObject } from "../../../../../validators"
|
|
5
|
-
import { withCustomError } from "../../../../../validators/function"
|
|
6
5
|
|
|
7
6
|
export const defaultImportImage = (field?: ImageDefinition) => {
|
|
8
7
|
// If there is not thumbnails we expect an empty object
|
|
9
8
|
if (!field?.config?.thumbnails || !field.config.thumbnails.length)
|
|
10
9
|
return EmptyObject
|
|
11
10
|
|
|
12
|
-
// If there are thumbnails, we expect an object with thumbnails as empty objects
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
),
|
|
11
|
+
// If there are thumbnails, we can expect an object with thumbnails as empty objects,
|
|
12
|
+
// however we don't accept any other properties for the empty state
|
|
13
|
+
return t.strict(
|
|
14
|
+
field.config.thumbnails.reduce(
|
|
15
|
+
(acc, thumbnail) => ({
|
|
16
|
+
...acc,
|
|
17
|
+
[thumbnail.name]: EmptyObject,
|
|
18
|
+
}),
|
|
19
|
+
{},
|
|
22
20
|
),
|
|
23
|
-
() => "The value must be an object",
|
|
24
21
|
)
|
|
25
22
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { map } from "fp-ts/Either"
|
|
2
2
|
import { pipe } from "fp-ts/function"
|
|
3
3
|
import type { Validation } from "io-ts"
|
|
4
4
|
import * as t from "io-ts"
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
mergeThumbnailsWithCtConstraints,
|
|
14
14
|
} from "./merge"
|
|
15
15
|
import type { ImageFieldWithThumbnails } from "./model"
|
|
16
|
-
import {
|
|
16
|
+
import { ImportImageWithThumbnails } from "./validators"
|
|
17
17
|
|
|
18
18
|
/* For code clarity, the output of this validator will be simplified
|
|
19
19
|
*
|
|
@@ -21,53 +21,46 @@ import { ImportImageView, ImportThumbnails } from "./validators"
|
|
|
21
21
|
* Output -> type ImageWithThumbnails 👇
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const ImageFieldCodec = (field?: ImageDefinition) => {
|
|
25
|
+
const ImageCodec = ImportImageWithThumbnails(field)
|
|
26
|
+
return new t.Type<ImageFieldWithThumbnails>(
|
|
26
27
|
"ImageField",
|
|
27
|
-
(u: unknown): u is ImageFieldWithThumbnails =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return pipe(
|
|
33
|
-
// Validating the higher level image
|
|
34
|
-
ImportImageView.validate(u, ctx),
|
|
35
|
-
chain((imageApiV2) => {
|
|
28
|
+
(u: unknown): u is ImageFieldWithThumbnails => ImageCodec.is(u),
|
|
29
|
+
(u: unknown, ctx): Validation<ImageFieldWithThumbnails> =>
|
|
30
|
+
pipe(
|
|
31
|
+
ImageCodec.validate(u, ctx),
|
|
32
|
+
map((imageApiV2) => {
|
|
36
33
|
const { id, dimensions, edit, copyright, alt, ...thumbnails } =
|
|
37
34
|
imageApiV2
|
|
38
35
|
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
field,
|
|
52
|
-
),
|
|
53
|
-
})),
|
|
54
|
-
)
|
|
36
|
+
return {
|
|
37
|
+
...mergeImageViewWithCtConstraints(
|
|
38
|
+
imageApiV2,
|
|
39
|
+
imageApiV2,
|
|
40
|
+
field?.config?.constraint,
|
|
41
|
+
),
|
|
42
|
+
thumbnails: mergeThumbnailsWithCtConstraints(
|
|
43
|
+
thumbnails,
|
|
44
|
+
imageApiV2,
|
|
45
|
+
field,
|
|
46
|
+
),
|
|
47
|
+
}
|
|
55
48
|
}),
|
|
56
|
-
)
|
|
57
|
-
},
|
|
49
|
+
),
|
|
58
50
|
t.identity,
|
|
59
51
|
)
|
|
60
|
-
|
|
61
|
-
const ImageCodec = (field?: ImageDefinition) =>
|
|
62
|
-
withCustomError(
|
|
63
|
-
DefaultOrElse<Record<never, never>, ImageFieldWithThumbnails>(
|
|
64
|
-
defaultImportImage(field),
|
|
65
|
-
)(ImageFieldCodec(field)),
|
|
66
|
-
() => "An image field must be an object",
|
|
67
|
-
)
|
|
52
|
+
}
|
|
68
53
|
|
|
69
54
|
export const ImportImage = (field?: ImageDefinition) =>
|
|
70
|
-
ImportContent(
|
|
55
|
+
ImportContent(
|
|
56
|
+
"Image",
|
|
57
|
+
withCustomError(
|
|
58
|
+
DefaultOrElse<Record<never, never>, ImageFieldWithThumbnails>(
|
|
59
|
+
defaultImportImage(field),
|
|
60
|
+
)(ImageFieldCodec(field)),
|
|
61
|
+
() => "An image field must be an object",
|
|
62
|
+
),
|
|
63
|
+
)
|
|
71
64
|
export type ImportImage = t.TypeOf<ReturnType<typeof ImportImage>>
|
|
72
65
|
|
|
73
66
|
export * from "./model"
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
+
import type {
|
|
4
|
+
Image as ImageDefinition,
|
|
5
|
+
Thumbnail,
|
|
6
|
+
} from "../../../../../customtypes"
|
|
3
7
|
import {
|
|
4
8
|
Number,
|
|
5
9
|
String,
|
|
@@ -7,39 +11,60 @@ import {
|
|
|
7
11
|
} from "../../../../../validators/BasicTypes"
|
|
8
12
|
import { withCustomError } from "../../../../../validators/function"
|
|
9
13
|
|
|
14
|
+
export const ImportImageViewShape = t.intersection([
|
|
15
|
+
t.type({
|
|
16
|
+
// Image Id
|
|
17
|
+
id: String,
|
|
18
|
+
}),
|
|
19
|
+
t.partial({
|
|
20
|
+
// Dimensions here will be used if they are not defined in the custom type
|
|
21
|
+
dimensions: withCustomError(
|
|
22
|
+
t.partial({
|
|
23
|
+
width: Number,
|
|
24
|
+
height: Number,
|
|
25
|
+
}),
|
|
26
|
+
() => "The value must be an object",
|
|
27
|
+
),
|
|
28
|
+
// Crop information
|
|
29
|
+
edit: withCustomError(
|
|
30
|
+
t.partial({
|
|
31
|
+
x: Number,
|
|
32
|
+
y: Number,
|
|
33
|
+
zoom: Number,
|
|
34
|
+
background: String,
|
|
35
|
+
}),
|
|
36
|
+
() => "The value must be an object",
|
|
37
|
+
),
|
|
38
|
+
// Copyrights and alt are set in the Asset by default but they can be overrided
|
|
39
|
+
copyright: StringOrNull,
|
|
40
|
+
alt: StringOrNull,
|
|
41
|
+
}),
|
|
42
|
+
])
|
|
43
|
+
|
|
10
44
|
export const ImportImageView = withCustomError(
|
|
11
|
-
|
|
12
|
-
t.type({
|
|
13
|
-
// Image Id
|
|
14
|
-
id: String,
|
|
15
|
-
}),
|
|
16
|
-
t.partial({
|
|
17
|
-
// Dimensions here will be used if they are not defined in the custom type
|
|
18
|
-
dimensions: withCustomError(
|
|
19
|
-
t.partial({
|
|
20
|
-
width: Number,
|
|
21
|
-
height: Number,
|
|
22
|
-
}),
|
|
23
|
-
() => "The value must be an object",
|
|
24
|
-
),
|
|
25
|
-
// Crop information
|
|
26
|
-
edit: withCustomError(
|
|
27
|
-
t.partial({
|
|
28
|
-
x: Number,
|
|
29
|
-
y: Number,
|
|
30
|
-
zoom: Number,
|
|
31
|
-
background: String,
|
|
32
|
-
}),
|
|
33
|
-
() => "The value must be an object",
|
|
34
|
-
),
|
|
35
|
-
// Copyrights and alt are set in the Asset by default but they can be overrided
|
|
36
|
-
copyright: StringOrNull,
|
|
37
|
-
alt: StringOrNull,
|
|
38
|
-
}),
|
|
39
|
-
]),
|
|
45
|
+
ImportImageViewShape,
|
|
40
46
|
() => "The value must be an object",
|
|
41
47
|
)
|
|
42
48
|
export type ImportImageView = t.TypeOf<typeof ImportImageView>
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
const ImportThumbnails = (thumbnails: readonly Thumbnail[]) =>
|
|
51
|
+
t.partial(
|
|
52
|
+
thumbnails.reduce<Record<string, typeof ImportImageView>>(
|
|
53
|
+
(acc, thumbnail) => ({
|
|
54
|
+
...acc,
|
|
55
|
+
[thumbnail.name]: ImportImageView,
|
|
56
|
+
}),
|
|
57
|
+
{},
|
|
58
|
+
),
|
|
59
|
+
) as t.Type<Record<string, ImportImageView>>
|
|
60
|
+
|
|
61
|
+
export type ImportThumbnails = t.TypeOf<ReturnType<typeof ImportThumbnails>>
|
|
62
|
+
|
|
63
|
+
export const ImportImageWithThumbnails = (def?: ImageDefinition) =>
|
|
64
|
+
withCustomError(
|
|
65
|
+
t.intersection([
|
|
66
|
+
ImportImageViewShape,
|
|
67
|
+
ImportThumbnails(def?.config?.thumbnails ?? []),
|
|
68
|
+
]),
|
|
69
|
+
() => "The value must be an object",
|
|
70
|
+
)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
import { WidgetKey } from "../../../../../../../common";
|
|
3
|
-
import type { NestableWidget } from "../../../../../../../customtypes";
|
|
4
|
-
import type { ImportNestable } from "../../../../nestable";
|
|
5
|
-
/**
|
|
6
|
-
* Represents the object in the 'primary' field or a single item in the 'items' array in the SharedSlice.
|
|
7
|
-
*/
|
|
8
|
-
export declare type SharedSliceContent = Record<WidgetKey, ImportNestable>;
|
|
9
|
-
/**
|
|
10
|
-
* Builds the decoder for a single entry in the 'primary' field or a single item in the 'items' array in the SharedSlice.
|
|
11
|
-
*
|
|
12
|
-
* @param sliceName name of the slice - used for error reporting in order to know which slice is being decoded
|
|
13
|
-
* @param sliceContentField 'primary' or 'items' - used for error reporting in order to know which field of the slice is being decoded
|
|
14
|
-
* @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
|
|
15
|
-
* @constructor
|
|
16
|
-
*/
|
|
17
|
-
export declare const SharedSliceContent: (sliceName: string, sliceContentField: "primary" | "items", sliceFieldModels: Record<WidgetKey, NestableWidget>) => t.Type<SharedSliceContent, SharedSliceContent, unknown>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SharedSliceContent = 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/lib/function");
|
|
7
|
-
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
-
const common_1 = require("../../../../../../../common");
|
|
9
|
-
const io_ts_1 = require("../../../../../../../utils/io-ts");
|
|
10
|
-
const function_2 = require("../../../../../../../validators/function");
|
|
11
|
-
const SharedSliceContentEntry_1 = require("./SharedSliceContentEntry");
|
|
12
|
-
/**
|
|
13
|
-
* Builds the decoder for a single entry in the 'primary' field or a single item in the 'items' array in the SharedSlice.
|
|
14
|
-
*
|
|
15
|
-
* @param sliceName name of the slice - used for error reporting in order to know which slice is being decoded
|
|
16
|
-
* @param sliceContentField 'primary' or 'items' - used for error reporting in order to know which field of the slice is being decoded
|
|
17
|
-
* @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
|
|
18
|
-
* @constructor
|
|
19
|
-
*/
|
|
20
|
-
const SharedSliceContent = (sliceName, sliceContentField, sliceFieldModels) => new t.Type("SharedSliceContent", (u) => t.record(common_1.WidgetKey, t.unknown).is(u), (u, c) => (0, function_1.pipe)(
|
|
21
|
-
// We first decode the raw content object in the shape of Record<WidgetKey, unknown>
|
|
22
|
-
(0, function_2.withCustomError)(t.UnknownRecord, () => "The value must be an object").validate(u, c), E.chain((rawContent) => (0, function_1.pipe)(
|
|
23
|
-
// We split the object into entries because there is no easy other way to decode each value with a different codec
|
|
24
|
-
Object.entries(rawContent).map((entry) => (0, SharedSliceContentEntry_1.SharedSliceContentEntry)(sliceName, sliceContentField, sliceFieldModels).validate(entry, c)),
|
|
25
|
-
// We get a validation result for each entry in the content object (t.Validation<SharedSliceContentEntry>[]),
|
|
26
|
-
// however we want to get a single validation result for the whole array of entries (t.Validation<SharedSliceContentEntry[]>).
|
|
27
|
-
io_ts_1.combineValidationResults,
|
|
28
|
-
// We build the object back from entries if all decoded successfully
|
|
29
|
-
E.map((entries) => entries.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}))))), t.identity);
|
|
30
|
-
exports.SharedSliceContent = SharedSliceContent;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
import { WidgetKey } from "../../../../../../../common";
|
|
3
|
-
import type { NestableWidget } from "../../../../../../../customtypes";
|
|
4
|
-
import { ImportNestable } from "../../../../nestable";
|
|
5
|
-
export declare type SharedSliceContentEntry = [WidgetKey, ImportNestable];
|
|
6
|
-
/**
|
|
7
|
-
* 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.
|
|
8
|
-
*
|
|
9
|
-
* For example, given the following slice:
|
|
10
|
-
* {
|
|
11
|
-
* "slice_type": "my_slice",
|
|
12
|
-
* "variation": "default",
|
|
13
|
-
* "primary": {
|
|
14
|
-
* "slice_text": "abc", // This is one entry
|
|
15
|
-
* "slice_text2": "def: // This is another entry
|
|
16
|
-
* },
|
|
17
|
-
* "items": [
|
|
18
|
-
* {
|
|
19
|
-
* "slice_number1": 0, // This is one entry
|
|
20
|
-
* "slice_number2": 1 // And this is yet another entry
|
|
21
|
-
* }
|
|
22
|
-
* ]
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* The 'primary' object is converted to following entries to be decoded:
|
|
26
|
-
* [
|
|
27
|
-
* ["slice_text", "abc"],
|
|
28
|
-
* ["slice_text2", "def"]
|
|
29
|
-
* ]
|
|
30
|
-
* and the first item in the 'items' array is converted to following entries to be decoded:
|
|
31
|
-
* [
|
|
32
|
-
* ["slice_number1", 0],
|
|
33
|
-
* ["slice_number2", 1]
|
|
34
|
-
* ]
|
|
35
|
-
*
|
|
36
|
-
* 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.
|
|
37
|
-
* 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.
|
|
38
|
-
*
|
|
39
|
-
* @param sliceName name of the slice - used for error reporting in order to know which slice is being decoded
|
|
40
|
-
* @param sliceContentField 'primary' or 'items' - used for error reporting in order to know which field of the slice is being decoded
|
|
41
|
-
* @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
|
|
42
|
-
*/
|
|
43
|
-
export declare const SharedSliceContentEntry: (sliceName: string, sliceContentField: "primary" | "items", sliceFieldModels: Record<WidgetKey, NestableWidget>) => t.Type<SharedSliceContentEntry, SharedSliceContentEntry, unknown>;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SharedSliceContentEntry = 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 t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
-
const common_1 = require("../../../../../../../common");
|
|
9
|
-
const nestable_1 = require("../../../../nestable");
|
|
10
|
-
const errors_1 = require("./errors");
|
|
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
|
-
const SharedSliceContentEntry = (sliceName, sliceContentField, sliceFieldModels) => new t.Type("SharedSliceContentEntry", (u) => t.tuple([common_1.WidgetKey, t.unknown]).is(u) && nestable_1.ImportNestable.is(u[1]), (u, c) => {
|
|
49
|
-
return (0, function_1.pipe)(t.tuple([common_1.WidgetKey, t.unknown]).validate(u, c), E.chain(([key, content]) => {
|
|
50
|
-
const model = sliceFieldModels[key];
|
|
51
|
-
if (!model) {
|
|
52
|
-
return t.failure([key, content], [...c, { key, actual: content, type: t.unknown }], errors_1.SharedSliceContentErrors.UnknownField(sliceName, sliceContentField, key));
|
|
53
|
-
}
|
|
54
|
-
const { codec, result } = nestable_1.ImportNestable.decode(model)(content);
|
|
55
|
-
return (0, function_1.pipe)(result, E.map((decodedContent) => [
|
|
56
|
-
key,
|
|
57
|
-
decodedContent,
|
|
58
|
-
]), E.mapLeft((errors) => errors.map((error) => {
|
|
59
|
-
const context = [
|
|
60
|
-
...c,
|
|
61
|
-
{ key, actual: content, type: codec },
|
|
62
|
-
...error.context.slice(1), // We ignore the first context element with "" key coming from ImportNestable decoder
|
|
63
|
-
];
|
|
64
|
-
const updatedError = { ...error, context };
|
|
65
|
-
return updatedError;
|
|
66
|
-
})));
|
|
67
|
-
}));
|
|
68
|
-
}, t.identity);
|
|
69
|
-
exports.SharedSliceContentEntry = SharedSliceContentEntry;
|
package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SharedSliceContentErrors = void 0;
|
|
4
|
-
exports.SharedSliceContentErrors = {
|
|
5
|
-
UnknownField: (sliceName, contentField, fieldName) => `Unsupported field '${fieldName}'for '${contentField}' content in Shared Slice '${sliceName}'`,
|
|
6
|
-
};
|
package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare type SharedSliceContentField = "primary" | "items";
|
package/lib/utils/io-ts.d.ts
DELETED
package/lib/utils/io-ts.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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;
|