@prismicio/types-internal 2.2.0-alpha.5 → 2.2.0-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.
- package/lib/common/Embed.d.ts +16 -0
- package/lib/common/Embed.js +10 -0
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/import/converters/Document.d.ts +2 -1
- package/lib/import/converters/Document.js +4 -4
- 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/Nestable.d.ts +2 -1
- package/lib/import/converters/fields/nestable/Nestable.js +2 -2
- package/lib/import/validators/fields/ImportField.d.ts +6 -51
- 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/Nestable.d.ts +6 -51
- package/package.json +1 -1
- package/src/common/Embed.ts +23 -0
- package/src/common/index.ts +1 -0
- package/src/import/converters/Document.ts +5 -2
- package/src/import/converters/fields/nestable/Embed.ts +29 -7
- package/src/import/converters/fields/nestable/Nestable.ts +3 -1
- package/src/import/validators/fields/nestable/Embed.ts +9 -41
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare type Embed = {
|
|
2
|
+
type: string;
|
|
3
|
+
version?: string | null;
|
|
4
|
+
author_name?: string | null;
|
|
5
|
+
author_url?: string | null;
|
|
6
|
+
provider_name?: string | null;
|
|
7
|
+
provider_url?: string | null;
|
|
8
|
+
cache_age?: string | null;
|
|
9
|
+
thumbnail_url?: string | null;
|
|
10
|
+
thumbnail_width?: number | null;
|
|
11
|
+
thumbnail_height?: number | null;
|
|
12
|
+
html?: string | null;
|
|
13
|
+
title?: string | null;
|
|
14
|
+
};
|
|
15
|
+
export declare type EmbedUrl = string;
|
|
16
|
+
export declare const getEmbedOrThrow: (embeds: Record<string, Embed>) => (embedUrl: string) => Embed;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEmbedOrThrow = void 0;
|
|
4
|
+
const getEmbedOrThrow = (embeds) => (embedUrl) => {
|
|
5
|
+
const embed = embeds[embedUrl];
|
|
6
|
+
if (!embed)
|
|
7
|
+
throw new Error(`Missing embed with url '${embedUrl}'`);
|
|
8
|
+
return embed;
|
|
9
|
+
};
|
|
10
|
+
exports.getEmbedOrThrow = getEmbedOrThrow;
|
package/lib/common/index.d.ts
CHANGED
package/lib/common/index.js
CHANGED
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
(0, tslib_1.__exportStar)(require("./Asset"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./Embed"), exports);
|
|
5
6
|
(0, tslib_1.__exportStar)(require("./WidgetKey"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Asset } from "../../common";
|
|
2
|
+
import type { Embed } from "../../common/Embed";
|
|
2
3
|
import type { Document } from "../../content";
|
|
3
4
|
import type { ImportDocument } from "../validators";
|
|
4
|
-
export declare function convertImportToContent(document: ImportDocument, assets: Record<string, Asset>): Document;
|
|
5
|
+
export declare function convertImportToContent(document: ImportDocument, assets: Record<string, Asset>, embeds: Record<string, Embed>): Document;
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertImportToContent = void 0;
|
|
4
4
|
const fields_1 = require("./fields");
|
|
5
|
-
function convertImportToContent(document, assets) {
|
|
5
|
+
function convertImportToContent(document, assets, embeds) {
|
|
6
6
|
return Object.entries(document).reduce((acc, [fieldKey, fieldValue]) => {
|
|
7
|
-
const newFieldValue = convertWidget(fieldValue, assets);
|
|
7
|
+
const newFieldValue = convertWidget(fieldValue, assets, embeds);
|
|
8
8
|
return newFieldValue ? { ...acc, [fieldKey]: newFieldValue } : acc;
|
|
9
9
|
}, {});
|
|
10
10
|
}
|
|
11
11
|
exports.convertImportToContent = convertImportToContent;
|
|
12
|
-
function convertWidget(field, assets) {
|
|
12
|
+
function convertWidget(field, assets, embeds) {
|
|
13
13
|
switch (field.type) {
|
|
14
14
|
case "UID":
|
|
15
15
|
return (0, fields_1.uidConverter)(field.value);
|
|
16
16
|
default:
|
|
17
|
-
return (0, fields_1.convertNestableWidget)(field, assets);
|
|
17
|
+
return (0, fields_1.convertNestableWidget)(field, assets, embeds);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Embed } from "../../../../common";
|
|
1
2
|
import type { EmbedContent } from "../../../../content";
|
|
2
3
|
import type { ImportEmbed } from "../../../validators";
|
|
3
|
-
export declare const embedConverter: (field: ImportEmbed["value"]) => EmbedContent | undefined;
|
|
4
|
+
export declare const embedConverter: (field: ImportEmbed["value"], embeds: Record<string, Embed>) => EmbedContent | undefined;
|
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.embedConverter = void 0;
|
|
4
|
-
const
|
|
4
|
+
const common_1 = require("../../../../common");
|
|
5
|
+
const Objects_1 = require("../../../../utils/Objects");
|
|
6
|
+
const embedConverter = (field, embeds) => {
|
|
5
7
|
if (field === null)
|
|
6
8
|
return;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const embed = (0, common_1.getEmbedOrThrow)(embeds)(field.embed_url);
|
|
10
|
+
return (0, Objects_1.withOptionals)({
|
|
11
|
+
embed_url: field.embed_url,
|
|
12
|
+
type: embed.type,
|
|
13
|
+
all: {
|
|
14
|
+
embed_url: field.embed_url,
|
|
15
|
+
...embed,
|
|
16
|
+
},
|
|
9
17
|
__TYPE__: "EmbedContent",
|
|
10
|
-
}
|
|
11
|
-
|
|
18
|
+
}, [
|
|
19
|
+
["version", embed.version],
|
|
20
|
+
["title", embed.title],
|
|
21
|
+
["author_name", embed.author_name],
|
|
22
|
+
["author_url", embed.author_url],
|
|
23
|
+
["provider_name", embed.provider_name],
|
|
24
|
+
["provider_url", embed.provider_url],
|
|
25
|
+
["cache_age", embed.cache_age],
|
|
26
|
+
["thumbnail_url", embed.thumbnail_url],
|
|
27
|
+
["thumbnail_width", embed.thumbnail_width],
|
|
28
|
+
["thumbnail_height", embed.thumbnail_height],
|
|
29
|
+
["html", embed.html],
|
|
30
|
+
]);
|
|
12
31
|
};
|
|
13
32
|
exports.embedConverter = embedConverter;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Asset } from "../../../../common";
|
|
2
|
+
import type { Embed } from "../../../../common/Embed";
|
|
2
3
|
import type { WidgetContent } from "../../../../content";
|
|
3
4
|
import type { ImportNestable } from "../../../validators";
|
|
4
|
-
export declare function convertNestableWidget(field: ImportNestable, assets: Record<string, Asset>): WidgetContent | undefined;
|
|
5
|
+
export declare function convertNestableWidget(field: ImportNestable, assets: Record<string, Asset>, embeds: Record<string, Embed>): WidgetContent | undefined;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertNestableWidget = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
-
function convertNestableWidget(field, assets) {
|
|
5
|
+
function convertNestableWidget(field, assets, embeds) {
|
|
6
6
|
switch (field.type) {
|
|
7
7
|
case "Boolean":
|
|
8
8
|
return (0, _1.booleanConverter)(field.value);
|
|
@@ -19,7 +19,7 @@ function convertNestableWidget(field, assets) {
|
|
|
19
19
|
case "Timestamp":
|
|
20
20
|
return (0, _1.timestampConverter)(field.value);
|
|
21
21
|
case "Embed":
|
|
22
|
-
return (0, _1.embedConverter)(field.value);
|
|
22
|
+
return (0, _1.embedConverter)(field.value, embeds);
|
|
23
23
|
case "GeoPoint":
|
|
24
24
|
return (0, _1.geopointConverter)(field.value);
|
|
25
25
|
case "Link":
|
|
@@ -16,42 +16,12 @@ export declare const ImportField: {
|
|
|
16
16
|
value: Date | null;
|
|
17
17
|
}, Date | undefined, unknown> | import("io-ts").Type<{
|
|
18
18
|
type: "Embed";
|
|
19
|
-
value:
|
|
19
|
+
value: {
|
|
20
20
|
embed_url: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
version?: string | number | null;
|
|
24
|
-
title?: string;
|
|
25
|
-
author_name?: string | null;
|
|
26
|
-
author_url?: string | null;
|
|
27
|
-
provider_name?: string | null;
|
|
28
|
-
provider_url?: string | null;
|
|
29
|
-
cache_age?: string | number | null;
|
|
30
|
-
thumbnail_url?: string | null;
|
|
31
|
-
thumbnail_width?: number | null;
|
|
32
|
-
thumbnail_height?: number | null;
|
|
33
|
-
html?: string | null;
|
|
34
|
-
} & {
|
|
35
|
-
all: unknown;
|
|
36
|
-
}) | null;
|
|
37
|
-
}, ({
|
|
21
|
+
} | null;
|
|
22
|
+
}, {
|
|
38
23
|
embed_url: string;
|
|
39
|
-
|
|
40
|
-
} & {
|
|
41
|
-
version?: string | number | null;
|
|
42
|
-
title?: string;
|
|
43
|
-
author_name?: string | null;
|
|
44
|
-
author_url?: string | null;
|
|
45
|
-
provider_name?: string | null;
|
|
46
|
-
provider_url?: string | null;
|
|
47
|
-
cache_age?: string | number | null;
|
|
48
|
-
thumbnail_url?: string | null;
|
|
49
|
-
thumbnail_width?: number | null;
|
|
50
|
-
thumbnail_height?: number | null;
|
|
51
|
-
html?: string | null;
|
|
52
|
-
} & {
|
|
53
|
-
all: unknown;
|
|
54
|
-
}) | undefined, unknown> | import("io-ts").Type<{
|
|
24
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
55
25
|
type: "GeoPoint";
|
|
56
26
|
value: {
|
|
57
27
|
latitude: number;
|
|
@@ -219,24 +189,9 @@ export declare const ImportField: {
|
|
|
219
189
|
} | null;
|
|
220
190
|
}> | import("fp-ts/lib/Either").Right<{
|
|
221
191
|
type: "Embed";
|
|
222
|
-
value:
|
|
192
|
+
value: {
|
|
223
193
|
embed_url: string;
|
|
224
|
-
|
|
225
|
-
} & {
|
|
226
|
-
version?: string | number | null;
|
|
227
|
-
title?: string;
|
|
228
|
-
author_name?: string | null;
|
|
229
|
-
author_url?: string | null;
|
|
230
|
-
provider_name?: string | null;
|
|
231
|
-
provider_url?: string | null;
|
|
232
|
-
cache_age?: string | number | null;
|
|
233
|
-
thumbnail_url?: string | null;
|
|
234
|
-
thumbnail_width?: number | null;
|
|
235
|
-
thumbnail_height?: number | null;
|
|
236
|
-
html?: string | null;
|
|
237
|
-
} & {
|
|
238
|
-
all: unknown;
|
|
239
|
-
}) | null;
|
|
194
|
+
} | null;
|
|
240
195
|
}> | import("fp-ts/lib/Either").Right<{
|
|
241
196
|
type: "Date";
|
|
242
197
|
value: Date | null;
|
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
declare const EmbedProto: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
3
|
-
embed_url: t.Type<string, string, unknown>;
|
|
4
|
-
type: t.StringC;
|
|
5
|
-
}>, t.PartialC<{
|
|
6
|
-
version: t.UnionC<[t.StringC, t.NumberC, t.NullC]>;
|
|
7
|
-
title: t.StringC;
|
|
8
|
-
author_name: t.UnionC<[t.StringC, t.NullC]>;
|
|
9
|
-
author_url: t.UnionC<[t.StringC, t.NullC]>;
|
|
10
|
-
provider_name: t.UnionC<[t.StringC, t.NullC]>;
|
|
11
|
-
provider_url: t.UnionC<[t.StringC, t.NullC]>;
|
|
12
|
-
cache_age: t.UnionC<[t.StringC, t.NumberC, t.NullC]>;
|
|
13
|
-
thumbnail_url: t.UnionC<[t.StringC, t.NullC]>;
|
|
14
|
-
thumbnail_width: t.UnionC<[t.NumberC, t.NullC]>;
|
|
15
|
-
thumbnail_height: t.UnionC<[t.NumberC, t.NullC]>;
|
|
16
|
-
html: t.UnionC<[t.StringC, t.NullC]>;
|
|
17
|
-
}>]>>;
|
|
18
|
-
declare type EmbedProto = t.TypeOf<typeof EmbedProto>;
|
|
19
|
-
declare type Embed = EmbedProto & {
|
|
20
|
-
all: unknown;
|
|
21
|
-
};
|
|
22
2
|
export declare const ImportEmbed: t.Type<{
|
|
23
3
|
type: "Embed";
|
|
24
|
-
value:
|
|
25
|
-
|
|
4
|
+
value: {
|
|
5
|
+
embed_url: string;
|
|
6
|
+
} | null;
|
|
7
|
+
}, {
|
|
8
|
+
embed_url: string;
|
|
9
|
+
} | undefined, unknown>;
|
|
26
10
|
export declare type ImportEmbed = t.TypeOf<typeof ImportEmbed>;
|
|
27
|
-
export {};
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImportEmbed = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const Either = (0, tslib_1.__importStar)(require("fp-ts/
|
|
5
|
+
const Either = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
7
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
-
const io_ts_types_1 = require("io-ts-types");
|
|
9
8
|
const validators_1 = require("../../../../validators");
|
|
10
|
-
const BasicTypes_1 = require("../../../../validators/BasicTypes");
|
|
11
9
|
const ImportContent_1 = require("../ImportContent");
|
|
12
10
|
function isValidHttpUrl(param) {
|
|
13
11
|
try {
|
|
@@ -29,26 +27,10 @@ const EmbedUrl = new t.Type("EmbedUrl", (u) => isValidHttpUrl(u), (u, c) => {
|
|
|
29
27
|
return t.failure(u, c, "The value must be a valid http/https url");
|
|
30
28
|
}
|
|
31
29
|
}, t.identity);
|
|
32
|
-
const EmbedProto = t.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})
|
|
37
|
-
t.partial({
|
|
38
|
-
version: (0, io_ts_types_1.withMessage)(t.union([t.string, t.number, t.null]), () => "The value must be either string, number or null"),
|
|
39
|
-
title: BasicTypes_1.String,
|
|
40
|
-
author_name: BasicTypes_1.StringOrNull,
|
|
41
|
-
author_url: BasicTypes_1.StringOrNull,
|
|
42
|
-
provider_name: BasicTypes_1.StringOrNull,
|
|
43
|
-
provider_url: BasicTypes_1.StringOrNull,
|
|
44
|
-
cache_age: (0, io_ts_types_1.withMessage)(t.union([t.string, t.number, t.null]), () => "The value must be either string, number or null"),
|
|
45
|
-
thumbnail_url: BasicTypes_1.StringOrNull,
|
|
46
|
-
thumbnail_width: BasicTypes_1.NumberOrNull,
|
|
47
|
-
thumbnail_height: BasicTypes_1.NumberOrNull,
|
|
48
|
-
html: BasicTypes_1.StringOrNull,
|
|
49
|
-
}),
|
|
50
|
-
]));
|
|
51
|
-
const embedValue = new t.Type("ImportEmbedValue", (u) => EmbedProto.is(u) && "all" in u, (u) => {
|
|
52
|
-
return (0, function_1.pipe)(EmbedProto.decode(u), Either.map((parsed) => ({ ...parsed, all: u })));
|
|
30
|
+
const EmbedProto = t.type({
|
|
31
|
+
embed_url: EmbedUrl,
|
|
32
|
+
});
|
|
33
|
+
const Embed = new t.Type("ImportEmbedValue", (u) => EmbedProto.is(u), (u) => {
|
|
34
|
+
return (0, function_1.pipe)(EmbedProto.decode(u), Either.map((parsed) => ({ embed_url: parsed.embed_url })));
|
|
53
35
|
}, t.identity);
|
|
54
|
-
exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(
|
|
36
|
+
exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(Embed));
|
|
@@ -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;
|
|
@@ -228,24 +198,9 @@ export declare const ImportNestable: {
|
|
|
228
198
|
} | null;
|
|
229
199
|
}> | import("fp-ts/lib/Either").Right<{
|
|
230
200
|
type: "Embed";
|
|
231
|
-
value:
|
|
201
|
+
value: {
|
|
232
202
|
embed_url: string;
|
|
233
|
-
|
|
234
|
-
} & {
|
|
235
|
-
version?: string | number | null;
|
|
236
|
-
title?: string;
|
|
237
|
-
author_name?: string | null;
|
|
238
|
-
author_url?: string | null;
|
|
239
|
-
provider_name?: string | null;
|
|
240
|
-
provider_url?: string | null;
|
|
241
|
-
cache_age?: string | number | null;
|
|
242
|
-
thumbnail_url?: string | null;
|
|
243
|
-
thumbnail_width?: number | null;
|
|
244
|
-
thumbnail_height?: number | null;
|
|
245
|
-
html?: string | null;
|
|
246
|
-
} & {
|
|
247
|
-
all: unknown;
|
|
248
|
-
}) | null;
|
|
203
|
+
} | null;
|
|
249
204
|
}> | import("fp-ts/lib/Either").Right<{
|
|
250
205
|
type: "Date";
|
|
251
206
|
value: Date | null;
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type Embed = {
|
|
2
|
+
type: string
|
|
3
|
+
version?: string | null
|
|
4
|
+
author_name?: string | null
|
|
5
|
+
author_url?: string | null
|
|
6
|
+
provider_name?: string | null
|
|
7
|
+
provider_url?: string | null
|
|
8
|
+
cache_age?: string | null
|
|
9
|
+
thumbnail_url?: string | null
|
|
10
|
+
thumbnail_width?: number | null
|
|
11
|
+
thumbnail_height?: number | null
|
|
12
|
+
html?: string | null
|
|
13
|
+
title?: string | null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type EmbedUrl = string
|
|
17
|
+
|
|
18
|
+
export const getEmbedOrThrow =
|
|
19
|
+
(embeds: Record<string, Embed>) => (embedUrl: string) => {
|
|
20
|
+
const embed = embeds[embedUrl]
|
|
21
|
+
if (!embed) throw new Error(`Missing embed with url '${embedUrl}'`)
|
|
22
|
+
return embed
|
|
23
|
+
}
|
package/src/common/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Asset } from "../../common"
|
|
2
|
+
import type { Embed } from "../../common/Embed"
|
|
2
3
|
import type { Document, WidgetContent } from "../../content"
|
|
3
4
|
import type { ImportDocument } from "../validators"
|
|
4
5
|
import type { ImportField } from "../validators/fields/ImportField"
|
|
@@ -7,10 +8,11 @@ import { convertNestableWidget, uidConverter } from "./fields"
|
|
|
7
8
|
export function convertImportToContent(
|
|
8
9
|
document: ImportDocument,
|
|
9
10
|
assets: Record<string, Asset>,
|
|
11
|
+
embeds: Record<string, Embed>,
|
|
10
12
|
): Document {
|
|
11
13
|
return Object.entries(document).reduce<Document>(
|
|
12
14
|
(acc, [fieldKey, fieldValue]) => {
|
|
13
|
-
const newFieldValue = convertWidget(fieldValue, assets)
|
|
15
|
+
const newFieldValue = convertWidget(fieldValue, assets, embeds)
|
|
14
16
|
return newFieldValue ? { ...acc, [fieldKey]: newFieldValue } : acc
|
|
15
17
|
},
|
|
16
18
|
{},
|
|
@@ -20,11 +22,12 @@ export function convertImportToContent(
|
|
|
20
22
|
function convertWidget(
|
|
21
23
|
field: ImportField,
|
|
22
24
|
assets: Record<string, Asset>,
|
|
25
|
+
embeds: Record<string, Embed>,
|
|
23
26
|
): WidgetContent | undefined {
|
|
24
27
|
switch (field.type) {
|
|
25
28
|
case "UID":
|
|
26
29
|
return uidConverter(field.value)
|
|
27
30
|
default:
|
|
28
|
-
return convertNestableWidget(field, assets)
|
|
31
|
+
return convertNestableWidget(field, assets, embeds)
|
|
29
32
|
}
|
|
30
33
|
}
|
|
@@ -1,15 +1,37 @@
|
|
|
1
|
+
import type { Embed } from "../../../../common"
|
|
2
|
+
import { getEmbedOrThrow } from "../../../../common"
|
|
1
3
|
import type { EmbedContent } from "../../../../content"
|
|
4
|
+
import { withOptionals } from "../../../../utils/Objects"
|
|
2
5
|
import type { ImportEmbed } from "../../../validators"
|
|
3
6
|
|
|
4
7
|
export const embedConverter = (
|
|
5
8
|
field: ImportEmbed["value"],
|
|
9
|
+
embeds: Record<string, Embed>,
|
|
6
10
|
): EmbedContent | undefined => {
|
|
7
11
|
if (field === null) return
|
|
8
|
-
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const embed = getEmbedOrThrow(embeds)(field.embed_url)
|
|
13
|
+
return withOptionals<EmbedContent>(
|
|
14
|
+
{
|
|
15
|
+
embed_url: field.embed_url,
|
|
16
|
+
type: embed.type,
|
|
17
|
+
all: {
|
|
18
|
+
embed_url: field.embed_url,
|
|
19
|
+
...embed,
|
|
20
|
+
},
|
|
21
|
+
__TYPE__: "EmbedContent",
|
|
22
|
+
},
|
|
23
|
+
[
|
|
24
|
+
["version", embed.version],
|
|
25
|
+
["title", embed.title],
|
|
26
|
+
["author_name", embed.author_name],
|
|
27
|
+
["author_url", embed.author_url],
|
|
28
|
+
["provider_name", embed.provider_name],
|
|
29
|
+
["provider_url", embed.provider_url],
|
|
30
|
+
["cache_age", embed.cache_age],
|
|
31
|
+
["thumbnail_url", embed.thumbnail_url],
|
|
32
|
+
["thumbnail_width", embed.thumbnail_width],
|
|
33
|
+
["thumbnail_height", embed.thumbnail_height],
|
|
34
|
+
["html", embed.html],
|
|
35
|
+
],
|
|
36
|
+
)
|
|
15
37
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Asset } from "../../../../common"
|
|
2
|
+
import type { Embed } from "../../../../common/Embed"
|
|
2
3
|
import type { WidgetContent } from "../../../../content"
|
|
3
4
|
import type { ImportNestable } from "../../../validators"
|
|
4
5
|
import {
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
export function convertNestableWidget(
|
|
19
20
|
field: ImportNestable,
|
|
20
21
|
assets: Record<string, Asset>,
|
|
22
|
+
embeds: Record<string, Embed>,
|
|
21
23
|
): WidgetContent | undefined {
|
|
22
24
|
switch (field.type) {
|
|
23
25
|
case "Boolean":
|
|
@@ -35,7 +37,7 @@ export function convertNestableWidget(
|
|
|
35
37
|
case "Timestamp":
|
|
36
38
|
return timestampConverter(field.value)
|
|
37
39
|
case "Embed":
|
|
38
|
-
return embedConverter(field.value)
|
|
40
|
+
return embedConverter(field.value, embeds)
|
|
39
41
|
case "GeoPoint":
|
|
40
42
|
return geopointConverter(field.value)
|
|
41
43
|
case "Link":
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import * as Either from "fp-ts/
|
|
1
|
+
import * as Either from "fp-ts/Either"
|
|
2
2
|
import { pipe } from "fp-ts/lib/function"
|
|
3
3
|
import * as t from "io-ts"
|
|
4
|
-
import { withMessage } from "io-ts-types"
|
|
5
4
|
|
|
6
5
|
import { EmptyObjectOrElse } from "../../../../validators"
|
|
7
|
-
import {
|
|
8
|
-
NumberOrNull,
|
|
9
|
-
String,
|
|
10
|
-
StringOrNull,
|
|
11
|
-
} from "../../../../validators/BasicTypes"
|
|
12
6
|
import { ImportContent } from "../ImportContent"
|
|
13
7
|
|
|
14
8
|
type URL = string
|
|
@@ -38,49 +32,23 @@ const EmbedUrl = new t.Type<URL, URL, unknown>(
|
|
|
38
32
|
t.identity,
|
|
39
33
|
)
|
|
40
34
|
|
|
41
|
-
const EmbedProto = t.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
embed_url: EmbedUrl,
|
|
45
|
-
type: String,
|
|
46
|
-
}),
|
|
47
|
-
t.partial({
|
|
48
|
-
version: withMessage(
|
|
49
|
-
t.union([t.string, t.number, t.null]),
|
|
50
|
-
() => "The value must be either string, number or null",
|
|
51
|
-
),
|
|
52
|
-
title: String,
|
|
53
|
-
author_name: StringOrNull,
|
|
54
|
-
author_url: StringOrNull,
|
|
55
|
-
provider_name: StringOrNull,
|
|
56
|
-
provider_url: StringOrNull,
|
|
57
|
-
cache_age: withMessage(
|
|
58
|
-
t.union([t.string, t.number, t.null]),
|
|
59
|
-
() => "The value must be either string, number or null",
|
|
60
|
-
),
|
|
61
|
-
thumbnail_url: StringOrNull,
|
|
62
|
-
thumbnail_width: NumberOrNull,
|
|
63
|
-
thumbnail_height: NumberOrNull,
|
|
64
|
-
html: StringOrNull,
|
|
65
|
-
}),
|
|
66
|
-
]),
|
|
67
|
-
)
|
|
35
|
+
const EmbedProto = t.type({
|
|
36
|
+
embed_url: EmbedUrl,
|
|
37
|
+
})
|
|
68
38
|
type EmbedProto = t.TypeOf<typeof EmbedProto>
|
|
69
39
|
|
|
70
|
-
type Embed = EmbedProto
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
const embedValue = new t.Type<Embed>(
|
|
40
|
+
type Embed = EmbedProto
|
|
41
|
+
const Embed = new t.Type<Embed>(
|
|
74
42
|
"ImportEmbedValue",
|
|
75
|
-
(u: unknown): u is Embed => EmbedProto.is(u)
|
|
43
|
+
(u: unknown): u is Embed => EmbedProto.is(u),
|
|
76
44
|
(u: unknown) => {
|
|
77
45
|
return pipe(
|
|
78
46
|
EmbedProto.decode(u),
|
|
79
|
-
Either.map((parsed) => ({
|
|
47
|
+
Either.map((parsed) => ({ embed_url: parsed.embed_url })),
|
|
80
48
|
)
|
|
81
49
|
},
|
|
82
50
|
t.identity,
|
|
83
51
|
)
|
|
84
52
|
|
|
85
|
-
export const ImportEmbed = ImportContent("Embed", EmptyObjectOrElse(
|
|
53
|
+
export const ImportEmbed = ImportContent("Embed", EmptyObjectOrElse(Embed))
|
|
86
54
|
export type ImportEmbed = t.TypeOf<typeof ImportEmbed>
|