@prismicio/types-internal 2.2.0-alpha.10 → 2.2.0-alpha.12
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/UUID.d.ts +7 -0
- package/lib/common/UUID.js +8 -0
- package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
- package/lib/import/converters/Document.d.ts +1 -2
- package/lib/import/converters/Document.js +2 -0
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
- package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
- package/lib/import/converters/fields/Slices/Slices.js +16 -0
- package/lib/import/converters/fields/Slices/index.d.ts +1 -0
- package/lib/import/converters/fields/Slices/index.js +4 -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/Nestable.d.ts +2 -2
- package/lib/import/validators/fields/ImportField.d.ts +11 -1
- package/lib/import/validators/fields/ImportField.js +6 -1
- package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +29 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +14 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +60 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/index.js +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
- package/lib/utils/io-ts.d.ts +2 -0
- package/lib/utils/io-ts.js +22 -0
- package/lib/validators/BasicTypes.d.ts +1 -0
- package/lib/validators/BasicTypes.js +2 -1
- package/lib/validators/NonEmptyString.js +2 -1
- package/package.json +4 -2
- package/src/common/UUID.ts +18 -0
- package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
- package/src/import/converters/Document.ts +8 -3
- package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
- package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
- package/src/import/converters/fields/Slices/Slices.ts +20 -0
- package/src/import/converters/fields/Slices/index.ts +1 -0
- package/src/import/converters/fields/index.ts +1 -0
- package/src/import/converters/fields/nestable/Nestable.ts +2 -2
- package/src/import/validators/fields/ImportField.ts +7 -2
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +114 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +6 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +20 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +61 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
- package/src/import/validators/fields/ImportSlices/index.ts +1 -0
- package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
- package/src/utils/io-ts.ts +29 -0
- package/src/validators/BasicTypes.ts +5 -0
- package/src/validators/NonEmptyString.ts +4 -4
- package/lib/import/validators/fields/nestable/Image.d.ts +0 -62
- package/lib/import/validators/fields/nestable/Image.js +0 -76
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedSliceId = exports.SharedSliceIdValidationError = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const UUID_1 = require("../../../../../../common/UUID");
|
|
9
|
+
const validators_1 = require("../../../../../../validators");
|
|
10
|
+
const baseErrorText = "Slice id must be a non empty string matching the following pattern 'slice_type$uuid'";
|
|
11
|
+
exports.SharedSliceIdValidationError = {
|
|
12
|
+
Base: baseErrorText,
|
|
13
|
+
IncorrectUUID: (uuid) => `Incorrect UUID: '${uuid}' - ${baseErrorText}`,
|
|
14
|
+
IncorrectSliceType: (sliceType) => `Incorrect slice_type: '${sliceType}' - ${baseErrorText}`,
|
|
15
|
+
};
|
|
16
|
+
exports.SharedSliceId = new t.Type("SharedSliceId", (u) => {
|
|
17
|
+
if (typeof u !== "string") {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const [sliceName, uuid] = u.split("$");
|
|
21
|
+
return validators_1.NonEmptyString.is(sliceName) && UUID_1.UUID.is(uuid);
|
|
22
|
+
}, (u, c) => (0, function_1.pipe)(validators_1.NonEmptyString.validate(u, c), E.mapLeft((errors) => errors.map((error) => ({
|
|
23
|
+
...error,
|
|
24
|
+
message: exports.SharedSliceIdValidationError.Base,
|
|
25
|
+
}))), E.chain((sliceId) => {
|
|
26
|
+
const [sliceName, uuid] = sliceId.split("$");
|
|
27
|
+
return (0, function_1.pipe)(t.tuple([validators_1.NonEmptyString, UUID_1.UUID]).validate([sliceName, uuid], c), E.mapLeft((errors) => errors.map((error) => {
|
|
28
|
+
const tupleErrorContext = error.context[error.context.length - 1];
|
|
29
|
+
return {
|
|
30
|
+
...error,
|
|
31
|
+
context: [
|
|
32
|
+
...error.context.slice(0, -1), // We don't want the tuple decoder error context
|
|
33
|
+
],
|
|
34
|
+
message: (tupleErrorContext === null || tupleErrorContext === void 0 ? void 0 : tupleErrorContext.key) === "0"
|
|
35
|
+
? exports.SharedSliceIdValidationError.IncorrectSliceType(sliceName)
|
|
36
|
+
: exports.SharedSliceIdValidationError.IncorrectUUID(uuid),
|
|
37
|
+
};
|
|
38
|
+
})));
|
|
39
|
+
}), E.map(([sliceName, uuid]) => `${sliceName}$${uuid}`)), (sliceId) => sliceId);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import { SharedSlice as SharedSliceCustomType } from "../../../../../../customtypes";
|
|
3
|
+
export declare type SharedSliceType = {
|
|
4
|
+
slice_type: string;
|
|
5
|
+
data: SharedSliceCustomType;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Builds the decoder for the 'slice_type' field in the SharedSlice. Alongside the decoded 'slice_type' it also returns the SharedSlice data matching the slice_type.
|
|
9
|
+
* @param slices all the SharedSlices from the custom type
|
|
10
|
+
*/
|
|
11
|
+
export declare const SharedSliceType: (slices: SharedSliceCustomType[]) => t.Type<SharedSliceType, string, unknown>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedSliceType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const customtypes_1 = require("../../../../../../customtypes");
|
|
9
|
+
const validators_1 = require("../../../../../../validators");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
/**
|
|
12
|
+
* slice_type - the validated slice_type
|
|
13
|
+
* slice - SharedSlice custom type data matching the slice_type. We return it alongside the validated slice_type, because it is needed to decode the 'variation' field in the SharedSlice (see SharedSliceVariation.ts)
|
|
14
|
+
*/
|
|
15
|
+
const SharedSliceTypeShape = t.type({
|
|
16
|
+
slice_type: validators_1.NonEmptyString,
|
|
17
|
+
slice: customtypes_1.SharedSlice,
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Builds the decoder for the 'slice_type' field in the SharedSlice. Alongside the decoded 'slice_type' it also returns the SharedSlice data matching the slice_type.
|
|
21
|
+
* @param slices all the SharedSlices from the custom type
|
|
22
|
+
*/
|
|
23
|
+
const SharedSliceType = (slices) => new t.Type("slice_type", (u) => SharedSliceTypeShape.is(u), (u, c) => (0, function_1.pipe)(validators_1.NonEmptyString.validate(u, c), E.chain((slice_type) => (0, function_1.pipe)((0, utils_1.findSlice)(slices)(slice_type), E.fold((err) => t.failure(u, c, err), (data) => t.success({ slice_type, data }))))), ({ slice_type }) => slice_type);
|
|
24
|
+
exports.SharedSliceType = SharedSliceType;
|
package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import { SharedSlice, Variation } from "../../../../../../customtypes";
|
|
3
|
+
export declare type SharedSliceVariation = {
|
|
4
|
+
variation: string;
|
|
5
|
+
data: Variation;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Builds the decoder for the 'variation' field in the SharedSlice. Alongside the decoded 'variation' it also returns the Variation data matching the variation custom type.
|
|
9
|
+
* @param slice SharedSlice from the custom type
|
|
10
|
+
*/
|
|
11
|
+
export declare const SharedSliceVariation: (slice: SharedSlice) => t.Type<SharedSliceVariation, string, unknown>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedSliceVariation = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const customtypes_1 = require("../../../../../../customtypes");
|
|
9
|
+
const validators_1 = require("../../../../../../validators");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
/**
|
|
12
|
+
* variation - the validated variation of the slice
|
|
13
|
+
* data - Variation data matching the variation. We return it alongside the validated variation, because it is needed to decode the 'primary' and 'items' fields in the SharedSlice.
|
|
14
|
+
*/
|
|
15
|
+
const SharedSliceVariationShape = t.type({
|
|
16
|
+
variation: validators_1.NonEmptyString,
|
|
17
|
+
data: customtypes_1.Variation,
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Builds the decoder for the 'variation' field in the SharedSlice. Alongside the decoded 'variation' it also returns the Variation data matching the variation custom type.
|
|
21
|
+
* @param slice SharedSlice from the custom type
|
|
22
|
+
*/
|
|
23
|
+
const SharedSliceVariation = (slice) => new t.Type("variation", (u) => SharedSliceVariationShape.is(u), (u, c) => (0, function_1.pipe)(validators_1.NonEmptyString.validate(u, c), E.chain((variation) => (0, function_1.pipe)((0, utils_1.findSliceVariation)(slice)(variation), E.fold((err) => t.failure(u, c, err), (data) => t.success({ variation, data }))))), ({ variation }) => variation);
|
|
24
|
+
exports.SharedSliceVariation = SharedSliceVariation;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./OptionalSharedSliceId"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./SharedSliceContent"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./SharedSliceId"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./SharedSliceType"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./SharedSliceVariation"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./errors"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./fields"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./SharedSlice"), exports);
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import * as E from "fp-ts/Either";
|
|
2
|
+
import type { SharedSlice as SharedSliceCustomType } from "../../../../../customtypes";
|
|
3
|
+
import type { Variation } from "../../../../../customtypes";
|
|
4
|
+
export declare const findSlice: (slices: SharedSliceCustomType[]) => (sliceId: string) => E.Either<string, {
|
|
5
|
+
id: string;
|
|
6
|
+
type: "SharedSlice";
|
|
7
|
+
name: string;
|
|
8
|
+
variations: readonly ({
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
imageUrl: string;
|
|
13
|
+
docURL: string;
|
|
14
|
+
version: string;
|
|
15
|
+
} & {
|
|
16
|
+
display?: string;
|
|
17
|
+
primary?: {
|
|
18
|
+
[x: string]: ({
|
|
19
|
+
type: "Boolean";
|
|
20
|
+
} & {
|
|
21
|
+
config?: {
|
|
22
|
+
label?: string | null | undefined;
|
|
23
|
+
default_value?: boolean;
|
|
24
|
+
placeholder_true?: string;
|
|
25
|
+
placeholder_false?: string;
|
|
26
|
+
};
|
|
27
|
+
}) | ({
|
|
28
|
+
type: "Color";
|
|
29
|
+
} & {
|
|
30
|
+
fieldset?: string | null | undefined;
|
|
31
|
+
config?: {
|
|
32
|
+
label?: string | null | undefined;
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
};
|
|
35
|
+
}) | ({
|
|
36
|
+
type: "Date";
|
|
37
|
+
} & {
|
|
38
|
+
fieldset?: string | null | undefined;
|
|
39
|
+
config?: {
|
|
40
|
+
label?: string | null | undefined;
|
|
41
|
+
placeholder?: string;
|
|
42
|
+
default?: string;
|
|
43
|
+
};
|
|
44
|
+
}) | ({
|
|
45
|
+
type: "Embed";
|
|
46
|
+
} & {
|
|
47
|
+
fieldset?: string | null | undefined;
|
|
48
|
+
config?: {
|
|
49
|
+
label?: string | null | undefined;
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
useAsTitle?: boolean;
|
|
52
|
+
};
|
|
53
|
+
}) | ({
|
|
54
|
+
type: "GeoPoint";
|
|
55
|
+
} & {
|
|
56
|
+
fieldset?: string | null | undefined;
|
|
57
|
+
config?: {
|
|
58
|
+
label?: string | null | undefined;
|
|
59
|
+
};
|
|
60
|
+
}) | ({
|
|
61
|
+
type: "Image";
|
|
62
|
+
} & {
|
|
63
|
+
fieldset?: string | null | undefined;
|
|
64
|
+
config?: {
|
|
65
|
+
label?: string | null | undefined;
|
|
66
|
+
placeholder?: string;
|
|
67
|
+
constraint?: {
|
|
68
|
+
width?: number | null;
|
|
69
|
+
height?: number | null;
|
|
70
|
+
};
|
|
71
|
+
thumbnails?: readonly ({
|
|
72
|
+
name: string;
|
|
73
|
+
} & {
|
|
74
|
+
width?: number | null;
|
|
75
|
+
height?: number | null;
|
|
76
|
+
})[];
|
|
77
|
+
};
|
|
78
|
+
}) | ({
|
|
79
|
+
type: "IntegrationFields";
|
|
80
|
+
} & {
|
|
81
|
+
fieldset?: string | null | undefined;
|
|
82
|
+
config?: {
|
|
83
|
+
label?: string | null | undefined;
|
|
84
|
+
placeholder?: string;
|
|
85
|
+
catalog?: string;
|
|
86
|
+
};
|
|
87
|
+
}) | ({
|
|
88
|
+
type: "Link";
|
|
89
|
+
} & {
|
|
90
|
+
fieldset?: string | null | undefined;
|
|
91
|
+
config?: {
|
|
92
|
+
label?: string | null | undefined;
|
|
93
|
+
useAsTitle?: boolean;
|
|
94
|
+
placeholder?: string;
|
|
95
|
+
select?: "media" | "document" | "web" | null;
|
|
96
|
+
customtypes?: readonly string[];
|
|
97
|
+
masks?: readonly string[];
|
|
98
|
+
tags?: readonly string[];
|
|
99
|
+
allowTargetBlank?: boolean;
|
|
100
|
+
};
|
|
101
|
+
}) | ({
|
|
102
|
+
type: "Number";
|
|
103
|
+
} & {
|
|
104
|
+
fieldset?: string | null | undefined;
|
|
105
|
+
config?: {
|
|
106
|
+
label?: string | null | undefined;
|
|
107
|
+
placeholder?: string;
|
|
108
|
+
min?: number;
|
|
109
|
+
max?: number;
|
|
110
|
+
step?: number;
|
|
111
|
+
};
|
|
112
|
+
}) | ({
|
|
113
|
+
type: "Range";
|
|
114
|
+
} & {
|
|
115
|
+
fieldset?: string | null | undefined;
|
|
116
|
+
config?: {
|
|
117
|
+
label?: string | null | undefined;
|
|
118
|
+
placeholder?: string;
|
|
119
|
+
min?: number;
|
|
120
|
+
max?: number;
|
|
121
|
+
step?: number;
|
|
122
|
+
};
|
|
123
|
+
}) | ({
|
|
124
|
+
type: "StructuredText";
|
|
125
|
+
} & {
|
|
126
|
+
fieldset?: string | null | undefined;
|
|
127
|
+
config?: {
|
|
128
|
+
label?: string | null | undefined;
|
|
129
|
+
placeholder?: string;
|
|
130
|
+
useAsTitle?: boolean;
|
|
131
|
+
single?: string;
|
|
132
|
+
multi?: string;
|
|
133
|
+
imageConstraint?: {
|
|
134
|
+
width?: number | null;
|
|
135
|
+
height?: number | null;
|
|
136
|
+
};
|
|
137
|
+
labels?: readonly string[];
|
|
138
|
+
allowTargetBlank?: boolean;
|
|
139
|
+
};
|
|
140
|
+
}) | ({
|
|
141
|
+
type: "Select";
|
|
142
|
+
} & {
|
|
143
|
+
fieldset?: string | null | undefined;
|
|
144
|
+
config?: {
|
|
145
|
+
label?: string | null | undefined;
|
|
146
|
+
placeholder?: string;
|
|
147
|
+
default_value?: string;
|
|
148
|
+
options?: readonly string[];
|
|
149
|
+
};
|
|
150
|
+
}) | ({
|
|
151
|
+
type: "Separator";
|
|
152
|
+
} & {
|
|
153
|
+
config?: {
|
|
154
|
+
label?: string | null | undefined;
|
|
155
|
+
};
|
|
156
|
+
}) | ({
|
|
157
|
+
type: "Text";
|
|
158
|
+
} & {
|
|
159
|
+
fieldset?: string | null | undefined;
|
|
160
|
+
config?: {
|
|
161
|
+
label?: string | null | undefined;
|
|
162
|
+
useAsTitle?: boolean;
|
|
163
|
+
placeholder?: string;
|
|
164
|
+
};
|
|
165
|
+
}) | ({
|
|
166
|
+
type: "Timestamp";
|
|
167
|
+
} & {
|
|
168
|
+
fieldset?: string | null | undefined;
|
|
169
|
+
config?: {
|
|
170
|
+
label?: string | null | undefined;
|
|
171
|
+
placeholder?: string;
|
|
172
|
+
default?: string;
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
items?: {
|
|
177
|
+
[x: string]: ({
|
|
178
|
+
type: "Boolean";
|
|
179
|
+
} & {
|
|
180
|
+
config?: {
|
|
181
|
+
label?: string | null | undefined;
|
|
182
|
+
default_value?: boolean;
|
|
183
|
+
placeholder_true?: string;
|
|
184
|
+
placeholder_false?: string;
|
|
185
|
+
};
|
|
186
|
+
}) | ({
|
|
187
|
+
type: "Color";
|
|
188
|
+
} & {
|
|
189
|
+
fieldset?: string | null | undefined;
|
|
190
|
+
config?: {
|
|
191
|
+
label?: string | null | undefined;
|
|
192
|
+
placeholder?: string;
|
|
193
|
+
};
|
|
194
|
+
}) | ({
|
|
195
|
+
type: "Date";
|
|
196
|
+
} & {
|
|
197
|
+
fieldset?: string | null | undefined;
|
|
198
|
+
config?: {
|
|
199
|
+
label?: string | null | undefined;
|
|
200
|
+
placeholder?: string;
|
|
201
|
+
default?: string;
|
|
202
|
+
};
|
|
203
|
+
}) | ({
|
|
204
|
+
type: "Embed";
|
|
205
|
+
} & {
|
|
206
|
+
fieldset?: string | null | undefined;
|
|
207
|
+
config?: {
|
|
208
|
+
label?: string | null | undefined;
|
|
209
|
+
placeholder?: string;
|
|
210
|
+
useAsTitle?: boolean;
|
|
211
|
+
};
|
|
212
|
+
}) | ({
|
|
213
|
+
type: "GeoPoint";
|
|
214
|
+
} & {
|
|
215
|
+
fieldset?: string | null | undefined;
|
|
216
|
+
config?: {
|
|
217
|
+
label?: string | null | undefined;
|
|
218
|
+
};
|
|
219
|
+
}) | ({
|
|
220
|
+
type: "Image";
|
|
221
|
+
} & {
|
|
222
|
+
fieldset?: string | null | undefined;
|
|
223
|
+
config?: {
|
|
224
|
+
label?: string | null | undefined;
|
|
225
|
+
placeholder?: string;
|
|
226
|
+
constraint?: {
|
|
227
|
+
width?: number | null;
|
|
228
|
+
height?: number | null;
|
|
229
|
+
};
|
|
230
|
+
thumbnails?: readonly ({
|
|
231
|
+
name: string;
|
|
232
|
+
} & {
|
|
233
|
+
width?: number | null;
|
|
234
|
+
height?: number | null;
|
|
235
|
+
})[];
|
|
236
|
+
};
|
|
237
|
+
}) | ({
|
|
238
|
+
type: "IntegrationFields";
|
|
239
|
+
} & {
|
|
240
|
+
fieldset?: string | null | undefined;
|
|
241
|
+
config?: {
|
|
242
|
+
label?: string | null | undefined;
|
|
243
|
+
placeholder?: string;
|
|
244
|
+
catalog?: string;
|
|
245
|
+
};
|
|
246
|
+
}) | ({
|
|
247
|
+
type: "Link";
|
|
248
|
+
} & {
|
|
249
|
+
fieldset?: string | null | undefined;
|
|
250
|
+
config?: {
|
|
251
|
+
label?: string | null | undefined;
|
|
252
|
+
useAsTitle?: boolean;
|
|
253
|
+
placeholder?: string;
|
|
254
|
+
select?: "media" | "document" | "web" | null;
|
|
255
|
+
customtypes?: readonly string[];
|
|
256
|
+
masks?: readonly string[];
|
|
257
|
+
tags?: readonly string[];
|
|
258
|
+
allowTargetBlank?: boolean;
|
|
259
|
+
};
|
|
260
|
+
}) | ({
|
|
261
|
+
type: "Number";
|
|
262
|
+
} & {
|
|
263
|
+
fieldset?: string | null | undefined;
|
|
264
|
+
config?: {
|
|
265
|
+
label?: string | null | undefined;
|
|
266
|
+
placeholder?: string;
|
|
267
|
+
min?: number;
|
|
268
|
+
max?: number;
|
|
269
|
+
step?: number;
|
|
270
|
+
};
|
|
271
|
+
}) | ({
|
|
272
|
+
type: "Range";
|
|
273
|
+
} & {
|
|
274
|
+
fieldset?: string | null | undefined;
|
|
275
|
+
config?: {
|
|
276
|
+
label?: string | null | undefined;
|
|
277
|
+
placeholder?: string;
|
|
278
|
+
min?: number;
|
|
279
|
+
max?: number;
|
|
280
|
+
step?: number;
|
|
281
|
+
};
|
|
282
|
+
}) | ({
|
|
283
|
+
type: "StructuredText";
|
|
284
|
+
} & {
|
|
285
|
+
fieldset?: string | null | undefined;
|
|
286
|
+
config?: {
|
|
287
|
+
label?: string | null | undefined;
|
|
288
|
+
placeholder?: string;
|
|
289
|
+
useAsTitle?: boolean;
|
|
290
|
+
single?: string;
|
|
291
|
+
multi?: string;
|
|
292
|
+
imageConstraint?: {
|
|
293
|
+
width?: number | null;
|
|
294
|
+
height?: number | null;
|
|
295
|
+
};
|
|
296
|
+
labels?: readonly string[];
|
|
297
|
+
allowTargetBlank?: boolean;
|
|
298
|
+
};
|
|
299
|
+
}) | ({
|
|
300
|
+
type: "Select";
|
|
301
|
+
} & {
|
|
302
|
+
fieldset?: string | null | undefined;
|
|
303
|
+
config?: {
|
|
304
|
+
label?: string | null | undefined;
|
|
305
|
+
placeholder?: string;
|
|
306
|
+
default_value?: string;
|
|
307
|
+
options?: readonly string[];
|
|
308
|
+
};
|
|
309
|
+
}) | ({
|
|
310
|
+
type: "Separator";
|
|
311
|
+
} & {
|
|
312
|
+
config?: {
|
|
313
|
+
label?: string | null | undefined;
|
|
314
|
+
};
|
|
315
|
+
}) | ({
|
|
316
|
+
type: "Text";
|
|
317
|
+
} & {
|
|
318
|
+
fieldset?: string | null | undefined;
|
|
319
|
+
config?: {
|
|
320
|
+
label?: string | null | undefined;
|
|
321
|
+
useAsTitle?: boolean;
|
|
322
|
+
placeholder?: string;
|
|
323
|
+
};
|
|
324
|
+
}) | ({
|
|
325
|
+
type: "Timestamp";
|
|
326
|
+
} & {
|
|
327
|
+
fieldset?: string | null | undefined;
|
|
328
|
+
config?: {
|
|
329
|
+
label?: string | null | undefined;
|
|
330
|
+
placeholder?: string;
|
|
331
|
+
default?: string;
|
|
332
|
+
};
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
})[];
|
|
336
|
+
} & {
|
|
337
|
+
description?: string;
|
|
338
|
+
}>;
|
|
339
|
+
export declare const findSliceVariation: (slice: SharedSliceCustomType) => (variation: string) => E.Either<string, Variation>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findSliceVariation = exports.findSlice = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
const findSlice = (slices) => (sliceId) => (0, function_1.pipe)(slices.find((slice) => slice.id === sliceId), E.fromNullable(errors_1.SharedSliceErrors.SliceTypeNotFound(sliceId)));
|
|
9
|
+
exports.findSlice = findSlice;
|
|
10
|
+
const findSliceVariation = (slice) => (variation) => (0, function_1.pipe)(slice.variations.find((v) => v.id === variation), E.fromNullable(errors_1.SharedSliceErrors.VariationNotFound(variation, slice.id)));
|
|
11
|
+
exports.findSliceVariation = findSliceVariation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ImportSlices";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SharedSlice as SharedSliceCustomType, StaticSlices } from "../../../../customtypes";
|
|
2
|
+
import type { SharedSlice, SharedSliceId } from "./SharedSlice";
|
|
3
|
+
export declare const extractSupportedSlices: (staticSlices: StaticSlices) => SharedSliceCustomType[];
|
|
4
|
+
export declare const findImportSharedSliceDuplicateIds: (slices: SharedSlice[]) => SharedSliceId[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findImportSharedSliceDuplicateIds = exports.extractSupportedSlices = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const A = (0, tslib_1.__importStar)(require("fp-ts/Array"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const O = (0, tslib_1.__importStar)(require("fp-ts/Option"));
|
|
8
|
+
const customtypes_1 = require("../../../../customtypes");
|
|
9
|
+
// Extracts all supported slices from the static slices object
|
|
10
|
+
// For now we only support the SharedSlice, if we want to support other slices in the future, we have to add them here
|
|
11
|
+
const extractSupportedSlices = (staticSlices) => {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
return (0, function_1.pipe)(Object.values((_b = (_a = staticSlices.config) === null || _a === void 0 ? void 0 : _a.choices) !== null && _b !== void 0 ? _b : {}).map((slice) => (0, function_1.pipe)(customtypes_1.SharedSlice.decode(slice), O.fromEither)), A.compact);
|
|
14
|
+
};
|
|
15
|
+
exports.extractSupportedSlices = extractSupportedSlices;
|
|
16
|
+
const findImportSharedSliceDuplicateIds = (slices) => {
|
|
17
|
+
const duplicatesMap = slices.reduce((acc, { id }) => {
|
|
18
|
+
var _a;
|
|
19
|
+
if (id) {
|
|
20
|
+
const currentNumOfDuplicates = (_a = acc[id]) !== null && _a !== void 0 ? _a : 0;
|
|
21
|
+
return {
|
|
22
|
+
...acc,
|
|
23
|
+
[id]: acc[id] === undefined ? 0 : currentNumOfDuplicates + 1,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
return Object.entries(duplicatesMap).flatMap(([id, numOfDuplicates]) => {
|
|
29
|
+
if (numOfDuplicates > 0) {
|
|
30
|
+
return [id];
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.findImportSharedSliceDuplicateIds = findImportSharedSliceDuplicateIds;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combineValidationResults = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const RA = (0, tslib_1.__importStar)(require("fp-ts/ReadonlyArray"));
|
|
8
|
+
/*
|
|
9
|
+
* Semigroup simply defines how to concatenate two values of the same type.
|
|
10
|
+
* In this instance, Errors from io-ts are arrays already, so we just need to concatenate them.
|
|
11
|
+
*/
|
|
12
|
+
const validationErrorsSemigroup = {
|
|
13
|
+
concat: (a, b) => [...a, ...b],
|
|
14
|
+
};
|
|
15
|
+
/*
|
|
16
|
+
* This is a helper function to combine multiple io-ts validations into one.
|
|
17
|
+
* t.array(...) works in the same way - it collects all the errors when decoding an array of values.
|
|
18
|
+
* However, it requires you to pass in a single io-ts validator as a parameter, which is not always convenient.
|
|
19
|
+
* Sometimes we have arrays of validation results received from function calls that don't have a validator instance.
|
|
20
|
+
*/
|
|
21
|
+
const combineValidationResults = (validationResults) => (0, function_1.pipe)(validationResults, RA.traverse(E.getApplicativeValidation(validationErrorsSemigroup))((validation) => validation));
|
|
22
|
+
exports.combineValidationResults = combineValidationResults;
|
|
@@ -9,3 +9,4 @@ export declare const EmptyObject: t.Type<Record<never, never>, {
|
|
|
9
9
|
}, unknown>;
|
|
10
10
|
export declare const EmptyArray: t.Type<never[], never[], unknown>;
|
|
11
11
|
export declare const AnyObject: t.RecordC<t.StringC, t.UnknownC>;
|
|
12
|
+
export declare const AnyArray: t.ArrayC<t.UnknownC>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AnyObject = exports.EmptyArray = exports.EmptyObject = exports.Boolean = exports.NumberOrNull = exports.Number = exports.StringOrNull = exports.String = void 0;
|
|
3
|
+
exports.AnyArray = exports.AnyObject = exports.EmptyArray = exports.EmptyObject = exports.Boolean = exports.NumberOrNull = exports.Number = exports.StringOrNull = exports.String = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
@@ -24,3 +24,4 @@ exports.EmptyArray = new t.Type("emptyArray", (u) => t.UnknownArray.is(u) && u.l
|
|
|
24
24
|
}));
|
|
25
25
|
}, () => []);
|
|
26
26
|
exports.AnyObject = (0, io_ts_types_1.withMessage)(t.record(t.string, t.unknown), () => "The value must be an object");
|
|
27
|
+
exports.AnyArray = (0, io_ts_types_1.withMessage)(t.array(t.unknown), () => "The value must be an array");
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
5
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
5
6
|
const function_1 = require("./function");
|
|
6
|
-
exports.default = (0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0);
|
|
7
|
+
exports.default = (0, io_ts_types_1.withMessage)((0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0), () => "The value must be a non-empty string");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/types-internal",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.12",
|
|
4
4
|
"description": "Prismic types for Custom Types and Prismic Data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -67,7 +67,9 @@
|
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"fp-ts": "^2.11.8",
|
|
69
69
|
"io-ts": "^2.2.16",
|
|
70
|
-
"io-ts-types": "^0.5.16"
|
|
70
|
+
"io-ts-types": "^0.5.16",
|
|
71
|
+
"uuid": "^9.0.0",
|
|
72
|
+
"@types/uuid": "^9.0.2"
|
|
71
73
|
},
|
|
72
74
|
"engines": {
|
|
73
75
|
"node": ">=12.7.0"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
import { withMessage } from "io-ts-types"
|
|
3
|
+
import { validate as validateUUID } from "uuid"
|
|
4
|
+
|
|
5
|
+
interface UUIDBrand {
|
|
6
|
+
readonly UUID: unique symbol
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const UUID = withMessage(
|
|
10
|
+
t.brand(
|
|
11
|
+
t.string,
|
|
12
|
+
(s): s is t.Branded<string, UUIDBrand> => validateUUID(s),
|
|
13
|
+
"UUID",
|
|
14
|
+
),
|
|
15
|
+
() => "The value must be a valid UUID",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
export type UUID = t.TypeOf<typeof UUID>
|