@prismicio/types-internal 2.0.0-alpha.7 → 2.0.0-alpha.8

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 (26) hide show
  1. package/lib/content/Document.d.ts +608 -32
  2. package/lib/content/fields/GroupContent.d.ts +190 -10
  3. package/lib/content/fields/WidgetContent.d.ts +912 -48
  4. package/lib/content/fields/nestable/EmbedContent.d.ts +44 -41
  5. package/lib/content/fields/nestable/EmbedContent.js +15 -38
  6. package/lib/content/fields/nestable/NestableContent.d.ts +114 -7
  7. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +76 -5
  8. package/lib/content/fields/nestable/RichTextContent/Blocks.js +15 -7
  9. package/lib/content/fields/nestable/RichTextContent/index.d.ts +76 -4
  10. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +228 -12
  11. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +76 -4
  12. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +228 -12
  13. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +190 -10
  14. package/lib/content/fields/slices/Slice/index.d.ts +421 -22
  15. package/lib/content/fields/slices/Slice/index.js +3 -0
  16. package/lib/content/fields/slices/SliceItem.d.ts +456 -24
  17. package/lib/content/fields/slices/SliceItem.js +2 -2
  18. package/lib/content/fields/slices/SlicesContent.d.ts +684 -36
  19. package/lib/content/fields/slices/index.d.ts +1 -3
  20. package/lib/content/fields/slices/index.js +1 -3
  21. package/package.json +1 -1
  22. package/src/content/fields/nestable/EmbedContent.ts +20 -59
  23. package/src/content/fields/nestable/RichTextContent/Blocks.ts +19 -8
  24. package/src/content/fields/slices/Slice/index.ts +4 -0
  25. package/src/content/fields/slices/SliceItem.ts +2 -2
  26. package/src/content/fields/slices/index.ts +1 -3
@@ -1,5 +1,3 @@
1
- export * from "./Slice/CompositeSliceContent";
2
- export * from "./Slice/SharedSliceContent";
3
- export * from "./Slice/SimpleSliceContent";
1
+ export * from "./Slice";
4
2
  export * from "./SliceItem";
5
3
  export * from "./SlicesContent";
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./Slice/CompositeSliceContent"), exports);
5
- tslib_1.__exportStar(require("./Slice/SharedSliceContent"), exports);
6
- tslib_1.__exportStar(require("./Slice/SimpleSliceContent"), exports);
4
+ tslib_1.__exportStar(require("./Slice"), exports);
7
5
  tslib_1.__exportStar(require("./SliceItem"), exports);
8
6
  tslib_1.__exportStar(require("./SlicesContent"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-alpha.8",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -2,7 +2,6 @@ import { either } from "fp-ts"
2
2
  import { pipe } from "fp-ts/lib/function"
3
3
  import * as t from "io-ts"
4
4
 
5
- import { withOptionals } from "../../../utils/Objects"
6
5
  import { NumberOrNull, StringOrNull } from "../../../validators"
7
6
  import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
8
7
  import { hasContentType } from "../../utils"
@@ -34,79 +33,41 @@ export const EmbedContentLegacy = t.exact(
34
33
  ]),
35
34
  )
36
35
 
37
- type EmbedLegacy = t.TypeOf<typeof EmbedContentLegacy>
36
+ export type EmbedLegacy = t.TypeOf<typeof EmbedContentLegacy>
38
37
 
39
38
  export const EmbedLegacy = (ctx: LegacyContentCtx) =>
