@prismicio/types-internal 2.7.0 → 2.9.0-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.
Files changed (44) hide show
  1. package/lib/_internal/utils.d.ts +3 -2
  2. package/lib/content/Document.d.ts +1457 -149
  3. package/lib/content/LegacyContentCtx.d.ts +15 -0
  4. package/lib/content/fields/RepeatableContent.d.ts +236 -0
  5. package/lib/content/fields/RepeatableContent.js +97 -0
  6. package/lib/content/fields/WidgetContent.d.ts +1465 -157
  7. package/lib/content/fields/nestable/LinkContent.d.ts +55 -32
  8. package/lib/content/fields/nestable/LinkContent.js +25 -10
  9. package/lib/content/fields/nestable/NestableContent.d.ts +242 -24
  10. package/lib/content/fields/nestable/NestableContent.js +21 -2
  11. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +106 -106
  12. package/lib/content/fields/nestable/RichTextContent/index.d.ts +20 -20
  13. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +482 -46
  14. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +84 -10
  15. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +484 -48
  16. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +242 -24
  17. package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +243 -25
  18. package/lib/content/fields/slices/Slice/index.d.ts +815 -85
  19. package/lib/content/fields/slices/SliceItem.d.ts +814 -84
  20. package/lib/content/fields/slices/SlicesContent.d.ts +1222 -132
  21. package/lib/customtypes/CustomType.d.ts +18 -0
  22. package/lib/customtypes/Section.d.ts +18 -0
  23. package/lib/customtypes/diff/SharedSlice.d.ts +8 -0
  24. package/lib/customtypes/diff/Variation.d.ts +8 -0
  25. package/lib/customtypes/widgets/Group.d.ts +6 -0
  26. package/lib/customtypes/widgets/Widget.d.ts +36 -0
  27. package/lib/customtypes/widgets/Widget.js +15 -0
  28. package/lib/customtypes/widgets/nestable/Link.d.ts +2 -0
  29. package/lib/customtypes/widgets/nestable/Link.js +5 -1
  30. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +3 -1
  31. package/lib/customtypes/widgets/nestable/NestableWidget.js +18 -1
  32. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -0
  33. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -0
  34. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +8 -0
  35. package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +6 -0
  36. package/lib/customtypes/widgets/slices/Slices.d.ts +28 -0
  37. package/package.json +1 -1
  38. package/src/_internal/utils.ts +3 -1
  39. package/src/content/fields/RepeatableContent.ts +156 -0
  40. package/src/content/fields/nestable/LinkContent.ts +26 -26
  41. package/src/content/fields/nestable/NestableContent.ts +28 -3
  42. package/src/customtypes/widgets/Widget.ts +15 -0
  43. package/src/customtypes/widgets/nestable/Link.ts +5 -1
  44. package/src/customtypes/widgets/nestable/NestableWidget.ts +34 -16
@@ -1,10 +1,33 @@
1
+ /**
2
+ * LinkContent is a union of different link content types.
3
+ *
4
+ * Most link content types are built from a union of a filled and an unfilled version.
5
+ *
6
+ * Filled versions make sure that the important fields that make the link work
7
+ * are present. They are also exported for when there's a need to ensure that
8
+ * the link is filled when used in a specific context, e.g. links in rich text fields.
9
+ *
10
+ * Unfilled versions are used when the link is not filled yet but contains other
11
+ * information like the text.
12
+ *
13
+ * There are some exceptions that don't have a filled version (e.g. MediaLink)
14
+ * for when the exact subtype is not yet known.
15
+ *
16
+ * Unfilled versions all have a special `kind` property that is used to
17
+ * determine the type of the link. For legacy reasons, filled versions don't
18
+ * necessarily require this property or its type is loose (e.g. `string`). In
19
+ * this cases, the type is determined based on a specific combination of the
20
+ * rest of the link data. This is why the order of the subtypes in the union is
21
+ * important and should be from the most specific to the least specific. A
22
+ * battery of tests ensures that the correct type is inferred.
23
+ */
1
24
  import * as t from "io-ts";
