@prismicio/types-internal 2.2.0-alpha.1 → 2.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/content/fields/GroupContent.js +11 -4
- 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 +3 -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 +3 -0
- package/lib/import/converters/fields/nestable/Embed.js +13 -0
- package/lib/import/converters/fields/nestable/Image.d.ts +18 -0
- package/lib/import/converters/fields/nestable/Image.js +45 -0
- package/lib/import/converters/fields/nestable/Link.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Link.js +19 -0
- package/lib/import/converters/fields/nestable/Nestable.d.ts +2 -1
- package/lib/import/converters/fields/nestable/Nestable.js +7 -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 +3 -0
- package/lib/import/converters/fields/nestable/index.js +3 -0
- package/lib/import/validators/Document.d.ts +4 -4
- package/lib/import/validators/Document.js +41 -44
- 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 +131 -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 +27 -0
- package/lib/import/validators/fields/nestable/Embed.js +54 -0
- package/lib/import/validators/fields/nestable/Image.d.ts +24 -0
- package/lib/import/validators/fields/nestable/Image.js +45 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +20 -0
- package/lib/import/validators/fields/nestable/Link.js +30 -0
- package/lib/import/validators/fields/nestable/Nestable.d.ts +124 -4
- package/lib/import/validators/fields/nestable/Nestable.js +50 -27
- 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 +3 -0
- package/lib/import/validators/fields/nestable/index.js +3 -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/index.d.ts +1 -1
- package/lib/validators/index.js +1 -1
- package/package.json +3 -2
- package/src/content/fields/GroupContent.ts +9 -5
- package/src/customtypes/widgets/nestable/NestableWidget.ts +0 -17
- package/src/import/converters/Document.ts +18 -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 +15 -0
- package/src/import/converters/fields/nestable/Image.ts +68 -0
- package/src/import/converters/fields/nestable/Nestable.ts +11 -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 +3 -0
- package/src/import/validators/Document.ts +94 -79
- 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 +86 -0
- package/src/import/validators/fields/nestable/Image.ts +90 -0
- package/src/import/validators/fields/nestable/Nestable.ts +55 -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 +3 -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/index.ts +1 -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
|
@@ -2,71 +2,68 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImportDocument = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const fp_ts_1 = require("fp-ts");
|
|
6
|
+
const Either_1 = require("fp-ts/Either");
|
|
7
|
+
const function_1 = require("fp-ts/lib/function");
|
|
6
8
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
-
const
|
|
9
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
8
10
|
const Objects_1 = require("../../utils/Objects");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
value: raw,
|
|
14
|
-
context: [],
|
|
15
|
-
message: "document is not an object",
|
|
16
|
-
};
|
|
17
|
-
return Either.left([error]);
|
|
18
|
-
}
|
|
19
|
-
// flattening the fields within the tabs
|
|
20
|
-
const maskFields = Object.values(mask.json).reduce((acc, tab) => ({
|
|
11
|
+
const ImportField_1 = require("./fields/ImportField");
|
|
12
|
+
const rawImportDocument = (0, io_ts_types_1.withMessage)(t.record(t.string, t.unknown), () => "document is not an object");
|
|
13
|
+
function flattenCustomTypeFields(customType) {
|
|
14
|
+
return Object.values(customType.json).reduce((acc, tab) => ({
|
|
21
15
|
...acc,
|
|
22
16
|
...tab,
|
|
23
17
|
}));
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
}
|
|
19
|
+
function validateField(document, customType) {
|
|
20
|
+
return (key, content, model) => {
|
|
27
21
|
// the field is not defined in the custom type -> extra field or typo
|
|
28
|
-
if (!
|
|
22
|
+
if (!model) {
|
|
29
23
|
const error = {
|
|
30
|
-
value:
|
|
31
|
-
context: [{ key:
|
|
32
|
-
message: `The field ${
|
|
24
|
+
value: content,
|
|
25
|
+
context: [{ key: key, type: t.unknown }],
|
|
26
|
+
message: `The field ${key} is not part of the Custom type`,
|
|
33
27
|
};
|
|
34
|
-
return
|
|
28
|
+
return fp_ts_1.either.left([error]);
|
|
35
29
|
}
|
|
36
30
|
// retrieving the right codec then testing out fieldValue with it.
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
// We need to override the context to make it right.
|
|
43
|
-
const errors = result.left.map(error => {
|
|
31
|
+
const { result, codec } = ImportField_1.ImportField.decode(model)(content);
|
|
32
|
+
// error.context is pointing at root when it should point to a `fieldKey`.
|
|
33
|
+
// We need to override the context to make it right.
|
|
34
|
+
if ((0, Either_1.isLeft)(result)) {
|
|
35
|
+
const errors = result.left.map((error) => {
|
|
44
36
|
const contextHead = error.context[0];
|
|
45
37
|
const context = [
|
|
46
|
-
{ key:
|
|
38
|
+
{ key: "", actual: document, type: (0, exports.ImportDocument)(customType) },
|
|
47
39
|
contextHead
|
|
48
|
-
? { ...contextHead, key:
|
|
49
|
-
: { key:
|
|
50
|
-
...error.context.slice(1)
|
|
40
|
+
? { ...contextHead, key: key }
|
|
41
|
+
: { key: key, actual: content, type: codec },
|
|
42
|
+
...error.context.slice(1),
|
|
51
43
|
];
|
|
52
44
|
return { ...error, context };
|
|
53
45
|
});
|
|
54
|
-
return
|
|
46
|
+
return fp_ts_1.either.left(errors);
|
|
55
47
|
}
|
|
56
|
-
|
|
48
|
+
return fp_ts_1.either.right(result.right);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function validateDocument(customType, rawDoc) {
|
|
52
|
+
const fieldModels = flattenCustomTypeFields(customType);
|
|
53
|
+
const { document, errors } = Object.entries(rawDoc).reduce((acc, [fieldKey, fieldValue]) => {
|
|
54
|
+
const parsedField = validateField(rawDoc, customType)(fieldKey, fieldValue, fieldModels[fieldKey]);
|
|
55
|
+
if ((0, Either_1.isLeft)(parsedField))
|
|
56
|
+
return { ...acc, errors: [...acc.errors, ...parsedField.left] };
|
|
57
57
|
return {
|
|
58
58
|
...acc,
|
|
59
|
-
document: { ...acc.document, [fieldKey]:
|
|
59
|
+
document: { ...acc.document, [fieldKey]: parsedField.right },
|
|
60
60
|
};
|
|
61
61
|
}, { document: {}, errors: [] });
|
|
62
|
-
// Returning either the errors of
|
|
63
62
|
if (errors.length > 0)
|
|
64
|
-
return
|
|
65
|
-
return
|
|
63
|
+
return fp_ts_1.either.left(errors);
|
|
64
|
+
return fp_ts_1.either.right(document);
|
|
65
|
+
}
|
|
66
|
+
const ImportDocument = (customType) => new t.Type("ImportDocument", (u) => (0, Objects_1.isObject)(u), (raw) => {
|
|
67
|
+
return (0, function_1.pipe)(rawImportDocument.decode(raw), fp_ts_1.either.chain((doc) => validateDocument(customType, doc)));
|
|
66
68
|
}, t.identity);
|
|
67
69
|
exports.ImportDocument = ImportDocument;
|
|
68
|
-
function getFieldCodec(maskValue) {
|
|
69
|
-
if ((0, customtypes_1.isNestableWidget)(maskValue))
|
|
70
|
-
return (0, fields_1.getNestableFieldCodec)(maskValue);
|
|
71
|
-
throw new Error(`Unsupported type of field ${maskValue.type}`);
|
|
72
|
-
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const ImportContent: <T extends "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp" | "Group" | "Choice" | "Slices" | "UID", A, O = A>(type: T, valueCodec: t.Type<A, O, unknown>) => t.Type<{
|
|
3
|
+
type: T;
|
|
4
|
+
value: A;
|
|
5
|
+
}, O, unknown>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportContent = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fp_ts_1 = require("fp-ts");
|
|
6
|
+
const function_1 = require("fp-ts/lib/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const Objects_1 = require("../../../utils/Objects");
|
|
9
|
+
const ImportContent = (type, valueCodec) => new t.Type("ImportField", (u) => {
|
|
10
|
+
if (!(0, Objects_1.isObject)(u))
|
|
11
|
+
return false;
|
|
12
|
+
return type === u["type"] && valueCodec.is(u["value"]);
|
|
13
|
+
}, (u) => {
|
|
14
|
+
return (0, function_1.pipe)(valueCodec.decode(u), fp_ts_1.either.map((decodedValue) => {
|
|
15
|
+
return {
|
|
16
|
+
type,
|
|
17
|
+
value: decodedValue,
|
|
18
|
+
};
|
|
19
|
+
}));
|
|
20
|
+
}, (field) => field.value);
|
|
21
|
+
exports.ImportContent = ImportContent;
|
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
type: string;
|
|
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
|
+
}, ({
|
|
38
|
+
embed_url: string;
|
|
39
|
+
type: string;
|
|
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<{
|
|
55
|
+
type: "Image";
|
|
56
|
+
value: (import("./nestable").ImageField & {
|
|
57
|
+
thumbnails: Record<string, import("./nestable").ImageField>;
|
|
58
|
+
}) | null;
|
|
59
|
+
}, (import("./nestable").ImageField & {
|
|
60
|
+
thumbnails: Record<string, import("./nestable").ImageField>;
|
|
61
|
+
}) | undefined, unknown> | import("io-ts").Type<{
|
|
62
|
+
type: "Number";
|
|
63
|
+
value: number | null;
|
|
64
|
+
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
65
|
+
type: "Select";
|
|
66
|
+
value: string | null;
|
|
67
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
68
|
+
type: "Text";
|
|
69
|
+
value: string | null;
|
|
70
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
71
|
+
type: "Timestamp";
|
|
72
|
+
value: Date | null;
|
|
73
|
+
}, Date | undefined, unknown>;
|
|
74
|
+
result: import("fp-ts/lib/Either").Left<import("io-ts").Errors> | import("fp-ts/lib/Either").Right<{
|
|
75
|
+
type: "Timestamp";
|
|
76
|
+
value: Date | null;
|
|
77
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
78
|
+
type: "Text";
|
|
79
|
+
value: string | null;
|
|
80
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
81
|
+
type: "Select";
|
|
82
|
+
value: string | null;
|
|
83
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
84
|
+
type: "Number";
|
|
85
|
+
value: number | null;
|
|
86
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
87
|
+
type: "Image";
|
|
88
|
+
value: (import("./nestable").ImageField & {
|
|
89
|
+
thumbnails: Record<string, import("./nestable").ImageField>;
|
|
90
|
+
}) | null;
|
|
91
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
92
|
+
type: "Embed";
|
|
93
|
+
value: ({
|
|
94
|
+
embed_url: string;
|
|
95
|
+
type: string;
|
|
96
|
+
} & {
|
|
97
|
+
version?: string | number | null;
|
|
98
|
+
title?: string;
|
|
99
|
+
author_name?: string | null;
|
|
100
|
+
author_url?: string | null;
|
|
101
|
+
provider_name?: string | null;
|
|
102
|
+
provider_url?: string | null;
|
|
103
|
+
cache_age?: string | number | null;
|
|
104
|
+
thumbnail_url?: string | null;
|
|
105
|
+
thumbnail_width?: number | null;
|
|
106
|
+
thumbnail_height?: number | null;
|
|
107
|
+
html?: string | null;
|
|
108
|
+
} & {
|
|
109
|
+
all: unknown;
|
|
110
|
+
}) | null;
|
|
111
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
112
|
+
type: "Date";
|
|
113
|
+
value: Date | null;
|
|
114
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
115
|
+
type: "Color";
|
|
116
|
+
value: `#${string}` | null;
|
|
117
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
118
|
+
type: "Boolean";
|
|
119
|
+
value: boolean | null;
|
|
120
|
+
}>;
|
|
121
|
+
} | {
|
|
122
|
+
codec: import("io-ts").Type<{
|
|
123
|
+
type: "UID";
|
|
124
|
+
value: string | null;
|
|
125
|
+
}, string | undefined, unknown>;
|
|
126
|
+
result: import("io-ts").Validation<{
|
|
127
|
+
type: "UID";
|
|
128
|
+
value: string | null;
|
|
129
|
+
}>;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
@@ -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,27 @@
|
|
|
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
|
+
export declare const ImportEmbed: t.Type<{
|
|
23
|
+
type: "Embed";
|
|
24
|
+
value: Embed | null;
|
|
25
|
+
}, Embed | undefined, unknown>;
|
|
26
|
+
export declare type ImportEmbed = t.TypeOf<typeof ImportEmbed>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
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/lib/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/lib/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
9
|
+
const validators_1 = require("../../../../validators");
|
|
10
|
+
const BasicTypes_1 = require("../../../../validators/BasicTypes");
|
|
11
|
+
const ImportContent_1 = require("../ImportContent");
|
|
12
|
+
function isValidHttpUrl(param) {
|
|
13
|
+
try {
|
|
14
|
+
if (typeof param !== "string") {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const url = new URL(param);
|
|
18
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const EmbedUrl = new t.Type("EmbedUrl", (u) => isValidHttpUrl(u), (u, c) => {
|
|
25
|
+
if (isValidHttpUrl(u)) {
|
|
26
|
+
return t.success(u);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return t.failure(u, c, "The value must be a valid http/https url");
|
|
30
|
+
}
|
|
31
|
+
}, t.identity);
|
|
32
|
+
const EmbedProto = t.exact(t.intersection([
|
|
33
|
+
t.type({
|
|
34
|
+
embed_url: EmbedUrl,
|
|
35
|
+
type: BasicTypes_1.String,
|
|
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 })));
|
|
53
|
+
}, t.identity);
|
|
54
|
+
exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(embedValue));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare type ImageField = {
|
|
3
|
+
id: string;
|
|
4
|
+
edit?: {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
zoom: number;
|
|
10
|
+
background: string;
|
|
11
|
+
};
|
|
12
|
+
alt?: string | null;
|
|
13
|
+
credit?: string | null;
|
|
14
|
+
};
|
|
15
|
+
declare type ImageFieldWithThumbnails = ImageField & {
|
|
16
|
+
thumbnails: Record<string, ImageField>;
|
|
17
|
+
};
|
|
18
|
+
declare const ImageFieldWithThumbnails: t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
|
|
19
|
+
export declare const ImportImage: t.Type<{
|
|
20
|
+
type: "Image";
|
|
21
|
+
value: ImageFieldWithThumbnails | null;
|
|
22
|
+
}, ImageFieldWithThumbnails | undefined, unknown>;
|
|
23
|
+
export declare type ImportImage = t.TypeOf<typeof ImportImage>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
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/lib/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const Objects_1 = require("../../../../utils/Objects");
|
|
9
|
+
const validators_1 = require("../../../../validators");
|
|
10
|
+
const BasicTypes_1 = require("../../../../validators/BasicTypes");
|
|
11
|
+
const ImportContent_1 = require("../ImportContent");
|
|
12
|
+
const ImageFieldCodec = validators_1.AnyObject.pipe(t.intersection([
|
|
13
|
+
t.type({
|
|
14
|
+
id: BasicTypes_1.String,
|
|
15
|
+
}),
|
|
16
|
+
t.partial({
|
|
17
|
+
edit: validators_1.AnyObject.pipe(t.strict({
|
|
18
|
+
x: validators_1.Number,
|
|
19
|
+
y: validators_1.Number,
|
|
20
|
+
width: validators_1.Number,
|
|
21
|
+
height: validators_1.Number,
|
|
22
|
+
zoom: validators_1.Number,
|
|
23
|
+
background: BasicTypes_1.String,
|
|
24
|
+
})),
|
|
25
|
+
credit: BasicTypes_1.StringOrNull,
|
|
26
|
+
alt: BasicTypes_1.StringOrNull,
|
|
27
|
+
}),
|
|
28
|
+
]));
|
|
29
|
+
const ThumbnailsCodec = t.record(t.string, ImageFieldCodec);
|
|
30
|
+
const ImageFieldWithThumbnails = new t.Type("ImageFieldWithThumbnails", (u) => ImageFieldCodec.is(u) &&
|
|
31
|
+
"thumbnails" in u &&
|
|
32
|
+
ThumbnailsCodec.is(u["thumbnails"]), (u, ctx) => {
|
|
33
|
+
return (0, function_1.pipe)(ImageFieldCodec.validate(u, ctx), (0, Either_1.chain)((proto) => {
|
|
34
|
+
const { id, edit, credit, alt, ...maybeThumbnails } = proto;
|
|
35
|
+
return (0, function_1.pipe)(ThumbnailsCodec.validate(maybeThumbnails, ctx), (0, Either_1.map)((thumbnails) => (0, Objects_1.withOptionals)({
|
|
36
|
+
id,
|
|
37
|
+
thumbnails,
|
|
38
|
+
}, [
|
|
39
|
+
["edit", edit],
|
|
40
|
+
["credit", credit],
|
|
41
|
+
["alt", alt],
|
|
42
|
+
])));
|
|
43
|
+
}));
|
|
44
|
+
}, t.identity);
|
|
45
|
+
exports.ImportImage = (0, ImportContent_1.ImportContent)("Image", (0, validators_1.NullOrElse)(ImageFieldWithThumbnails));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TypeOf } from "io-ts";
|
|
2
|
+
import * as t from "io-ts";
|
|
3
|
+
export declare const ImportLink: t.Type<{
|
|
4
|
+
type: "Link";
|
|
5
|
+
value: ({
|
|
6
|
+
link_type: "Web";
|
|
7
|
+
url: string;
|
|
8
|
+
} & {
|
|
9
|
+
target?: string;
|
|
10
|
+
}) | {
|
|
11
|
+
link_type: "Document";
|
|
12
|
+
id: string;
|
|
13
|
+
} | {
|
|
14
|
+
link_type: "Media";
|
|
15
|
+
id: string;
|
|
16
|
+
} | null;
|
|
17
|
+
}, {
|
|
18
|
+
link_type: "Document" | "Web" | "Media";
|
|
19
|
+
} | undefined, unknown>;
|
|
20
|
+
export declare type ImportLink = TypeOf<typeof ImportLink>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportLink = 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 io_ts_types_1 = require("io-ts-types");
|
|
9
|
+
const AnyLink = t.type({
|
|
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`"),
|
|
11
|
+
});
|
|
12
|
+
const WebLink = t.intersection([
|
|
13
|
+
t.type({
|
|
14
|
+
link_type: t.literal("Web"),
|
|
15
|
+
url: validators_1.String,
|
|
16
|
+
}),
|
|
17
|
+
t.partial({
|
|
18
|
+
target: validators_1.String,
|
|
19
|
+
}),
|
|
20
|
+
]);
|
|
21
|
+
const DocumentLink = t.type({
|
|
22
|
+
link_type: t.literal("Document"),
|
|
23
|
+
id: validators_1.String,
|
|
24
|
+
});
|
|
25
|
+
const MediaLink = t.type({
|
|
26
|
+
link_type: t.literal("Media"),
|
|
27
|
+
id: validators_1.String,
|
|
28
|
+
});
|
|
29
|
+
const Link = AnyLink.pipe(t.union([WebLink, DocumentLink, MediaLink]));
|
|
30
|
+
exports.ImportLink = (0, ImportContent_1.ImportContent)("Link", (0, validators_1.NullOrElse)(Link));
|