@prismicio/types-internal 2.2.0-alpha.3 → 2.2.0-alpha.5
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/Asset.d.ts +1 -0
- package/lib/common/Asset.js +8 -0
- package/lib/import/converters/fields/nestable/Link.d.ts +3 -2
- package/lib/import/converters/fields/nestable/Link.js +62 -11
- package/lib/import/converters/fields/nestable/Nestable.js +2 -0
- package/lib/import/converters/fields/nestable/index.d.ts +1 -0
- package/lib/import/converters/fields/nestable/index.js +1 -0
- package/lib/import/validators/fields/ImportField.d.ts +30 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Link.js +11 -6
- package/lib/import/validators/fields/nestable/Nestable.d.ts +32 -1
- package/lib/import/validators/fields/nestable/Nestable.js +6 -2
- package/lib/import/validators/fields/nestable/index.d.ts +1 -0
- package/lib/import/validators/fields/nestable/index.js +1 -0
- package/lib/utils/DocumentId.d.ts +1 -0
- package/lib/utils/DocumentId.js +7 -0
- package/package.json +1 -1
- package/src/common/Asset.ts +7 -0
- package/src/import/converters/fields/nestable/Link.ts +77 -0
- package/src/import/converters/fields/nestable/Nestable.ts +3 -0
- package/src/import/converters/fields/nestable/index.ts +1 -0
- package/src/import/validators/fields/nestable/Link.ts +54 -0
- package/src/import/validators/fields/nestable/Nestable.ts +7 -2
- package/src/import/validators/fields/nestable/index.ts +1 -0
- package/src/utils/DocumentId.ts +9 -0
package/lib/common/Asset.d.ts
CHANGED
package/lib/common/Asset.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAssetOrThrow = void 0;
|
|
4
|
+
const getAssetOrThrow = (assets) => (assetId) => {
|
|
5
|
+
const asset = assets[assetId];
|
|
6
|
+
if (!asset)
|
|
7
|
+
throw new Error(`Missing asset with id '${assetId}'`);
|
|
8
|
+
return asset;
|
|
9
|
+
};
|
|
10
|
+
exports.getAssetOrThrow = getAssetOrThrow;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Asset } from "../../../../common";
|
|
2
2
|
import type { LinkContent } from "../../../../content";
|
|
3
|
-
|
|
3
|
+
import type { ImportLink } from "../../../validators";
|
|
4
|
+
export declare const linkConverter: (field: ImportLink["value"], assets: Record<string, Asset>) => LinkContent | undefined;
|
|
@@ -1,19 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.linkConverter = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const common_1 = require("../../../../common");
|
|
5
|
+
const webLinkConverter = (field) => ({
|
|
6
|
+
value: {
|
|
7
|
+
url: field.url,
|
|
8
|
+
target: field.target,
|
|
9
|
+
__TYPE__: "ExternalLink",
|
|
10
|
+
},
|
|
11
|
+
__TYPE__: "LinkContent",
|
|
12
|
+
});
|
|
13
|
+
const documentLinkConverter = (field) => ({
|
|
14
|
+
value: {
|
|
15
|
+
id: field.id,
|
|
16
|
+
__TYPE__: "DocumentLink",
|
|
17
|
+
},
|
|
18
|
+
__TYPE__: "LinkContent",
|
|
19
|
+
});
|
|
20
|
+
const fileLinkConverter = (field, asset) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
return ({
|
|
23
|
+
value: {
|
|
24
|
+
id: field.id,
|
|
25
|
+
url: asset.url,
|
|
26
|
+
name: (_a = asset.filename) !== null && _a !== void 0 ? _a : "unknown.jpg",
|
|
27
|
+
kind: asset.kind,
|
|
28
|
+
size: (_b = asset.size) !== null && _b !== void 0 ? _b : "0",
|
|
29
|
+
__TYPE__: "FileLink",
|
|
30
|
+
},
|
|
31
|
+
__TYPE__: "LinkContent",
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const imageLinkConverter = (field, asset) => {
|
|
35
|
+
var _a, _b, _c, _d;
|
|
36
|
+
return ({
|
|
11
37
|
value: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
38
|
+
id: field.id,
|
|
39
|
+
url: asset.url,
|
|
40
|
+
height: String((_a = asset.height) !== null && _a !== void 0 ? _a : 1),
|
|
41
|
+
width: String((_b = asset.width) !== null && _b !== void 0 ? _b : 1),
|
|
42
|
+
name: (_c = asset.filename) !== null && _c !== void 0 ? _c : "unknown.jpg",
|
|
43
|
+
kind: asset.kind,
|
|
44
|
+
size: (_d = asset.size) !== null && _d !== void 0 ? _d : "0",
|
|
45
|
+
__TYPE__: "ImageLink",
|
|
15
46
|
},
|
|
16
47
|
__TYPE__: "LinkContent",
|
|
17
|
-
};
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const linkConverter = (field, assets) => {
|
|
51
|
+
if (field === null) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
switch (field.link_type) {
|
|
55
|
+
case "Web":
|
|
56
|
+
return webLinkConverter(field);
|
|
57
|
+
case "Document":
|
|
58
|
+
return documentLinkConverter(field);
|
|
59
|
+
case "Media": {
|
|
60
|
+
const asset = (0, common_1.getAssetOrThrow)(assets)(field.id);
|
|
61
|
+
switch (asset.kind) {
|
|
62
|
+
case "all":
|
|
63
|
+
return fileLinkConverter(field, asset);
|
|
64
|
+
case "image":
|
|
65
|
+
return imageLinkConverter(field, asset);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
18
69
|
};
|
|
19
70
|
exports.linkConverter = linkConverter;
|
|
@@ -22,6 +22,8 @@ function convertNestableWidget(field, assets) {
|
|
|
22
22
|
return (0, _1.embedConverter)(field.value);
|
|
23
23
|
case "GeoPoint":
|
|
24
24
|
return (0, _1.geopointConverter)(field.value);
|
|
25
|
+
case "Link":
|
|
26
|
+
return (0, _1.linkConverter)(field.value, assets);
|
|
25
27
|
case "Image":
|
|
26
28
|
return (0, _1.imageConverter)(field.value, assets);
|
|
27
29
|
default:
|
|
@@ -7,6 +7,7 @@ const tslib_1 = require("tslib");
|
|
|
7
7
|
(0, tslib_1.__exportStar)(require("./Embed"), exports);
|
|
8
8
|
(0, tslib_1.__exportStar)(require("./GeooPoint"), exports);
|
|
9
9
|
(0, tslib_1.__exportStar)(require("./Image"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./Link"), exports);
|
|
10
11
|
(0, tslib_1.__exportStar)(require("./Nestable"), exports);
|
|
11
12
|
(0, tslib_1.__exportStar)(require("./Number"), exports);
|
|
12
13
|
(0, tslib_1.__exportStar)(require("./Select"), exports);
|
|
@@ -124,6 +124,22 @@ export declare const ImportField: {
|
|
|
124
124
|
};
|
|
125
125
|
};
|
|
126
126
|
}) | undefined, unknown> | import("io-ts").Type<{
|
|
127
|
+
type: "Link";
|
|
128
|
+
value: ({
|
|
129
|
+
link_type: "Web";
|
|
130
|
+
url: string;
|
|
131
|
+
} & {
|
|
132
|
+
target?: string;
|
|
133
|
+
}) | {
|
|
134
|
+
link_type: "Document";
|
|
135
|
+
id: string;
|
|
136
|
+
} | {
|
|
137
|
+
link_type: "Media";
|
|
138
|
+
id: string;
|
|
139
|
+
} | null;
|
|
140
|
+
}, {
|
|
141
|
+
link_type: "Document" | "Web" | "Media";
|
|
142
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
127
143
|
type: "Number";
|
|
128
144
|
value: number | null;
|
|
129
145
|
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
@@ -148,6 +164,20 @@ export declare const ImportField: {
|
|
|
148
164
|
}> | import("fp-ts/lib/Either").Right<{
|
|
149
165
|
type: "Number";
|
|
150
166
|
value: number | null;
|
|
167
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
168
|
+
type: "Link";
|
|
169
|
+
value: ({
|
|
170
|
+
link_type: "Web";
|
|
171
|
+
url: string;
|
|
172
|
+
} & {
|
|
173
|
+
target?: string;
|
|
174
|
+
}) | {
|
|
175
|
+
link_type: "Document";
|
|
176
|
+
id: string;
|
|
177
|
+
} | {
|
|
178
|
+
link_type: "Media";
|
|
179
|
+
id: string;
|
|
180
|
+
} | null;
|
|
151
181
|
}> | import("fp-ts/lib/Either").Right<{
|
|
152
182
|
type: "Image";
|
|
153
183
|
value: ({
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { TypeOf } from "io-ts";
|
|
2
2
|
import * as t from "io-ts";
|
|
3
|
+
declare const WebLink: t.IntersectionC<[t.TypeC<{
|
|
4
|
+
link_type: t.LiteralC<"Web">;
|
|
5
|
+
url: t.StringC;
|
|
6
|
+
}>, t.PartialC<{
|
|
7
|
+
target: t.StringC;
|
|
8
|
+
}>]>;
|
|
9
|
+
export declare type WebLink = t.TypeOf<typeof WebLink>;
|
|
10
|
+
declare const DocumentLink: t.TypeC<{
|
|
11
|
+
link_type: t.LiteralC<"Document">;
|
|
12
|
+
id: t.Type<string, string, unknown>;
|
|
13
|
+
}>;
|
|
14
|
+
export declare type DocumentLink = t.TypeOf<typeof DocumentLink>;
|
|
15
|
+
declare const MediaLink: t.TypeC<{
|
|
16
|
+
link_type: t.LiteralC<"Media">;
|
|
17
|
+
id: t.StringC;
|
|
18
|
+
}>;
|
|
19
|
+
export declare type MediaLink = t.TypeOf<typeof MediaLink>;
|
|
3
20
|
export declare const ImportLink: t.Type<{
|
|
4
21
|
type: "Link";
|
|
5
22
|
value: ({
|
|
@@ -18,3 +35,4 @@ export declare const ImportLink: t.Type<{
|
|
|
18
35
|
link_type: "Document" | "Web" | "Media";
|
|
19
36
|
} | undefined, unknown>;
|
|
20
37
|
export declare type ImportLink = TypeOf<typeof ImportLink>;
|
|
38
|
+
export {};
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ImportLink = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
7
|
+
const DocumentId_1 = require("../../../../utils/DocumentId");
|
|
6
8
|
const validators_1 = require("../../../../validators");
|
|
7
9
|
const ImportContent_1 = require("../ImportContent");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
link_type: (0, io_ts_types_1.withMessage)(t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]), () => "The value must be one of `Web`, `Document` or `Media`"),
|
|
10
|
+
const LinkTypeValidator = t.type({
|
|
11
|
+
link_type: (0, io_ts_types_1.withMessage)(t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]), () => "The value must be `Web`, `Document` or `Media`"),
|
|
11
12
|
});
|
|
12
13
|
const WebLink = t.intersection([
|
|
13
14
|
t.type({
|
|
@@ -20,11 +21,15 @@ const WebLink = t.intersection([
|
|
|
20
21
|
]);
|
|
21
22
|
const DocumentLink = t.type({
|
|
22
23
|
link_type: t.literal("Document"),
|
|
23
|
-
id:
|
|
24
|
+
id: DocumentId_1.DocumentId,
|
|
24
25
|
});
|
|
25
26
|
const MediaLink = t.type({
|
|
26
27
|
link_type: t.literal("Media"),
|
|
27
28
|
id: validators_1.String,
|
|
28
29
|
});
|
|
29
|
-
const Link =
|
|
30
|
-
|
|
30
|
+
const Link = LinkTypeValidator.pipe(t.union([WebLink, DocumentLink, MediaLink]));
|
|
31
|
+
// This is the default value for the link
|
|
32
|
+
const AnyLink = t.type({
|
|
33
|
+
link_type: t.literal("Any"),
|
|
34
|
+
});
|
|
35
|
+
exports.ImportLink = (0, ImportContent_1.ImportContent)("Link", (0, validators_1.DefaultOrElse)(AnyLink)(Link));
|
|
@@ -5,11 +5,12 @@ import { ImportDate } from "./Date";
|
|
|
5
5
|
import { ImportEmbed } from "./Embed";
|
|
6
6
|
import { ImportGeoPoint } from "./GeoPoint";
|
|
7
7
|
import { ImportImage } from "./Image";
|
|
8
|
+
import { ImportLink } from "./Link";
|
|
8
9
|
import { ImportNumber } from "./Number";
|
|
9
10
|
import { ImportSelect } from "./Select";
|
|
10
11
|
import { ImportText } from "./Text";
|
|
11
12
|
import { ImportTimestamp } from "./Timestamp";
|
|
12
|
-
export declare type ImportNestable = ImportBoolean | ImportColor | ImportNumber | ImportSelect | ImportText | ImportDate | ImportTimestamp | ImportEmbed | ImportGeoPoint | ImportImage;
|
|
13
|
+
export declare type ImportNestable = ImportBoolean | ImportColor | ImportNumber | ImportSelect | ImportText | ImportDate | ImportTimestamp | ImportEmbed | ImportLink | ImportGeoPoint | ImportImage;
|
|
13
14
|
export declare const ImportNestable: {
|
|
14
15
|
is(u: unknown): u is ImportNestable;
|
|
15
16
|
decode: (field: NestableWidget) => (content: unknown) => {
|
|
@@ -132,6 +133,22 @@ export declare const ImportNestable: {
|
|
|
132
133
|
};
|
|
133
134
|
};
|
|
134
135
|
}) | undefined, unknown> | import("io-ts").Type<{
|
|
136
|
+
type: "Link";
|
|
137
|
+
value: ({
|
|
138
|
+
link_type: "Web";
|
|
139
|
+
url: string;
|
|
140
|
+
} & {
|
|
141
|
+
target?: string;
|
|
142
|
+
}) | {
|
|
143
|
+
link_type: "Document";
|
|
144
|
+
id: string;
|
|
145
|
+
} | {
|
|
146
|
+
link_type: "Media";
|
|
147
|
+
id: string;
|
|
148
|
+
} | null;
|
|
149
|
+
}, {
|
|
150
|
+
link_type: "Document" | "Web" | "Media";
|
|
151
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
135
152
|
type: "Number";
|
|
136
153
|
value: number | null;
|
|
137
154
|
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
@@ -156,6 +173,20 @@ export declare const ImportNestable: {
|
|
|
156
173
|
}> | import("fp-ts/lib/Either").Right<{
|
|
157
174
|
type: "Number";
|
|
158
175
|
value: number | null;
|
|
176
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
177
|
+
type: "Link";
|
|
178
|
+
value: ({
|
|
179
|
+
link_type: "Web";
|
|
180
|
+
url: string;
|
|
181
|
+
} & {
|
|
182
|
+
target?: string;
|
|
183
|
+
}) | {
|
|
184
|
+
link_type: "Document";
|
|
185
|
+
id: string;
|
|
186
|
+
} | {
|
|
187
|
+
link_type: "Media";
|
|
188
|
+
id: string;
|
|
189
|
+
} | null;
|
|
159
190
|
}> | import("fp-ts/lib/Either").Right<{
|
|
160
191
|
type: "Image";
|
|
161
192
|
value: ({
|
|
@@ -7,6 +7,7 @@ const Date_1 = require("./Date");
|
|
|
7
7
|
const Embed_1 = require("./Embed");
|
|
8
8
|
const GeoPoint_1 = require("./GeoPoint");
|
|
9
9
|
const Image_1 = require("./Image");
|
|
10
|
+
const Link_1 = require("./Link");
|
|
10
11
|
const Number_1 = require("./Number");
|
|
11
12
|
const Select_1 = require("./Select");
|
|
12
13
|
const Text_1 = require("./Text");
|
|
@@ -21,6 +22,7 @@ exports.ImportNestable = {
|
|
|
21
22
|
Date_1.ImportDate.is(u) ||
|
|
22
23
|
Timestamp_1.ImportTimestamp.is(u) ||
|
|
23
24
|
Embed_1.ImportEmbed.is(u) ||
|
|
25
|
+
Link_1.ImportLink.is(u) ||
|
|
24
26
|
GeoPoint_1.ImportGeoPoint.is(u) ||
|
|
25
27
|
Image_1.ImportImage.is(u));
|
|
26
28
|
},
|
|
@@ -42,10 +44,12 @@ exports.ImportNestable = {
|
|
|
42
44
|
return Date_1.ImportDate;
|
|
43
45
|
case "Timestamp":
|
|
44
46
|
return Timestamp_1.ImportTimestamp;
|
|
45
|
-
case "Image":
|
|
46
|
-
return Image_1.ImportImage;
|
|
47
47
|
case "Embed":
|
|
48
48
|
return Embed_1.ImportEmbed;
|
|
49
|
+
case "Link":
|
|
50
|
+
return Link_1.ImportLink;
|
|
51
|
+
case "Image":
|
|
52
|
+
return Image_1.ImportImage;
|
|
49
53
|
case "GeoPoint":
|
|
50
54
|
return GeoPoint_1.ImportGeoPoint;
|
|
51
55
|
default:
|
|
@@ -7,6 +7,7 @@ const tslib_1 = require("tslib");
|
|
|
7
7
|
(0, tslib_1.__exportStar)(require("./Embed"), exports);
|
|
8
8
|
(0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
|
|
9
9
|
(0, tslib_1.__exportStar)(require("./Image"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./Link"), exports);
|
|
10
11
|
(0, tslib_1.__exportStar)(require("./Nestable"), exports);
|
|
11
12
|
(0, tslib_1.__exportStar)(require("./Number"), exports);
|
|
12
13
|
(0, tslib_1.__exportStar)(require("./Select"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DocumentId: import("io-ts").Type<string, string, unknown>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentId = void 0;
|
|
4
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
5
|
+
const validators_1 = require("../validators");
|
|
6
|
+
const function_1 = require("../validators/function");
|
|
7
|
+
exports.DocumentId = (0, io_ts_types_1.withMessage)((0, function_1.refineType)(validators_1.String, "DocumentId", (s) => s.length === 16), () => "DocumentId must be a 16 character string");
|
package/package.json
CHANGED
package/src/common/Asset.ts
CHANGED
|
@@ -13,3 +13,10 @@ export type Asset = {
|
|
|
13
13
|
credits?: string
|
|
14
14
|
alt?: string
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
export const getAssetOrThrow =
|
|
18
|
+
(assets: Record<string, Asset>) => (assetId: string) => {
|
|
19
|
+
const asset = assets[assetId]
|
|
20
|
+
if (!asset) throw new Error(`Missing asset with id '${assetId}'`)
|
|
21
|
+
return asset
|
|
22
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Asset } from "../../../../common"
|
|
2
|
+
import { getAssetOrThrow } from "../../../../common"
|
|
3
|
+
import type { LinkContent } from "../../../../content"
|
|
4
|
+
import type {
|
|
5
|
+
DocumentLink,
|
|
6
|
+
ImportLink,
|
|
7
|
+
MediaLink,
|
|
8
|
+
WebLink,
|
|
9
|
+
} from "../../../validators"
|
|
10
|
+
|
|
11
|
+
const webLinkConverter = (field: WebLink): LinkContent => ({
|
|
12
|
+
value: {
|
|
13
|
+
url: field.url,
|
|
14
|
+
target: field.target,
|
|
15
|
+
__TYPE__: "ExternalLink",
|
|
16
|
+
},
|
|
17
|
+
__TYPE__: "LinkContent",
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const documentLinkConverter = (field: DocumentLink): LinkContent => ({
|
|
21
|
+
value: {
|
|
22
|
+
id: field.id,
|
|
23
|
+
__TYPE__: "DocumentLink",
|
|
24
|
+
},
|
|
25
|
+
__TYPE__: "LinkContent",
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const fileLinkConverter = (field: MediaLink, asset: Asset): LinkContent => ({
|
|
29
|
+
value: {
|
|
30
|
+
id: field.id,
|
|
31
|
+
url: asset.url,
|
|
32
|
+
name: asset.filename ?? "unknown.jpg",
|
|
33
|
+
kind: asset.kind,
|
|
34
|
+
size: asset.size ?? "0",
|
|
35
|
+
__TYPE__: "FileLink",
|
|
36
|
+
},
|
|
37
|
+
__TYPE__: "LinkContent",
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const imageLinkConverter = (field: MediaLink, asset: Asset): LinkContent => ({
|
|
41
|
+
value: {
|
|
42
|
+
id: field.id,
|
|
43
|
+
url: asset.url,
|
|
44
|
+
height: String(asset.height ?? 1),
|
|
45
|
+
width: String(asset.width ?? 1),
|
|
46
|
+
name: asset.filename ?? "unknown.jpg",
|
|
47
|
+
kind: asset.kind,
|
|
48
|
+
size: asset.size ?? "0",
|
|
49
|
+
__TYPE__: "ImageLink",
|
|
50
|
+
},
|
|
51
|
+
__TYPE__: "LinkContent",
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
export const linkConverter = (
|
|
55
|
+
field: ImportLink["value"],
|
|
56
|
+
assets: Record<string, Asset>,
|
|
57
|
+
): LinkContent | undefined => {
|
|
58
|
+
if (field === null) {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
switch (field.link_type) {
|
|
63
|
+
case "Web":
|
|
64
|
+
return webLinkConverter(field)
|
|
65
|
+
case "Document":
|
|
66
|
+
return documentLinkConverter(field)
|
|
67
|
+
case "Media": {
|
|
68
|
+
const asset = getAssetOrThrow(assets)(field.id)
|
|
69
|
+
switch (asset.kind) {
|
|
70
|
+
case "all":
|
|
71
|
+
return fileLinkConverter(field, asset)
|
|
72
|
+
case "image":
|
|
73
|
+
return imageLinkConverter(field, asset)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
embedConverter,
|
|
9
9
|
geopointConverter,
|
|
10
10
|
imageConverter,
|
|
11
|
+
linkConverter,
|
|
11
12
|
numberConverter,
|
|
12
13
|
selectConverter,
|
|
13
14
|
textConverter,
|
|
@@ -37,6 +38,8 @@ export function convertNestableWidget(
|
|
|
37
38
|
return embedConverter(field.value)
|
|
38
39
|
case "GeoPoint":
|
|
39
40
|
return geopointConverter(field.value)
|
|
41
|
+
case "Link":
|
|
42
|
+
return linkConverter(field.value, assets)
|
|
40
43
|
case "Image":
|
|
41
44
|
return imageConverter(field.value, assets)
|
|
42
45
|
default:
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { OutputOf, TypeOf } from "io-ts"
|
|
2
|
+
import * as t from "io-ts"
|
|
3
|
+
import { withMessage } from "io-ts-types"
|
|
4
|
+
|
|
5
|
+
import { DocumentId } from "../../../../utils/DocumentId"
|
|
6
|
+
import { DefaultOrElse, String } from "../../../../validators"
|
|
7
|
+
import { ImportContent } from "../ImportContent"
|
|
8
|
+
|
|
9
|
+
const LinkTypeValidator = t.type({
|
|
10
|
+
link_type: withMessage(
|
|
11
|
+
t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]),
|
|
12
|
+
() => "The value must be `Web`, `Document` or `Media`",
|
|
13
|
+
),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const WebLink = t.intersection([
|
|
17
|
+
t.type({
|
|
18
|
+
link_type: t.literal("Web"),
|
|
19
|
+
url: String,
|
|
20
|
+
}),
|
|
21
|
+
t.partial({
|
|
22
|
+
target: String,
|
|
23
|
+
}),
|
|
24
|
+
])
|
|
25
|
+
export type WebLink = t.TypeOf<typeof WebLink>
|
|
26
|
+
|
|
27
|
+
const DocumentLink = t.type({
|
|
28
|
+
link_type: t.literal("Document"),
|
|
29
|
+
id: DocumentId,
|
|
30
|
+
})
|
|
31
|
+
export type DocumentLink = t.TypeOf<typeof DocumentLink>
|
|
32
|
+
|
|
33
|
+
const MediaLink = t.type({
|
|
34
|
+
link_type: t.literal("Media"),
|
|
35
|
+
id: String,
|
|
36
|
+
})
|
|
37
|
+
export type MediaLink = t.TypeOf<typeof MediaLink>
|
|
38
|
+
|
|
39
|
+
const Link = LinkTypeValidator.pipe(t.union([WebLink, DocumentLink, MediaLink]))
|
|
40
|
+
|
|
41
|
+
// This is the default value for the link
|
|
42
|
+
const AnyLink = t.type({
|
|
43
|
+
link_type: t.literal("Any"),
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export const ImportLink = ImportContent(
|
|
47
|
+
"Link",
|
|
48
|
+
DefaultOrElse<
|
|
49
|
+
TypeOf<typeof AnyLink>,
|
|
50
|
+
TypeOf<typeof Link>,
|
|
51
|
+
OutputOf<typeof Link>
|
|
52
|
+
>(AnyLink)(Link),
|
|
53
|
+
)
|
|
54
|
+
export type ImportLink = TypeOf<typeof ImportLink>
|
|
@@ -5,6 +5,7 @@ import { ImportDate } from "./Date"
|
|
|
5
5
|
import { ImportEmbed } from "./Embed"
|
|
6
6
|
import { ImportGeoPoint } from "./GeoPoint"
|
|
7
7
|
import { ImportImage } from "./Image"
|
|
8
|
+
import { ImportLink } from "./Link"
|
|
8
9
|
import { ImportNumber } from "./Number"
|
|
9
10
|
import { ImportSelect } from "./Select"
|
|
10
11
|
import { ImportText } from "./Text"
|
|
@@ -19,6 +20,7 @@ export type ImportNestable =
|
|
|
19
20
|
| ImportDate
|
|
20
21
|
| ImportTimestamp
|
|
21
22
|
| ImportEmbed
|
|
23
|
+
| ImportLink
|
|
22
24
|
| ImportGeoPoint
|
|
23
25
|
| ImportImage
|
|
24
26
|
|
|
@@ -33,6 +35,7 @@ export const ImportNestable = {
|
|
|
33
35
|
ImportDate.is(u) ||
|
|
34
36
|
ImportTimestamp.is(u) ||
|
|
35
37
|
ImportEmbed.is(u) ||
|
|
38
|
+
ImportLink.is(u) ||
|
|
36
39
|
ImportGeoPoint.is(u) ||
|
|
37
40
|
ImportImage.is(u)
|
|
38
41
|
)
|
|
@@ -55,10 +58,12 @@ export const ImportNestable = {
|
|
|
55
58
|
return ImportDate
|
|
56
59
|
case "Timestamp":
|
|
57
60
|
return ImportTimestamp
|
|
58
|
-
case "Image":
|
|
59
|
-
return ImportImage
|
|
60
61
|
case "Embed":
|
|
61
62
|
return ImportEmbed
|
|
63
|
+
case "Link":
|
|
64
|
+
return ImportLink
|
|
65
|
+
case "Image":
|
|
66
|
+
return ImportImage
|
|
62
67
|
case "GeoPoint":
|
|
63
68
|
return ImportGeoPoint
|
|
64
69
|
default:
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { withMessage } from "io-ts-types"
|
|
2
|
+
|
|
3
|
+
import { String } from "../validators"
|
|
4
|
+
import { refineType } from "../validators/function"
|
|
5
|
+
|
|
6
|
+
export const DocumentId = withMessage(
|
|
7
|
+
refineType(String, "DocumentId", (s) => s.length === 16),
|
|
8
|
+
() => "DocumentId must be a 16 character string",
|
|
9
|
+
)
|