@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
@@ -1,6 +1,5 @@
1
- export declare type AssetId = string;
2
1
  export declare type Asset = {
3
- id: AssetId;
2
+ id: string;
4
3
  last_modified: string;
5
4
  kind: "image" | "all";
6
5
  filename?: string;
@@ -14,4 +13,4 @@ export declare type Asset = {
14
13
  credits?: string;
15
14
  alt?: string;
16
15
  };
17
- export declare const getAssetOrThrow: (assets: Record<AssetId, Asset>) => (assetId: AssetId) => Asset;
16
+ export declare const getAssetOrThrow: (assets: Record<string, Asset>) => (assetId: string) => Asset;
@@ -3,9 +3,8 @@ 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}'!`);
8
- }
6
+ if (!asset)
7
+ throw new Error(`Missing asset with id '${assetId}'`);
9
8
  return asset;
10
9
  };
11
10
  exports.getAssetOrThrow = getAssetOrThrow;
@@ -0,0 +1,16 @@
1
+ export declare 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
+ export declare type EmbedUrl = string;
16
+ export declare const getEmbedOrThrow: (embeds: Record<string, Embed>) => (embedUrl: string) => Embed;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEmbedOrThrow = void 0;
4
+ const getEmbedOrThrow = (embeds) => (embedUrl) => {
5
+ const embed = embeds[embedUrl];
6
+ if (!embed)
7
+ throw new Error(`Missing embed with url '${embedUrl}'`);
8
+ return embed;
9
+ };
10
+ exports.getEmbedOrThrow = getEmbedOrThrow;
@@ -1,2 +1,3 @@
1
1
  export * from "./Asset";
2
+ export * from "./Embed";
2
3
  export * from "./WidgetKey";
@@ -2,4 +2,5 @@
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);
5
6
  (0, tslib_1.__exportStar)(require("./WidgetKey"), exports);
@@ -2,7 +2,6 @@ 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";
6
5
  export declare const CustomTypeFormat: {
7
6
  page: string;
8
7
  custom: string;
@@ -2394,5 +2393,4 @@ export declare function toStatic(customType: CustomType, sharedSlices: Map<strin
2394
2393
  export declare function validateSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): Either<CustomTypeSlicesError, CustomType>;
2395
2394
  export declare function collectWidgets(customType: CustomType, f: (ref: string, widget: DynamicWidget) => DynamicWidget | undefined): CustomType;
2396
2395
  export declare function filterMissingSharedSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): CustomType;
2397
- export declare function flattenCustomTypeFields(customType: StaticCustomType): Partial<Record<string, StaticWidget>>;
2398
2396
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
3
+ 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,10 +133,3 @@ 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,5 @@
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 } from "../../content";
3
- import type { StaticCustomType } from "../../customtypes";
4
4
  import type { ImportDocument } from "../validators";
5
- export declare function convertImportToContent(document: ImportDocument, assets: Record<AssetId, Asset>, customType: StaticCustomType): Document;
5
+ export declare function convertImportToContent(document: ImportDocument, assets: Record<string, Asset>, embeds: Record<string, Embed>): Document;
@@ -1,21 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertImportToContent = void 0;
4
- const customtypes_1 = require("../../customtypes");
5
4
  const fields_1 = require("./fields");
6
- function convertImportToContent(document, assets, customType) {
7
- const fieldModels = (0, customtypes_1.flattenCustomTypeFields)(customType);
5
+ function convertImportToContent(document, assets, embeds) {
8
6
  return Object.entries(document).reduce((acc, [fieldKey, fieldValue]) => {
9
- const newFieldValue = convertWidget(fieldValue, assets, fieldModels[fieldKey]);
7
+ const newFieldValue = convertWidget(fieldValue, assets, embeds);
10
8
  return newFieldValue ? { ...acc, [fieldKey]: newFieldValue } : acc;
11
9
  }, {});
12
10
  }
13
11
  exports.convertImportToContent = convertImportToContent;
14
- function convertWidget(field, assets, model) {
12
+ function convertWidget(field, assets, embeds) {
15
13
  switch (field.type) {
16
14
  case "UID":
17
15
  return (0, fields_1.uidConverter)(field.value);
18
16
  default:
19
- return (0, fields_1.convertNestableWidget)(field, assets, model);
17
+ return (0, fields_1.convertNestableWidget)(field, assets, embeds);
20
18
  }
21
19
  }
@@ -1,3 +1,4 @@
1
+ import type { Embed } from "../../../../common";
1
2
  import type { EmbedContent } from "../../../../content";
2
3
  import type { ImportEmbed } from "../../../validators";
3
- export declare const embedConverter: (field: ImportEmbed["value"]) => EmbedContent | undefined;
4
+ export declare const embedConverter: (field: ImportEmbed["value"], embeds: Record<string, Embed>) => EmbedContent | undefined;
@@ -1,13 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.embedConverter = void 0;
4
- const embedConverter = (field) => {
4
+ const common_1 = require("../../../../common");
5
+ const Objects_1 = require("../../../../utils/Objects");
6
+ const embedConverter = (field, embeds) => {
5
7
  if (field === null)
6
8
  return;
7
- return {
8
- ...field,
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
+ },
9
17
  __TYPE__: "EmbedContent",
10
- };
11
- return;
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
+ ]);
12
31
  };
13
32
  exports.embedConverter = embedConverter;