@prismicio/types-internal 2.2.0-traverse.alpha-6 → 2.2.0-traverse.alpha-7

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.
Files changed (62) hide show
  1. package/lib/_internal/utils.d.ts +3 -3
  2. package/lib/content/Document.d.ts +1248 -32
  3. package/lib/content/fields/GroupContent.d.ts +273 -7
  4. package/lib/content/fields/WidgetContent.d.ts +1248 -32
  5. package/lib/content/fields/nestable/NestableContent.d.ts +156 -4
  6. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +582 -28
  7. package/lib/content/fields/nestable/RichTextContent/Blocks.js +29 -46
  8. package/lib/content/fields/nestable/RichTextContent/index.d.ts +195 -5
  9. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +314 -10
  10. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +3 -5
  11. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +117 -3
  12. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +312 -8
  13. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +312 -8
  14. package/lib/content/fields/slices/Slice/index.d.ts +702 -18
  15. package/lib/content/fields/slices/SliceItem.d.ts +702 -18
  16. package/lib/content/fields/slices/SlicesContent.d.ts +936 -24
  17. package/lib/content/fields/slices/SlicesContent.js +2 -4
  18. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +0 -5
  19. package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
  20. package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
  21. package/lib/import/converters/fields/nestable/Image.d.ts +25 -3
  22. package/lib/import/converters/fields/nestable/Image.js +21 -25
  23. package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
  24. package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
  25. package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
  26. package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
  27. package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
  28. package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
  29. package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
  30. package/lib/import/converters/fields/nestable/RichText/textBlock.js +41 -0
  31. package/lib/import/converters/fields/nestable/index.d.ts +1 -1
  32. package/lib/import/converters/fields/nestable/index.js +1 -1
  33. package/lib/import/validators/fields/ImportContent.js +3 -3
  34. package/lib/import/validators/fields/ImportField.d.ts +1 -1
  35. package/lib/import/validators/fields/ImportSlices/ImportSlices.js +4 -3
  36. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +1 -1
  37. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +1 -1
  38. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +20 -14
  39. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +16 -2
  40. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +7 -5
  41. package/lib/import/validators/fields/nestable/Nestable.d.ts +1 -1
  42. package/lib/validators/DefaultOrElse.js +3 -3
  43. package/package.json +1 -1
  44. package/src/_internal/utils.ts +3 -3
  45. package/src/content/fields/nestable/RichTextContent/Blocks.ts +48 -58
  46. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +4 -9
  47. package/src/content/fields/slices/SlicesContent.ts +4 -6
  48. package/src/customtypes/widgets/slices/CompositeSlice.ts +0 -6
  49. package/src/import/converters/fields/nestable/Image.ts +10 -22
  50. package/src/import/converters/fields/nestable/RichText/embedBlock.ts +17 -0
  51. package/src/import/converters/fields/nestable/RichText/imageBlock.ts +17 -0
  52. package/src/import/converters/fields/nestable/RichText/index.ts +23 -0
  53. package/src/import/converters/fields/nestable/RichText/textBlock.ts +48 -0
  54. package/src/import/converters/fields/nestable/index.ts +1 -1
  55. package/src/import/validators/fields/ImportContent.ts +3 -3
  56. package/src/import/validators/fields/ImportSlices/ImportSlices.ts +7 -5
  57. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +1 -1
  58. package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +38 -25
  59. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +9 -5
  60. package/src/validators/DefaultOrElse.ts +4 -4
  61. package/src/import/converters/fields/nestable/RichText.ts +0 -62
  62. /package/src/import/converters/fields/nestable/{GeooPoint.ts → GeoPoint.ts} +0 -0
@@ -91,10 +91,8 @@ function findSliceModel(slicesPath, model, content) {
91
91
  if ((0, customtypes_1.isCompositeSlice)(defaultModel)) {
92
92
  return {
93
93
  type: "Slice",
94
- fields: {
95
- "non-repeat": defaultModel["non-repeat"] || {},
96
- repeat: defaultModel.repeat || {},
97
- },
94
+ "non-repeat": defaultModel["non-repeat"] || {},
95
+ repeat: defaultModel.repeat || {},
98
96
  };
99
97
  }
100
98
  if ((0, customtypes_1.isLegacySlice)(defaultModel)) {
@@ -1,5 +1,4 @@
1
1
  import * as t from "io-ts";
2
- import type { PickOnly } from "../../../_internal/utils";
3
2
  import type { DynamicSlice, StaticSlice } from "./Slice";
4
3
  export declare const CompositeSliceType = "Slice";
5
4
  export declare const CompositeSliceConfig: t.ExactC<t.PartialC<{
@@ -332,8 +331,4 @@ export declare const CompositeSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
332
331
  }>>;
333
332
  }>]>>;
