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

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 (31) hide show
  1. package/lib/common/Asset.d.ts +3 -1
  2. package/lib/common/Asset.js +9 -0
  3. package/lib/customtypes/CustomType.d.ts +2 -0
  4. package/lib/customtypes/CustomType.js +8 -1
  5. package/lib/import/converters/Document.d.ts +3 -2
  6. package/lib/import/converters/Document.js +6 -4
  7. package/lib/import/converters/fields/nestable/Image.d.ts +1340 -2
  8. package/lib/import/converters/fields/nestable/Image.js +53 -21
  9. package/lib/import/converters/fields/nestable/Link.d.ts +2 -1
  10. package/lib/import/converters/fields/nestable/Link.js +58 -19
  11. package/lib/import/converters/fields/nestable/Nestable.d.ts +3 -2
  12. package/lib/import/converters/fields/nestable/Nestable.js +3 -3
  13. package/lib/import/validators/Document.js +2 -7
  14. package/lib/import/validators/fields/ImportField.d.ts +36 -36
  15. package/lib/import/validators/fields/nestable/Image.d.ts +12 -12
  16. package/lib/import/validators/fields/nestable/Image.js +1 -1
  17. package/lib/import/validators/fields/nestable/Link.d.ts +18 -0
  18. package/lib/import/validators/fields/nestable/Nestable.d.ts +36 -36
  19. package/lib/utils/Objects.d.ts +1 -1
  20. package/lib/utils/Objects.js +1 -1
  21. package/package.json +1 -1
  22. package/src/common/Asset.ts +12 -1
  23. package/src/customtypes/CustomType.ts +13 -0
  24. package/src/import/converters/Document.ts +14 -5
  25. package/src/import/converters/fields/nestable/Image.ts +99 -23
  26. package/src/import/converters/fields/nestable/Link.ts +62 -18
  27. package/src/import/converters/fields/nestable/Nestable.ts +6 -4
  28. package/src/import/validators/Document.ts +1 -9
  29. package/src/import/validators/fields/nestable/Image.ts +1 -1
  30. package/src/import/validators/fields/nestable/Link.ts +3 -0
  31. package/src/utils/Objects.ts +2 -2
@@ -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,3 +14,4 @@ export declare type Asset = {
13
14
  credits?: string;
14
15
  alt?: string;
15
16
  };
17
+ export declare const getAssetOrThrow: (assets: Record<AssetId, Asset>) => (assetId: AssetId) => Asset;
@@ -1,2 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAssetOrThrow = void 0;
4
+ const getAssetOrThrow = (assets) => (assetId) => {
5
+ const asset = assets[assetId];
6
+ if (!asset) {
7
+ throw new Error(`Missing asset with id '${assetId}'!`);
8
+ }
9
+ return asset;
10
+ };
11
+ exports.getAssetOrThrow = getAssetOrThrow;
@@ -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,4 +1,5 @@
1
- import type { Asset } from "../../common";
1
+ import type { Asset, AssetId } from "../../common";
2
2
  import type { Document } from "../../content";
3
+ import type { StaticCustomType } from "../../customtypes";
3
4
  import type { ImportDocument } from "../validators";
4
- export declare function convertImportToContent(document: ImportDocument, assets: Record<string, Asset>): Document;
5
+ export declare function convertImportToContent(document: ImportDocument, assets: Record<AssetId, Asset>, customType: StaticCustomType): Document;
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertImportToContent = void 0;
4
+ const customtypes_1 = require("../../customtypes");
4
5
  const fields_1 = require("./fields");
5
- function convertImportToContent(document, assets) {
6
+ function convertImportToContent(document, assets, customType) {
7
+ const fieldModels = (0, customtypes_1.flattenCustomTypeFields)(customType);
6
8
  return Object.entries(document).reduce((acc, [fieldKey, fieldValue]) => {
7
- const newFieldValue = convertWidget(fieldValue, assets);
9
+ const newFieldValue = convertWidget(fieldValue, assets, fieldModels[fieldKey]);
8
10
  return newFieldValue ? { ...acc, [fieldKey]: newFieldValue } : acc;
9
11
  }, {});
10
12
  }
11
13
  exports.convertImportToContent = convertImportToContent;
12
- function convertWidget(field, assets) {
14
+ function convertWidget(field, assets, model) {
13
15
  switch (field.type) {
14
16
  case "UID":
15
17
  return (0, fields_1.uidConverter)(field.value);
16
18
  default:
17
- return (0, fields_1.convertNestableWidget)(field, assets);
19
+ return (0, fields_1.convertNestableWidget)(field, assets, model);
18
20
  }
19
21
  }