@prismicio/types-internal 2.2.0-alpha.11 → 2.2.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/import/converters/fields/utils.d.ts +1 -0
- package/lib/import/converters/fields/utils.js +10 -0
- package/lib/import/validators/fields/nestable/Image/index.js +12 -1
- package/lib/validators/DefaultOrElse.js +1 -1
- package/lib/validators/NullOrT.d.ts +2 -0
- package/lib/validators/NullOrT.js +13 -0
- package/package.json +1 -1
- package/src/import/validators/fields/nestable/Image/index.ts +33 -2
- package/src/validators/DefaultOrElse.ts +1 -1
- package/lib/import/converters/fields/Slices/SliceItem.d.ts +0 -4
- package/lib/import/converters/fields/Slices/SliceItem.js +0 -24
- package/lib/import/validators/fields/ImportSlices/ImportSliceId.d.ts +0 -9
- package/lib/import/validators/fields/ImportSlices/ImportSliceId.js +0 -43
- package/lib/import/validators/fields/ImportSlices/ImportSliceItem.d.ts +0 -24
- package/lib/import/validators/fields/ImportSlices/ImportSliceItem.js +0 -87
- package/lib/import/validators/fields/ImportSlices/ImportSliceItemContent.d.ts +0 -12
- package/lib/import/validators/fields/ImportSlices/ImportSliceItemContent.js +0 -41
- package/lib/import/validators/fields/Slices/SharedSlice/SharedSlice.d.ts +0 -14
- package/lib/import/validators/fields/Slices/SharedSlice/SharedSlice.js +0 -60
- package/lib/import/validators/fields/Slices/SharedSlice/errors.d.ts +0 -5
- package/lib/import/validators/fields/Slices/SharedSlice/errors.js +0 -8
- package/lib/import/validators/fields/Slices/SharedSlice/fields/OptionalSharedSliceId.d.ts +0 -2
- package/lib/import/validators/fields/Slices/SharedSlice/fields/OptionalSharedSliceId.js +0 -15
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +0 -17
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +0 -38
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +0 -43
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +0 -69
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/errors.d.ts +0 -5
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/errors.js +0 -9
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/index.d.ts +0 -2
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/index.js +0 -5
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/types.d.ts +0 -1
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceContent/types.js +0 -2
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceId.d.ts +0 -9
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceId.js +0 -39
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceItems.d.ts +0 -11
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceItems.js +0 -25
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceType.d.ts +0 -11
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceType.js +0 -24
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceVariation.d.ts +0 -11
- package/lib/import/validators/fields/Slices/SharedSlice/fields/SharedSliceVariation.js +0 -24
- package/lib/import/validators/fields/Slices/SharedSlice/fields/index.d.ts +0 -6
- package/lib/import/validators/fields/Slices/SharedSlice/fields/index.js +0 -9
- package/lib/import/validators/fields/Slices/SharedSlice/index.d.ts +0 -3
- package/lib/import/validators/fields/Slices/SharedSlice/index.js +0 -6
- package/lib/import/validators/fields/Slices/SharedSlice/utils.d.ts +0 -339
- package/lib/import/validators/fields/Slices/SharedSlice/utils.js +0 -11
- package/lib/import/validators/fields/Slices/Slices.d.ts +0 -8
- package/lib/import/validators/fields/Slices/Slices.js +0 -29
- package/lib/import/validators/fields/Slices/index.d.ts +0 -1
- package/lib/import/validators/fields/Slices/index.js +0 -4
- package/lib/import/validators/fields/Slices/utils.d.ts +0 -4
- package/lib/import/validators/fields/Slices/utils.js +0 -35
- package/lib/import/validators/fields/Slices.d.ts +0 -4
- package/lib/import/validators/fields/Slices.js +0 -12
- package/lib/import/validators/fields/nestable/Image.d.ts +0 -45
- package/lib/import/validators/fields/nestable/Image.js +0 -45
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
import type { StaticSlices } from "../../../../customtypes";
|
|
3
|
-
import { SharedSlice } from "./SharedSlice";
|
|
4
|
-
export declare const Slices: (staticSlices: StaticSlices) => t.Type<{
|
|
5
|
-
type: "Slices";
|
|
6
|
-
value: SharedSlice[] | null;
|
|
7
|
-
}, SharedSlice[] | undefined, unknown>;
|
|
8
|
-
export declare type Slices = t.TypeOf<ReturnType<typeof Slices>>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Slices = 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 validators_1 = require("../../../../validators");
|
|
9
|
-
const ImportContent_1 = require("../ImportContent");
|
|
10
|
-
const SharedSlice_1 = require("./SharedSlice");
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
|
-
const Slices = (staticSlices) => {
|
|
13
|
-
const supportedSlices = (0, utils_1.extractSupportedSlices)(staticSlices);
|
|
14
|
-
// For now we only support the SharedSlice, however if we want to support more in the future
|
|
15
|
-
// we would have to change the codec here to something like this: t.array(t.union([ImportSharedSlice(sharedSlices), NewSliceCodec(newSliceCustomTypes)])).
|
|
16
|
-
const SlicesArrayCodec = t.array((0, SharedSlice_1.SharedSlice)(supportedSlices));
|
|
17
|
-
return (0, ImportContent_1.ImportContent)("Slices", (0, validators_1.EmptyObjectOrElse)(new t.Type("ImportSlices", (u) => SlicesArrayCodec.is(u), (u, c) => {
|
|
18
|
-
return (0, function_1.pipe)(SlicesArrayCodec.validate(u, c), E.chain((slices) => {
|
|
19
|
-
// This part might not make sense for all Slice types in the future, but for now we only support the SharedSlice
|
|
20
|
-
// In case we support more in the future, we would have to filter only the relevant type for this check
|
|
21
|
-
const sharedSliceDuplicates = (0, utils_1.findImportSharedSliceDuplicateIds)(slices);
|
|
22
|
-
if (sharedSliceDuplicates.length > 0) {
|
|
23
|
-
return t.failure(slices, [], `Duplicate slice IDs detected: ${sharedSliceDuplicates.join(", ")}`);
|
|
24
|
-
}
|
|
25
|
-
return t.success(slices);
|
|
26
|
-
}));
|
|
27
|
-
}, t.identity)));
|
|
28
|
-
};
|
|
29
|
-
exports.Slices = Slices;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Slices";
|
|
@@ -1,4 +0,0 @@
|
|
|
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[];
|
|
@@ -1,35 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SliceId = 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 io_ts_types_1 = require("io-ts-types");
|
|
9
|
-
exports.SliceId = t.string.pipe(new t.Type("SliceId", (u) => typeof u === "string", (u, c) => {
|
|
10
|
-
const [sliceType, uuid] = u.split("$");
|
|
11
|
-
return (0, function_1.pipe)(t.string.validate(sliceType, c), E.chain((sliceType) => (0, function_1.pipe)(io_ts_types_1.UUID.validate(uuid, c), E.map((decodedUUID) => `${sliceType}$${decodedUUID}`))));
|
|
12
|
-
}, t.identity));
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
declare const ImageFieldCodec: t.Type<{
|
|
3
|
-
id: string;
|
|
4
|
-
} & {
|
|
5
|
-
edit?: {
|
|
6
|
-
x: number;
|
|
7
|
-
y: number;
|
|
8
|
-
width: number;
|
|
9
|
-
height: number;
|
|
10
|
-
zoom: number;
|
|
11
|
-
background: string;
|
|
12
|
-
};
|
|
13
|
-
credit?: string | null;
|
|
14
|
-
alt?: string | null;
|
|
15
|
-
}, {
|
|
16
|
-
[x: string]: unknown;
|
|
17
|
-
}, unknown>;
|
|
18
|
-
declare const ThumbnailsCodec: t.RecordC<t.StringC, t.Type<{
|
|
19
|
-
id: string;
|
|
20
|
-
} & {
|
|
21
|
-
edit?: {
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
width: number;
|
|
25
|
-
height: number;
|
|
26
|
-
zoom: number;
|
|
27
|
-
background: string;
|
|
28
|
-
};
|
|
29
|
-
credit?: string | null;
|
|
30
|
-
alt?: string | null;
|
|
31
|
-
}, {
|
|
32
|
-
[x: string]: unknown;
|
|
33
|
-
}, unknown>>;
|
|
34
|
-
declare type Thumbnails = t.TypeOf<typeof ThumbnailsCodec>;
|
|
35
|
-
export declare type ImageField = t.TypeOf<typeof ImageFieldCodec>;
|
|
36
|
-
declare type ImageFieldWithThumbnails = ImageField & {
|
|
37
|
-
thumbnails: Thumbnails;
|
|
38
|
-
};
|
|
39
|
-
declare const ImageFieldWithThumbnails: t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
|
|
40
|
-
export declare const ImportImage: t.Type<{
|
|
41
|
-
type: "Image";
|
|
42
|
-
value: ImageFieldWithThumbnails | null;
|
|
43
|
-
}, ImageFieldWithThumbnails | undefined, unknown>;
|
|
44
|
-
export declare type ImportImage = t.TypeOf<typeof ImportImage>;
|
|
45
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
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));
|