334
333
  export declare type CompositeSlice = t.TypeOf<typeof CompositeSlice>;
335
- export declare type CompositeSliceFields = {
336
- type: "Slice";
337
- fields: PickOnly<CompositeSlice, "non-repeat" | "repeat">;
338
- };
339
334
  export declare function isCompositeSlice(slice: DynamicSlice | StaticSlice): slice is CompositeSlice;
@@ -0,0 +1,3 @@
1
+ import type { GeoPointContent } from "../../../../content";
2
+ import type { ImportGeoPoint } from "../../../validators";
3
+ export declare const geopointConverter: (field: ImportGeoPoint["value"]) => GeoPointContent | undefined;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.geopointConverter = void 0;
4
+ const geopointConverter = (field) => {
5
+ if (field === null)
6
+ return;
7
+ return {
8
+ position: {
9
+ lat: field.latitude,
10
+ lng: field.longitude,
11
+ },
12
+ __TYPE__: "GeoPointContent",
13
+ };
14
+ };
15
+ exports.geopointConverter = geopointConverter;
@@ -1,6 +1,28 @@
1
1
  import type { Asset } from "../../../../common";
2
- import type { ImageContent, ImageContentView } from "../../../../content";
3
- import type { ImportImage } from "../../../validators";
2
+ import type { ImageContent } from "../../../../content";
3
+ import type { ImageField, ImportImage } from "../../../validators";
4
4
  import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks";
