@prismicio/types-internal 2.2.0-alpha.7 → 2.2.0-alpha.8

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.
Files changed (38) hide show
  1. package/lib/common/Asset.d.ts +3 -2
  2. package/lib/common/Asset.js +3 -2
  3. package/lib/common/index.d.ts +0 -1
  4. package/lib/common/index.js +0 -1
  5. package/lib/customtypes/CustomType.d.ts +2 -0
  6. package/lib/customtypes/CustomType.js +8 -1
  7. package/lib/import/converters/Document.d.ts +2 -3
  8. package/lib/import/converters/Document.js +4 -4
  9. package/lib/import/converters/fields/nestable/Embed.d.ts +1 -2
  10. package/lib/import/converters/fields/nestable/Embed.js +5 -24
  11. package/lib/import/converters/fields/nestable/Image.d.ts +2 -2
  12. package/lib/import/converters/fields/nestable/Image.js +31 -21
  13. package/lib/import/converters/fields/nestable/Nestable.d.ts +2 -3
  14. package/lib/import/converters/fields/nestable/Nestable.js +2 -2
  15. package/lib/import/validators/Document.js +2 -7
  16. package/lib/import/validators/fields/ImportField.d.ts +57 -96
  17. package/lib/import/validators/fields/nestable/Embed.d.ts +23 -6
  18. package/lib/import/validators/fields/nestable/Embed.js +25 -7
  19. package/lib/import/validators/fields/nestable/Image.d.ts +46 -31
  20. package/lib/import/validators/fields/nestable/Image.js +51 -24
  21. package/lib/import/validators/fields/nestable/Nestable.d.ts +57 -96
  22. package/lib/import/validators/fields/nestable/Nestable.js +2 -2
  23. package/lib/utils/Objects.d.ts +1 -1
  24. package/lib/utils/Objects.js +1 -1
  25. package/package.json +1 -1
  26. package/src/common/Asset.ts +7 -3
  27. package/src/common/index.ts +0 -1
  28. package/src/customtypes/CustomType.ts +13 -0
  29. package/src/import/converters/Document.ts +5 -8
  30. package/src/import/converters/fields/nestable/Embed.ts +7 -29
  31. package/src/import/converters/fields/nestable/Image.ts +46 -26
  32. package/src/import/converters/fields/nestable/Nestable.ts +3 -5
  33. package/src/import/validators/Document.ts +1 -9
  34. package/src/import/validators/fields/nestable/Embed.ts +41 -9
  35. package/src/import/validators/fields/nestable/Image.ts +98 -47
  36. package/src/import/validators/fields/nestable/Nestable.ts +2 -2
  37. package/src/utils/Objects.ts +2 -2
  38. package/src/common/Embed.ts +0 -23
@@ -1,5 +1,6 @@
1
+ export declare type AssetId = string;
1
2
  export declare type Asset = {
2
- id: string;
3
+ id: AssetId;
3
4
  last_modified: string;
4
5
  kind: "image" | "all";
5
6
  filename?: string;
@@ -13,4 +14,4 @@ export declare type Asset = {
13
14
  credits?: string;
14
15
  alt?: string;
15
16
  };
16
- export declare const getAssetOrThrow: (assets: Record<string, Asset>) => (assetId: string) => Asset;
17
+ export declare const getAssetOrThrow: (assets: Record<AssetId, Asset>) => (assetId: AssetId) => Asset;
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAssetOrThrow = void 0;
4
4
  const getAssetOrThrow = (assets) => (assetId) => {
5
5
  const asset = assets[assetId];
6
- if (!asset)
7
- throw new Error(`Missing asset with id '${assetId}'`);
6
+ if (!asset) {
7
+ throw new Error(`Missing asset with id '${assetId}'!`);
8
+ }
8
9
  return asset;
9
10
  };
10
11
  exports.getAssetOrThrow = getAssetOrThrow;
@@ -1,3 +1,2 @@
1
1
  export * from "./Asset";
2
- export * from "./Embed";
3
2
  export * from "./WidgetKey";
@@ -2,5 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  (0, tslib_1.__exportStar)(require("./Asset"), exports);
5
- (0, tslib_1.__exportStar)(require("./Embed"), exports);
6
5
  (0, tslib_1.__exportStar)(require("./WidgetKey"), exports);
@@ -2,6 +2,7 @@ import { Either } from "fp-ts/lib/Either";
2
2
  import * as t from "io-ts";
3
3
  import type { SharedSlice } from "./widgets/slices/SharedSlice";
4
4
  import type { DynamicWidget } from "./widgets/Widget";
5
+ import type { StaticWidget } from "./widgets/Widget";
5
6
  export declare const CustomTypeFormat: {
6
7
  page: string;
7
8
  custom: string;
@@ -2393,4 +2394,5 @@ export declare function toStatic(customType: CustomType, sharedSlices: Map<strin
2393
2394
  export declare function validateSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): Either<CustomTypeSlicesError, CustomType>;
2394
2395
  export declare function collectWidgets(customType: CustomType, f: (ref: string, widget: DynamicWidget) => DynamicWidget | undefined): CustomType;
2395
2396
  export declare function filterMissingSharedSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): CustomType;
2397
+ export declare function flattenCustomTypeFields(customType: StaticCustomType): Partial<Record<string, StaticWidget>>;
2396
2398
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
3
+ exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const Either_1 = require("fp-ts/lib/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
@@ -133,3 +133,10 @@ function filterMissingSharedSlices(customType, sharedSlices) {
133
133
  });
134
134
  }
