@prismicio/types-internal 2.2.0-alpha.0 → 2.2.0-alpha.10
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 +16 -0
- package/lib/common/Asset.js +11 -0
- package/lib/common/Embed.d.ts +15 -0
- package/lib/common/Embed.js +10 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/content/Document.d.ts +40 -40
- package/lib/content/fields/GroupContent.d.ts +12 -12
- package/lib/content/fields/GroupContent.js +11 -4
- package/lib/content/fields/WidgetContent.d.ts +56 -56
- package/lib/content/fields/nestable/NestableContent.d.ts +7 -7
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +12 -12
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +9 -9
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +14 -14
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -5
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +14 -14
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +14 -14
- package/lib/content/fields/slices/Slice/index.d.ts +30 -30
- package/lib/content/fields/slices/SliceItem.d.ts +30 -30
- package/lib/content/fields/slices/SlicesContent.d.ts +42 -42
- package/lib/customtypes/CustomType.d.ts +2 -0
- package/lib/customtypes/CustomType.js +8 -1
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +0 -157
- package/lib/customtypes/widgets/nestable/NestableWidget.js +1 -17
- package/lib/import/converters/Document.d.ts +4 -2
- package/lib/import/converters/Document.js +9 -7
- package/lib/import/converters/fields/UID.d.ts +3 -0
- package/lib/import/converters/fields/UID.js +12 -0
- package/lib/import/converters/fields/index.d.ts +1 -0
- package/lib/import/converters/fields/index.js +1 -0
- package/lib/import/converters/fields/nestable/Boolean.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Boolean.js +12 -0
- package/lib/import/converters/fields/nestable/Color.js +9 -6
- package/lib/import/converters/fields/nestable/Date.d.ts +1 -1
- package/lib/import/converters/fields/nestable/Date.js +5 -5
- package/lib/import/converters/fields/nestable/Embed.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Embed.js +32 -0
- package/lib/import/converters/fields/nestable/GeooPoint.d.ts +3 -0
- package/lib/import/converters/fields/nestable/GeooPoint.js +15 -0
- package/lib/import/converters/fields/nestable/Image.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Image.js +55 -0
- package/lib/import/converters/fields/nestable/Link.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Link.js +70 -0
- package/lib/import/converters/fields/nestable/Nestable.d.ts +3 -1
- package/lib/import/converters/fields/nestable/Nestable.js +11 -1
- package/lib/import/converters/fields/nestable/Number.js +9 -6
- package/lib/import/converters/fields/nestable/Select.js +9 -6
- package/lib/import/converters/fields/nestable/Text.js +9 -6
- package/lib/import/converters/fields/nestable/Timestamp.d.ts +1 -1
- package/lib/import/converters/fields/nestable/Timestamp.js +9 -6
- package/lib/import/converters/fields/nestable/index.d.ts +5 -0
- package/lib/import/converters/fields/nestable/index.js +5 -0
- package/lib/import/validators/Document.d.ts +4 -4
- package/lib/import/validators/Document.js +45 -39
- package/lib/import/validators/fields/ImportContent.d.ts +5 -0
- package/lib/import/validators/fields/ImportContent.js +21 -0
- package/lib/import/validators/fields/ImportField.d.ts +125 -0
- package/lib/import/validators/fields/ImportField.js +24 -0
- package/lib/import/validators/fields/UID.d.ts +6 -0
- package/lib/import/validators/fields/UID.js +15 -0
- package/lib/import/validators/fields/index.d.ts +1 -5
- package/lib/import/validators/fields/index.js +1 -0
- package/lib/import/validators/fields/nestable/Boolean.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Boolean.js +6 -0
- package/lib/import/validators/fields/nestable/Color.d.ts +5 -4
- package/lib/import/validators/fields/nestable/Color.js +4 -4
- package/lib/import/validators/fields/nestable/Date.d.ts +5 -3
- package/lib/import/validators/fields/nestable/Date.js +4 -2
- package/lib/import/validators/fields/nestable/Embed.d.ts +10 -0
- package/lib/import/validators/fields/nestable/Embed.js +36 -0
- package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
- package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
- package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/Decoder.js +40 -0
- package/lib/import/validators/fields/nestable/Image/Validator.d.ts +37 -0
- package/lib/import/validators/fields/nestable/Image/Validator.js +26 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/index.js +28 -0
- package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Image/model.js +2 -0
- package/lib/import/validators/fields/nestable/Image.d.ts +62 -0
- package/lib/import/validators/fields/nestable/Image.js +76 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +38 -0
- package/lib/import/validators/fields/nestable/Link.js +35 -0
- package/lib/import/validators/fields/nestable/Nestable.d.ts +120 -4
- package/lib/import/validators/fields/nestable/Nestable.js +59 -28
- package/lib/import/validators/fields/nestable/Number.d.ts +16 -9
- package/lib/import/validators/fields/nestable/Number.js +5 -4
- package/lib/import/validators/fields/nestable/Select.d.ts +15 -8
- package/lib/import/validators/fields/nestable/Select.js +4 -2
- package/lib/import/validators/fields/nestable/Text.d.ts +6 -3
- package/lib/import/validators/fields/nestable/Text.js +2 -1
- package/lib/import/validators/fields/nestable/Timestamp.d.ts +5 -3
- package/lib/import/validators/fields/nestable/Timestamp.js +4 -2
- package/lib/import/validators/fields/nestable/index.d.ts +6 -0
- package/lib/import/validators/fields/nestable/index.js +6 -0
- package/lib/utils/DocumentId.d.ts +1 -0
- package/lib/utils/DocumentId.js +7 -0
- package/lib/utils/Objects.d.ts +1 -0
- package/lib/utils/Objects.js +5 -1
- package/lib/validators/BasicTypes.d.ts +8 -0
- package/lib/validators/BasicTypes.js +19 -1
- package/lib/validators/DefaultOrElse.d.ts +5 -0
- package/lib/validators/DefaultOrElse.js +21 -0
- package/lib/validators/NumberRange.d.ts +32 -0
- package/lib/validators/NumberRange.js +40 -0
- package/lib/validators/function.d.ts +20 -0
- package/lib/validators/function.js +41 -1
- package/lib/validators/index.d.ts +2 -1
- package/lib/validators/index.js +4 -2
- package/package.json +3 -2
- package/src/common/Asset.ts +25 -0
- package/src/common/Embed.ts +22 -0
- package/src/common/index.ts +2 -0
- package/src/content/fields/GroupContent.ts +9 -5
- package/src/customtypes/CustomType.ts +13 -0
- package/src/customtypes/widgets/nestable/NestableWidget.ts +0 -17
- package/src/import/converters/Document.ts +22 -11
- package/src/import/converters/fields/UID.ts +13 -0
- package/src/import/converters/fields/index.ts +1 -0
- package/src/import/converters/fields/nestable/Boolean.ts +13 -0
- package/src/import/converters/fields/nestable/Color.ts +7 -5
- package/src/import/converters/fields/nestable/Date.ts +12 -13
- package/src/import/converters/fields/nestable/Embed.ts +37 -0
- package/src/import/converters/fields/nestable/GeooPoint.ts +16 -0
- package/src/import/converters/fields/nestable/Image.ts +73 -0
- package/src/import/converters/fields/nestable/Link.ts +77 -0
- package/src/import/converters/fields/nestable/Nestable.ts +19 -0
- package/src/import/converters/fields/nestable/Number.ts +7 -5
- package/src/import/converters/fields/nestable/Select.ts +7 -5
- package/src/import/converters/fields/nestable/Text.ts +7 -5
- package/src/import/converters/fields/nestable/Timestamp.ts +8 -6
- package/src/import/converters/fields/nestable/index.ts +5 -0
- package/src/import/validators/Document.ts +87 -63
- package/src/import/validators/fields/ImportContent.ts +30 -0
- package/src/import/validators/fields/ImportField.ts +25 -0
- package/src/import/validators/fields/UID.ts +27 -0
- package/src/import/validators/fields/index.ts +1 -7
- package/src/import/validators/fields/nestable/Boolean.ts +7 -0
- package/src/import/validators/fields/nestable/Color.ts +23 -23
- package/src/import/validators/fields/nestable/Date.ts +26 -27
- package/src/import/validators/fields/nestable/Embed.ts +54 -0
- package/src/import/validators/fields/nestable/GeoPoint.ts +21 -0
- package/src/import/validators/fields/nestable/Image/Decoder.ts +61 -0
- package/src/import/validators/fields/nestable/Image/Validator.ts +35 -0
- package/src/import/validators/fields/nestable/Image/index.ts +45 -0
- package/src/import/validators/fields/nestable/Image/model.ts +18 -0
- package/src/import/validators/fields/nestable/Link.ts +54 -0
- package/src/import/validators/fields/nestable/Nestable.ts +65 -26
- package/src/import/validators/fields/nestable/Number.ts +32 -30
- package/src/import/validators/fields/nestable/Select.ts +32 -30
- package/src/import/validators/fields/nestable/Text.ts +6 -6
- package/src/import/validators/fields/nestable/Timestamp.ts +29 -26
- package/src/import/validators/fields/nestable/index.ts +6 -0
- package/src/utils/DocumentId.ts +9 -0
- package/src/utils/Objects.ts +10 -0
- package/src/validators/BasicTypes.ts +48 -0
- package/src/validators/DefaultOrElse.ts +24 -0
- package/src/validators/NumberRange.ts +51 -0
- package/src/validators/function.ts +44 -0
- package/src/validators/index.ts +2 -1
- package/lib/import/converters/fields/utils.d.ts +0 -1
- package/lib/import/converters/fields/utils.js +0 -10
- package/lib/validators/NullOrT.d.ts +0 -2
- package/lib/validators/NullOrT.js +0 -13
- package/src/import/converters/fields/utils.ts +0 -7
- package/src/validators/NullOrT.ts +0 -18
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { StaticWidget } from "../../../customtypes";
|
|
2
|
+
import { ImportNestable } from "./nestable";
|
|
3
|
+
import { ImportUID } from "./UID";
|
|
4
|
+
export declare type ImportField = ImportUID | ImportNestable;
|
|
5
|
+
export declare const ImportField: {
|
|
6
|
+
is(u: unknown): u is ImportNestable;
|
|
7
|
+
decode: (field: StaticWidget) => (content: unknown) => {
|
|
8
|
+
codec: import("io-ts").Type<{
|
|
9
|
+
type: "Boolean";
|
|
10
|
+
value: boolean | null;
|
|
11
|
+
}, boolean | undefined, unknown> | import("io-ts").Type<{
|
|
12
|
+
type: "Color";
|
|
13
|
+
value: `#${string}` | null;
|
|
14
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
15
|
+
type: "Date";
|
|
16
|
+
value: Date | null;
|
|
17
|
+
}, Date | undefined, unknown> | import("io-ts").Type<{
|
|
18
|
+
type: "Embed";
|
|
19
|
+
value: {
|
|
20
|
+
embed_url: string;
|
|
21
|
+
} | null;
|
|
22
|
+
}, {
|
|
23
|
+
embed_url: string;
|
|
24
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
25
|
+
type: "GeoPoint";
|
|
26
|
+
value: {
|
|
27
|
+
latitude: number;
|
|
28
|
+
longitude: number;
|
|
29
|
+
} | null;
|
|
30
|
+
}, {
|
|
31
|
+
latitude: number;
|
|
32
|
+
longitude: number;
|
|
33
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
34
|
+
type: "Image";
|
|
35
|
+
value: import("./nestable").ImageFieldWithThumbnails | null;
|
|
36
|
+
}, import("./nestable").ImageFieldWithThumbnails | undefined, unknown> | import("io-ts").Type<{
|
|
37
|
+
type: "Link";
|
|
38
|
+
value: ({
|
|
39
|
+
link_type: "Web";
|
|
40
|
+
url: string;
|
|
41
|
+
} & {
|
|
42
|
+
target?: string;
|
|
43
|
+
}) | {
|
|
44
|
+
link_type: "Document";
|
|
45
|
+
id: string;
|
|
46
|
+
} | {
|
|
47
|
+
link_type: "Media";
|
|
48
|
+
id: string;
|
|
49
|
+
} | null;
|
|
50
|
+
}, {
|
|
51
|
+
link_type: "Document" | "Web" | "Media";
|
|
52
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
53
|
+
type: "Number";
|
|
54
|
+
value: number | null;
|
|
55
|
+
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
56
|
+
type: "Select";
|
|
57
|
+
value: string | null;
|
|
58
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
59
|
+
type: "Text";
|
|
60
|
+
value: string | null;
|
|
61
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
62
|
+
type: "Timestamp";
|
|
63
|
+
value: Date | null;
|
|
64
|
+
}, Date | undefined, unknown>;
|
|
65
|
+
result: import("fp-ts/lib/Either").Left<import("io-ts").Errors> | import("fp-ts/lib/Either").Right<{
|
|
66
|
+
type: "Timestamp";
|
|
67
|
+
value: Date | null;
|
|
68
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
69
|
+
type: "Text";
|
|
70
|
+
value: string | null;
|
|
71
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
72
|
+
type: "Select";
|
|
73
|
+
value: string | null;
|
|
74
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
75
|
+
type: "Number";
|
|
76
|
+
value: number | null;
|
|
77
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
78
|
+
type: "Link";
|
|
79
|
+
value: ({
|
|
80
|
+
link_type: "Web";
|
|
81
|
+
url: string;
|
|
82
|
+
} & {
|
|
83
|
+
target?: string;
|
|
84
|
+
}) | {
|
|
85
|
+
link_type: "Document";
|
|
86
|
+
id: string;
|
|
87
|
+
} | {
|
|
88
|
+
link_type: "Media";
|
|
89
|
+
id: string;
|
|
90
|
+
} | null;
|
|
91
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
92
|
+
type: "Image";
|
|
93
|
+
value: import("./nestable").ImageFieldWithThumbnails | null;
|
|
94
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
95
|
+
type: "GeoPoint";
|
|
96
|
+
value: {
|
|
97
|
+
latitude: number;
|
|
98
|
+
longitude: number;
|
|
99
|
+
} | null;
|
|
100
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
101
|
+
type: "Embed";
|
|
102
|
+
value: {
|
|
103
|
+
embed_url: string;
|
|
104
|
+
} | null;
|
|
105
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
106
|
+
type: "Date";
|
|
107
|
+
value: Date | null;
|
|
108
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
109
|
+
type: "Color";
|
|
110
|
+
value: `#${string}` | null;
|
|
111
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
112
|
+
type: "Boolean";
|
|
113
|
+
value: boolean | null;
|
|
114
|
+
}>;
|
|
115
|
+
} | {
|
|
116
|
+
codec: import("io-ts").Type<{
|
|
117
|
+
type: "UID";
|
|
118
|
+
value: string | null;
|
|
119
|
+
}, string | undefined, unknown>;
|
|
120
|
+
result: import("io-ts").Validation<{
|
|
121
|
+
type: "UID";
|
|
122
|
+
value: string | null;
|
|
123
|
+
}>;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportField = void 0;
|
|
4
|
+
const nestable_1 = require("./nestable");
|
|
5
|
+
const UID_1 = require("./UID");
|
|
6
|
+
exports.ImportField = {
|
|
7
|
+
is(u) {
|
|
8
|
+
return UID_1.ImportUID.is(u) || nestable_1.ImportNestable.is(u);
|
|
9
|
+
},
|
|
10
|
+
decode: (field) => {
|
|
11
|
+
return (content) => {
|
|
12
|
+
switch (field.type) {
|
|
13
|
+
case "UID":
|
|
14
|
+
return { codec: UID_1.ImportUID, result: UID_1.ImportUID.decode(content) };
|
|
15
|
+
case "Choice":
|
|
16
|
+
case "Slices":
|
|
17
|
+
case "Group":
|
|
18
|
+
throw new Error(`Unsupported type of field ${field.type}`);
|
|
19
|
+
default:
|
|
20
|
+
return nestable_1.ImportNestable.decode(field)(content);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportUID = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../validators");
|
|
7
|
+
const ImportContent_1 = require("./ImportContent");
|
|
8
|
+
const regex = /^[a-z0-9-_.]+$/;
|
|
9
|
+
const uidValue = validators_1.String.pipe(new t.Type("ImportUIDField", (u) => validators_1.String.is(u), (n, c) => {
|
|
10
|
+
if (regex.test(n)) {
|
|
11
|
+
return t.success(n);
|
|
12
|
+
}
|
|
13
|
+
return t.failure(n, c, "UID can only contain alphanumeric characters, dashes, underscores, and dots");
|
|
14
|
+
}, t.identity));
|
|
15
|
+
exports.ImportUID = (0, ImportContent_1.ImportContent)("UID", (0, validators_1.NullOrElse)(uidValue));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportBoolean = void 0;
|
|
4
|
+
const validators_1 = require("../../../../validators");
|
|
5
|
+
const ImportContent_1 = require("../ImportContent");
|
|
6
|
+
exports.ImportBoolean = (0, ImportContent_1.ImportContent)("Boolean", (0, validators_1.NullOrElse)(validators_1.Boolean));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare const ImportColor: t.Type<{
|
|
3
|
+
type: "Color";
|
|
4
|
+
value: `#${string}` | null;
|
|
5
|
+
}, string | undefined, unknown>;
|
|
6
|
+
export declare type ImportColor = t.TypeOf<typeof ImportColor>;
|
|
@@ -5,11 +5,11 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const HexaColorCode_1 = require("../../../../common/HexaColorCode");
|
|
7
7
|
const validators_1 = require("../../../../validators");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
validators_1.String.pipe(new t.Type("ImportColorField", (u) => validators_1.String.is(u) && HexaColorCode_1.HexaColor.is(u), (s, c) => {
|
|
8
|
+
const ImportContent_1 = require("../ImportContent");
|
|
9
|
+
const colorValue = new t.Type("ImportColorValue", (u) => validators_1.String.is(u) && HexaColorCode_1.HexaColor.is(u), (s, c) => {
|
|
11
10
|
if (!HexaColorCode_1.HexaColor.is(s)) {
|
|
12
11
|
return t.failure(s, c, "The color value must be an hexadecimal color code");
|
|
13
12
|
}
|
|
14
13
|
return t.success(s);
|
|
15
|
-
}, t.identity)
|
|
14
|
+
}, t.identity);
|
|
15
|
+
exports.ImportColor = (0, ImportContent_1.ImportContent)("Color", (0, validators_1.NullOrElse)(validators_1.String.pipe(colorValue)));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const ImportDate: t.Type<{
|
|
3
|
+
type: "Date";
|
|
4
|
+
value: Date | null;
|
|
5
|
+
}, Date | undefined, unknown>;
|
|
6
|
+
export declare type ImportDate = t.TypeOf<typeof ImportDate>;
|
|
@@ -6,12 +6,14 @@ const Either_1 = require("fp-ts/Either");
|
|
|
6
6
|
const function_1 = require("fp-ts/function");
|
|
7
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
8
|
const validators_1 = require("../../../../validators");
|
|
9
|
+
const ImportContent_1 = require("../ImportContent");
|
|
9
10
|
const DATE_INPUT_REGEX = /^(\d{1,4})-(\d{1,2})-(\d{1,2})$/;
|
|
10
|
-
|
|
11
|
+
const dateValue = new t.Type("ImportNumberValue", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(validators_1.String.validate(u, c), (0, Either_1.chain)((s) => {
|
|
11
12
|
const date = new Date(s);
|
|
12
13
|
const isInvalidDate = isNaN(date.getTime());
|
|
13
14
|
if (isInvalidDate || !DATE_INPUT_REGEX.test(s)) {
|
|
14
15
|
return t.failure(u, c, "The value must be a Date in the format YYYY-MM-DD");
|
|
15
16
|
}
|
|
16
17
|
return t.success(date);
|
|
17
|
-
})), t.identity)
|
|
18
|
+
})), t.identity);
|
|
19
|
+
exports.ImportDate = (0, ImportContent_1.ImportContent)("Date", (0, validators_1.NullOrElse)(dateValue));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportEmbed = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/lib/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const validators_1 = require("../../../../validators");
|
|
9
|
+
const ImportContent_1 = require("../ImportContent");
|
|
10
|
+
function isValidHttpUrl(param) {
|
|
11
|
+
try {
|
|
12
|
+
if (typeof param !== "string") {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const url = new URL(param);
|
|
16
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const EmbedUrl = new t.Type("EmbedUrl", (u) => isValidHttpUrl(u), (u, c) => {
|
|
23
|
+
if (isValidHttpUrl(u)) {
|
|
24
|
+
return t.success(u);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return t.failure(u, c, "The value must be a valid http/https url");
|
|
28
|
+
}
|
|
29
|
+
}, t.identity);
|
|
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 })));
|
|
35
|
+
}, t.identity);
|
|
36
|
+
exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(Embed));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TypeOf } from "io-ts";
|
|
2
|
+
import * as t from "io-ts";
|
|
3
|
+
export declare const ImportGeoPoint: t.Type<{
|
|
4
|
+
type: "GeoPoint";
|
|
5
|
+
value: {
|
|
6
|
+
latitude: number;
|
|
7
|
+
longitude: number;
|
|
8
|
+
} | null;
|
|
9
|
+
}, {
|
|
10
|
+
latitude: number;
|
|
11
|
+
longitude: number;
|
|
12
|
+
} | undefined, unknown>;
|
|
13
|
+
export declare type ImportGeoPoint = TypeOf<typeof ImportGeoPoint>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportGeoPoint = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../../validators");
|
|
7
|
+
const function_1 = require("../../../../validators/function");
|
|
8
|
+
const ImportContent_1 = require("../ImportContent");
|
|
9
|
+
const GeooPoint = (0, function_1.withFallbackMessage)(t.strict({
|
|
10
|
+
latitude: (0, validators_1.NumberRange)(-90, 90, "latitude"),
|
|
11
|
+
longitude: (0, validators_1.NumberRange)(-180, 180, "longitude"),
|
|
12
|
+
}), () => "GeoPoint must be an object with the properties `latitude` and `longitude` between the given ranges");
|
|
13
|
+
exports.ImportGeoPoint = (0, ImportContent_1.ImportContent)("GeoPoint", (0, validators_1.EmptyObjectOrElse)(GeooPoint));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TypeOf } from "io-ts";
|
|
2
|
+
import type { ImageField } from "./model";
|
|
3
|
+
import type { ImageFieldValidator, ThumbnailsValidator } from "./Validator";
|
|
4
|
+
export declare const decodeImageField: (image: TypeOf<typeof ImageFieldValidator> | undefined, mainImage: TypeOf<typeof ImageFieldValidator>, constraints?: {
|
|
5
|
+
width?: number | null;
|
|
6
|
+
height?: number | null;
|
|
7
|
+
} | undefined) => ImageField;
|
|
8
|
+
export declare const decodeThumbnails: (mainImage: TypeOf<typeof ImageFieldValidator>, thumbnails: TypeOf<typeof ThumbnailsValidator>, field?: ({
|
|
9
|
+
type: "Image";
|
|
10
|
+
} & {
|
|
11
|
+
fieldset?: string | null | undefined;
|
|
12
|
+
config?: {
|
|
13
|
+
label?: string | null | undefined;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
constraint?: {
|
|
16
|
+
width?: number | null;
|
|
17
|
+
height?: number | null;
|
|
18
|
+
};
|
|
19
|
+
thumbnails?: readonly ({
|
|
20
|
+
name: string;
|
|
21
|
+
} & {
|
|
22
|
+
width?: number | null;
|
|
23
|
+
height?: number | null;
|
|
24
|
+
})[];
|
|
25
|
+
};
|
|
26
|
+
}) | undefined) => {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeThumbnails = exports.decodeImageField = void 0;
|
|
4
|
+
// This function merges user input with custom type constraints.
|
|
5
|
+
// If `image` is missing, `mainImage` is used for the encoding
|
|
6
|
+
// (case when user input lacks thumbnail definition)
|
|
7
|
+
const decodeImageField = (image, mainImage, constraints) => {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
9
|
+
const background = (_a = image === null || image === void 0 ? void 0 : image.edit) === null || _a === void 0 ? void 0 : _a.background;
|
|
10
|
+
const width = (_d = (_b = constraints === null || constraints === void 0 ? void 0 : constraints.width) !== null && _b !== void 0 ? _b : (_c = image === null || image === void 0 ? void 0 : image.dimensions) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : (_e = mainImage.dimensions) === null || _e === void 0 ? void 0 : _e.width;
|
|
11
|
+
const height = (_h = (_f = constraints === null || constraints === void 0 ? void 0 : constraints.height) !== null && _f !== void 0 ? _f : (_g = image === null || image === void 0 ? void 0 : image.dimensions) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : (_j = mainImage.dimensions) === null || _j === void 0 ? void 0 : _j.height;
|
|
12
|
+
const alt = image === null || image === void 0 ? void 0 : image.alt;
|
|
13
|
+
const credit = image === null || image === void 0 ? void 0 : image.credit;
|
|
14
|
+
return {
|
|
15
|
+
id: (_k = image === null || image === void 0 ? void 0 : image.id) !== null && _k !== void 0 ? _k : mainImage === null || mainImage === void 0 ? void 0 : mainImage.id,
|
|
16
|
+
edit: {
|
|
17
|
+
x: (_m = (_l = image === null || image === void 0 ? void 0 : image.edit) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
|
|
18
|
+
y: (_p = (_o = image === null || image === void 0 ? void 0 : image.edit) === null || _o === void 0 ? void 0 : _o.y) !== null && _p !== void 0 ? _p : 0,
|
|
19
|
+
zoom: (_r = (_q = image === null || image === void 0 ? void 0 : image.edit) === null || _q === void 0 ? void 0 : _q.zoom) !== null && _r !== void 0 ? _r : 1,
|
|
20
|
+
...(background !== undefined ? { background } : {}),
|
|
21
|
+
},
|
|
22
|
+
dimensions: {
|
|
23
|
+
...(width !== undefined ? { width } : {}),
|
|
24
|
+
...(height !== undefined ? { height } : {}),
|
|
25
|
+
},
|
|
26
|
+
...(alt !== undefined ? { alt } : {}),
|
|
27
|
+
...(credit !== undefined ? { credit } : {}),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.decodeImageField = decodeImageField;
|
|
31
|
+
// Merges provided thumbnails with custom type constraints.
|
|
32
|
+
// If any thumbnail is missing, it is created using the origin image (`mainImage`)
|
|
33
|
+
const decodeThumbnails = (mainImage, thumbnails, field) => {
|
|
34
|
+
var _a, _b, _c;
|
|
35
|
+
return (_c = (_b = (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.thumbnails) === null || _b === void 0 ? void 0 : _b.reduce((acc, thumbnail) => ({
|
|
36
|
+
...acc,
|
|
37
|
+
[thumbnail.name]: (0, exports.decodeImageField)(thumbnails[thumbnail.name], mainImage, thumbnail),
|
|
38
|
+
}), {})) !== null && _c !== void 0 ? _c : {};
|
|
39
|
+
};
|
|
40
|
+
exports.decodeThumbnails = decodeThumbnails;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const ImageFieldValidator: t.Type<{
|
|
3
|
+
id: string;
|
|
4
|
+
} & {
|
|
5
|
+
dimensions?: {
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
};
|
|
9
|
+
edit?: {
|
|
10
|
+
x?: number;
|
|
11
|
+
y?: number;
|
|
12
|
+
zoom?: number;
|
|
13
|
+
background?: string;
|
|
14
|
+
};
|
|
15
|
+
credit?: string | null;
|
|
16
|
+
alt?: string | null;
|
|
17
|
+
}, {
|
|
18
|
+
[x: string]: unknown;
|
|
19
|
+
}, unknown>;
|
|
20
|
+
export declare const ThumbnailsValidator: t.RecordC<t.StringC, t.Type<{
|
|
21
|
+
id: string;
|
|
22
|
+
} & {
|
|
23
|
+
dimensions?: {
|
|
24
|
+
width?: number;
|
|
25
|
+
height?: number;
|
|
26
|
+
};
|
|
27
|
+
edit?: {
|
|
28
|
+
x?: number;
|
|
29
|
+
y?: number;
|
|
30
|
+
zoom?: number;
|
|
31
|
+
background?: string;
|
|
32
|
+
};
|
|
33
|
+
credit?: string | null;
|
|
34
|
+
alt?: string | null;
|
|
35
|
+
}, {
|
|
36
|
+
[x: string]: unknown;
|
|
37
|
+
}, unknown>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThumbnailsValidator = exports.ImageFieldValidator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const BasicTypes_1 = require("../../../../../validators/BasicTypes");
|
|
7
|
+
exports.ImageFieldValidator = BasicTypes_1.AnyObject.pipe(t.intersection([
|
|
8
|
+
t.type({
|
|
9
|
+
id: BasicTypes_1.String,
|
|
10
|
+
}),
|
|
11
|
+
t.partial({
|
|
12
|
+
dimensions: BasicTypes_1.AnyObject.pipe(t.partial({
|
|
13
|
+
width: BasicTypes_1.Number,
|
|
14
|
+
height: BasicTypes_1.Number,
|
|
15
|
+
})),
|
|
16
|
+
edit: BasicTypes_1.AnyObject.pipe(t.partial({
|
|
17
|
+
x: BasicTypes_1.Number,
|
|
18
|
+
y: BasicTypes_1.Number,
|
|
19
|
+
zoom: BasicTypes_1.Number,
|
|
20
|
+
background: BasicTypes_1.String,
|
|
21
|
+
})),
|
|
22
|
+
credit: BasicTypes_1.StringOrNull,
|
|
23
|
+
alt: BasicTypes_1.StringOrNull,
|
|
24
|
+
}),
|
|
25
|
+
]));
|
|
26
|
+
exports.ThumbnailsValidator = t.record(t.string, exports.ImageFieldValidator);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import type { ImageFieldWithThumbnails } from "./model";
|
|
3
|
+
export declare const ImportImage: (field?: ({
|
|
4
|
+
type: "Image";
|
|
5
|
+
} & {
|
|
6
|
+
fieldset?: string | null | undefined;
|
|
7
|
+
config?: {
|
|
8
|
+
label?: string | null | undefined;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
constraint?: {
|
|
11
|
+
width?: number | null;
|
|
12
|
+
height?: number | null;
|
|
13
|
+
};
|
|
14
|
+
thumbnails?: readonly ({
|
|
15
|
+
name: string;
|
|
16
|
+
} & {
|
|
17
|
+
width?: number | null;
|
|
18
|
+
height?: number | null;
|
|
19
|
+
})[];
|
|
20
|
+
};
|
|
21
|
+
}) | undefined) => t.Type<{
|
|
22
|
+
type: "Image";
|
|
23
|
+
value: ImageFieldWithThumbnails | null;
|
|
24
|
+
}, ImageFieldWithThumbnails | undefined, unknown>;
|
|
25
|
+
export declare type ImportImage = t.TypeOf<ReturnType<typeof ImportImage>>;
|
|
26
|
+
export * from "./model";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportImage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/Either");
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const validators_1 = require("../../../../../validators");
|
|
9
|
+
const ImportContent_1 = require("../../ImportContent");
|
|
10
|
+
const Decoder_1 = require("./Decoder");
|
|
11
|
+
const Validator_1 = require("./Validator");
|
|
12
|
+
const ImageField = (field) => new t.Type("ImageField", (u) => Validator_1.ImageFieldValidator.is(u) &&
|
|
13
|
+
"thumbnails" in u &&
|
|
14
|
+
Validator_1.ThumbnailsValidator.is(u["thumbnails"]), (u, ctx) => {
|
|
15
|
+
return (0, function_1.pipe)(Validator_1.ImageFieldValidator.validate(u, ctx), (0, Either_1.chain)((mainImage) => {
|
|
16
|
+
const { id, dimensions, edit, credit, alt, ...maybeThumbnails } = mainImage;
|
|
17
|
+
return (0, function_1.pipe)(Validator_1.ThumbnailsValidator.validate(maybeThumbnails, ctx), (0, Either_1.map)((thumbnails) => {
|
|
18
|
+
var _a;
|
|
19
|
+
return ({
|
|
20
|
+
...(0, Decoder_1.decodeImageField)(mainImage, mainImage, (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.constraint),
|
|
21
|
+
thumbnails: (0, Decoder_1.decodeThumbnails)(mainImage, thumbnails, field),
|
|
22
|
+
});
|
|
23
|
+
}));
|
|
24
|
+
}));
|
|
25
|
+
}, t.identity);
|
|
26
|
+
const ImportImage = (field) => (0, ImportContent_1.ImportContent)("Image", (0, validators_1.NullOrElse)(ImageField(field)));
|
|
27
|
+
exports.ImportImage = ImportImage;
|
|
28
|
+
(0, tslib_1.__exportStar)(require("./model"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare type ImageField = {
|
|
2
|
+
id: string;
|
|
3
|
+
edit: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
zoom: number;
|
|
7
|
+
background?: string;
|
|
8
|
+
};
|
|
9
|
+
dimensions: {
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
};
|
|
13
|
+
credit?: string | null;
|
|
14
|
+
alt?: string | null;
|
|
15
|
+
};
|
|
16
|
+
export declare type ImageFieldWithThumbnails = ImageField & {
|
|
17
|
+
thumbnails: Record<string, ImageField>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare type ImageField = {
|
|
3
|
+
id: string;
|
|
4
|
+
edit: {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
zoom: number;
|
|
8
|
+
background?: string;
|
|
9
|
+
};
|
|
10
|
+
dimensions: {
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
};
|
|
14
|
+
credit?: string | null;
|
|
15
|
+
alt?: string | null;
|
|
16
|
+
};
|
|
17
|
+
declare type ImageFieldWithThumbnails = ImageField & {
|
|
18
|
+
thumbnails: Record<string, ImageField>;
|
|
19
|
+
};
|
|
20
|
+
declare const ImageFieldWithThumbnails: (field?: ({
|
|
21
|
+
type: "Image";
|
|
22
|
+
} & {
|
|
23
|
+
fieldset?: string | null | undefined;
|
|
24
|
+
config?: {
|
|
25
|
+
label?: string | null | undefined;
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
constraint?: {
|
|
28
|
+
width?: number | null;
|
|
29
|
+
height?: number | null;
|
|
30
|
+
};
|
|
31
|
+
thumbnails?: readonly ({
|
|
32
|
+
name: string;
|
|
33
|
+
} & {
|
|
34
|
+
width?: number | null;
|
|
35
|
+
height?: number | null;
|
|
36
|
+
})[];
|
|
37
|
+
};
|
|
38
|
+
}) | undefined) => t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
|
|
39
|
+
export declare const ImportImage: (field?: ({
|
|
40
|
+
type: "Image";
|
|
41
|
+
} & {
|
|
42
|
+
fieldset?: string | null | undefined;
|
|
43
|
+
config?: {
|
|
44
|
+
label?: string | null | undefined;
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
constraint?: {
|
|
47
|
+
width?: number | null;
|
|
48
|
+
height?: number | null;
|
|
49
|
+
};
|
|
50
|
+
thumbnails?: readonly ({
|
|
51
|
+
name: string;
|
|
52
|
+
} & {
|
|
53
|
+
width?: number | null;
|
|
54
|
+
height?: number | null;
|
|
55
|
+
})[];
|
|
56
|
+
};
|
|
57
|
+
}) | undefined) => t.Type<{
|
|
58
|
+
type: "Image";
|
|
59
|
+
value: ImageFieldWithThumbnails | null;
|
|
60
|
+
}, ImageFieldWithThumbnails | undefined, unknown>;
|
|
61
|
+
export declare type ImportImage = t.TypeOf<ReturnType<typeof ImportImage>>;
|
|
62
|
+
export {};
|