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

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 +2 -3
  2. package/lib/common/Asset.js +2 -3
  3. package/lib/common/Embed.d.ts +16 -0
  4. package/lib/common/Embed.js +10 -0
  5. package/lib/common/index.d.ts +1 -0
  6. package/lib/common/index.js +1 -0
  7. package/lib/customtypes/CustomType.d.ts +0 -2
  8. package/lib/customtypes/CustomType.js +1 -8
  9. package/lib/import/converters/Document.d.ts +3 -3
  10. package/lib/import/converters/Document.js +4 -6
  11. package/lib/import/converters/fields/nestable/Embed.d.ts +2 -1
  12. package/lib/import/converters/fields/nestable/Embed.js +24 -5
  13. package/lib/import/converters/fields/nestable/Image.d.ts +2 -1340
  14. package/lib/import/converters/fields/nestable/Image.js +21 -53
  15. package/lib/import/converters/fields/nestable/Nestable.d.ts +3 -3
  16. package/lib/import/converters/fields/nestable/Nestable.js +3 -3
  17. package/lib/import/validators/Document.js +7 -2
  18. package/lib/import/validators/fields/ImportField.d.ts +42 -87
  19. package/lib/import/validators/fields/nestable/Embed.d.ts +6 -23
  20. package/lib/import/validators/fields/nestable/Embed.js +7 -25
  21. package/lib/import/validators/fields/nestable/Image.d.ts +12 -12
  22. package/lib/import/validators/fields/nestable/Image.js +1 -1
  23. package/lib/import/validators/fields/nestable/Nestable.d.ts +42 -87
  24. package/lib/utils/Objects.d.ts +1 -1
  25. package/lib/utils/Objects.js +1 -1
  26. package/package.json +1 -1
  27. package/src/common/Asset.ts +3 -7
  28. package/src/common/Embed.ts +23 -0
  29. package/src/common/index.ts +1 -0
  30. package/src/customtypes/CustomType.ts +0 -13
  31. package/src/import/converters/Document.ts +8 -14
  32. package/src/import/converters/fields/nestable/Embed.ts +29 -7
  33. package/src/import/converters/fields/nestable/Image.ts +23 -99
  34. package/src/import/converters/fields/nestable/Nestable.ts +6 -6
  35. package/src/import/validators/Document.ts +9 -1
  36. package/src/import/validators/fields/nestable/Embed.ts +9 -41
  37. package/src/import/validators/fields/nestable/Image.ts +1 -1
  38. package/src/utils/Objects.ts +2 -2