5
- export declare const imageBlockConverter: (imageBlock: ImportImageBlock, assets: Record<Asset["id"], Asset | undefined>) => ImageContentView;
5
+ export declare function convertImageView<Input extends ImageField | ImportImageBlock>(inputImage: Input, image: Asset): {
6
+ origin: {
7
+ id: string;
8
+ url: string;
9
+ width: number;
10
+ height: number;
11
+ };
12
+ width: number;
13
+ height: number;
14
+ edit: {
15
+ zoom: number;
16
+ crop: {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ background: string;
21
+ };
22
+ } & {
23
+ url?: string;
24
+ credits?: string | null;
25
+ alt?: string | null;
26
+ provider?: string | null | undefined;
27
+ };
6
28
  export declare const imageConverter: (imageField: ImportImage["value"], assets: Record<Asset["id"], Asset | undefined>) => ImageContent | undefined;
@@ -1,43 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.imageConverter = exports.imageBlockConverter = void 0;
3
+ exports.imageConverter = exports.convertImageView = void 0;
4
4
  const common_1 = require("../../../../common");
5
5
  const Objects_1 = require("../../../../utils/Objects");
6
- function convertImage(inputImage, image) {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
6
+ function convertImageView(inputImage, image) {
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
8
8
  // We can do that because anyway all properties being read
9
9
  const imageField = {
10
10
  ...inputImage,
11
- edit: "edit" in inputImage
12
- ? inputImage.edit
13
- : {
14
- x: 0,
15
- y: 0,
16
- zoom: 1,
17
- },
18
- dimensions: "dimensions" in inputImage ? inputImage.dimensions : {},
11
+ edit: {
12
+ x: 0,
13
+ y: 0,
14
+ zoom: 1,
15
+ ...inputImage.edit,
16
+ },
17
+ dimensions: (_a = inputImage.dimensions) !== null && _a !== void 0 ? _a : {},
19
18
  };
20
19
  return (0, Objects_1.withOptionals)({
21
20
  origin: {
22
21
  id: image.id,
23
22
  url: image.origin_url,
24
23
  // All images returned form Asset API should have width and height properties.
25
- width: (_a = image.width) !== null && _a !== void 0 ? _a : 0,
26
- height: (_b = image.height) !== null && _b !== void 0 ? _b : 0,
24
+ width: (_b = image.width) !== null && _b !== void 0 ? _b : 0,
25
+ height: (_c = image.height) !== null && _c !== void 0 ? _c : 0,
27
26
  },
28
27
  // All images returned form Asset API should have width and height properties.
29
28
  // Image width and height will be only applied if there are no constraints and user didn't overwrite it
30
- width: (_e = (_d = (_c = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : image.width) !== null && _e !== void 0 ? _e : 0,
31
- height: (_h = (_g = (_f = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _f === void 0 ? void 0 : _f.height) !== null && _g !== void 0 ? _g : image.height) !== null && _h !== void 0 ? _h : 0,
29
+ width: (_f = (_e = (_d = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _d === void 0 ? void 0 : _d.width) !== null && _e !== void 0 ? _e : image.width) !== null && _f !== void 0 ? _f : 0,
30
+ height: (_j = (_h = (_g = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : image.height) !== null && _j !== void 0 ? _j : 0,
32
31
  // If edit is not provided, we crop constraint width and height from the left upper corner.
33
32
  // WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
34
33
  edit: {
35
- zoom: (_k = (_j = imageField.edit) === null || _j === void 0 ? void 0 : _j.zoom) !== null && _k !== void 0 ? _k : 1,
34
+ zoom: (_l = (_k = imageField.edit) === null || _k === void 0 ? void 0 : _k.zoom) !== null && _l !== void 0 ? _l : 1,
36
35
  crop: {
37
- x: (_m = (_l = imageField.edit) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
38
- y: (_p = (_o = imageField.edit) === null || _o === void 0 ? void 0 : _o.y) !== null && _p !== void 0 ? _p : 0,
36
+ x: (_o = (_m = imageField.edit) === null || _m === void 0 ? void 0 : _m.x) !== null && _o !== void 0 ? _o : 0,
37
+ y: (_q = (_p = imageField.edit) === null || _p === void 0 ? void 0 : _p.y) !== null && _q !== void 0 ? _q : 0,
39
38
  },
40
- background: (_r = (_q = imageField.edit) === null || _q === void 0 ? void 0 : _q.background) !== null && _r !== void 0 ? _r : (image.extension === "png" ? "transparent" : "#ffffff"),
39
+ background: (_s = (_r = imageField.edit) === null || _r === void 0 ? void 0 : _r.background) !== null && _s !== void 0 ? _s : (image.extension === "png" ? "transparent" : "#ffffff"),
41
40
  },
42
41
  url: image.url,
43
42
  }, [
@@ -45,25 +44,22 @@ function convertImage(inputImage, image) {
45
44
  ["credits", (imageField === null || imageField === void 0 ? void 0 : imageField.copyright) || image.credits],
46
45
  ]);
47
46
  }
47
+ exports.convertImageView = convertImageView;
48
48
  function convertThumbnails(imageField, assets) {
49
49
  return Object.entries(imageField.thumbnails).reduce((acc, [thumbnailName, thumbnail]) => {
50
50
  return {
51
51
  ...acc,
52
- [thumbnailName]: convertImage(thumbnail, (0, common_1.getAssetOrThrow)(assets)(thumbnail.id)),
52
+ [thumbnailName]: convertImageView(thumbnail, (0, common_1.getAssetOrThrow)(assets)(thumbnail.id)),
53
53
  };
54
54
  }, {});
55
55
  }
56
- const imageBlockConverter = (imageBlock, assets) => {
57
- return convertImage(imageBlock, (0, common_1.getAssetOrThrow)(assets)(imageBlock.id));
58
- };
59
- exports.imageBlockConverter = imageBlockConverter;
60
56
  // All assets from `imageField` must be present in `assets`
61
57
  // If not then function will throw an error
62
58
  const imageConverter = (imageField, assets) => {
63
59
  if (!imageField)
64
60
  return;
65
61
  return {
66
- ...convertImage(imageField, (0, common_1.getAssetOrThrow)(assets)(imageField.id)),
62
+ ...convertImageView(imageField, (0, common_1.getAssetOrThrow)(assets)(imageField.id)),
67
63
  thumbnails: convertThumbnails(imageField, assets),
68
64
  __TYPE__: "ImageContent",
69
65
  };
@@ -0,0 +1,4 @@
1
+ import type { Embed } from "../../../../../common";
2
+ import type { EmbedBlock } from "../../../../../content";
3
+ import type { ImportEmbedBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
4
+ export declare function embedBlockConverter(block: ImportEmbedBlock, embeds: Record<string, Embed | undefined>): EmbedBlock;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.embedBlockConverter = void 0;
4
+ const Embed_1 = require("../Embed");
5
+ function embedBlockConverter(block, embeds) {
6
+ const embedData = (0, Embed_1.embedConverter)(block.oembed, embeds);
7
+ if (!embedData)
8
+ throw new Error("Failed to convert embed data");
9
+ return {
10
+ type: block.type,
11
+ data: embedData,
12
+ };
13
+ }
14
+ exports.embedBlockConverter = embedBlockConverter;
@@ -0,0 +1,4 @@
1
+ import { Asset } from "../../../../../common";
2
+ import type { ImageBlock } from "../../../../../content";
3
+ import type { ImportImageBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
4
+ export declare function imageBlockConverter(block: ImportImageBlock, assets: Record<Asset["id"], Asset | undefined>): ImageBlock;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imageBlockConverter = void 0;
4
+ const common_1 = require("../../../../../common");
5
+ const Image_1 = require("../Image");
6
+ function imageBlockConverter(block, assets) {
7
+ return {
8
+ type: block.type,
9
+ data: (0, Image_1.convertImageView)(block, (0, common_1.getAssetOrThrow)(assets)(block.id)),
10
+ };
11
+ }
12
+ exports.imageBlockConverter = imageBlockConverter;
@@ -0,0 +1,4 @@
1
+ import type { Asset, Embed } from "../../../../../common";
2
+ import type { RichTextContent } from "../../../../../content";
3
+ import type { ImportRichText } from "../../../../validators";
4
+ export declare const richTextConverter: (richTextField: ImportRichText["value"], assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>) => RichTextContent | undefined;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.richTextConverter = void 0;
4
+ const content_1 = require("../../../../../content");
5
+ const embedBlock_1 = require("./embedBlock");
6
+ const imageBlock_1 = require("./imageBlock");
7
+ const textBlock_1 = require("./textBlock");
8
+ const richTextConverter = (richTextField, assets, embeds) => {
9
+ if (richTextField === null)
10
+ return;
11
+ return {
12
+ __TYPE__: content_1.RichTextContentType,
13
+ value: richTextField.map((block) => {
14
+ if (block.type === "image")
15
+ return (0, imageBlock_1.imageBlockConverter)(block, assets);
16
+ else if (block.type === "embed")
17
+ return (0, embedBlock_1.embedBlockConverter)(block, embeds);
18
+ return (0, textBlock_1.textBlockConverter)(block, assets);
19
+ }),
20
+ };
21
+ };
22
+ exports.richTextConverter = richTextConverter;
@@ -0,0 +1,4 @@
1
+ import type { Asset } from "../../../../../common";
2
+ import type { TextBlock } from "../../../../../content";
3
+ import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
4
+ export declare function textBlockConverter(block: ImportTextBlock, assets: Record<Asset["id"], Asset | undefined>): TextBlock;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.textBlockConverter = void 0;
4
+ const Link_1 = require("../Link");
5
+ function textBlockConverter(block, assets) {
6
+ return {
7
+ type: block.type,
8
+ content: {
9
+ text: block.text,
10
+ ...(() => {
11
+ if (block.spans) {
12
+ const convertedSpans = spansConverter(block.spans, assets);
13
+ if (!convertedSpans)
14
+ return {};
15
+ return { spans: convertedSpans };
16
+ }
17
+ return {};
18
+ })(),
19
+ },
20
+ ...(block.direction ? { direction: block.direction } : {}),
21
+ };
22
+ }
23
+ exports.textBlockConverter = textBlockConverter;
24
+ function spansConverter(spans, assets) {
25
+ return spans.map((span) => {
26
+ return {
27
+ type: span.type,
28
+ start: span.start,
29
+ end: span.end,
30
+ ...(() => {
31
+ if (span.type === "hyperlink") {
32
+ const convertedLinkContent = (0, Link_1.linkConverter)(span.data, assets);
33
+ if (!convertedLinkContent)
34
+ return {};
35
+ return { data: convertedLinkContent === null || convertedLinkContent === void 0 ? void 0 : convertedLinkContent.value };
36
+ }
37
+ return {};
38
+ })(),
39
+ };
40
+ });
41
+ }
@@ -2,7 +2,7 @@ export * from "./Boolean";
2
2
  export * from "./Color";
3
3
  export * from "./Date";
4
4
  export * from "./Embed";
5
- export * from "./GeooPoint";
5
+ export * from "./GeoPoint";
6
6
  export * from "./Image";
7
7
  export * from "./Link";
8
8
  export * from "./Nestable";
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
5
5
  (0, tslib_1.__exportStar)(require("./Color"), exports);
6
6
  (0, tslib_1.__exportStar)(require("./Date"), exports);
7
7
  (0, tslib_1.__exportStar)(require("./Embed"), exports);
8
- (0, tslib_1.__exportStar)(require("./GeooPoint"), exports);
8
+ (0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
9
9
  (0, tslib_1.__exportStar)(require("./Image"), exports);
10
10
  (0, tslib_1.__exportStar)(require("./Link"), exports);
11
11
  (0, tslib_1.__exportStar)(require("./Nestable"), exports);
@@ -6,12 +6,12 @@ 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
8
  const Objects_1 = require("../../../utils/Objects");
9
- const ImportContent = (type, valueCodec) => new t.Type("ImportField", (u) => {
9
+ const ImportContent = (type, valueCodec) => new t.Type(`ImportField: ${valueCodec.name}`, (u) => {
10
10
  if (!(0, Objects_1.isObject)(u))
11
11
  return false;
12
12
  return type === u["type"] && valueCodec.is(u["value"]);
13
- }, (u) => {
14
- return (0, function_1.pipe)(valueCodec.decode(u), fp_ts_1.either.map((decodedValue) => {
13
+ }, (u, c) => {
14
+ return (0, function_1.pipe)(valueCodec.validate(u, c), fp_ts_1.either.map((decodedValue) => {
15
15
  return {
16
16
  type,
17
17
  value: decodedValue,
@@ -52,7 +52,7 @@ export declare const ImportField: {
52
52
  } | undefined, unknown> | import("io-ts").Type<{
53
53
  type: "StructuredText";
54
54
  value: import("./nestable").ImportBlock[] | null;
55
- }, unknown[] | undefined, unknown> | import("io-ts").Type<{
55
+ }, import("./nestable").ImportBlock[] | undefined, unknown> | import("io-ts").Type<{
56
56
  type: "Number";
57
57
  value: number | null;
58
58
  }, number | undefined, unknown> | import("io-ts").Type<{
@@ -13,8 +13,9 @@ const ImportSlices = (staticSlices) => {
13
13
  const supportedSlices = (0, utils_1.extractSupportedSlices)(staticSlices);
14
14
  // For now we only support the SharedSlice, however if we want to support more in the future
15
15
  // we would have to change the codec here to something like this: t.array(t.union([ImportSharedSlice(sharedSlices), NewSliceCodec(newSliceCustomTypes)])).
16
- const SlicesArrayCodec = t.array((0, SharedSlice_1.SharedSlice)(supportedSlices));
17
- return (0, ImportContent_1.ImportContent)("Slices", (0, validators_1.EmptyObjectOrElse)(new t.Type("ImportSlices", (u) => SlicesArrayCodec.is(u), (u, c) => {
16
+ const SharedSliceCodec = (0, SharedSlice_1.SharedSlice)(supportedSlices);
17
+ const SlicesArrayCodec = t.array(SharedSliceCodec);
18
+ return (0, ImportContent_1.ImportContent)("Slices", (0, validators_1.EmptyArrayOrElse)(new t.ArrayType(SlicesArrayCodec.name, (u) => SlicesArrayCodec.is(u), (u, c) => {
18
19
  return (0, function_1.pipe)(SlicesArrayCodec.validate(u, c), E.chain((slices) => {
19
20
  // This part might not make sense for all Slice types in the future, but for now we only support the SharedSlice
20
21
  // In case we support more in the future, we would have to filter only the relevant type for this check
@@ -24,6 +25,6 @@ const ImportSlices = (staticSlices) => {
24
25
  }
25
26
  return t.success(slices);
26
27
  }));
27
- }, t.identity)));
28
+ }, t.identity, SharedSliceCodec)));
28
29
  };
29
30
  exports.ImportSlices = ImportSlices;
@@ -58,8 +58,8 @@ const SharedSliceContentEntry = (sliceName, sliceContentField, sliceFieldModels)
58
58
  ]), E.mapLeft((errors) => errors.map((error) => {
59
59
  const context = [
60
60
  ...c,
61
- ...error.context.filter(({ key }) => !!key),
62
61
  { key, actual: content, type: codec },
62
+ ...error.context.slice(1), // We ignore the first context element with "" key coming from ImportNestable decoder
63
63
  ];
64
64
  const updatedError = { ...error, context };
65
65
  return updatedError;
@@ -20,5 +20,5 @@ export declare const ImportRichText: (customType?: ({
20
20
  }) | undefined) => t.Type<{
21
21
  type: "StructuredText";
22
22
  value: ImportBlock[] | null;
23
- }, unknown[] | undefined, unknown>;
23
+ }, ImportBlock[] | undefined, unknown>;
24
24
  export declare type ImportRichText = t.TypeOf<ReturnType<typeof ImportRichText>>;
@@ -2,25 +2,31 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImportRichText = void 0;
4
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");
5
7
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
8
  const validators_1 = require("../../../../../validators");
7
- const function_1 = require("../../../../../validators/function");
9
+ const function_2 = require("../../../../../validators/function");
8
10
  const ImportContent_1 = require("../../ImportContent");
9
11
  const ImportBlock_1 = require("./ImportBlock");
10
- const ImportRichText = (customType) => (0, ImportContent_1.ImportContent)("StructuredText", (0, validators_1.EmptyArrayOrElse)((0, function_1.withCustomError)(t.array(t.unknown).pipe(new t.Type("RichTextField", (u) => t.array((0, ImportBlock_1.ImportBlock)([])).is(u), (u, c) => {
12
+ const ImportRichText = (customType) => {
11
13
  var _a, _b, _c, _d;
12
14
  const single = (_b = (_a = customType === null || customType === void 0 ? void 0 : customType.config) === null || _a === void 0 ? void 0 : _a.single) === null || _b === void 0 ? void 0 : _b.split(",");
13
15
  const multi = (_d = (_c = customType === null || customType === void 0 ? void 0 : customType.config) === null || _c === void 0 ? void 0 : _c.multi) === null || _d === void 0 ? void 0 : _d.split(",");
14
- if (multi) {
15
- return t.array((0, ImportBlock_1.ImportBlock)(multi)).validate(u, c);
16
- }
17
- else if (single) {
18
- return u.length > 1
19
- ? t.failure(u, c, "This field only allows one block")
20
- : t.array((0, ImportBlock_1.ImportBlock)(single)).validate(u, c);
21
- }
22
- else {
23
- throw new Error("Rich text config must have either a 'single' or 'multi' field defined");
24
- }
25
- }, t.identity)), () => "Rich text field must be an array")));
16
+ const allowedBlockTypes = multi || single;
17
+ const isSingleBlockAllowed = multi === undefined && single !== undefined;
18
+ const BlockCodec = (0, ImportBlock_1.ImportBlock)(allowedBlockTypes !== null && allowedBlockTypes !== void 0 ? allowedBlockTypes : []);
19
+ const RichTextArrayCodec = (0, function_2.withCustomError)(t.array(BlockCodec), () => "Rich text field must be an array");
20
+ return (0, ImportContent_1.ImportContent)("StructuredText", (0, validators_1.EmptyArrayOrElse)(new t.ArrayType(RichTextArrayCodec.name, (u) => RichTextArrayCodec.is(u), (u, c) => {
21
+ if (allowedBlockTypes === undefined) {
22
+ throw new Error("Invalid custom type for the rich text field: the model is missing a 'single' or 'multi' field defining a list of allowed block types");
23
+ }
24
+ return (0, function_1.pipe)(RichTextArrayCodec.validate(u, c), E.chain((blocks) => {
25
+ if (isSingleBlockAllowed && blocks.length > 1) {
26
+ return t.failure(blocks, c, "This field only allows one block");
27
+ }
28
+ return t.success(blocks);
29
+ }));
30
+ }, t.identity, BlockCodec)));
31
+ };
26
32
  exports.ImportRichText = ImportRichText;
@@ -1,8 +1,22 @@
1
1
  import * as t from "io-ts";
2
2
  export declare const ImportImageBlockType: t.LiteralC<"image">;
3
3
  export declare type ImportImageBlockType = t.TypeOf<typeof ImportImageBlockType>;
4
- export declare const ImportImageBlock: t.ExactC<t.TypeC<{
4
+ export declare const ImportImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
5
5
  type: t.LiteralC<"image">;
6
+ }>, t.IntersectionC<[t.TypeC<{
6
7
  id: t.StringC;
7
- }>>;
8
+ }>, t.PartialC<{
9
+ dimensions: t.PartialC<{
10
+ width: t.NumberC;
11
+ height: t.NumberC;
12
+ }>;
13
+ edit: t.PartialC<{
14
+ x: t.NumberC;
15
+ y: t.NumberC;
16
+ zoom: t.NumberC;
17
+ background: t.StringC;
18
+ }>;
19
+ copyright: t.UnionC<[t.StringC, t.NullC]>;
20
+ alt: t.UnionC<[t.StringC, t.NullC]>;
21
+ }>]>]>>;
8
22
  export declare type ImportImageBlock = t.TypeOf<typeof ImportImageBlock>;
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImportImageBlock = exports.ImportImageBlockType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
- const validators_1 = require("../../../../../../validators");
6
+ const validators_1 = require("../../Image/validators");
7
7
  exports.ImportImageBlockType = t.literal("image");
8
- exports.ImportImageBlock = t.strict({
9
- type: exports.ImportImageBlockType,
10
- id: validators_1.String,
11
- });
8
+ exports.ImportImageBlock = t.exact(t.intersection([
9
+ t.type({
10
+ type: exports.ImportImageBlockType,
11
+ }),
12
+ validators_1.ImportImageView,
13
+ ]));
@@ -62,7 +62,7 @@ export declare const ImportNestable: {
62
62
  } | undefined, unknown> | import("io-ts").Type<{
63
63
  type: "StructuredText";
64
64
  value: import("./ImportRichText").ImportBlock[] | null;
65
- }, unknown[] | undefined, unknown> | import("io-ts").Type<{
65
+ }, import("./ImportRichText").ImportBlock[] | undefined, unknown> | import("io-ts").Type<{
66
66
  type: "Number";
67
67
  value: number | null;
68
68
  }, number | undefined, unknown> | import("io-ts").Type<{
@@ -6,10 +6,10 @@ 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("DefaultOrElse", (u) => null === u || codec.is(u), (u) => {
10
- if ((0, Either_1.isRight)(inputValidator.decode(u)))
9
+ return (codec) => new t.Type(`DefaultOrElse<${inputValidator.name}, ${codec.name}>`, (u) => null === u || codec.is(u), (u, c) => {
10
+ if ((0, Either_1.isRight)(inputValidator.validate(u, c)))
11
11
  return t.success(null);
12
- return codec.decode(u);
12
+ return codec.validate(u, c);
13
13
  }, (chunk) => (chunk ? codec.encode(chunk) : undefined));
14
14
  };
15
15
  exports.DefaultOrElse = DefaultOrElse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.2.0-traverse.alpha-6",
3
+ "version": "2.2.0-traverse.alpha-7",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -4,7 +4,7 @@ import type {
4
4
  WidgetContent,
5
5
  } from "../content"
6
6
  import type {
7
- CompositeSliceFields,
7
+ CompositeSlice,
8
8
  Group,
9
9
  NestableWidget,
10
10
  StaticSlices,
@@ -18,7 +18,7 @@ export type PickOnly<T, K extends keyof T> = Pick<T, K> & {
18
18
 
19
19
  export type TraverseSliceContentFn = <
20
20
  S extends SliceItemContent | SharedSliceItemContent,
21
- D extends VariationFields | CompositeSliceFields | Group | NestableWidget,
21
+ D extends VariationFields | CompositeSlice | Group | NestableWidget,
22
22
  >({
23
23
  path,
24
24
  key,
@@ -91,5 +91,5 @@ export const ContentPath = {
91
91
  export type SliceModel =
92
92
  | VariationFields
93
93
  | NestableWidget
94
- | CompositeSliceFields
94
+ | CompositeSlice
95
95
  | Group