40
- new t.Type<EmbedContent, WithTypes<EmbedLegacy>, unknown>(
39
+ new t.Type<EmbedContent, WithTypes<unknown>, unknown>(
41
40
  "EmbedLegacy",
42
41
  isEmbedContent,
43
42
  (u) => {
44
43
  return pipe(
45
44
  EmbedContentLegacy.decode(u),
46
- either.map((embed) =>
47
- buildEmbedContent({
48
- ...embed,
49
- __TYPE__: EmbedContentType,
50
- }),
51
- ),
45
+ either.map((embed) => ({
46
+ ...embed,
47
+ all: u,
48
+ __TYPE__: EmbedContentType,
49
+ })),
52
50
  )
53
51
  },
54
52
 
55
53
  (embed: EmbedContent) => {
56
54
  return {
57
- content: buildEmbedContent(embed).all,
55
+ /**
56
+ * we cast here because actually in the all property
57
+ * we can have extra keys that are never parsed and we don't want to loose them.
58
+ **/
59
+ content: embed.all,
58
60
  types: { [ctx.keyOfType]: "Embed" },
59
61
  }
60
62
  },
61
63
  )
62
64
 
63
- export type EmbedContent = EmbedLegacy & {
64
- __TYPE__: typeof EmbedContentType
65
- all: unknown
66
- }
65
+ export const EmbedContent = t.intersection([
66
+ EmbedContentLegacy,
67
+ t.strict({
68
+ __TYPE__: t.literal(EmbedContentType),
69
+ all: t.unknown,
70
+ }),
71
+ ])
67
72
 
68
- export const EmbedContent = new t.Type<EmbedContent>(
69
- "EmbedContent",
70
- isEmbedContent,
71
- (u: unknown) => {
72
- return pipe(
73
- t
74
- .intersection([
75
- EmbedContentLegacy,
76
- t.strict({
77
- __TYPE__: t.literal(EmbedContentType),
78
- }),
79
- ])
80
- .decode(u),
81
- either.map((parsedEmbed: Omit<EmbedContent, "all">) => {
82
- return buildEmbedContent(parsedEmbed)
83
- }),
84
- )
85
- },
86
- (e) => e,
87
- )
88
-
89
- export function buildEmbedContent(embed: Omit<EmbedContent, "all">) {
90
- return {
91
- ...embed,
92
- all: withOptionals<EmbedLegacy>(
93
- {
94
- embed_url: embed.embed_url,
95
- type: embed.type,
96
- },
97
- [
98
- ["author_name", embed.author_name],
99
- ["author_url", embed.author_url],
100
- ["cache_age", embed.cache_age],
101
- ["html", embed.html],
102
- ["provider_name", embed.provider_name],
103
- ["provider_url", embed.provider_url],
104
- ["thumbnail_height", embed.thumbnail_height],
105
- ["thumbnail_width", embed.thumbnail_width],
106
- ["thumbnail_url", embed.thumbnail_url],
107
- ["title", embed.title],
108
- ["version", embed.version],
109
- ],
110
- ),
111
- }
112
- }
73
+ export type EmbedContent = t.TypeOf<typeof EmbedContent>
@@ -10,10 +10,10 @@ import {
10
10
  import { StringOrNull } from "../../../../validators"
11
11
  import { nullable, refineType } from "../../../../validators/function"
12
12
  import {
13
- buildEmbedContent,
14
13
  EmbedContent,
15
14
  EmbedContentLegacy,
16
15
  EmbedContentType,
16
+ EmbedLegacy,
17
17
  } from "../EmbedContent"
18
18
  import { ImageContentView } from "../ImageContent"
19
19
  import { Link, LinkLegacy } from "../LinkContent"
@@ -103,7 +103,7 @@ const embedBlockLegacyCodec = t.exact(
103
103
  t.intersection([
104
104
  t.type({
105
105
  type: t.literal(RichTextNodeType.embed),
106
- data: EmbedContentLegacy,
106
+ data: t.unknown,
107
107
  }),
108
108
  t.partial({
109
109
  label: StringOrNull,
@@ -120,18 +120,29 @@ const EmbedBlockLegacy = new t.Type<EmbedBlock, EmbedBlockLegacy, unknown>(
120
120
  (block) =>
121
121
  pipe(
122
122
  embedBlockLegacyCodec.decode(block),
123
- either.map((parsedBlock) => {
123
+ either.chain((decodedBlock) => {
124
+ return either.map<EmbedLegacy, [EmbedBlockLegacy, EmbedLegacy]>(
125
+ (decodedData: EmbedLegacy) => {
126
+ return [decodedBlock, decodedData]
127
+ },
128
+ )(EmbedContentLegacy.decode(decodedBlock.data))
129
+ }),
130
+ either.map(([block, parsedData]) => {
124
131
  return EmbedBlock.encode({
125
- ...parsedBlock,
126
- data: buildEmbedContent({
127
- ...parsedBlock.data,
132
+ ...block,
133
+ data: {
134
+ ...parsedData,
128
135
  __TYPE__: EmbedContentType,
129
- }),
136
+ all: block.data,
137
+ },
130
138
  })
131
139
  }),
132
140
  ),
133
141
  (embedBlock: EmbedBlock): EmbedBlockLegacy => {
134
- return embedBlockLegacyCodec.encode(embedBlock)
142
+ return {
143
+ ...embedBlockLegacyCodec.encode(embedBlock),
144
+ data: EmbedContentLegacy.encode(embedBlock.data),
145
+ }
135
146
  },
136
147
  )
137
148
  export const EmbedBlock = t.exact(
@@ -45,3 +45,7 @@ export const SliceContent = t.union([
45
45
  ])
46
46
 
47
47
  export type SliceContent = t.TypeOf<typeof SliceContent>
48
+
49
+ export * from "./CompositeSliceContent"
50
+ export * from "./SharedSliceContent"
51
+ export * from "./SimpleSliceContent"
@@ -53,7 +53,7 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
53
53
  0,
54
54
  stopIdx > 0 ? stopIdx : undefined,
55
55
  )
56
- const itemCtx = getFieldCtx(parsedSlice.key, ctx)
56
+ const itemCtx = getFieldCtx(sliceName, ctx)
57
57
  const item = SliceLegacy(itemCtx).decode(parsedSlice.value)
58
58
  if (!item || isLeft(item)) return t.failure(sliceItem, context)
59
59
 
@@ -67,7 +67,7 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
67
67
  )
68
68
  },
69
69
  (sItem: SliceItemContent) => {
70
- const itemCtx = getFieldCtx(sItem.key, ctx)
70
+ const itemCtx = getFieldCtx(sItem.name, ctx)
71
71
  const result = SliceLegacy(itemCtx).encode(sItem.widget)
72
72
 
73
73
  return {
@@ -1,5 +1,3 @@
1
- export * from "./Slice/CompositeSliceContent"
2
- export * from "./Slice/SharedSliceContent"
3
- export * from "./Slice/SimpleSliceContent"
1
+ export * from "./Slice"
4
2
  export * from "./SliceItem"
5
3
  export * from "./SlicesContent"