@@ -25,42 +25,12 @@ export declare const ImportNestable: {
25
25
  value: Date | null;
26
26
  }, Date | undefined, unknown> | import("io-ts").Type<{
27
27
  type: "Embed";
28
- value: ({
28
+ value: {
29
29
  embed_url: string;
30
- type: string;
31
- } & {
32
- version?: string | number | null;
33
- title?: string;
34
- author_name?: string | null;
35
- author_url?: string | null;
36
- provider_name?: string | null;
37
- provider_url?: string | null;
38
- cache_age?: string | number | null;
39
- thumbnail_url?: string | null;
40
- thumbnail_width?: number | null;
41
- thumbnail_height?: number | null;
42
- html?: string | null;
43
- } & {
44
- all: unknown;
45
- }) | null;
46
- }, ({
30
+ } | null;
31
+ }, {
47
32
  embed_url: string;
48
- type: string;
49
- } & {
50
- version?: string | number | null;
51
- title?: string;
52
- author_name?: string | null;
53
- author_url?: string | null;
54
- provider_name?: string | null;
55
- provider_url?: string | null;
56
- cache_age?: string | number | null;
57
- thumbnail_url?: string | null;
58
- thumbnail_width?: number | null;
59
- thumbnail_height?: number | null;
60
- html?: string | null;
61
- } & {
62
- all: unknown;
63
- }) | undefined, unknown> | import("io-ts").Type<{
33
+ } | undefined, unknown> | import("io-ts").Type<{
64
34
  type: "GeoPoint";
65
35
  value: {
66
36
  latitude: number;
@@ -75,12 +45,12 @@ export declare const ImportNestable: {
75
45
  id: string;
76
46
  } & {
77
47
  edit?: {
78
- x?: number;
79
- y?: number;
80
- width?: number;
81
- height?: number;
82
- zoom?: number;
83
- background?: string;
48
+ x: number;
49
+ y: number;
50
+ width: number;
51
+ height: number;
52
+ zoom: number;
53
+ background: string;
84
54
  };
85
55
  credit?: string | null;
86
56
  alt?: string | null;
@@ -90,12 +60,12 @@ export declare const ImportNestable: {
90
60
  id: string;
91
61
  } & {
92
62
  edit?: {
93
- x?: number;
94
- y?: number;
95
- width?: number;
96
- height?: number;
97
- zoom?: number;
98
- background?: string;
63
+ x: number;
64
+ y: number;
65
+ width: number;
66
+ height: number;
67
+ zoom: number;
68
+ background: string;
99
69
  };
100
70
  credit?: string | null;
101
71
  alt?: string | null;
@@ -106,12 +76,12 @@ export declare const ImportNestable: {
106
76
  id: string;
107
77
  } & {
108
78
  edit?: {
109
- x?: number;
110
- y?: number;
111
- width?: number;
112
- height?: number;
113
- zoom?: number;
114
- background?: string;
79
+ x: number;
80
+ y: number;
81
+ width: number;
82
+ height: number;
83
+ zoom: number;
84
+ background: string;
115
85
  };
116
86
  credit?: string | null;
117
87
  alt?: string | null;
@@ -121,12 +91,12 @@ export declare const ImportNestable: {
121
91
  id: string;
122
92
  } & {
123
93
  edit?: {
124
- x?: number;
125
- y?: number;
126
- width?: number;
127
- height?: number;
128
- zoom?: number;
129
- background?: string;
94
+ x: number;
95
+ y: number;
96
+ width: number;
97
+ height: number;
98
+ zoom: number;
99
+ background: string;
130
100
  };
131
101
  credit?: string | null;
132
102
  alt?: string | null;
@@ -193,12 +163,12 @@ export declare const ImportNestable: {
193
163
  id: string;
194
164
  } & {
195
165
  edit?: {
196
- x?: number;
197
- y?: number;
198
- width?: number;
199
- height?: number;
200
- zoom?: number;
201
- background?: string;
166
+ x: number;
167
+ y: number;
168
+ width: number;
169
+ height: number;
170
+ zoom: number;
171
+ background: string;
202
172
  };
203
173
  credit?: string | null;
204
174
  alt?: string | null;
@@ -208,12 +178,12 @@ export declare const ImportNestable: {
208
178
  id: string;
209
179
  } & {
210
180
  edit?: {
211
- x?: number;
212
- y?: number;
213
- width?: number;
214
- height?: number;
215
- zoom?: number;
216
- background?: string;
181
+ x: number;
182
+ y: number;
183
+ width: number;
184
+ height: number;
185
+ zoom: number;
186
+ background: string;
217
187
  };
218
188
  credit?: string | null;
219
189
  alt?: string | null;
@@ -228,24 +198,9 @@ export declare const ImportNestable: {
228
198
  } | null;
229
199
  }> | import("fp-ts/lib/Either").Right<{
230
200
  type: "Embed";
231
- value: ({
201
+ value: {
232
202
  embed_url: string;
233
- type: string;
234
- } & {
235
- version?: string | number | null;
236
- title?: string;
237
- author_name?: string | null;
238
- author_url?: string | null;
239
- provider_name?: string | null;
240
- provider_url?: string | null;
241
- cache_age?: string | number | null;
242
- thumbnail_url?: string | null;
243
- thumbnail_width?: number | null;
244
- thumbnail_height?: number | null;
245
- html?: string | null;
246
- } & {
247
- all: unknown;
248
- }) | null;
203
+ } | null;
249
204
  }> | import("fp-ts/lib/Either").Right<{
250
205
  type: "Date";
251
206
  value: Date | null;
@@ -5,4 +5,4 @@ export declare function zipObjects<A, B = A>(objLeft?: Partial<Record<string, A>
5
5
  export declare function isNotEmpty<A extends object>(obj: A): boolean;
6
6
  export declare function withOptionals<T extends object>(object: T, optionals: Array<[keyof T, T[keyof T] | null | undefined]>): T;
7
7
  export declare function isObject(value: unknown): value is Record<string, unknown>;
8
- export declare function mapValues<T, O>(record: Record<string, T>, fn: (value: T, key: string) => O): Record<string, O>;
8
+ export declare function mapValues<T, O>(record: Record<string, T>, fn: (value: T) => O): Record<string, O>;
@@ -37,6 +37,6 @@ function isObject(value) {
37
37
  }
38
38
  exports.isObject = isObject;
39
39
  function mapValues(record, fn) {
40
- return Object.entries(record).reduce((acc, [key, value]) => ({ ...acc, [key]: fn(value, key) }), {});
40
+ return Object.entries(record).reduce((acc, [key, value]) => ({ ...acc, [key]: fn(value) }), {});
41
41
  }
42
42
  exports.mapValues = mapValues;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.2.0-alpha.6",
3
+ "version": "2.2.0-alpha.7",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -1,7 +1,5 @@
1
- export type AssetId = string
2
-
3
1
  export type Asset = {
4
- id: AssetId
2
+ id: string
5
3
  last_modified: string
6
4
  kind: "image" | "all"
7
5
  filename?: string
@@ -17,10 +15,8 @@ export type Asset = {
17
15
  }
18
16
 
19
17
  export const getAssetOrThrow =
20
- (assets: Record<AssetId, Asset>) => (assetId: AssetId) => {
18
+ (assets: Record<string, Asset>) => (assetId: string) => {
21
19
  const asset = assets[assetId]
22
- if (!asset) {
23
- throw new Error(`Missing asset with id '${assetId}'!`)
24
- }
20
+ if (!asset) throw new Error(`Missing asset with id '${assetId}'`)
25
21
  return asset
26
22
  }
@@ -0,0 +1,23 @@
1
+ export type Embed = {
2
+ type: string
3
+ version?: string | null
4
+ author_name?: string | null
5
+ author_url?: string | null
6
+ provider_name?: string | null
7
+ provider_url?: string | null
8
+ cache_age?: string | null
9
+ thumbnail_url?: string | null
10
+ thumbnail_width?: number | null
11
+ thumbnail_height?: number | null
12
+ html?: string | null
13
+ title?: string | null
14
+ }
15
+
16
+ export type EmbedUrl = string
17
+
18
+ export const getEmbedOrThrow =
19
+ (embeds: Record<string, Embed>) => (embedUrl: string) => {
20
+ const embed = embeds[embedUrl]
21
+ if (!embed) throw new Error(`Missing embed with url '${embedUrl}'`)
22
+ return embed
23
+ }
@@ -1,2 +1,3 @@
1
1
  export * from "./Asset"
2
+ export * from "./Embed"
2
3
  export * from "./WidgetKey"
@@ -8,7 +8,6 @@ import type { SharedSlice } from "./widgets/slices/SharedSlice"
8
8
  import type { DynamicSlice } from "./widgets/slices/Slice"
9
9
  import type { DynamicSlices } from "./widgets/slices/Slices"
10
10
  import type { DynamicWidget } from "./widgets/Widget"
11
- import type { StaticWidget } from "./widgets/Widget"
12
11
 
13
12
  export const CustomTypeFormat = {
14
13
  page: "page",
@@ -195,15 +194,3 @@ export function filterMissingSharedSlices(
195
194
  return widget
196
195
  })
197
196
  }
198
-
199
- export function flattenCustomTypeFields(
200
- customType: StaticCustomType,
201
- ): Partial<Record<string, StaticWidget>> {
202
- return Object.values(customType.json).reduce(
203
- (acc, tab) => ({
204
- ...acc,
205
- ...tab,
206
- }),
207
- {},
208
- )
209
- }
@@ -1,24 +1,18 @@
1
- import type { Asset, AssetId } from "../../common"
1
+ import type { Asset } from "../../common"
2
+ import type { Embed } from "../../common/Embed"
2
3
  import type { Document, WidgetContent } from "../../content"
3
- import type { StaticCustomType } from "../../customtypes"
4
- import { flattenCustomTypeFields, StaticWidget } from "../../customtypes"
5
4
  import type { ImportDocument } from "../validators"
6
5
  import type { ImportField } from "../validators/fields/ImportField"
7
6
  import { convertNestableWidget, uidConverter } from "./fields"
8
7
 
9
8
  export function convertImportToContent(
10
9
  document: ImportDocument,
11
- assets: Record<AssetId, Asset>,
12
- customType: StaticCustomType,
10
+ assets: Record<string, Asset>,
11
+ embeds: Record<string, Embed>,
13
12
  ): Document {
14
- const fieldModels = flattenCustomTypeFields(customType)
15
13
  return Object.entries(document).reduce<Document>(
16
14
  (acc, [fieldKey, fieldValue]) => {
17
- const newFieldValue = convertWidget(
18
- fieldValue,
19
- assets,
20
- fieldModels[fieldKey],
21
- )
15
+ const newFieldValue = convertWidget(fieldValue, assets, embeds)
22
16
  return newFieldValue ? { ...acc, [fieldKey]: newFieldValue } : acc
23
17
  },
24
18
  {},
@@ -27,13 +21,13 @@ export function convertImportToContent(
27
21
 
28
22
  function convertWidget(
29
23
  field: ImportField,
30
- assets: Record<AssetId, Asset>,
31
- model?: StaticWidget,
24
+ assets: Record<string, Asset>,
25
+ embeds: Record<string, Embed>,
32
26
  ): WidgetContent | undefined {
33
27
  switch (field.type) {
34
28
  case "UID":
35
29
  return uidConverter(field.value)
36
30
  default:
37
- return convertNestableWidget(field, assets, model)
31
+ return convertNestableWidget(field, assets, embeds)
38
32
  }
39
33
  }
@@ -1,15 +1,37 @@
1
+ import type { Embed } from "../../../../common"
2
+ import { getEmbedOrThrow } from "../../../../common"
1
3
  import type { EmbedContent } from "../../../../content"
4
+ import { withOptionals } from "../../../../utils/Objects"
2
5
  import type { ImportEmbed } from "../../../validators"
3
6
 
4
7
  export const embedConverter = (
5
8
  field: ImportEmbed["value"],
9
+ embeds: Record<string, Embed>,
6
10
  ): EmbedContent | undefined => {
7
11
  if (field === null) return
8
-
9
- return {
10
- ...field,
11
- __TYPE__: "EmbedContent",
12
- }
13
-
14
- return
12
+ const embed = getEmbedOrThrow(embeds)(field.embed_url)
13
+ return withOptionals<EmbedContent>(
14
+ {
15
+ embed_url: field.embed_url,
16
+ type: embed.type,
17
+ all: {
18
+ embed_url: field.embed_url,
19
+ ...embed,
20
+ },
21
+ __TYPE__: "EmbedContent",
22
+ },
23
+ [
24
+ ["version", embed.version],
25
+ ["title", embed.title],
26
+ ["author_name", embed.author_name],
27
+ ["author_url", embed.author_url],
28
+ ["provider_name", embed.provider_name],
29
+ ["provider_url", embed.provider_url],
30
+ ["cache_age", embed.cache_age],
31
+ ["thumbnail_url", embed.thumbnail_url],
32
+ ["thumbnail_width", embed.thumbnail_width],
33
+ ["thumbnail_height", embed.thumbnail_height],
34
+ ["html", embed.html],
35
+ ],
36
+ )
15
37
  }
@@ -1,129 +1,53 @@
1
- import type { Asset, AssetId } from "../../../../common"
2
- import { getAssetOrThrow } from "../../../../common"
1
+ import type { Asset } from "../../../../common"
3
2
  import type { ImageContent } from "../../../../content"
4
- import type {
5
- ImageConstraint,
6
- StaticWidget,
7
- Thumbnail,
8
- } from "../../../../customtypes"
9
- import { withOptionals } from "../../../../utils/Objects"
3
+ import { mapValues, withOptionals } from "../../../../utils/Objects"
10
4
  import type { ImageField, ImportImage } from "../../../validators"
11
5
 
12
- function convertImage(
13
- imageField: ImageField | undefined,
14
- edit: ImageField["edit"] | undefined,
15
- constraints: ImageConstraint | undefined,
16
- image: Asset,
17
- ) {
6
+ function convertImage(field: ImageField, image: Asset) {
18
7
  return withOptionals<Omit<ImageContent, "__TYPE__" | "thumbnails">>(
19
8
  {
20
9
  origin: {
21
- id: image.id,
10
+ id: field.id,
22
11
  url: image.origin_url,
23
- // All images returned form Asset API should have width and height properties.
24
12
  width: image.width ?? 0,
25
13
  height: image.height ?? 0,
26
14
  },
27
- // All images returned form Asset API should have width and height properties.
28
- // Edit can only overwrite width and height if there are no constraints set
29
- width: constraints?.width ?? edit?.width ?? image.width ?? 0,
30
- height: constraints?.height ?? edit?.height ?? image.height ?? 0,
31
- // If edit is not provided, we crop constraint width and height from the left upper corner.
32
- // WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
15
+ width: field.edit?.width ?? image.width ?? 0,
16
+ height: field.edit?.height ?? image.height ?? 0,
33
17
  edit: {
34
- zoom: edit?.zoom ?? 1,
18
+ zoom: field.edit?.zoom ?? 1,
35
19
  crop: {
36
- x: edit?.x ?? 0,
37
- y: edit?.y ?? 0,
20
+ x: field.edit?.x ?? 0,
21
+ y: field.edit?.y ?? 0,
38
22
  },
39
- background:
40
- edit?.background ??
41
- (image.extension === "png" ? "transparent" : "#ffffff"),
23
+ background: field.edit?.background ?? "transparent",
42
24
  },
43
25
  url: image.url,
44
26
  },
45
27
  [
46
- ["alt", imageField?.alt || image.alt],
47
- ["credits", imageField?.credit || image.credits],
28
+ ["alt", field.alt || image.alt],
29
+ ["credits", field.credit || image.credits],
48
30
  ],
49
31
  )
50
32
  }
51
33
 
52
- // If image field contains thumbnailName definition use it to generate thumbnail
53
- // If image field is missing thumbnailName derive thumbnail from main image
54
- // WARN: edit is not inherited from main image as each thumbnail have different constraints
55
- function convertThumbnail(
56
- thumbnailName: string,
57
- thumbnailConstraints: ImageConstraint | undefined,
58
- imageField: Exclude<ImportImage["value"], null>,
59
- assets: Record<AssetId, Asset>,
60
- ) {
61
- const maybeThumbnail = imageField.thumbnails[thumbnailName]
62
- if (maybeThumbnail) {
63
- return convertImage(
64
- maybeThumbnail,
65
- maybeThumbnail.edit,
66
- thumbnailConstraints,
67
- getAssetOrThrow(assets)(maybeThumbnail.id),
68
- )
69
- } else {
70
- return convertImage(
71
- imageField,
72
- undefined,
73
- thumbnailConstraints,
74
- getAssetOrThrow(assets)(imageField.id),
75
- )
76
- }
77
- }
78
-
79
- function convertThumbnails(
80
- imageField: Exclude<ImportImage["value"], null>,
81
- assets: Record<AssetId, Asset>,
82
- thumbnailsModel: readonly Thumbnail[],
83
- ) {
84
- return thumbnailsModel.reduce<
85
- Record<string, ReturnType<typeof convertImage>>
86
- >((acc, { name, ...constraints }) => {
87
- return {
88
- ...acc,
89
- [name]: convertThumbnail(name, constraints, imageField, assets),
90
- }
91
- }, {})
92
- }
93
-
94
- // Function constraints:
95
- // * `model` is required
96
- // * `mode` is of type Image
97
- // * All assets from `imageField` must be present in `assets`
98
- // If any of these constraints is not met, function will throw an error
99
34
  export const imageConverter = (
100
- imageField: ImportImage["value"],
101
- assets: Record<AssetId, Asset>,
102
- model?: StaticWidget,
35
+ field: ImportImage["value"],
36
+ assets: Record<string, Asset>,
103
37
  ): ImageContent | undefined => {
104
- if (!model) {
105
- throw new Error(`'model' parameter is required!`)
106
- }
107
- if (model.type !== "Image") {
108
- throw new Error(
109
- `Wrong model type! Expected 'Image' but got '${model.type}'`,
110
- )
38
+ const getImageById = (id: string): Asset => {
39
+ const image = assets[id]
40
+ if (!image) throw new Error(`Missing asset with id '${id}'`)
41
+ return image
111
42
  }
112
43
 
113
- if (!imageField) return
44
+ if (!field) return
114
45
 
115
46
  return {
116
- ...convertImage(
117
- imageField,
118
- imageField.edit,
119
- model.config?.constraint,
120
- getAssetOrThrow(assets)(imageField.id),
121
- ),
122
- thumbnails: convertThumbnails(
123
- imageField,
124
- assets,
125
- model.config?.thumbnails ?? [],
47
+ ...convertImage(field, getImageById(field.id)),
48
+ thumbnails: mapValues(field.thumbnails, (thumbnail) =>
49
+ convertImage(thumbnail, getImageById(thumbnail.id)),
126
50
  ),
127
- __TYPE__: "ImageContent" as const,
51
+ __TYPE__: "ImageContent",
128
52
  }
129
53
  }
@@ -1,6 +1,6 @@
1
- import type { Asset, AssetId } from "../../../../common"
1
+ import type { Asset } from "../../../../common"
2
+ import type { Embed } from "../../../../common/Embed"
2
3
  import type { WidgetContent } from "../../../../content"
3
- import type { StaticWidget } from "../../../../customtypes"
4
4
  import type { ImportNestable } from "../../../validators"
5
5
  import {
6
6
  booleanConverter,
@@ -18,8 +18,8 @@ import {
18
18
 
19
19
  export function convertNestableWidget(
20
20
  field: ImportNestable,
21
- assets: Record<AssetId, Asset>,
22
- model?: StaticWidget,
21
+ assets: Record<string, Asset>,
22
+ embeds: Record<string, Embed>,
23
23
  ): WidgetContent | undefined {
24
24
  switch (field.type) {
25
25
  case "Boolean":
@@ -37,13 +37,13 @@ export function convertNestableWidget(
37
37
  case "Timestamp":
38
38
  return timestampConverter(field.value)
39
39
  case "Embed":
40
- return embedConverter(field.value)
40
+ return embedConverter(field.value, embeds)
41
41
  case "GeoPoint":
42
42
  return geopointConverter(field.value)
43
43
  case "Link":
44
44
  return linkConverter(field.value, assets)
45
45
  case "Image":
46
- return imageConverter(field.value, assets, model)
46
+ return imageConverter(field.value, assets)
47
47
  default:
48
48
  throw new Error(
49
49
  `Unsupported type of nestable converter ${JSON.stringify(field)}`,
@@ -6,7 +6,6 @@ import { withMessage } from "io-ts-types"
6
6
 
7
7
  import type { WidgetKey } from "../../common"
8
8
  import type { StaticCustomType, StaticWidget } from "../../customtypes"
9
- import { flattenCustomTypeFields } from "../../customtypes"
10
9
  import { isObject } from "../../utils/Objects"
11
10
  import { ImportField } from "./fields/ImportField"
12
11
 
@@ -15,6 +14,15 @@ const rawImportDocument = withMessage(
15
14
  () => "document is not an object",
16
15
  )
17
16
 
17
+ function flattenCustomTypeFields(
18
+ customType: StaticCustomType,
19
+ ): Partial<Record<string, StaticWidget>> {
20
+ return Object.values(customType.json).reduce((acc, tab) => ({
21
+ ...acc,
22
+ ...tab,
23
+ }))
24
+ }
25
+
18
26
  function validateField(
19
27
  document: Record<string, unknown>,
20
28
  customType: StaticCustomType,
@@ -1,14 +1,8 @@
1
- import * as Either from "fp-ts/lib/Either"
1
+ import * as Either from "fp-ts/Either"
2
2
  import { pipe } from "fp-ts/lib/function"
3
3
  import * as t from "io-ts"
4
- import { withMessage } from "io-ts-types"
5
4
 
6
5
  import { EmptyObjectOrElse } from "../../../../validators"
7
- import {
8
- NumberOrNull,
9
- String,
10
- StringOrNull,
11
- } from "../../../../validators/BasicTypes"
12
6
  import { ImportContent } from "../ImportContent"
13
7
 
14
8
  type URL = string
@@ -38,49 +32,23 @@ const EmbedUrl = new t.Type<URL, URL, unknown>(
38
32
  t.identity,
39
33
  )
40
34
 
41
- const EmbedProto = t.exact(
42
- t.intersection([
43
- t.type({
44
- embed_url: EmbedUrl,
45
- type: String,
46
- }),
47
- t.partial({
48
- version: withMessage(
49
- t.union([t.string, t.number, t.null]),
50
- () => "The value must be either string, number or null",
51
- ),
52
- title: String,
53
- author_name: StringOrNull,
54
- author_url: StringOrNull,
55
- provider_name: StringOrNull,
56
- provider_url: StringOrNull,
57
- cache_age: withMessage(
58
- t.union([t.string, t.number, t.null]),
59
- () => "The value must be either string, number or null",
60
- ),
61
- thumbnail_url: StringOrNull,
62
- thumbnail_width: NumberOrNull,
63
- thumbnail_height: NumberOrNull,
64
- html: StringOrNull,
65
- }),
66
- ]),
67
- )
35
+ const EmbedProto = t.type({
36
+ embed_url: EmbedUrl,
37
+ })
68
38
  type EmbedProto = t.TypeOf<typeof EmbedProto>
69
39
 
70
- type Embed = EmbedProto & {
71
- all: unknown
72
- }
73
- const embedValue = new t.Type<Embed>(
40
+ type Embed = EmbedProto
41
+ const Embed = new t.Type<Embed>(
74
42
  "ImportEmbedValue",
75
- (u: unknown): u is Embed => EmbedProto.is(u) && "all" in u,
43
+ (u: unknown): u is Embed => EmbedProto.is(u),
76
44
  (u: unknown) => {
77
45
  return pipe(
78
46
  EmbedProto.decode(u),
79
- Either.map((parsed) => ({ ...parsed, all: u })),
47
+ Either.map((parsed) => ({ embed_url: parsed.embed_url })),
80
48
  )
81
49
  },
82
50
  t.identity,
83
51
  )
84
52
 
85
- export const ImportEmbed = ImportContent("Embed", EmptyObjectOrElse(embedValue))
53
+ export const ImportEmbed = ImportContent("Embed", EmptyObjectOrElse(Embed))
86
54
  export type ImportEmbed = t.TypeOf<typeof ImportEmbed>
@@ -15,7 +15,7 @@ const ImageFieldCodec = AnyObject.pipe(
15
15
  }),
16
16
  t.partial({
17
17
  edit: AnyObject.pipe(
18
- t.partial({
18
+ t.strict({
19
19
  x: Number,
20
20
  y: Number,
21
21
  width: Number,