@prismicio/types-internal 2.2.0-alpha.17 → 2.2.0-alpha.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.2.0-alpha.17",
3
+ "version": "2.2.0-alpha.18",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -1 +0,0 @@
1
- export declare const nullableConverter: <I, O>(value: I | null, converter: (value: I) => O) => O | undefined;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nullableConverter = void 0;
4
- const nullableConverter = (value, converter) => {
5
- if (value === null)
6
- return undefined;
7
- else
8
- return converter(value);
9
- };
10
- exports.nullableConverter = nullableConverter;
@@ -1,26 +0,0 @@
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) => {};
@@ -1,40 +0,0 @@
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 copyright = image === null || image === void 0 ? void 0 : image.copyright;
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
- ...(copyright !== undefined ? { copyright } : {}),
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;
@@ -1,33 +0,0 @@
1
- import * as t from "io-ts";
2
- export declare const ImageFieldValidator: t.IntersectionC<[t.TypeC<{
3
- id: t.StringC;
4
- }>, t.PartialC<{
5
- dimensions: t.PartialC<{
6
- width: t.NumberC;
7
- height: t.NumberC;
8
- }>;
9
- edit: t.PartialC<{
10
- x: t.NumberC;
11
- y: t.NumberC;
12
- zoom: t.NumberC;
13
- background: t.StringC;
14
- }>;
15
- copyright: t.UnionC<[t.StringC, t.NullC]>;
16
- alt: t.UnionC<[t.StringC, t.NullC]>;
17
- }>]>;
18
- export declare const ThumbnailsValidator: t.RecordC<t.StringC, t.IntersectionC<[t.TypeC<{
19
- id: t.StringC;
20
- }>, t.PartialC<{
21
- dimensions: t.PartialC<{
22
- width: t.NumberC;
23
- height: t.NumberC;
24
- }>;
25
- edit: t.PartialC<{
26
- x: t.NumberC;
27
- y: t.NumberC;
28
- zoom: t.NumberC;
29
- background: t.StringC;
30
- }>;
31
- copyright: t.UnionC<[t.StringC, t.NullC]>;
32
- alt: t.UnionC<[t.StringC, t.NullC]>;
33
- }>]>>;
@@ -1,27 +0,0 @@
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
- const function_1 = require("../../../../../validators/function");
8
- exports.ImageFieldValidator = (0, function_1.withCustomError)(t.intersection([
9
- t.type({
10
- id: BasicTypes_1.String,
11
- }),
12
- t.partial({
13
- dimensions: (0, function_1.withCustomError)(t.partial({
14
- width: BasicTypes_1.Number,
15
- height: BasicTypes_1.Number,
16
- }), () => "The value must be an object"),
17
- edit: (0, function_1.withCustomError)(t.partial({
18
- x: BasicTypes_1.Number,
19
- y: BasicTypes_1.Number,
20
- zoom: BasicTypes_1.Number,
21
- background: BasicTypes_1.String,
22
- }), () => "The value must be an object"),
23
- copyright: BasicTypes_1.StringOrNull,
24
- alt: BasicTypes_1.StringOrNull,
25
- }),
26
- ]), () => "The value must be an object");
27
- exports.ThumbnailsValidator = t.record(t.string, exports.ImageFieldValidator);
@@ -1,2 +0,0 @@
1
- import * as t from "io-ts";
2
- export declare const NullOrT: <T, O = T>(codec: t.Type<T, T, unknown>) => (asO: (value: T | null) => O) => t.Type<O, O, unknown>;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NullOrT = void 0;
4
- const tslib_1 = require("tslib");
5
- const fp_ts_1 = require("fp-ts");
6
- const function_1 = require("fp-ts/function");
7
- const t = (0, tslib_1.__importStar)(require("io-ts"));
8
- const NullOrT = (codec) => {
9
- return (asO) => new t.Type(`NullOr${codec.name}`, (u) => t.null.is(u) || codec.is(u), (u) => {
10
- return (0, function_1.pipe)(t.union([t.null, codec]).decode(u), fp_ts_1.either.map((decoded) => asO(decoded)));
11
- }, (f) => f);
12
- };
13
- exports.NullOrT = NullOrT;