@prismicio/types-internal 2.2.0-alpha.3 → 2.2.0-alpha.4
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/import/converters/fields/nestable/Link.d.ts +1 -1
- package/lib/import/converters/fields/nestable/Link.js +23 -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.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/import/converters/fields/nestable/Link.ts +33 -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 +51 -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
|
@@ -2,18 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.linkConverter = void 0;
|
|
4
4
|
const linkConverter = (field) => {
|
|
5
|
-
if (field === null)
|
|
5
|
+
if (field === null) {
|
|
6
6
|
return;
|
|
7
|
-
if (field.link_type === "Document" || field.link_type === "Media") {
|
|
8
|
-
throw new Error("`Document` and `Media` links are not yet supported");
|
|
9
7
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
switch (field.link_type) {
|
|
9
|
+
case "Web":
|
|
10
|
+
return {
|
|
11
|
+
value: {
|
|
12
|
+
url: field.url,
|
|
13
|
+
target: field.target,
|
|
14
|
+
__TYPE__: "ExternalLink",
|
|
15
|
+
},
|
|
16
|
+
__TYPE__: "LinkContent",
|
|
17
|
+
};
|
|
18
|
+
case "Document":
|
|
19
|
+
return {
|
|
20
|
+
value: {
|
|
21
|
+
id: field.id,
|
|
22
|
+
__TYPE__: "DocumentLink",
|
|
23
|
+
},
|
|
24
|
+
__TYPE__: "LinkContent",
|
|
25
|
+
};
|
|
26
|
+
// TODO: https://linear.app/prismic/issue/AGE-90/[content-validation-and-error-management]-link-to-media
|
|
27
|
+
case "Media":
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
18
30
|
};
|
|
19
31
|
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);
|
|
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: ({
|
|
@@ -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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LinkContent } from "../../../../content"
|
|
2
|
+
import type { ImportLink } from "../../../validators"
|
|
3
|
+
|
|
4
|
+
export const linkConverter = (
|
|
5
|
+
field: ImportLink["value"],
|
|
6
|
+
): LinkContent | undefined => {
|
|
7
|
+
if (field === null) {
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
switch (field.link_type) {
|
|
12
|
+
case "Web":
|
|
13
|
+
return {
|
|
14
|
+
value: {
|
|
15
|
+
url: field.url,
|
|
16
|
+
target: field.target,
|
|
17
|
+
__TYPE__: "ExternalLink",
|
|
18
|
+
},
|
|
19
|
+
__TYPE__: "LinkContent",
|
|
20
|
+
}
|
|
21
|
+
case "Document":
|
|
22
|
+
return {
|
|
23
|
+
value: {
|
|
24
|
+
id: field.id,
|
|
25
|
+
__TYPE__: "DocumentLink",
|
|
26
|
+
},
|
|
27
|
+
__TYPE__: "LinkContent",
|
|
28
|
+
}
|
|
29
|
+
// TODO: https://linear.app/prismic/issue/AGE-90/[content-validation-and-error-management]-link-to-media
|
|
30
|
+
case "Media":
|
|
31
|
+
return undefined
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -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)
|
|
40
43
|
case "Image":
|
|
41
44
|
return imageConverter(field.value, assets)
|
|
42
45
|
default:
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
|
|
26
|
+
const DocumentLink = t.type({
|
|
27
|
+
link_type: t.literal("Document"),
|
|
28
|
+
id: DocumentId,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const MediaLink = t.type({
|
|
32
|
+
link_type: t.literal("Media"),
|
|
33
|
+
id: String,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const Link = LinkTypeValidator.pipe(t.union([WebLink, DocumentLink, MediaLink]))
|
|
37
|
+
|
|
38
|
+
// This is the default value for the link
|
|
39
|
+
const AnyLink = t.type({
|
|
40
|
+
link_type: t.literal("Any"),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export const ImportLink = ImportContent(
|
|
44
|
+
"Link",
|
|
45
|
+
DefaultOrElse<
|
|
46
|
+
TypeOf<typeof AnyLink>,
|
|
47
|
+
TypeOf<typeof Link>,
|
|
48
|
+
OutputOf<typeof Link>
|
|
49
|
+
>(AnyLink)(Link),
|
|
50
|
+
)
|
|
51
|
+
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
|
+
)
|