135
135
  exports.filterMissingSharedSlices = filterMissingSharedSlices;
136
+ function flattenCustomTypeFields(customType) {
137
+ return Object.values(customType.json).reduce((acc, tab) => ({
138
+ ...acc,
139
+ ...tab,
140
+ }), {});
141
+ }
142
+ exports.flattenCustomTypeFields = flattenCustomTypeFields;
@@ -1,5 +1,4 @@
1
- import type { Asset } from "../../common";
2
- import type { Embed } from "../../common/Embed";
1
+ import type { Asset, AssetId } from "../../common";
3
2
  import type { Document } from "../../content";
4
3
  import type { ImportDocument } from "../validators";
5
- export declare function convertImportToContent(document: ImportDocument, assets: Record<string, Asset>, embeds: Record<string, Embed>): Document;
4
+ export declare function convertImportToContent(document: ImportDocument, assets: Record<AssetId, Asset>): Document;
@@ -2,18 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertImportToContent = void 0;
4
4
  const fields_1 = require("./fields");
5
- function convertImportToContent(document, assets, embeds) {
5
+ function convertImportToContent(document, assets) {
6
6
  return Object.entries(document).reduce((acc, [fieldKey, fieldValue]) => {
7
- const newFieldValue = convertWidget(fieldValue, assets, embeds);
7
+ const newFieldValue = convertWidget(fieldValue, assets);
8
8
  return newFieldValue ? { ...acc, [fieldKey]: newFieldValue } : acc;
9
9
  }, {});
10
10
  }
11
11
  exports.convertImportToContent = convertImportToContent;
12
- function convertWidget(field, assets, embeds) {
12
+ function convertWidget(field, assets) {
13
13
  switch (field.type) {
14
14
  case "UID":
15
15
  return (0, fields_1.uidConverter)(field.value);
16
16
  default:
17
- return (0, fields_1.convertNestableWidget)(field, assets, embeds);
17
+ return (0, fields_1.convertNestableWidget)(field, assets);
18
18
  }
19
19
  }
@@ -1,4 +1,3 @@
1
- import type { Embed } from "../../../../common";
2
1
  import type { EmbedContent } from "../../../../content";
3
2
  import type { ImportEmbed } from "../../../validators";
4
- export declare const embedConverter: (field: ImportEmbed["value"], embeds: Record<string, Embed>) => EmbedContent | undefined;
3
+ export declare const embedConverter: (field: ImportEmbed["value"]) => EmbedContent | undefined;
@@ -1,32 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.embedConverter = void 0;
4
- const common_1 = require("../../../../common");
5
- const Objects_1 = require("../../../../utils/Objects");
6
- const embedConverter = (field, embeds) => {
4
+ const embedConverter = (field) => {
7
5
  if (field === null)
8
6
  return;
9
- const embed = (0, common_1.getEmbedOrThrow)(embeds)(field.embed_url);
10
- return (0, Objects_1.withOptionals)({
11
- embed_url: field.embed_url,
12
- type: embed.type,
13
- all: {
14
- embed_url: field.embed_url,
15
- ...embed,
16
- },
7
+ return {
8
+ ...field,
17
9
  __TYPE__: "EmbedContent",
18
- }, [
19
- ["version", embed.version],
20
- ["title", embed.title],
21
- ["author_name", embed.author_name],
22
- ["author_url", embed.author_url],
23
- ["provider_name", embed.provider_name],
24
- ["provider_url", embed.provider_url],
25
- ["cache_age", embed.cache_age],
26
- ["thumbnail_url", embed.thumbnail_url],
27
- ["thumbnail_width", embed.thumbnail_width],
28
- ["thumbnail_height", embed.thumbnail_height],
29
- ["html", embed.html],
30
- ]);
10
+ };
11
+ return;
31
12
  };
32
13
  exports.embedConverter = embedConverter;
@@ -1,4 +1,4 @@
1
- import type { Asset } from "../../../../common";
1
+ import type { Asset, AssetId } from "../../../../common";
2
2
  import type { ImageContent } from "../../../../content";
3
3
  import type { ImportImage } from "../../../validators";
4
- export declare const imageConverter: (field: ImportImage["value"], assets: Record<string, Asset>) => ImageContent | undefined;
4
+ export declare const imageConverter: (imageField: ImportImage["value"], assets: Record<AssetId, Asset>) => ImageContent | undefined;
@@ -1,44 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.imageConverter = void 0;
4
+ const common_1 = require("../../../../common");
4
5
  const Objects_1 = require("../../../../utils/Objects");
5
- function convertImage(field, image) {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
6
+ function convertImage(imageField, image) {
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
7
8
  return (0, Objects_1.withOptionals)({
8
9
  origin: {
9
- id: field.id,
10
+ id: image.id,
10
11
  url: image.origin_url,
12
+ // All images returned form Asset API should have width and height properties.
11
13
  width: (_a = image.width) !== null && _a !== void 0 ? _a : 0,
12
14
  height: (_b = image.height) !== null && _b !== void 0 ? _b : 0,
13
15
  },
14
- width: (_e = (_d = (_c = field.edit) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : image.width) !== null && _e !== void 0 ? _e : 0,
15
- height: (_h = (_g = (_f = field.edit) === null || _f === void 0 ? void 0 : _f.height) !== null && _g !== void 0 ? _g : image.height) !== null && _h !== void 0 ? _h : 0,
16
+ // All images returned form Asset API should have width and height properties.
17
+ // Image width and height will be only applied if there are no constraints and user didn't overwrite it
18
+ width: (_d = (_c = imageField === null || imageField === void 0 ? void 0 : imageField.width) !== null && _c !== void 0 ? _c : image.width) !== null && _d !== void 0 ? _d : 0,
19
+ height: (_f = (_e = imageField === null || imageField === void 0 ? void 0 : imageField.height) !== null && _e !== void 0 ? _e : image.height) !== null && _f !== void 0 ? _f : 0,
20
+ // If edit is not provided, we crop constraint width and height from the left upper corner.
21
+ // WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
16
22
  edit: {
17
- zoom: (_k = (_j = field.edit) === null || _j === void 0 ? void 0 : _j.zoom) !== null && _k !== void 0 ? _k : 1,
23
+ zoom: (_h = (_g = imageField.edit) === null || _g === void 0 ? void 0 : _g.zoom) !== null && _h !== void 0 ? _h : 1,
18
24
  crop: {
19
- x: (_m = (_l = field.edit) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
20
- y: (_p = (_o = field.edit) === null || _o === void 0 ? void 0 : _o.y) !== null && _p !== void 0 ? _p : 0,
25
+ x: (_k = (_j = imageField.edit) === null || _j === void 0 ? void 0 : _j.x) !== null && _k !== void 0 ? _k : 0,
26
+ y: (_m = (_l = imageField.edit) === null || _l === void 0 ? void 0 : _l.y) !== null && _m !== void 0 ? _m : 0,
21
27
  },
22
- background: (_r = (_q = field.edit) === null || _q === void 0 ? void 0 : _q.background) !== null && _r !== void 0 ? _r : "transparent",
28
+ background: (_p = (_o = imageField.edit) === null || _o === void 0 ? void 0 : _o.background) !== null && _p !== void 0 ? _p : (image.extension === "png" ? "transparent" : "#ffffff"),
23
29
  },
24
30
  url: image.url,
25
31
  }, [
26
- ["alt", field.alt || image.alt],
27
- ["credits", field.credit || image.credits],
32
+ ["alt", (imageField === null || imageField === void 0 ? void 0 : imageField.alt) || image.alt],
33
+ ["credits", (imageField === null || imageField === void 0 ? void 0 : imageField.credit) || image.credits],
28
34
  ]);
29
35
  }
30
- const imageConverter = (field, assets) => {
31
- const getImageById = (id) => {
32
- const image = assets[id];
33
- if (!image)
34
- throw new Error(`Missing asset with id '${id}'`);
35
- return image;
36
- };
37
- if (!field)
36
+ function convertThumbnails(imageField, assets) {
37
+ return Object.entries(imageField.thumbnails).reduce((acc, [thumbnailName, thumbnail]) => {
38
+ return {
39
+ ...acc,
40
+ [thumbnailName]: convertImage(thumbnail, (0, common_1.getAssetOrThrow)(assets)(thumbnail.id)),
41
+ };
42
+ }, {});
43
+ }
44
+ // All assets from `imageField` must be present in `assets`
45
+ // If not then function will throw an error
46
+ const imageConverter = (imageField, assets) => {
47
+ if (!imageField)
38
48
  return;
39
49
  return {
40
- ...convertImage(field, getImageById(field.id)),
41
- thumbnails: (0, Objects_1.mapValues)(field.thumbnails, (thumbnail) => convertImage(thumbnail, getImageById(thumbnail.id))),
50
+ ...convertImage(imageField, (0, common_1.getAssetOrThrow)(assets)(imageField.id)),
51
+ thumbnails: convertThumbnails(imageField, assets),
42
52
  __TYPE__: "ImageContent",
43
53
  };
44
54
  };
@@ -1,5 +1,4 @@
1
- import type { Asset } from "../../../../common";
2
- import type { Embed } from "../../../../common/Embed";
1
+ import type { Asset, AssetId } from "../../../../common";
3
2
  import type { WidgetContent } from "../../../../content";
4
3
  import type { ImportNestable } from "../../../validators";
5
- export declare function convertNestableWidget(field: ImportNestable, assets: Record<string, Asset>, embeds: Record<string, Embed>): WidgetContent | undefined;
4
+ export declare function convertNestableWidget(field: ImportNestable, assets: Record<AssetId, Asset>): WidgetContent | undefined;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertNestableWidget = void 0;
4
4
  const _1 = require(".");
5
- function convertNestableWidget(field, assets, embeds) {
5
+ function convertNestableWidget(field, assets) {
6
6
  switch (field.type) {
7
7
  case "Boolean":
8
8
  return (0, _1.booleanConverter)(field.value);
@@ -19,7 +19,7 @@ function convertNestableWidget(field, assets, embeds) {
19
19
  case "Timestamp":
20
20
  return (0, _1.timestampConverter)(field.value);
21
21
  case "Embed":
22
- return (0, _1.embedConverter)(field.value, embeds);
22
+ return (0, _1.embedConverter)(field.value);
23
23
  case "GeoPoint":
24
24
  return (0, _1.geopointConverter)(field.value);
25
25
  case "Link":
@@ -7,15 +7,10 @@ const Either_1 = require("fp-ts/Either");
7
7
  const function_1 = require("fp-ts/lib/function");
8
8
  const t = (0, tslib_1.__importStar)(require("io-ts"));
9
9
  const io_ts_types_1 = require("io-ts-types");
10
+ const customtypes_1 = require("../../customtypes");
10
11
  const Objects_1 = require("../../utils/Objects");
11
12
  const ImportField_1 = require("./fields/ImportField");
12
13
  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) => ({
15
- ...acc,
16
- ...tab,
17
- }));
18
- }
19
14
  function validateField(document, customType) {
20
15
  return (key, content, model) => {
21
16
  // the field is not defined in the custom type -> extra field or typo
@@ -49,7 +44,7 @@ function validateField(document, customType) {
49
44
  };
50
45
  }
51
46
  function validateDocument(customType, rawDoc) {
52
- const fieldModels = flattenCustomTypeFields(customType);
47
+ const fieldModels = (0, customtypes_1.flattenCustomTypeFields)(customType);
53
48
  const { document, errors } = Object.entries(rawDoc).reduce((acc, [fieldKey, fieldValue]) => {
54
49
  const parsedField = validateField(rawDoc, customType)(fieldKey, fieldValue, fieldModels[fieldKey]);
55
50
  if ((0, Either_1.isLeft)(parsedField))
@@ -16,12 +16,42 @@ export declare const ImportField: {
16
16
  value: Date | null;
17
17
  }, Date | undefined, unknown> | import("io-ts").Type<{
18
18
  type: "Embed";
19
- value: {
19
+ value: ({
20
20
  embed_url: string;
21
- } | null;
22
- }, {
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
+ }, ({
23
38
  embed_url: string;
24
- } | undefined, unknown> | import("io-ts").Type<{
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<{
25
55
  type: "GeoPoint";
26
56
  value: {
27
57
  latitude: number;
@@ -32,67 +62,11 @@ export declare const ImportField: {
32
62
  longitude: number;
33
63
  } | undefined, unknown> | import("io-ts").Type<{
34
64
  type: "Image";
35
- value: ({
36
- id: string;
37
- } & {
38
- edit?: {
39
- x: number;
40
- y: number;
41
- width: number;
42
- height: number;
43
- zoom: number;
44
- background: string;
45
- };
46
- credit?: string | null;
47
- alt?: string | null;
48
- } & {
49
- thumbnails: {
50
- [x: string]: {
51
- id: string;
52
- } & {
53
- edit?: {
54
- x: number;
55
- y: number;
56
- width: number;
57
- height: number;
58
- zoom: number;
59
- background: string;
60
- };
61
- credit?: string | null;
62
- alt?: string | null;
63
- };
64
- };
65
+ value: (import("./nestable").ImageField & {
66
+ thumbnails: Record<string, import("./nestable").ImageField>;
65
67
  }) | null;
66
- }, ({
67
- id: string;
68
- } & {
69
- edit?: {
70
- x: number;
71
- y: number;
72
- width: number;
73
- height: number;
74
- zoom: number;
75
- background: string;
76
- };
77
- credit?: string | null;
78
- alt?: string | null;
79
- } & {
80
- thumbnails: {
81
- [x: string]: {
82
- id: string;
83
- } & {
84
- edit?: {
85
- x: number;
86
- y: number;
87
- width: number;
88
- height: number;
89
- zoom: number;
90
- background: string;
91
- };
92
- credit?: string | null;
93
- alt?: string | null;
94
- };
95
- };
68
+ }, (import("./nestable").ImageField & {
69
+ thumbnails: Record<string, import("./nestable").ImageField>;
96
70
  }) | undefined, unknown> | import("io-ts").Type<{
97
71
  type: "Link";
98
72
  value: ({
@@ -150,36 +124,8 @@ export declare const ImportField: {
150
124
  } | null;
151
125
  }> | import("fp-ts/lib/Either").Right<{
152
126
  type: "Image";
153
- value: ({
154
- id: string;
155
- } & {
156
- edit?: {
157
- x: number;
158
- y: number;
159
- width: number;
160
- height: number;
161
- zoom: number;
162
- background: string;
163
- };
164
- credit?: string | null;
165
- alt?: string | null;
166
- } & {
167
- thumbnails: {
168
- [x: string]: {
169
- id: string;
170
- } & {
171
- edit?: {
172
- x: number;
173
- y: number;
174
- width: number;
175
- height: number;
176
- zoom: number;
177
- background: string;
178
- };
179
- credit?: string | null;
180
- alt?: string | null;
181
- };
182
- };
127
+ value: (import("./nestable").ImageField & {
128
+ thumbnails: Record<string, import("./nestable").ImageField>;
183
129
  }) | null;
184
130
  }> | import("fp-ts/lib/Either").Right<{
185
131
  type: "GeoPoint";
@@ -189,9 +135,24 @@ export declare const ImportField: {
189
135
  } | null;
190
136
  }> | import("fp-ts/lib/Either").Right<{
191
137
  type: "Embed";
192
- value: {
138
+ value: ({
193
139
  embed_url: string;
194
- } | null;
140
+ type: string;
141
+ } & {
142
+ version?: string | number | null;
143
+ title?: string;
144
+ author_name?: string | null;
145
+ author_url?: string | null;
146
+ provider_name?: string | null;
147
+ provider_url?: string | null;
148
+ cache_age?: string | number | null;
149
+ thumbnail_url?: string | null;
150
+ thumbnail_width?: number | null;
151
+ thumbnail_height?: number | null;
152
+ html?: string | null;
153
+ } & {
154
+ all: unknown;
155
+ }) | null;
195
156
  }> | import("fp-ts/lib/Either").Right<{
196
157
  type: "Date";
197
158
  value: Date | null;
@@ -1,10 +1,27 @@
1
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
+ };
2
22
  export declare const ImportEmbed: t.Type<{
3
23
  type: "Embed";
4
- value: {
5
- embed_url: string;
6
- } | null;
7
- }, {
8
- embed_url: string;
9
- } | undefined, unknown>;
24
+ value: Embed | null;
25
+ }, Embed | undefined, unknown>;
10
26
  export declare type ImportEmbed = t.TypeOf<typeof ImportEmbed>;
27
+ export {};
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImportEmbed = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const Either = (0, tslib_1.__importStar)(require("fp-ts/Either"));
5
+ const Either = (0, tslib_1.__importStar)(require("fp-ts/lib/Either"));
6
6
  const function_1 = require("fp-ts/lib/function");
7
7
  const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const io_ts_types_1 = require("io-ts-types");
8
9
  const validators_1 = require("../../../../validators");
10
+ const BasicTypes_1 = require("../../../../validators/BasicTypes");
9
11
  const ImportContent_1 = require("../ImportContent");
10
12
  function isValidHttpUrl(param) {
11
13
  try {
@@ -27,10 +29,26 @@ const EmbedUrl = new t.Type("EmbedUrl", (u) => isValidHttpUrl(u), (u, c) => {
27
29
  return t.failure(u, c, "The value must be a valid http/https url");
28
30
  }
29
31
  }, 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 })));
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 })));
35
53
  }, t.identity);
36
- exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(Embed));
54
+ exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(embedValue));
@@ -1,45 +1,60 @@
1
1
  import * as t from "io-ts";
2
- declare const ImageFieldCodec: t.Type<{
2
+ export declare type ImageField = {
3
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?: {
4
+ width?: number;
5
+ height?: number;
6
+ edit: {
22
7
  x: number;
23
8
  y: number;
24
- width: number;
25
- height: number;
26
9
  zoom: number;
27
- background: string;
10
+ background?: string;
28
11
  };
29
12
  credit?: string | null;
30
13
  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>;
14
+ };
36
15
  declare type ImageFieldWithThumbnails = ImageField & {
37
- thumbnails: Thumbnails;
16
+ thumbnails: Record<string, ImageField>;
38
17
  };
39
- declare const ImageFieldWithThumbnails: t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
40
- export declare const ImportImage: t.Type<{
18
+ declare const ImageFieldWithThumbnails: (field?: ({
19
+ type: "Image";
20
+ } & {
21
+ fieldset?: string | null | undefined;
22
+ config?: {
23
+ label?: string | null | undefined;
24
+ placeholder?: string;
25
+ constraint?: {
26
+ width?: number | null;
27
+ height?: number | null;
28
+ };
29
+ thumbnails?: readonly ({
30
+ name: string;
31
+ } & {
32
+ width?: number | null;
33
+ height?: number | null;
34
+ })[];
35
+ };
36
+ }) | undefined) => t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
37
+ export declare const ImportImage: (field?: ({
38
+ type: "Image";
39
+ } & {
40
+ fieldset?: string | null | undefined;
41
+ config?: {
42
+ label?: string | null | undefined;
43
+ placeholder?: string;
44
+ constraint?: {
45
+ width?: number | null;
46
+ height?: number | null;
47
+ };
48
+ thumbnails?: readonly ({
49
+ name: string;
50
+ } & {
51
+ width?: number | null;
52
+ height?: number | null;
53
+ })[];
54
+ };
55
+ }) | undefined) => t.Type<{
41
56
  type: "Image";
42
57
  value: ImageFieldWithThumbnails | null;
43
58
  }, ImageFieldWithThumbnails | undefined, unknown>;
44
- export declare type ImportImage = t.TypeOf<typeof ImportImage>;
59
+ export declare type ImportImage = t.TypeOf<ReturnType<typeof ImportImage>>;
45
60
  export {};