2
25
  import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
3
26
  export declare const ImageLinkType = "ImageLink";
4
27
  export declare const FilledImageLinkContent: t.IntersectionC<[t.ExactC<t.TypeC<{
5
28
  __TYPE__: t.LiteralC<"ImageLink">;
6
29
  }>>, t.IntersectionC<[t.ExactC<t.TypeC<{
7
- kind: t.Type<"image", "image", unknown>;
30
+ kind: t.StringC;
8
31
  id: t.StringC;
9
32
  url: t.StringC;
10
33
  height: t.StringC;
@@ -18,7 +41,7 @@ export declare type FilledImageLinkContent = t.TypeOf<typeof FilledImageLinkCont
18
41
  export declare const ImageLinkContent: t.IntersectionC<[t.ExactC<t.TypeC<{
19
42
  __TYPE__: t.LiteralC<"ImageLink">;
20
43
  }>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
21
- kind: t.Type<"image", "image", unknown>;
44
+ kind: t.StringC;
22
45
  id: t.StringC;
23
46
  url: t.StringC;
24
47
  height: t.StringC;
@@ -38,7 +61,7 @@ export declare const FileLinkType = "FileLink";
38
61
  export declare const FilledFileLinkContent: t.IntersectionC<[t.ExactC<t.TypeC<{
39
62
  __TYPE__: t.LiteralC<"FileLink">;
40
63
  }>>, t.ExactC<t.IntersectionC<[t.TypeC<{
41
- kind: t.Type<"file", "file", unknown>;
64
+ kind: t.StringC;
42
65
  id: t.StringC;
43
66
  url: t.StringC;
44
67
  name: t.StringC;
@@ -50,7 +73,7 @@ export declare type FilledFileLinkContent = t.TypeOf<typeof FilledFileLinkConten
50
73
  export declare const FileLinkContent: t.IntersectionC<[t.ExactC<t.TypeC<{
51
74
  __TYPE__: t.LiteralC<"FileLink">;
52
75
  }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
53
- kind: t.Type<"file", "file", unknown>;
76
+ kind: t.StringC;
54
77
  id: t.StringC;
55
78
  url: t.StringC;
56
79
  name: t.StringC;
@@ -137,7 +160,7 @@ export declare const isLinkContent: (u: unknown) => u is {
137
160
  value: ({
138
161
  __TYPE__: "ImageLink";
139
162
  } & (({
140
- kind: "image";
163
+ kind: string;
141
164
  id: string;
142
165
  url: string;
143
166
  height: string;
@@ -154,7 +177,7 @@ export declare const isLinkContent: (u: unknown) => u is {
154
177
  })) | ({
155
178
  __TYPE__: "FileLink";
156
179
  } & (({
157
- kind: "file";
180
+ kind: string;
158
181
  id: string;
159
182
  url: string;
160
183
  name: string;
@@ -204,7 +227,7 @@ export declare const isLinkContent: (u: unknown) => u is {
204
227
  export declare const LinkLegacy: t.UnionC<[t.Type<{
205
228
  __TYPE__: "ImageLink";
206
229
  } & (({
207
- kind: "image";
230
+ kind: string;
208
231
  id: string;
209
232
  url: string;
210
233
  height: string;
@@ -219,7 +242,7 @@ export declare const LinkLegacy: t.UnionC<[t.Type<{
219
242
  kind: "image";
220
243
  text: string;
221
244
  }), ({
222
- kind: "image";
245
+ kind: string;
223
246
  id: string;
224
247
  url: string;
225
248
  height: string;
@@ -236,7 +259,7 @@ export declare const LinkLegacy: t.UnionC<[t.Type<{
236
259
  }, unknown>, t.Type<{
237
260
  __TYPE__: "FileLink";
238
261
  } & (({
239
- kind: "file";
262
+ kind: string;
240
263
  id: string;
241
264
  url: string;
242
265
  name: string;
@@ -249,7 +272,7 @@ export declare const LinkLegacy: t.UnionC<[t.Type<{
249
272
  kind: "file";
250
273
  text: string;
251
274
  }), ({
252
- kind: "file";
275
+ kind: string;
253
276
  id: string;
254
277
  url: string;
255
278
  name: string;
@@ -325,7 +348,7 @@ export declare const LinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<{
325
348
  value: ({
326
349
  __TYPE__: "ImageLink";
327
350
  } & (({
328
- kind: "image";
351
+ kind: string;
329
352
  id: string;
330
353
  url: string;
331
354
  height: string;
@@ -342,7 +365,7 @@ export declare const LinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<{
342
365
  })) | ({
343
366
  __TYPE__: "FileLink";
344
367
  } & (({
345
- kind: "file";
368
+ kind: string;
346
369
  id: string;
347
370
  url: string;
348
371
  name: string;
@@ -389,7 +412,7 @@ export declare const LinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<{
389
412
  text: string;
390
413
  });
391
414
  }, WithTypes<({
392
- kind: "image";
415
+ kind: string;
393
416
  id: string;
394
417
  url: string;
395
418
  height: string;
@@ -404,7 +427,7 @@ export declare const LinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<{
404
427
  kind: "image";
405
428
  text: string;
406
429
  } | ({
407
- kind: "file";
430
+ kind: string;
408
431
  id: string;
409
432
  url: string;
410
433
  name: string;
@@ -445,7 +468,7 @@ export declare const LinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<{
445
468
  export declare const Link: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
446
469
  __TYPE__: t.LiteralC<"ImageLink">;
447
470
  }>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
448
- kind: t.Type<"image", "image", unknown>;
471
+ kind: t.StringC;
449
472
  id: t.StringC;
450
473
  url: t.StringC;
451
474
  height: t.StringC;
@@ -462,7 +485,7 @@ export declare const Link: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
462
485
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
463
486
  __TYPE__: t.LiteralC<"FileLink">;
464
487
  }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
465
- kind: t.Type<"file", "file", unknown>;
488
+ kind: t.StringC;
466
489
  id: t.StringC;
467
490
  url: t.StringC;
468
491
  name: t.StringC;
@@ -515,7 +538,7 @@ export declare const LinkContent: t.ExactC<t.TypeC<{
515
538
  value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
516
539
  __TYPE__: t.LiteralC<"ImageLink">;
517
540
  }>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
518
- kind: t.Type<"image", "image", unknown>;
541
+ kind: t.StringC;
519
542
  id: t.StringC;
520
543
  url: t.StringC;
521
544
  height: t.StringC;
@@ -532,7 +555,7 @@ export declare const LinkContent: t.ExactC<t.TypeC<{
532
555
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
533
556
  __TYPE__: t.LiteralC<"FileLink">;
534
557
  }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
535
- kind: t.Type<"file", "file", unknown>;
558
+ kind: t.StringC;
536
559
  id: t.StringC;
537
560
  url: t.StringC;
538
561
  name: t.StringC;
@@ -588,7 +611,7 @@ export declare const isFilledLinkContent: (u: unknown) => u is {
588
611
  value: ({
589
612
  __TYPE__: "ImageLink";
590
613
  } & {
591
- kind: "image";
614
+ kind: string;
592
615
  id: string;
593
616
  url: string;
594
617
  height: string;
@@ -600,7 +623,7 @@ export declare const isFilledLinkContent: (u: unknown) => u is {
600
623
  }) | ({
601
624
  __TYPE__: "FileLink";
602
625
  } & {
603
- kind: "file";
626
+ kind: string;
604
627
  id: string;
605
628
  url: string;
606
629
  name: string;
@@ -626,7 +649,7 @@ export declare const isFilledLinkContent: (u: unknown) => u is {
626
649
  export declare const FilledLinkLegacy: t.UnionC<[t.Type<{
627
650
  __TYPE__: "ImageLink";
628
651
  } & {
629
- kind: "image";
652
+ kind: string;
630
653
  id: string;
631
654
  url: string;
632
655
  height: string;
@@ -636,7 +659,7 @@ export declare const FilledLinkLegacy: t.UnionC<[t.Type<{
636
659
  } & {
637
660
  date?: string | null | undefined;
638
661
  }, {
639
- kind: "image";
662
+ kind: string;
640
663
  id: string;
641
664
  url: string;
642
665
  height: string;
@@ -648,7 +671,7 @@ export declare const FilledLinkLegacy: t.UnionC<[t.Type<{
648
671
  }, unknown>, t.Type<{
649
672
  __TYPE__: "FileLink";
650
673
  } & {
651
- kind: "file";
674
+ kind: string;
652
675
  id: string;
653
676
  url: string;
654
677
  name: string;
@@ -656,7 +679,7 @@ export declare const FilledLinkLegacy: t.UnionC<[t.Type<{
656
679
  } & {
657
680
  date?: string | null | undefined;
658
681
  }, {
659
- kind: "file";
682
+ kind: string;
660
683
  id: string;
661
684
  url: string;
662
685
  name: string;
@@ -693,7 +716,7 @@ export declare const FilledLinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<
693
716
  value: ({
694
717
  __TYPE__: "ImageLink";
695
718
  } & {
696
- kind: "image";
719
+ kind: string;
697
720
  id: string;
698
721
  url: string;
699
722
  height: string;
@@ -705,7 +728,7 @@ export declare const FilledLinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<
705
728
  }) | ({
706
729
  __TYPE__: "FileLink";
707
730
  } & {
708
- kind: "file";
731
+ kind: string;
709
732
  id: string;
710
733
  url: string;
711
734
  name: string;
@@ -728,7 +751,7 @@ export declare const FilledLinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<
728
751
  } | null | undefined;
729
752
  });
730
753
  }, WithTypes<({
731
- kind: "image";
754
+ kind: string;
732
755
  id: string;
733
756
  url: string;
734
757
  height: string;
@@ -738,7 +761,7 @@ export declare const FilledLinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<
738
761
  } & {
739
762
  date?: string | null | undefined;
740
763
  }) | ({
741
- kind: "file";
764
+ kind: string;
742
765
  id: string;
743
766
  url: string;
744
767
  name: string;
@@ -759,7 +782,7 @@ export declare const FilledLinkContentLegacy: (ctx: LegacyContentCtx) => t.Type<
759
782
  export declare const FilledLink: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
760
783
  __TYPE__: t.LiteralC<"ImageLink">;
761
784
  }>>, t.IntersectionC<[t.ExactC<t.TypeC<{
762
- kind: t.Type<"image", "image", unknown>;
785
+ kind: t.StringC;
763
786
  id: t.StringC;
764
787
  url: t.StringC;
765
788
  height: t.StringC;
@@ -771,7 +794,7 @@ export declare const FilledLink: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
771
794
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
772
795
  __TYPE__: t.LiteralC<"FileLink">;
773
796
  }>>, t.ExactC<t.IntersectionC<[t.TypeC<{
774
- kind: t.Type<"file", "file", unknown>;
797
+ kind: t.StringC;
775
798
  id: t.StringC;
776
799
  url: t.StringC;
777
800
  name: t.StringC;
@@ -800,7 +823,7 @@ export declare const FilledLinkContent: t.ExactC<t.TypeC<{
800
823
  value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
801
824
  __TYPE__: t.LiteralC<"ImageLink">;
802
825
  }>>, t.IntersectionC<[t.ExactC<t.TypeC<{
803
- kind: t.Type<"image", "image", unknown>;
826
+ kind: t.StringC;
804
827
  id: t.StringC;
805
828
  url: t.StringC;
806
829
  height: t.StringC;
@@ -812,7 +835,7 @@ export declare const FilledLinkContent: t.ExactC<t.TypeC<{
812
835
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
813
836
  __TYPE__: t.LiteralC<"FileLink">;
814
837
  }>>, t.ExactC<t.IntersectionC<[t.TypeC<{
815
- kind: t.Type<"file", "file", unknown>;
838
+ kind: t.StringC;
816
839
  id: t.StringC;
817
840
  url: t.StringC;
818
841
  name: t.StringC;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ /**
3
+ * LinkContent is a union of different link content types.
4
+ *
5
+ * Most link content types are built from a union of a filled and an unfilled version.
6
+ *
7
+ * Filled versions make sure that the important fields that make the link work
8
+ * are present. They are also exported for when there's a need to ensure that
9
+ * the link is filled when used in a specific context, e.g. links in rich text fields.
10
+ *
11
+ * Unfilled versions are used when the link is not filled yet but contains other
12
+ * information like the text.
13
+ *
14
+ * There are some exceptions that don't have a filled version (e.g. MediaLink)
15
+ * for when the exact subtype is not yet known.
16
+ *
17
+ * Unfilled versions all have a special `kind` property that is used to
18
+ * determine the type of the link. For legacy reasons, filled versions don't
19
+ * necessarily require this property or its type is loose (e.g. `string`). In
20
+ * this cases, the type is determined based on a specific combination of the
21
+ * rest of the link data. This is why the order of the subtypes in the union is
22
+ * important and should be from the most specific to the least specific. A
23
+ * battery of tests ensures that the correct type is inferred.
24
+ */
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.FilledLinkContent = exports.FilledLink = exports.FilledLinkContentLegacy = exports.FilledLinkLegacy = exports.isFilledLinkContent = exports.LinkContent = exports.Link = exports.LinkContentLegacy = exports.LinkLegacy = exports.isLinkContent = exports.LinkContentType = exports.AnyLinkContent = exports.AnyLinkType = exports.ExternalLinkContent = exports.FilledExternalLinkContent = exports.ExternalLinkType = exports.DocumentLinkContent = exports.FilledDocumentLinkContent = exports.DocumentLinkType = exports.MediaLinkContent = exports.MediaLinkType = exports.FileLinkContent = exports.FilledFileLinkContent = exports.FileLinkType = exports.ImageLinkContent = exports.FilledImageLinkContent = exports.ImageLinkType = void 0;
4
27
  const tslib_1 = require("tslib");
@@ -11,13 +34,9 @@ const function_2 = require("../../../validators/function");
11
34
  const utils_1 = require("../../utils");
12
35
  // ImageLink.
13
36
  exports.ImageLinkType = "ImageLink";
14
- const isImageLinkKind = (input) => typeof input === "string";
15
- const ImageLinkKind = new t.Type("ImageLinkKind", (input) => isImageLinkKind(input), (input, context) => isImageLinkKind(input)
16
- ? t.success("image")
17
- : t.failure(input, context), () => "image");
18
37
  const filledImageLinkLegacyCodec = t.intersection([
19
38
  t.strict({
20
- kind: ImageLinkKind,
39
+ kind: t.string,
21
40
  id: t.string,
22
41
  url: t.string,
23
42
  height: t.string,
@@ -73,13 +92,9 @@ exports.ImageLinkContent = t.intersection([
73
92
  ]);
74
93
  // FileLink.
75
94
  exports.FileLinkType = "FileLink";
76
- const isFileLinkKind = (input) => typeof input === "string";
77
- const FileLinkKind = new t.Type("FileLinkKind", (input) => isFileLinkKind(input), (input, context) => isFileLinkKind(input)
78
- ? t.success("file")
79
- : t.failure(input, context), () => "file");
80
95
  const filledFileLinkLegacyCodec = t.exact(t.intersection([
81
96
  t.type({
82
- kind: FileLinkKind,
97
+ kind: t.string,
83
98
  id: t.string,
84
99
  url: t.string,
85
100
  name: t.string,