@prismicio/types-internal 2.2.0-alpha.9 → 2.2.0-traverse.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/_internal/utils.d.ts +17 -0
- package/lib/_internal/utils.js +9 -0
- package/lib/common/Asset.d.ts +3 -4
- package/lib/common/Embed.d.ts +1 -2
- package/lib/common/UUID.d.ts +7 -0
- package/lib/common/UUID.js +8 -0
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/content/Document.d.ts +22 -3
- package/lib/content/Document.js +71 -1
- package/lib/content/fields/GroupContent.d.ts +7 -0
- package/lib/content/fields/GroupContent.js +34 -1
- package/lib/content/fields/WidgetContent.d.ts +6 -6
- package/lib/content/fields/nestable/NestableContent.d.ts +2 -0
- package/lib/content/fields/nestable/NestableContent.js +29 -1
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +8 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +56 -1
- package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +58 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +7 -0
- package/lib/content/fields/slices/SlicesContent.js +70 -1
- package/lib/customtypes/CustomType.d.ts +1 -0
- package/lib/customtypes/CustomType.js +8 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.js +5 -1
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -0
- package/lib/customtypes/widgets/slices/LegacySlice.js +5 -1
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +4 -0
- package/lib/customtypes/widgets/slices/SharedSlice.js +9 -1
- package/lib/import/converters/Document.d.ts +2 -2
- package/lib/import/converters/Document.js +6 -6
- 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/UID.d.ts +1 -1
- package/lib/import/converters/fields/UID.js +0 -2
- 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/Embed.d.ts +2 -1
- package/lib/import/converters/fields/nestable/Embed.js +24 -5
- package/lib/import/converters/fields/nestable/Image.d.ts +2 -2
- package/lib/import/converters/fields/nestable/Image.js +1 -1
- package/lib/import/converters/fields/nestable/Link.d.ts +1 -1
- package/lib/import/converters/fields/nestable/Link.js +6 -6
- package/lib/import/converters/fields/nestable/Nestable.d.ts +4 -3
- package/lib/import/converters/fields/nestable/Nestable.js +2 -2
- package/lib/import/validators/Document.js +2 -2
- package/lib/import/validators/fields/ImportField.d.ts +17 -68
- package/lib/import/validators/fields/ImportField.js +8 -4
- 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 +61 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/index.js +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
- package/lib/import/validators/fields/UID.d.ts +2 -2
- package/lib/import/validators/fields/UID.js +1 -1
- package/lib/import/validators/fields/nestable/Embed.d.ts +6 -23
- package/lib/import/validators/fields/nestable/Embed.js +7 -25
- package/lib/import/validators/fields/nestable/GeoPoint.js +1 -1
- package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/Decoder.js +40 -0
- package/lib/import/validators/fields/nestable/Image/Validator.d.ts +33 -0
- package/lib/import/validators/fields/nestable/Image/Validator.js +27 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/index.js +41 -0
- package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Image/model.js +2 -0
- package/lib/import/validators/fields/nestable/Link.js +2 -2
- package/lib/import/validators/fields/nestable/Nestable.d.ts +9 -60
- package/lib/import/validators/fields/nestable/index.d.ts +1 -0
- package/lib/import/validators/fields/nestable/index.js +1 -0
- package/lib/utils/DocumentId.d.ts +2 -1
- package/lib/utils/DocumentId.js +3 -3
- package/lib/utils/io-ts.d.ts +2 -0
- package/lib/utils/io-ts.js +22 -0
- package/lib/validators/BasicTypes.d.ts +0 -1
- package/lib/validators/BasicTypes.js +7 -8
- package/lib/validators/DefaultOrElse.js +1 -1
- package/lib/validators/NonEmptyString.js +1 -1
- package/lib/validators/NullOrT.d.ts +2 -0
- package/lib/validators/NullOrT.js +12 -0
- package/lib/validators/function.d.ts +4 -4
- package/lib/validators/function.js +6 -6
- package/package.json +4 -2
- package/src/_internal/utils.ts +39 -0
- package/src/common/Asset.ts +4 -5
- package/src/common/Embed.ts +22 -0
- package/src/common/UUID.ts +19 -0
- package/src/common/index.ts +1 -0
- package/src/content/Document.ts +96 -1
- package/src/content/fields/GroupContent.ts +47 -0
- package/src/content/fields/nestable/NestableContent.ts +32 -0
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +77 -0
- package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +82 -0
- package/src/content/fields/slices/SlicesContent.ts +96 -0
- package/src/customtypes/CustomType.ts +17 -0
- package/src/customtypes/widgets/slices/CompositeSlice.ts +7 -0
- package/src/customtypes/widgets/slices/LegacySlice.ts +7 -0
- package/src/customtypes/widgets/slices/SharedSlice.ts +12 -0
- package/src/import/converters/Document.ts +10 -8
- package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
- package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
- package/src/import/converters/fields/Slices/Slices.ts +20 -0
- package/src/import/converters/fields/Slices/index.ts +1 -0
- package/src/import/converters/fields/UID.ts +1 -5
- package/src/import/converters/fields/index.ts +1 -0
- package/src/import/converters/fields/nestable/Embed.ts +29 -7
- package/src/import/converters/fields/nestable/Image.ts +4 -4
- package/src/import/converters/fields/nestable/Link.ts +5 -5
- package/src/import/converters/fields/nestable/Nestable.ts +7 -5
- package/src/import/validators/Document.ts +3 -3
- package/src/import/validators/fields/ImportField.ts +12 -6
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +116 -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 +64 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
- package/src/import/validators/fields/ImportSlices/index.ts +1 -0
- package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
- package/src/import/validators/fields/UID.ts +2 -2
- package/src/import/validators/fields/nestable/Embed.ts +9 -41
- package/src/import/validators/fields/nestable/GeoPoint.ts +2 -2
- package/src/import/validators/fields/nestable/Image/Decoder.ts +61 -0
- package/src/import/validators/fields/nestable/Image/Validator.ts +38 -0
- package/src/import/validators/fields/nestable/Image/index.ts +75 -0
- package/src/import/validators/fields/nestable/Image/model.ts +18 -0
- package/src/import/validators/fields/nestable/Link.ts +2 -2
- package/src/import/validators/fields/nestable/index.ts +1 -0
- package/src/utils/DocumentId.ts +4 -5
- package/src/utils/io-ts.ts +29 -0
- package/src/validators/BasicTypes.ts +13 -11
- package/src/validators/DefaultOrElse.ts +1 -1
- package/src/validators/NonEmptyString.ts +4 -5
- package/src/validators/function.ts +4 -4
- package/lib/import/validators/fields/nestable/Image.d.ts +0 -62
- package/lib/import/validators/fields/nestable/Image.js +0 -76
- package/src/import/validators/fields/nestable/Image.ts +0 -147
|
@@ -0,0 +1,41 @@
|
|
|
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/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const validators_1 = require("../../../../../validators");
|
|
9
|
+
const function_2 = require("../../../../../validators/function");
|
|
10
|
+
const ImportContent_1 = require("../../ImportContent");
|
|
11
|
+
const Decoder_1 = require("./Decoder");
|
|
12
|
+
const Validator_1 = require("./Validator");
|
|
13
|
+
const defaultImage = (field) => {
|
|
14
|
+
var _a;
|
|
15
|
+
// If there is not thumbnails we expect an empty object
|
|
16
|
+
if (!((_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.thumbnails) || !field.config.thumbnails.length)
|
|
17
|
+
return validators_1.EmptyObject;
|
|
18
|
+
// If there are thumbnails, we expect an object with thumbnails as empty objects
|
|
19
|
+
return (0, function_2.withCustomError)(t.strict(field.config.thumbnails.reduce((acc, thumbnail) => ({
|
|
20
|
+
...acc,
|
|
21
|
+
[thumbnail.name]: validators_1.EmptyObject,
|
|
22
|
+
}), {})), () => "The value must be an object");
|
|
23
|
+
};
|
|
24
|
+
const ImageField = (field) => new t.Type("ImageField", (u) => Validator_1.ImageFieldValidator.is(u) &&
|
|
25
|
+
"thumbnails" in u &&
|
|
26
|
+
Validator_1.ThumbnailsValidator.is(u["thumbnails"]), (u, ctx) => {
|
|
27
|
+
return (0, function_1.pipe)(Validator_1.ImageFieldValidator.validate(u, ctx), (0, Either_1.chain)((mainImage) => {
|
|
28
|
+
const { id, dimensions, edit, copyright, alt, ...maybeThumbnails } = mainImage;
|
|
29
|
+
return (0, function_1.pipe)(Validator_1.ThumbnailsValidator.validate(maybeThumbnails, ctx), (0, Either_1.map)((thumbnails) => {
|
|
30
|
+
var _a;
|
|
31
|
+
return ({
|
|
32
|
+
...(0, Decoder_1.decodeImageField)(mainImage, mainImage, (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.constraint),
|
|
33
|
+
thumbnails: (0, Decoder_1.decodeThumbnails)(mainImage, thumbnails, field),
|
|
34
|
+
});
|
|
35
|
+
}));
|
|
36
|
+
}));
|
|
37
|
+
}, t.identity);
|
|
38
|
+
const ImageCodec = (field) => (0, function_2.withCustomError)((0, validators_1.DefaultOrElse)(defaultImage(field))(ImageField(field)), () => "An image field must be an object");
|
|
39
|
+
const ImportImage = (field) => (0, ImportContent_1.ImportContent)("Image", ImageCodec(field));
|
|
40
|
+
exports.ImportImage = ImportImage;
|
|
41
|
+
(0, tslib_1.__exportStar)(require("./model"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare type ImageField = {
|
|
2
|
+
id: string;
|
|
3
|
+
edit: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
zoom: number;
|
|
7
|
+
background?: string;
|
|
8
|
+
};
|
|
9
|
+
dimensions: {
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
};
|
|
13
|
+
copyright?: string | null;
|
|
14
|
+
alt?: string | null;
|
|
15
|
+
};
|
|
16
|
+
export declare type ImageFieldWithThumbnails = ImageField & {
|
|
17
|
+
thumbnails: Record<string, ImageField>;
|
|
18
|
+
};
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ImportLink = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
-
const io_ts_types_1 = require("io-ts-types");
|
|
7
6
|
const DocumentId_1 = require("../../../../utils/DocumentId");
|
|
8
7
|
const validators_1 = require("../../../../validators");
|
|
8
|
+
const function_1 = require("../../../../validators/function");
|
|
9
9
|
const ImportContent_1 = require("../ImportContent");
|
|
10
10
|
const LinkTypeValidator = t.type({
|
|
11
|
-
link_type: (0,
|
|
11
|
+
link_type: (0, function_1.withCustomError)(t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]), () => "The value must be `Web`, `Document` or `Media`"),
|
|
12
12
|
});
|
|
13
13
|
const WebLink = t.intersection([
|
|
14
14
|
t.type({
|
|
@@ -25,42 +25,12 @@ export declare const ImportNestable: {
|
|
|
25
25
|
value: Date | null;
|
|
26
26
|
}, Date | undefined, unknown> | import("io-ts").Type<{
|
|
27
27
|
type: "Embed";
|
|
28
|
-
value:
|
|
28
|
+
value: {
|
|
29
29
|
embed_url: string;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
version?: string | number | null;
|
|
33
|
-
title?: string;
|
|
34
|
-
author_name?: string | null;
|
|
35
|
-
author_url?: string | null;
|
|
36
|
-
provider_name?: string | null;
|
|
37
|
-
provider_url?: string | null;
|
|
38
|
-
cache_age?: string | number | null;
|
|
39
|
-
thumbnail_url?: string | null;
|
|
40
|
-
thumbnail_width?: number | null;
|
|
41
|
-
thumbnail_height?: number | null;
|
|
42
|
-
html?: string | null;
|
|
43
|
-
} & {
|
|
44
|
-
all: unknown;
|
|
45
|
-
}) | null;
|
|
46
|
-
}, ({
|
|
30
|
+
} | null;
|
|
31
|
+
}, {
|
|
47
32
|
embed_url: string;
|
|
48
|
-
|
|
49
|
-
} & {
|
|
50
|
-
version?: string | number | null;
|
|
51
|
-
title?: string;
|
|
52
|
-
author_name?: string | null;
|
|
53
|
-
author_url?: string | null;
|
|
54
|
-
provider_name?: string | null;
|
|
55
|
-
provider_url?: string | null;
|
|
56
|
-
cache_age?: string | number | null;
|
|
57
|
-
thumbnail_url?: string | null;
|
|
58
|
-
thumbnail_width?: number | null;
|
|
59
|
-
thumbnail_height?: number | null;
|
|
60
|
-
html?: string | null;
|
|
61
|
-
} & {
|
|
62
|
-
all: unknown;
|
|
63
|
-
}) | undefined, unknown> | import("io-ts").Type<{
|
|
33
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
64
34
|
type: "GeoPoint";
|
|
65
35
|
value: {
|
|
66
36
|
latitude: number;
|
|
@@ -71,12 +41,8 @@ export declare const ImportNestable: {
|
|
|
71
41
|
longitude: number;
|
|
72
42
|
} | undefined, unknown> | import("io-ts").Type<{
|
|
73
43
|
type: "Image";
|
|
74
|
-
value:
|
|
75
|
-
|
|
76
|
-
}) | null;
|
|
77
|
-
}, (import("./Image").ImageField & {
|
|
78
|
-
thumbnails: Record<string, import("./Image").ImageField>;
|
|
79
|
-
}) | undefined, unknown> | import("io-ts").Type<{
|
|
44
|
+
value: import("./Image").ImageFieldWithThumbnails | null;
|
|
45
|
+
}, import("./Image").ImageFieldWithThumbnails | undefined, unknown> | import("io-ts").Type<{
|
|
80
46
|
type: "Link";
|
|
81
47
|
value: ({
|
|
82
48
|
link_type: "Web";
|
|
@@ -133,9 +99,7 @@ export declare const ImportNestable: {
|
|
|
133
99
|
} | null;
|
|
134
100
|
}> | import("fp-ts/lib/Either").Right<{
|
|
135
101
|
type: "Image";
|
|
136
|
-
value:
|
|
137
|
-
thumbnails: Record<string, import("./Image").ImageField>;
|
|
138
|
-
}) | null;
|
|
102
|
+
value: import("./Image").ImageFieldWithThumbnails | null;
|
|
139
103
|
}> | import("fp-ts/lib/Either").Right<{
|
|
140
104
|
type: "GeoPoint";
|
|
141
105
|
value: {
|
|
@@ -144,24 +108,9 @@ export declare const ImportNestable: {
|
|
|
144
108
|
} | null;
|
|
145
109
|
}> | import("fp-ts/lib/Either").Right<{
|
|
146
110
|
type: "Embed";
|
|
147
|
-
value:
|
|
111
|
+
value: {
|
|
148
112
|
embed_url: string;
|
|
149
|
-
|
|
150
|
-
} & {
|
|
151
|
-
version?: string | number | null;
|
|
152
|
-
title?: string;
|
|
153
|
-
author_name?: string | null;
|
|
154
|
-
author_url?: string | null;
|
|
155
|
-
provider_name?: string | null;
|
|
156
|
-
provider_url?: string | null;
|
|
157
|
-
cache_age?: string | number | null;
|
|
158
|
-
thumbnail_url?: string | null;
|
|
159
|
-
thumbnail_width?: number | null;
|
|
160
|
-
thumbnail_height?: number | null;
|
|
161
|
-
html?: string | null;
|
|
162
|
-
} & {
|
|
163
|
-
all: unknown;
|
|
164
|
-
}) | null;
|
|
113
|
+
} | null;
|
|
165
114
|
}> | import("fp-ts/lib/Either").Right<{
|
|
166
115
|
type: "Date";
|
|
167
116
|
value: Date | null;
|
|
@@ -7,6 +7,7 @@ const tslib_1 = require("tslib");
|
|
|
7
7
|
(0, tslib_1.__exportStar)(require("./Embed"), exports);
|
|
8
8
|
(0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
|
|
9
9
|
(0, tslib_1.__exportStar)(require("./Image"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./Image/index"), exports);
|
|
10
11
|
(0, tslib_1.__exportStar)(require("./Link"), exports);
|
|
11
12
|
(0, tslib_1.__exportStar)(require("./Nestable"), exports);
|
|
12
13
|
(0, tslib_1.__exportStar)(require("./Number"), exports);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const DocumentId: t.Type<string, string, unknown>;
|
package/lib/utils/DocumentId.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocumentId = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const function_1 = require("../validators/function");
|
|
7
|
-
exports.DocumentId = (0,
|
|
7
|
+
exports.DocumentId = (0, function_1.withCustomError)((0, function_1.refineType)(t.string, "DocumentId", (s) => s.length === 16), () => "DocumentId must be a 16 character string");
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combineValidationResults = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const RA = (0, tslib_1.__importStar)(require("fp-ts/ReadonlyArray"));
|
|
8
|
+
/*
|
|
9
|
+
* Semigroup simply defines how to concatenate two values of the same type.
|
|
10
|
+
* In this instance, Errors from io-ts are arrays already, so we just need to concatenate them.
|
|
11
|
+
*/
|
|
12
|
+
const validationErrorsSemigroup = {
|
|
13
|
+
concat: (a, b) => [...a, ...b],
|
|
14
|
+
};
|
|
15
|
+
/*
|
|
16
|
+
* This is a helper function to combine multiple io-ts validations into one.
|
|
17
|
+
* t.array(...) works in the same way - it collects all the errors when decoding an array of values.
|
|
18
|
+
* However, it requires you to pass in a single io-ts validator as a parameter, which is not always convenient.
|
|
19
|
+
* Sometimes we have arrays of validation results received from function calls that don't have a validator instance.
|
|
20
|
+
*/
|
|
21
|
+
const combineValidationResults = (validationResults) => (0, function_1.pipe)(validationResults, RA.traverse(E.getApplicativeValidation(validationErrorsSemigroup))((validation) => validation));
|
|
22
|
+
exports.combineValidationResults = combineValidationResults;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.EmptyArray = exports.EmptyObject = exports.Boolean = exports.NumberOrNull = exports.Number = exports.StringOrNull = exports.String = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
7
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
-
const
|
|
9
|
-
exports.String = (0,
|
|
10
|
-
exports.StringOrNull = (0,
|
|
11
|
-
exports.Number = (0,
|
|
12
|
-
exports.NumberOrNull = (0,
|
|
13
|
-
exports.Boolean = (0,
|
|
8
|
+
const function_2 = require("./function");
|
|
9
|
+
exports.String = (0, function_2.withCustomError)(t.string, () => "The value must be a string");
|
|
10
|
+
exports.StringOrNull = (0, function_2.withCustomError)(t.union([t.string, t.null]), () => "The value must be a string or null");
|
|
11
|
+
exports.Number = (0, function_2.withCustomError)(t.number, () => "The value must be a number");
|
|
12
|
+
exports.NumberOrNull = (0, function_2.withCustomError)(t.union([t.number, t.null]), () => "The value must be a number or null");
|
|
13
|
+
exports.Boolean = (0, function_2.withCustomError)(t.boolean, () => "The value must be a boolean");
|
|
14
14
|
exports.EmptyObject = t.UnknownRecord.pipe(new t.Type("emptyObject", (u) => t.UnknownRecord.is(u), (u, c) => {
|
|
15
15
|
if (Object.keys(u).length > 0)
|
|
16
16
|
return t.failure(u, c, "The object is not empty.");
|
|
@@ -23,4 +23,3 @@ exports.EmptyArray = new t.Type("emptyArray", (u) => t.UnknownArray.is(u) && u.l
|
|
|
23
23
|
return t.success(new Array());
|
|
24
24
|
}));
|
|
25
25
|
}, () => []);
|
|
26
|
-
exports.AnyObject = (0, io_ts_types_1.withMessage)(t.record(t.string, t.unknown), () => "The value must be an object");
|
|
@@ -6,7 +6,7 @@ const Either_1 = require("fp-ts/lib/Either");
|
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
7
|
const BasicTypes_1 = require("./BasicTypes");
|
|
8
8
|
const DefaultOrElse = (inputValidator) => {
|
|
9
|
-
return (codec) => new t.Type("
|
|
9
|
+
return (codec) => new t.Type("DefaultOrElse", (u) => null === u || codec.is(u), (u) => {
|
|
10
10
|
if ((0, Either_1.isRight)(inputValidator.decode(u)))
|
|
11
11
|
return t.success(null);
|
|
12
12
|
return codec.decode(u);
|
|
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
5
5
|
const function_1 = require("./function");
|
|
6
|
-
exports.default = (0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0);
|
|
6
|
+
exports.default = (0, function_1.withCustomError)((0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0), () => "The value must be a non-empty string");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NullOrElse = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
const NullOrElse = (codec) => new t.Type("NullOrT", (u) => null === u || codec.is(u), (u) => {
|
|
8
|
+
if ((0, Either_1.isRight)(t.null.decode(u)))
|
|
9
|
+
return t.success(null);
|
|
10
|
+
return codec.decode(u);
|
|
11
|
+
}, (chunk) => (chunk ? codec.encode(chunk) : undefined));
|
|
12
|
+
exports.NullOrElse = NullOrElse;
|
|
@@ -19,16 +19,16 @@ export declare function addType<A, O extends object, I, T extends string>(codec:
|
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* expect(
|
|
22
|
-
*
|
|
23
|
-
* t.type({age:
|
|
22
|
+
* withCustomError(
|
|
23
|
+
* t.type({age: withCustomError(t.number, () => 'Invalid child')}),
|
|
24
24
|
* () => "Invalid parent"
|
|
25
25
|
* )
|
|
26
26
|
* ).toSubsetEqualLeft([{message: "Invalid child"}])
|
|
27
27
|
* expect(
|
|
28
|
-
*
|
|
28
|
+
* withCustomError(
|
|
29
29
|
* t.type({age: t.number}),
|
|
30
30
|
* () => "Invalid parent"
|
|
31
31
|
* )
|
|
32
32
|
* ).toSubsetEqualLeft([{message: "Invalid parent"}])
|
|
33
33
|
*/
|
|
34
|
-
export declare function
|
|
34
|
+
export declare function withCustomError<C extends t.Any>(codec: C, message: (i: t.InputOf<C>, c: t.Context) => string): C;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.withCustomError = exports.addType = exports.isEmpty = exports.objectToMap = exports.grouped = exports.formatDate = exports.formatDateTime = exports.filterDouble = exports.refineType = exports.nullable = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const function_1 = require("fp-ts/function");
|
|
@@ -66,19 +66,19 @@ exports.addType = addType;
|
|
|
66
66
|
*
|
|
67
67
|
* @example
|
|
68
68
|
* expect(
|
|
69
|
-
*
|
|
70
|
-
* t.type({age:
|
|
69
|
+
* withCustomError(
|
|
70
|
+
* t.type({age: withCustomError(t.number, () => 'Invalid child')}),
|
|
71
71
|
* () => "Invalid parent"
|
|
72
72
|
* )
|
|
73
73
|
* ).toSubsetEqualLeft([{message: "Invalid child"}])
|
|
74
74
|
* expect(
|
|
75
|
-
*
|
|
75
|
+
* withCustomError(
|
|
76
76
|
* t.type({age: t.number}),
|
|
77
77
|
* () => "Invalid parent"
|
|
78
78
|
* )
|
|
79
79
|
* ).toSubsetEqualLeft([{message: "Invalid parent"}])
|
|
80
80
|
*/
|
|
81
|
-
function
|
|
81
|
+
function withCustomError(codec, message) {
|
|
82
82
|
return (0, io_ts_types_1.withValidate)(codec, (i, c) => {
|
|
83
83
|
return fp_ts_1.either.mapLeft((errors) => {
|
|
84
84
|
if (errors.find((error) => error.message)) {
|
|
@@ -97,4 +97,4 @@ function withFallbackMessage(codec, message) {
|
|
|
97
97
|
})(codec.validate(i, c));
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
exports.
|
|
100
|
+
exports.withCustomError = withCustomError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/types-internal",
|
|
3
|
-
"version": "2.2.0-alpha
|
|
3
|
+
"version": "2.2.0-traverse.alpha-0",
|
|
4
4
|
"description": "Prismic types for Custom Types and Prismic Data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -67,7 +67,9 @@
|
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"fp-ts": "^2.11.8",
|
|
69
69
|
"io-ts": "^2.2.16",
|
|
70
|
-
"io-ts-types": "^0.5.16"
|
|
70
|
+
"io-ts-types": "^0.5.16",
|
|
71
|
+
"uuid": "^9.0.0",
|
|
72
|
+
"@types/uuid": "^9.0.2"
|
|
71
73
|
},
|
|
72
74
|
"engines": {
|
|
73
75
|
"node": ">=12.7.0"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SliceContent, WidgetContent } from "../content"
|
|
2
|
+
import type { StaticSlice, StaticWidget } from "../customtypes"
|
|
3
|
+
|
|
4
|
+
export type TraverseContentFn = <
|
|
5
|
+
C extends WidgetContent | SliceContent,
|
|
6
|
+
D extends StaticWidget | StaticSlice,
|
|
7
|
+
>({
|
|
8
|
+
path,
|
|
9
|
+
key,
|
|
10
|
+
apiId,
|
|
11
|
+
model,
|
|
12
|
+
content,
|
|
13
|
+
}: {
|
|
14
|
+
path: ContentPath
|
|
15
|
+
key: string
|
|
16
|
+
apiId: string
|
|
17
|
+
model?: D | undefined
|
|
18
|
+
content: C
|
|
19
|
+
}) => C | undefined
|
|
20
|
+
|
|
21
|
+
export type ContentPathEntry = {
|
|
22
|
+
type:
|
|
23
|
+
| "CustomType"
|
|
24
|
+
| WidgetContent["__TYPE__"]
|
|
25
|
+
| SliceContent["__TYPE__"]
|
|
26
|
+
| "GroupItem"
|
|
27
|
+
| "primary"
|
|
28
|
+
| "items"
|
|
29
|
+
key: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type ContentPath = ReadonlyArray<ContentPathEntry>
|
|
33
|
+
|
|
34
|
+
const PATH_SEPARATOR = "::"
|
|
35
|
+
export const ContentPath = {
|
|
36
|
+
serialize(path: ContentPath): string {
|
|
37
|
+
return path.map((entry) => entry.key).join(PATH_SEPARATOR)
|
|
38
|
+
},
|
|
39
|
+
}
|
package/src/common/Asset.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
export type AssetId = string
|
|
2
|
-
|
|
3
1
|
export type Asset = {
|
|
4
|
-
id:
|
|
2
|
+
id: string
|
|
5
3
|
last_modified: string
|
|
6
4
|
kind: "image" | "all"
|
|
7
5
|
filename?: string
|
|
8
6
|
extension?: string
|
|
9
|
-
size?:
|
|
7
|
+
size?: number
|
|
10
8
|
origin_url: string
|
|
11
9
|
url: string
|
|
12
10
|
width?: number
|
|
@@ -17,7 +15,8 @@ export type Asset = {
|
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export const getAssetOrThrow =
|
|
20
|
-
(assets: Record<
|
|
18
|
+
(assets: Record<Asset["id"], Asset | undefined>) =>
|
|
19
|
+
(assetId: Asset["id"]) => {
|
|
21
20
|
const asset = assets[assetId]
|
|
22
21
|
if (!asset) {
|
|
23
22
|
throw new Error(`Missing asset with id '${assetId}'!`)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// This type represents response format from oEmbed API
|
|
2
|
+
export type Embed = {
|
|
3
|
+
type: string
|
|
4
|
+
version?: string | null
|
|
5
|
+
author_name?: string | null
|
|
6
|
+
author_url?: string | null
|
|
7
|
+
provider_name?: string | null
|
|
8
|
+
provider_url?: string | null
|
|
9
|
+
cache_age?: string | null
|
|
10
|
+
thumbnail_url?: string | null
|
|
11
|
+
thumbnail_width?: number | null
|
|
12
|
+
thumbnail_height?: number | null
|
|
13
|
+
html?: string | null
|
|
14
|
+
title?: string | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getEmbedOrThrow =
|
|
18
|
+
(embeds: Record<string, Embed | undefined>) => (embedUrl: string) => {
|
|
19
|
+
const embed = embeds[embedUrl]
|
|
20
|
+
if (!embed) throw new Error(`Missing embed with url '${embedUrl}'`)
|
|
21
|
+
return embed
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
import { validate as validateUUID } from "uuid"
|
|
3
|
+
|
|
4
|
+
import { withCustomError } from "../validators/function"
|
|
5
|
+
|
|
6
|
+
interface UUIDBrand {
|
|
7
|
+
readonly UUID: unique symbol
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const UUID = withCustomError(
|
|
11
|
+
t.brand(
|
|
12
|
+
t.string,
|
|
13
|
+
(s): s is t.Branded<string, UUIDBrand> => validateUUID(s),
|
|
14
|
+
"UUID",
|
|
15
|
+
),
|
|
16
|
+
() => "The value must be a valid UUID",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
export type UUID = t.TypeOf<typeof UUID>
|
package/src/common/index.ts
CHANGED
package/src/content/Document.ts
CHANGED
|
@@ -3,8 +3,20 @@ import { isLeft, isRight } from "fp-ts/lib/Either"
|
|
|
3
3
|
import { pipe } from "fp-ts/lib/function"
|
|
4
4
|
import * as t from "io-ts"
|
|
5
5
|
|
|
6
|
+
import { type TraverseContentFn, ContentPath } from "../_internal/utils"
|
|
6
7
|
import { WidgetKey } from "../common"
|
|
7
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type StaticCustomType,
|
|
10
|
+
type StaticWidget,
|
|
11
|
+
flattenStaticWidgets,
|
|
12
|
+
} from "../customtypes"
|
|
13
|
+
import {
|
|
14
|
+
SliceContent,
|
|
15
|
+
traverseGroupContent,
|
|
16
|
+
traverseSlices,
|
|
17
|
+
WidgetContent,
|
|
18
|
+
WidgetLegacy,
|
|
19
|
+
} from "./fields"
|
|
8
20
|
import {
|
|
9
21
|
defaultCtx,
|
|
10
22
|
FieldOrSliceType,
|
|
@@ -133,3 +145,86 @@ export const DocumentLegacy = {
|
|
|
133
145
|
parse: parseLegacyDocument,
|
|
134
146
|
encode: encodeToLegacyDocument,
|
|
135
147
|
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
*
|
|
151
|
+
* @param model: can be optional if we simply want to loop through the content without any consideration for the attached model
|
|
152
|
+
* @param document: The content we actually want to iterate on in an immutable fashion
|
|
153
|
+
* @param transform: A user function that provides a way to transform any kind of content wherever it is in a structured Prismic object content.
|
|
154
|
+
* @returns a transformed document with the user's transformation applied with the transform function
|
|
155
|
+
*/
|
|
156
|
+
export function traverseDocument(document: Document, model?: StaticCustomType) {
|
|
157
|
+
return (transform: TraverseContentFn): Document => {
|
|
158
|
+
const fieldDefs =
|
|
159
|
+
model &&
|
|
160
|
+
flattenStaticWidgets(model).reduce<Record<string, StaticWidget>>(
|
|
161
|
+
(acc, [key, def]) => ({ ...acc, [key]: def }),
|
|
162
|
+
{},
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
return Object.entries(document).reduce((acc, [key, content]) => {
|
|
166
|
+
const fieldDef = fieldDefs && fieldDefs[key]
|
|
167
|
+
|
|
168
|
+
const path = [{ key, type: content.__TYPE__ }]
|
|
169
|
+
const transformedWidgetContent = (() => {
|
|
170
|
+
switch (content.__TYPE__) {
|
|
171
|
+
case "SliceContentType":
|
|
172
|
+
return traverseSlices({
|
|
173
|
+
path,
|
|
174
|
+
model:
|
|
175
|
+
fieldDef?.type === "Slices" || fieldDef?.type === "Choice"
|
|
176
|
+
? fieldDef
|
|
177
|
+
: undefined,
|
|
178
|
+
content,
|
|
179
|
+
})(transform)
|
|
180
|
+
case "GroupContentType":
|
|
181
|
+
return traverseGroupContent({
|
|
182
|
+
path,
|
|
183
|
+
model: fieldDef?.type === "Group" ? fieldDef : undefined,
|
|
184
|
+
content,
|
|
185
|
+
})(transform)
|
|
186
|
+
default:
|
|
187
|
+
return content
|
|
188
|
+
}
|
|
189
|
+
})()
|
|
190
|
+
|
|
191
|
+
const transformedWidget =
|
|
192
|
+
transformedWidgetContent &&
|
|
193
|
+
transform({
|
|
194
|
+
path,
|
|
195
|
+
key,
|
|
196
|
+
apiId: key,
|
|
197
|
+
model: fieldDef,
|
|
198
|
+
content: transformedWidgetContent,
|
|
199
|
+
})
|
|
200
|
+
return {
|
|
201
|
+
...acc,
|
|
202
|
+
...(transformedWidget ? { [key]: transformedWidget } : {}),
|
|
203
|
+
}
|
|
204
|
+
}, {})
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The goal is to be able to collect all widgets or slices of a given type at any level of nesting inside a prismic content
|
|
210
|
+
*
|
|
211
|
+
* @param document parsed prismic content
|
|
212
|
+
* @param is typeguard to match specifically the type of widget we want to collect
|
|
213
|
+
* @returns a record containing the path of the widget as key and the typed collected content as value
|
|
214
|
+
*/
|
|
215
|
+
export function collectWidgets<W extends WidgetContent | SliceContent>(
|
|
216
|
+
document: Document,
|
|
217
|
+
is: (
|
|
218
|
+
content: WidgetContent | SliceContent,
|
|
219
|
+
path: ContentPath,
|
|
220
|
+
) => content is W,
|
|
221
|
+
): Record<string, W> {
|
|
222
|
+
const collected: Record<string, W> = {}
|
|
223
|
+
|
|
224
|
+
traverseDocument(document)(({ content, path }) => {
|
|
225
|
+
const key = ContentPath.serialize(path)
|
|
226
|
+
if (is(content, path)) collected[key] = content
|
|
227
|
+
return content
|
|
228
|
+
})
|
|
229
|
+
return collected
|
|
230
|
+
}
|