@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.
- package/lib/content/Document.d.ts +608 -32
- package/lib/content/fields/GroupContent.d.ts +190 -10
- package/lib/content/fields/WidgetContent.d.ts +912 -48
- package/lib/content/fields/nestable/EmbedContent.d.ts +44 -41
- package/lib/content/fields/nestable/EmbedContent.js +15 -38
- package/lib/content/fields/nestable/NestableContent.d.ts +114 -7
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +76 -5
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +15 -7
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +76 -4
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +228 -12
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +76 -4
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +228 -12
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +190 -10
- package/lib/content/fields/slices/Slice/index.d.ts +421 -22
- package/lib/content/fields/slices/Slice/index.js +3 -0
- package/lib/content/fields/slices/SliceItem.d.ts +456 -24
- package/lib/content/fields/slices/SliceItem.js +2 -2
- package/lib/content/fields/slices/SlicesContent.d.ts +684 -36
- package/lib/content/fields/slices/index.d.ts +1 -3
- package/lib/content/fields/slices/index.js +1 -3
- package/package.json +1 -1
- package/src/content/fields/nestable/EmbedContent.ts +20 -59
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +19 -8
- package/src/content/fields/slices/Slice/index.ts +4 -0
- package/src/content/fields/slices/SliceItem.ts +2 -2
- package/src/content/fields/slices/index.ts +1 -3
|
@@ -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
|
|
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
|
@@ -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<
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
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:
|
|
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.
|
|
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
|
-
...
|
|
126
|
-
data:
|
|
127
|
-
...
|
|
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
|
|
142
|
+
return {
|
|
143
|
+
...embedBlockLegacyCodec.encode(embedBlock),
|
|
144
|
+
data: EmbedContentLegacy.encode(embedBlock.data),
|
|
145
|
+
}
|
|
135
146
|
},
|
|
136
147
|
)
|
|
137
148
|
export const EmbedBlock = t.exact(
|
|
@@ -53,7 +53,7 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
|
|
|
53
53
|
0,
|
|
54
54
|
stopIdx > 0 ? stopIdx : undefined,
|
|
55
55
|
)
|
|
56
|
-
const itemCtx = getFieldCtx(
|
|
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.
|
|
70
|
+
const itemCtx = getFieldCtx(sItem.name, ctx)
|
|
71
71
|
const result = SliceLegacy(itemCtx).encode(sItem.widget)
|
|
72
72
|
|
|
73
73
|
return {
|