@prismicio/types-internal 2.2.0-alpha.9 → 2.2.0-traverse.alpha-1
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/lib/_internal/utils.d.ts +17 -0
- package/lib/_internal/utils.js +9 -0
- package/lib/common/Asset.d.ts +3 -4
- package/lib/common/Embed.d.ts +1 -2
- package/lib/common/UUID.d.ts +7 -0
- package/lib/common/UUID.js +8 -0
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/content/Document.d.ts +22 -3
- package/lib/content/Document.js +71 -1
- package/lib/content/fields/GroupContent.d.ts +12 -0
- package/lib/content/fields/GroupContent.js +46 -1
- package/lib/content/fields/WidgetContent.d.ts +6 -6
- package/lib/content/fields/nestable/NestableContent.d.ts +2 -0
- package/lib/content/fields/nestable/NestableContent.js +29 -1
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +8 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +38 -1
- package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +40 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +7 -0
- package/lib/content/fields/slices/SlicesContent.js +68 -1
- package/lib/customtypes/CustomType.d.ts +1 -0
- package/lib/customtypes/CustomType.js +8 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.js +5 -1
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -0
- package/lib/customtypes/widgets/slices/LegacySlice.js +5 -1
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +4 -0
- package/lib/customtypes/widgets/slices/SharedSlice.js +9 -1
- package/lib/import/converters/Document.d.ts +2 -2
- package/lib/import/converters/Document.js +6 -6
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
- package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
- package/lib/import/converters/fields/Slices/Slices.js +16 -0
- package/lib/import/converters/fields/Slices/index.d.ts +1 -0
- package/lib/import/converters/fields/Slices/index.js +4 -0
- package/lib/import/converters/fields/UID.d.ts +1 -1
- package/lib/import/converters/fields/UID.js +0 -2
- package/lib/import/converters/fields/index.d.ts +1 -0
- package/lib/import/converters/fields/index.js +1 -0
- package/lib/import/converters/fields/nestable/Embed.d.ts +2 -1
- package/lib/import/converters/fields/nestable/Embed.js +24 -5
- package/lib/import/converters/fields/nestable/Image.d.ts +2 -2
- package/lib/import/converters/fields/nestable/Image.js +1 -1
- package/lib/import/converters/fields/nestable/Link.d.ts +1 -1
- package/lib/import/converters/fields/nestable/Link.js +6 -6
- package/lib/import/converters/fields/nestable/Nestable.d.ts +4 -3
- package/lib/import/converters/fields/nestable/Nestable.js +2 -2
- package/lib/import/validators/Document.js +2 -2
- package/lib/import/validators/fields/ImportField.d.ts +17 -68
- package/lib/import/validators/fields/ImportField.js +8 -4
- package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +29 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +14 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/index.js +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
- package/lib/import/validators/fields/UID.d.ts +2 -2
- package/lib/import/validators/fields/UID.js +1 -1
- package/lib/import/validators/fields/nestable/Embed.d.ts +6 -23
- package/lib/import/validators/fields/nestable/Embed.js +7 -25
- package/lib/import/validators/fields/nestable/GeoPoint.js +1 -1
- package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/Decoder.js +40 -0
- package/lib/import/validators/fields/nestable/Image/Validator.d.ts +33 -0
- package/lib/import/validators/fields/nestable/Image/Validator.js +27 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/index.js +41 -0
- package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Image/model.js +2 -0
- package/lib/import/validators/fields/nestable/Link.js +2 -2
- package/lib/import/validators/fields/nestable/Nestable.d.ts +9 -60
- package/lib/import/validators/fields/nestable/index.d.ts +1 -0
- package/lib/import/validators/fields/nestable/index.js +1 -0
- package/lib/utils/DocumentId.d.ts +2 -1
- package/lib/utils/DocumentId.js +3 -3
- package/lib/utils/io-ts.d.ts +2 -0
- package/lib/utils/io-ts.js +22 -0
- package/lib/validators/BasicTypes.d.ts +0 -1
- package/lib/validators/BasicTypes.js +7 -8
- package/lib/validators/DefaultOrElse.js +1 -1
- package/lib/validators/NonEmptyString.js +1 -1
- package/lib/validators/function.d.ts +4 -4
- package/lib/validators/function.js +6 -6
- package/package.json +4 -2
- package/src/_internal/utils.ts +39 -0
- package/src/common/Asset.ts +4 -5
- package/src/common/Embed.ts +22 -0
- package/src/common/UUID.ts +19 -0
- package/src/common/index.ts +1 -0
- package/src/content/Document.ts +96 -1
- package/src/content/fields/GroupContent.ts +68 -0
- package/src/content/fields/nestable/NestableContent.ts +32 -0
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +55 -0
- package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +60 -0
- package/src/content/fields/slices/SlicesContent.ts +94 -0
- package/src/customtypes/CustomType.ts +17 -0
- package/src/customtypes/widgets/slices/CompositeSlice.ts +7 -0
- package/src/customtypes/widgets/slices/LegacySlice.ts +7 -0
- package/src/customtypes/widgets/slices/SharedSlice.ts +12 -0
- package/src/import/converters/Document.ts +10 -8
- package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
- package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
- package/src/import/converters/fields/Slices/Slices.ts +20 -0
- package/src/import/converters/fields/Slices/index.ts +1 -0
- package/src/import/converters/fields/UID.ts +1 -5
- package/src/import/converters/fields/index.ts +1 -0
- package/src/import/converters/fields/nestable/Embed.ts +29 -7
- package/src/import/converters/fields/nestable/Image.ts +4 -4
- package/src/import/converters/fields/nestable/Link.ts +5 -5
- package/src/import/converters/fields/nestable/Nestable.ts +7 -5
- package/src/import/validators/Document.ts +3 -3
- package/src/import/validators/fields/ImportField.ts +12 -6
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +116 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +6 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +20 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +64 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
- package/src/import/validators/fields/ImportSlices/index.ts +1 -0
- package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
- package/src/import/validators/fields/UID.ts +2 -2
- package/src/import/validators/fields/nestable/Embed.ts +9 -41
- package/src/import/validators/fields/nestable/GeoPoint.ts +2 -2
- package/src/import/validators/fields/nestable/Image/Decoder.ts +61 -0
- package/src/import/validators/fields/nestable/Image/Validator.ts +38 -0
- package/src/import/validators/fields/nestable/Image/index.ts +75 -0
- package/src/import/validators/fields/nestable/Image/model.ts +18 -0
- package/src/import/validators/fields/nestable/Link.ts +2 -2
- package/src/import/validators/fields/nestable/index.ts +1 -0
- package/src/utils/DocumentId.ts +4 -5
- package/src/utils/io-ts.ts +29 -0
- package/src/validators/BasicTypes.ts +13 -11
- package/src/validators/DefaultOrElse.ts +1 -1
- package/src/validators/NonEmptyString.ts +4 -5
- package/src/validators/function.ts +4 -4
- package/lib/import/validators/fields/nestable/Image.d.ts +0 -62
- package/lib/import/validators/fields/nestable/Image.js +0 -76
- package/src/import/validators/fields/nestable/Image.ts +0 -147
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SliceContent, WidgetContent } from "../content";
|
|
2
|
+
import type { StaticSlice, StaticWidget } from "../customtypes";
|
|
3
|
+
export declare type TraverseContentFn = <C extends WidgetContent | SliceContent, D extends StaticWidget | StaticSlice>({ path, key, apiId, model, content, }: {
|
|
4
|
+
path: ContentPath;
|
|
5
|
+
key: string;
|
|
6
|
+
apiId: string;
|
|
7
|
+
model?: D | undefined;
|
|
8
|
+
content: C;
|
|
9
|
+
}) => C | undefined;
|
|
10
|
+
export declare type ContentPathEntry = {
|
|
11
|
+
type: "CustomType" | WidgetContent["__TYPE__"] | SliceContent["__TYPE__"] | "GroupItem" | "primary" | "items";
|
|
12
|
+
key: string;
|
|
13
|
+
};
|
|
14
|
+
export declare type ContentPath = ReadonlyArray<ContentPathEntry>;
|
|
15
|
+
export declare const ContentPath: {
|
|
16
|
+
serialize(path: ContentPath): string;
|
|
17
|
+
};
|
package/lib/common/Asset.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export declare type AssetId = string;
|
|
2
1
|
export declare type Asset = {
|
|
3
|
-
id:
|
|
2
|
+
id: string;
|
|
4
3
|
last_modified: string;
|
|
5
4
|
kind: "image" | "all";
|
|
6
5
|
filename?: string;
|
|
7
6
|
extension?: string;
|
|
8
|
-
size?:
|
|
7
|
+
size?: number;
|
|
9
8
|
origin_url: string;
|
|
10
9
|
url: string;
|
|
11
10
|
width?: number;
|
|
@@ -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<
|
|
16
|
+
export declare const getAssetOrThrow: (assets: Record<Asset["id"], Asset | undefined>) => (assetId: Asset["id"]) => Asset;
|
package/lib/common/Embed.d.ts
CHANGED
|
@@ -12,5 +12,4 @@ export declare type Embed = {
|
|
|
12
12
|
html?: string | null;
|
|
13
13
|
title?: string | null;
|
|
14
14
|
};
|
|
15
|
-
export declare
|
|
16
|
-
export declare const getEmbedOrThrow: (embeds: Record<string, Embed>) => (embedUrl: string) => Embed;
|
|
15
|
+
export declare const getEmbedOrThrow: (embeds: Record<string, Embed | undefined>) => (embedUrl: string) => Embed;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UUID = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
const function_1 = require("../validators/function");
|
|
8
|
+
exports.UUID = (0, function_1.withCustomError)(t.brand(t.string, (s) => (0, uuid_1.validate)(s), "UUID"), () => "The value must be a valid UUID");
|
package/lib/common/index.d.ts
CHANGED
package/lib/common/index.js
CHANGED
|
@@ -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);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import { type TraverseContentFn, ContentPath } from "../_internal/utils";
|
|
2
3
|
import { WidgetKey } from "../common";
|
|
4
|
+
import { type StaticCustomType } from "../customtypes";
|
|
5
|
+
import { SliceContent, WidgetContent } from "./fields";
|
|
3
6
|
import { FieldOrSliceType, WithTypes } from "./LegacyContentCtx";
|
|
4
7
|
export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.UnionC<[t.ExactC<t.TypeC<{
|
|
5
8
|
__TYPE__: t.LiteralC<"GroupContentType">;
|
|
@@ -2993,6 +2996,9 @@ export declare const DocumentLegacy: {
|
|
|
2993
2996
|
__TYPE__: "SeparatorContent";
|
|
2994
2997
|
}][];
|
|
2995
2998
|
}[];
|
|
2999
|
+
} | {
|
|
3000
|
+
__TYPE__: "UIDContent";
|
|
3001
|
+
value: string;
|
|
2996
3002
|
} | {
|
|
2997
3003
|
__TYPE__: "SliceContentType";
|
|
2998
3004
|
value: {
|
|
@@ -4622,9 +4628,6 @@ export declare const DocumentLegacy: {
|
|
|
4622
4628
|
}[];
|
|
4623
4629
|
};
|
|
4624
4630
|
}[];
|
|
4625
|
-
} | {
|
|
4626
|
-
__TYPE__: "UIDContent";
|
|
4627
|
-
value: string;
|
|
4628
4631
|
};
|
|
4629
4632
|
}, WithTypes<{
|
|
4630
4633
|
[x: string]: unknown;
|
|
@@ -4633,4 +4636,20 @@ export declare const DocumentLegacy: {
|
|
|
4633
4636
|
parse: typeof parseLegacyDocument;
|
|
4634
4637
|
encode: typeof encodeToLegacyDocument;
|
|
4635
4638
|
};
|
|
4639
|
+
/**
|
|
4640
|
+
*
|
|
4641
|
+
* @param model: can be optional if we simply want to loop through the content without any consideration for the attached model
|
|
4642
|
+
* @param document: The content we actually want to iterate on in an immutable fashion
|
|
4643
|
+
* @param transform: A user function that provides a way to transform any kind of content wherever it is in a structured Prismic object content.
|
|
4644
|
+
* @returns a transformed document with the user's transformation applied with the transform function
|
|
4645
|
+
*/
|
|
4646
|
+
export declare function traverseDocument(document: Document, model?: StaticCustomType): (transform: TraverseContentFn) => Document;
|
|
4647
|
+
/**
|
|
4648
|
+
* The goal is to be able to collect all widgets or slices of a given type at any level of nesting inside a prismic content
|
|
4649
|
+
*
|
|
4650
|
+
* @param document parsed prismic content
|
|
4651
|
+
* @param is typeguard to match specifically the type of widget we want to collect
|
|
4652
|
+
* @returns a record containing the path of the widget as key and the typed collected content as value
|
|
4653
|
+
*/
|
|
4654
|
+
export declare function collectWidgets<W extends WidgetContent | SliceContent>(document: Document, is: (content: WidgetContent | SliceContent, path: ContentPath) => content is W): Record<string, W>;
|
|
4636
4655
|
export {};
|
package/lib/content/Document.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocumentLegacy = exports.Document = void 0;
|
|
3
|
+
exports.collectWidgets = exports.traverseDocument = exports.DocumentLegacy = exports.Document = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
7
7
|
const function_1 = require("fp-ts/lib/function");
|
|
8
8
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
9
|
+
const utils_1 = require("../_internal/utils");
|
|
9
10
|
const common_1 = require("../common");
|
|
11
|
+
const customtypes_1 = require("../customtypes");
|
|
10
12
|
const fields_1 = require("./fields");
|
|
11
13
|
const LegacyContentCtx_1 = require("./LegacyContentCtx");
|
|
12
14
|
exports.Document = t.record(common_1.WidgetKey, fields_1.WidgetContent);
|
|
@@ -91,3 +93,71 @@ exports.DocumentLegacy = {
|
|
|
91
93
|
parse: parseLegacyDocument,
|
|
92
94
|
encode: encodeToLegacyDocument,
|
|
93
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @param model: can be optional if we simply want to loop through the content without any consideration for the attached model
|
|
99
|
+
* @param document: The content we actually want to iterate on in an immutable fashion
|
|
100
|
+
* @param transform: A user function that provides a way to transform any kind of content wherever it is in a structured Prismic object content.
|
|
101
|
+
* @returns a transformed document with the user's transformation applied with the transform function
|
|
102
|
+
*/
|
|
103
|
+
function traverseDocument(document, model) {
|
|
104
|
+
return (transform) => {
|
|
105
|
+
const fieldDefs = model &&
|
|
106
|
+
(0, customtypes_1.flattenStaticWidgets)(model).reduce((acc, [key, def]) => ({ ...acc, [key]: def }), {});
|
|
107
|
+
return Object.entries(document).reduce((acc, [key, content]) => {
|
|
108
|
+
const fieldDef = fieldDefs && fieldDefs[key];
|
|
109
|
+
const path = [{ key, type: content.__TYPE__ }];
|
|
110
|
+
const transformedWidgetContent = (() => {
|
|
111
|
+
switch (content.__TYPE__) {
|
|
112
|
+
case "SliceContentType":
|
|
113
|
+
return (0, fields_1.traverseSlices)({
|
|
114
|
+
path,
|
|
115
|
+
model: (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Slices" || (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Choice"
|
|
116
|
+
? fieldDef
|
|
117
|
+
: undefined,
|
|
118
|
+
content,
|
|
119
|
+
})(transform);
|
|
120
|
+
case "GroupContentType":
|
|
121
|
+
return (0, fields_1.traverseGroupContent)({
|
|
122
|
+
path,
|
|
123
|
+
model: (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Group" ? fieldDef : undefined,
|
|
124
|
+
content,
|
|
125
|
+
})(transform);
|
|
126
|
+
default:
|
|
127
|
+
return content;
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
const transformedWidget = transformedWidgetContent &&
|
|
131
|
+
transform({
|
|
132
|
+
path,
|
|
133
|
+
key,
|
|
134
|
+
apiId: key,
|
|
135
|
+
model: fieldDef,
|
|
136
|
+
content: transformedWidgetContent,
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
...acc,
|
|
140
|
+
...(transformedWidget ? { [key]: transformedWidget } : {}),
|
|
141
|
+
};
|
|
142
|
+
}, {});
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
exports.traverseDocument = traverseDocument;
|
|
146
|
+
/**
|
|
147
|
+
* The goal is to be able to collect all widgets or slices of a given type at any level of nesting inside a prismic content
|
|
148
|
+
*
|
|
149
|
+
* @param document parsed prismic content
|
|
150
|
+
* @param is typeguard to match specifically the type of widget we want to collect
|
|
151
|
+
* @returns a record containing the path of the widget as key and the typed collected content as value
|
|
152
|
+
*/
|
|
153
|
+
function collectWidgets(document, is) {
|
|
154
|
+
const collected = {};
|
|
155
|
+
traverseDocument(document)(({ content, path }) => {
|
|
156
|
+
const key = utils_1.ContentPath.serialize(path);
|
|
157
|
+
if (is(content, path))
|
|
158
|
+
collected[key] = content;
|
|
159
|
+
return content;
|
|
160
|
+
});
|
|
161
|
+
return collected;
|
|
162
|
+
}
|
|
163
|
+
exports.collectWidgets = collectWidgets;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { ContentPath, TraverseContentFn } from "../../_internal/utils";
|
|
3
|
+
import type { Group, NestableWidget } from "../../customtypes";
|
|
2
4
|
import { LegacyContentCtx, WithTypes } from "../LegacyContentCtx";
|
|
3
5
|
export declare const GroupItemContentType: "GroupItemContent";
|
|
4
6
|
export declare const GroupItemContent: t.ExactC<t.TypeC<{
|
|
@@ -1436,4 +1438,14 @@ export declare const GroupContent: t.ExactC<t.TypeC<{
|
|
|
1436
1438
|
}>>>;
|
|
1437
1439
|
}>>;
|
|
1438
1440
|
export declare type GroupContent = t.TypeOf<typeof GroupContent>;
|
|
1441
|
+
export declare function traverseGroupContent({ path, model, content, }: {
|
|
1442
|
+
path: ContentPath;
|
|
1443
|
+
content: GroupContent;
|
|
1444
|
+
model?: Group | undefined;
|
|
1445
|
+
}): (transform: TraverseContentFn) => GroupContent;
|
|
1446
|
+
export declare function traverseGroupItemsContent({ path, model, content, }: {
|
|
1447
|
+
path: ContentPath;
|
|
1448
|
+
content: Array<GroupItemContent>;
|
|
1449
|
+
model?: Record<string, NestableWidget> | undefined;
|
|
1450
|
+
}): (transform: TraverseContentFn) => Array<GroupItemContent>;
|
|
1439
1451
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
|
|
3
|
+
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -81,3 +81,48 @@ exports.GroupContent = t.strict({
|
|
|
81
81
|
__TYPE__: t.literal(exports.GroupContentType),
|
|
82
82
|
value: t.array(exports.GroupItemContent),
|
|
83
83
|
});
|
|
84
|
+
function traverseGroupContent({ path, model, content, }) {
|
|
85
|
+
return (transform) => {
|
|
86
|
+
var _a;
|
|
87
|
+
const groupItems = traverseGroupItemsContent({
|
|
88
|
+
path,
|
|
89
|
+
model: (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.fields,
|
|
90
|
+
content: content.value,
|
|
91
|
+
})(transform);
|
|
92
|
+
return {
|
|
93
|
+
__TYPE__: content.__TYPE__,
|
|
94
|
+
value: groupItems,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
exports.traverseGroupContent = traverseGroupContent;
|
|
99
|
+
function traverseGroupItemsContent({ path, model, content, }) {
|
|
100
|
+
return (transform) => {
|
|
101
|
+
return content.map((groupItem, index) => {
|
|
102
|
+
const groupItemPath = path.concat([
|
|
103
|
+
{ key: index.toString(), type: "GroupItem" },
|
|
104
|
+
]);
|
|
105
|
+
const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
106
|
+
const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
|
|
107
|
+
const transformedField = transform({
|
|
108
|
+
path: groupItemPath.concat([
|
|
109
|
+
{ key: fieldKey, type: fieldContent.__TYPE__ },
|
|
110
|
+
]),
|
|
111
|
+
key: fieldKey,
|
|
112
|
+
apiId: fieldKey,
|
|
113
|
+
model: fieldDef,
|
|
114
|
+
content: fieldContent,
|
|
115
|
+
});
|
|
116
|
+
// Can happen if the transform function returns undefined to filter out a field
|
|
117
|
+
if (!transformedField)
|
|
118
|
+
return acc;
|
|
119
|
+
return acc.concat([[fieldKey, transformedField]]);
|
|
120
|
+
}, []);
|
|
121
|
+
return {
|
|
122
|
+
__TYPE__: groupItem.__TYPE__,
|
|
123
|
+
value: groupItemFields,
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
exports.traverseGroupItemsContent = traverseGroupItemsContent;
|
|
@@ -2977,6 +2977,9 @@ export declare const isWidgetContent: (u: unknown) => u is {
|
|
|
2977
2977
|
__TYPE__: "SeparatorContent";
|
|
2978
2978
|
}][];
|
|
2979
2979
|
}[];
|
|
2980
|
+
} | {
|
|
2981
|
+
__TYPE__: "UIDContent";
|
|
2982
|
+
value: string;
|
|
2980
2983
|
} | {
|
|
2981
2984
|
__TYPE__: "SliceContentType";
|
|
2982
2985
|
value: {
|
|
@@ -4606,9 +4609,6 @@ export declare const isWidgetContent: (u: unknown) => u is {
|
|
|
4606
4609
|
}[];
|
|
4607
4610
|
};
|
|
4608
4611
|
}[];
|
|
4609
|
-
} | {
|
|
4610
|
-
__TYPE__: "UIDContent";
|
|
4611
|
-
value: string;
|
|
4612
4612
|
};
|
|
4613
4613
|
export declare type WidgetContent = t.TypeOf<typeof WidgetContent>;
|
|
4614
4614
|
export declare type ContentType = WidgetContent["__TYPE__"];
|
|
@@ -5151,6 +5151,9 @@ export declare const WidgetLegacy: (ctx: LegacyContentCtx) => {
|
|
|
5151
5151
|
__TYPE__: "SeparatorContent";
|
|
5152
5152
|
}][];
|
|
5153
5153
|
}[];
|
|
5154
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
5155
|
+
__TYPE__: "UIDContent";
|
|
5156
|
+
value: string;
|
|
5154
5157
|
}> | import("fp-ts/lib/Either").Right<{
|
|
5155
5158
|
__TYPE__: "SliceContentType";
|
|
5156
5159
|
value: {
|
|
@@ -6780,9 +6783,6 @@ export declare const WidgetLegacy: (ctx: LegacyContentCtx) => {
|
|
|
6780
6783
|
}[];
|
|
6781
6784
|
};
|
|
6782
6785
|
}[];
|
|
6783
|
-
}> | import("fp-ts/lib/Either").Right<{
|
|
6784
|
-
__TYPE__: "UIDContent";
|
|
6785
|
-
value: string;
|
|
6786
6786
|
}> | undefined;
|
|
6787
6787
|
encode(value: WidgetContent): import("../LegacyContentCtx").WithTypes<unknown> | undefined;
|
|
6788
6788
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { NestableWidget } from "../../../customtypes";
|
|
2
3
|
import type { LegacyContentCtx } from "../../LegacyContentCtx";
|
|
3
4
|
export declare const NestableContent: t.UnionC<[t.ExactC<t.TypeC<{
|
|
4
5
|
type: t.StringC;
|
|
@@ -840,3 +841,4 @@ export declare const NestableLegacy: (ctx: LegacyContentCtx) => {
|
|
|
840
841
|
}> | undefined;
|
|
841
842
|
encode(value: NestableContent): import("../../LegacyContentCtx").WithTypes<unknown> | undefined;
|
|
842
843
|
};
|
|
844
|
+
export declare function isValidStaticNestableContent(content: NestableContent, model?: NestableWidget): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NestableLegacy = exports.isNestableContent = exports.NestableContent = void 0;
|
|
3
|
+
exports.isValidStaticNestableContent = exports.NestableLegacy = exports.isNestableContent = exports.NestableContent = 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"));
|
|
@@ -140,3 +140,31 @@ const NestableLegacy = (ctx) => {
|
|
|
140
140
|
};
|
|
141
141
|
};
|
|
142
142
|
exports.NestableLegacy = NestableLegacy;
|
|
143
|
+
function isValidStaticNestableContent(content, model) {
|
|
144
|
+
if (!model)
|
|
145
|
+
return false;
|
|
146
|
+
switch (content.__TYPE__) {
|
|
147
|
+
// special case for no content so we can consider it valid no matter its model
|
|
148
|
+
case "EmptyContent":
|
|
149
|
+
return true;
|
|
150
|
+
case "BooleanContent":
|
|
151
|
+
return model.type === "Boolean";
|
|
152
|
+
case "EmbedContent":
|
|
153
|
+
return model.type === "Embed";
|
|
154
|
+
case "FieldContent":
|
|
155
|
+
return content.type === model.type;
|
|
156
|
+
case "GeoPointContent":
|
|
157
|
+
return model.type === "GeoPoint";
|
|
158
|
+
case "ImageContent":
|
|
159
|
+
return model.type === "Image";
|
|
160
|
+
case "IntegrationFieldsContent":
|
|
161
|
+
return model.type === "IntegrationFields";
|
|
162
|
+
case "LinkContent":
|
|
163
|
+
return model.type === "Link";
|
|
164
|
+
case "StructuredTextContent":
|
|
165
|
+
return model.type === "StructuredText";
|
|
166
|
+
case "SeparatorContent":
|
|
167
|
+
return model.type === "Separator";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.isValidStaticNestableContent = isValidStaticNestableContent;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { ContentPath, TraverseContentFn } from "../../../../_internal/utils";
|
|
3
|
+
import type { CompositeSlice } from "../../../../customtypes";
|
|
2
4
|
import { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx";
|
|
3
5
|
export declare const CompositeSliceContentType = "CompositeSliceContent";
|
|
4
6
|
export declare const isCompositeSliceContent: (u: unknown) => u is {
|
|
@@ -1699,3 +1701,9 @@ export declare const CompositeSliceContent: t.ExactC<t.TypeC<{
|
|
|
1699
1701
|
}>>>;
|
|
1700
1702
|
}>>;
|
|
1701
1703
|
export declare type CompositeSliceContent = t.TypeOf<typeof CompositeSliceContent>;
|
|
1704
|
+
export declare function traverseCompositeSliceContent({ path, sliceName, model, content, }: {
|
|
1705
|
+
path: ContentPath;
|
|
1706
|
+
sliceName: string;
|
|
1707
|
+
content: CompositeSliceContent;
|
|
1708
|
+
model?: CompositeSlice | undefined;
|
|
1709
|
+
}): (transform: TraverseContentFn) => CompositeSliceContent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompositeSliceContent = exports.CompositeSliceLegacy = exports.isCompositeSliceContent = exports.CompositeSliceContentType = void 0;
|
|
3
|
+
exports.traverseCompositeSliceContent = exports.CompositeSliceContent = exports.CompositeSliceLegacy = exports.isCompositeSliceContent = exports.CompositeSliceContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -8,6 +8,7 @@ const function_1 = require("fp-ts/lib/function");
|
|
|
8
8
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
9
9
|
const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
|
|
10
10
|
const utils_1 = require("../../../utils");
|
|
11
|
+
const GroupContent_1 = require("../../GroupContent");
|
|
11
12
|
const nestable_1 = require("../../nestable");
|
|
12
13
|
const RepeatableContent_1 = require("./RepeatableContent");
|
|
13
14
|
exports.CompositeSliceContentType = "CompositeSliceContent";
|
|
@@ -79,3 +80,39 @@ exports.CompositeSliceContent = t.strict({
|
|
|
79
80
|
nonRepeat: t.record(t.string, nestable_1.NestableContent),
|
|
80
81
|
repeat: RepeatableContent_1.RepeatableWidgets,
|
|
81
82
|
});
|
|
83
|
+
function traverseCompositeSliceContent({ path, sliceName, model, content, }) {
|
|
84
|
+
return (transform) => {
|
|
85
|
+
const primary = Object.entries(content.nonRepeat).reduce((acc, [fieldKey, fieldContent]) => {
|
|
86
|
+
var _a;
|
|
87
|
+
const fieldDef = (_a = model === null || model === void 0 ? void 0 : model["non-repeat"]) === null || _a === void 0 ? void 0 : _a[fieldKey];
|
|
88
|
+
const transformedField = transform({
|
|
89
|
+
path: path.concat([
|
|
90
|
+
{ key: "non-repeat", type: "primary" },
|
|
91
|
+
{ key: fieldKey, type: fieldContent.__TYPE__ },
|
|
92
|
+
]),
|
|
93
|
+
key: fieldKey,
|
|
94
|
+
apiId: sliceName,
|
|
95
|
+
model: fieldDef,
|
|
96
|
+
content: fieldContent,
|
|
97
|
+
});
|
|
98
|
+
// Can happen if the transform function returns undefined to filter out a field
|
|
99
|
+
if (!transformedField)
|
|
100
|
+
return acc;
|
|
101
|
+
return {
|
|
102
|
+
...acc,
|
|
103
|
+
[fieldKey]: transformedField,
|
|
104
|
+
};
|
|
105
|
+
}, {});
|
|
106
|
+
const items = (0, GroupContent_1.traverseGroupItemsContent)({
|
|
107
|
+
path: path.concat([{ key: "repeat", type: "items" }]),
|
|
108
|
+
model: model === null || model === void 0 ? void 0 : model.repeat,
|
|
109
|
+
content: content.repeat,
|
|
110
|
+
})(transform);
|
|
111
|
+
return {
|
|
112
|
+
__TYPE__: content.__TYPE__,
|
|
113
|
+
repeat: items,
|
|
114
|
+
nonRepeat: primary,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
exports.traverseCompositeSliceContent = traverseCompositeSliceContent;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { ContentPath, TraverseContentFn } from "../../../../_internal/utils";
|
|
3
|
+
import type { SharedSlice } from "../../../../customtypes";
|
|
2
4
|
import { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx";
|
|
3
5
|
export declare const SharedSliceContentType = "SharedSliceContent";
|
|
4
6
|
export declare const isSharedSliceContent: (u: unknown) => u is {
|
|
@@ -1703,3 +1705,9 @@ export declare const SharedSliceContent: t.ExactC<t.TypeC<{
|
|
|
1703
1705
|
}>>>;
|
|
1704
1706
|
}>>;
|
|
1705
1707
|
export declare type SharedSliceContent = t.TypeOf<typeof SharedSliceContent>;
|
|
1708
|
+
export declare function traverseSharedSliceContent({ path, sliceName, model, content, }: {
|
|
1709
|
+
path: ContentPath;
|
|
1710
|
+
sliceName: string;
|
|
1711
|
+
content: SharedSliceContent;
|
|
1712
|
+
model?: SharedSlice | undefined;
|
|
1713
|
+
}): (transform: TraverseContentFn) => SharedSliceContent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SharedSliceContent = exports.SharedSliceLegacy = exports.isSharedSliceContent = exports.SharedSliceContentType = void 0;
|
|
3
|
+
exports.traverseSharedSliceContent = exports.SharedSliceContent = exports.SharedSliceLegacy = exports.isSharedSliceContent = exports.SharedSliceContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -9,6 +9,7 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
|
9
9
|
const io_ts_types_1 = require("io-ts-types");
|
|
10
10
|
const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
|
|
11
11
|
const utils_1 = require("../../../utils");
|
|
12
|
+
const GroupContent_1 = require("../../GroupContent");
|
|
12
13
|
const nestable_1 = require("../../nestable");
|
|
13
14
|
const RepeatableContent_1 = require("./RepeatableContent");
|
|
14
15
|
exports.SharedSliceContentType = "SharedSliceContent";
|
|
@@ -96,3 +97,41 @@ exports.SharedSliceContent = t.strict({
|
|
|
96
97
|
primary: t.record(t.string, nestable_1.NestableContent),
|
|
97
98
|
items: RepeatableContent_1.RepeatableWidgets,
|
|
98
99
|
});
|
|
100
|
+
function traverseSharedSliceContent({ path, sliceName, model, content, }) {
|
|
101
|
+
return (transform) => {
|
|
102
|
+
const variationDef = model === null || model === void 0 ? void 0 : model.variations.find((v) => v.id === content.variation);
|
|
103
|
+
const primary = Object.entries(content.primary).reduce((acc, [fieldKey, fieldContent]) => {
|
|
104
|
+
var _a;
|
|
105
|
+
const fieldDef = variationDef && ((_a = variationDef.primary) === null || _a === void 0 ? void 0 : _a[fieldKey]);
|
|
106
|
+
const transformedField = transform({
|
|
107
|
+
path: path.concat([
|
|
108
|
+
{ key: "primary", type: "primary" },
|
|
109
|
+
{ key: fieldKey, type: fieldContent.__TYPE__ },
|
|
110
|
+
]),
|
|
111
|
+
key: fieldKey,
|
|
112
|
+
apiId: sliceName,
|
|
113
|
+
model: fieldDef,
|
|
114
|
+
content: fieldContent,
|
|
115
|
+
});
|
|
116
|
+
// Can happen if the transform function returns undefined to filter out a field
|
|
117
|
+
if (!transformedField)
|
|
118
|
+
return acc;
|
|
119
|
+
return {
|
|
120
|
+
...acc,
|
|
121
|
+
[fieldKey]: transformedField,
|
|
122
|
+
};
|
|
123
|
+
}, {});
|
|
124
|
+
const items = (0, GroupContent_1.traverseGroupItemsContent)({
|
|
125
|
+
path: path.concat([{ key: "items", type: "items" }]),
|
|
126
|
+
model: variationDef === null || variationDef === void 0 ? void 0 : variationDef.items,
|
|
127
|
+
content: content.items,
|
|
128
|
+
})(transform);
|
|
129
|
+
return {
|
|
130
|
+
__TYPE__: content.__TYPE__,
|
|
131
|
+
variation: content.variation,
|
|
132
|
+
primary,
|
|
133
|
+
items,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
exports.traverseSharedSliceContent = traverseSharedSliceContent;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { ContentPath, TraverseContentFn } from "../../../_internal/utils";
|
|
3
|
+
import { type StaticSlices } from "../../../customtypes";
|
|
2
4
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
|
|
3
5
|
export declare const SlicesContentType = "SliceContentType";
|
|
4
6
|
export declare const isSlicesContent: (u: unknown) => u is {
|
|
@@ -5093,4 +5095,9 @@ export declare const SlicesContent: t.TypeC<{
|
|
|
5093
5095
|
}>>;
|
|
5094
5096
|
}>;
|
|
5095
5097
|
export declare type SlicesContent = t.TypeOf<typeof SlicesContent>;
|
|
5098
|
+
export declare function traverseSlices({ path, model, content, }: {
|
|
5099
|
+
path: ContentPath;
|
|
5100
|
+
content: SlicesContent;
|
|
5101
|
+
model?: StaticSlices | undefined;
|
|
5102
|
+
}): (transform: TraverseContentFn) => SlicesContent;
|
|
5096
5103
|
export {};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SlicesContent = exports.SlicesLegacy = exports.isSlicesContent = exports.SlicesContentType = void 0;
|
|
3
|
+
exports.traverseSlices = exports.SlicesContent = exports.SlicesLegacy = exports.isSlicesContent = exports.SlicesContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
7
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const customtypes_1 = require("../../../customtypes");
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
const GroupContent_1 = require("../GroupContent");
|
|
11
|
+
const CompositeSliceContent_1 = require("./Slice/CompositeSliceContent");
|
|
12
|
+
const SharedSliceContent_1 = require("./Slice/SharedSliceContent");
|
|
9
13
|
const SliceItem_1 = require("./SliceItem");
|
|
10
14
|
exports.SlicesContentType = "SliceContentType";
|
|
11
15
|
const isSlicesContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.SlicesContentType;
|
|
@@ -32,3 +36,66 @@ exports.SlicesContent = t.type({
|
|
|
32
36
|
__TYPE__: t.literal(exports.SlicesContentType),
|
|
33
37
|
value: t.array(SliceItem_1.SliceItemContent),
|
|
34
38
|
});
|
|
39
|
+
function traverseSlices({ path, model, content, }) {
|
|
40
|
+
return (transform) => {
|
|
41
|
+
const value = content.value.reduce((acc, sliceContent) => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const sliceModel = (_b = (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.choices) === null || _b === void 0 ? void 0 : _b[sliceContent.name];
|
|
44
|
+
const slicePath = path.concat({
|
|
45
|
+
key: sliceContent.key,
|
|
46
|
+
type: sliceContent.widget.__TYPE__,
|
|
47
|
+
});
|
|
48
|
+
const convertedSliceWidget = (() => {
|
|
49
|
+
switch (sliceContent.widget.__TYPE__) {
|
|
50
|
+
case "SharedSliceContent":
|
|
51
|
+
return (0, SharedSliceContent_1.traverseSharedSliceContent)({
|
|
52
|
+
path: slicePath,
|
|
53
|
+
sliceName: sliceContent.name,
|
|
54
|
+
model: sliceModel && (0, customtypes_1.isStaticSharedSlice)(sliceModel)
|
|
55
|
+
? sliceModel
|
|
56
|
+
: undefined,
|
|
57
|
+
content: sliceContent.widget,
|
|
58
|
+
})(transform);
|
|
59
|
+
case "CompositeSliceContent":
|
|
60
|
+
return (0, CompositeSliceContent_1.traverseCompositeSliceContent)({
|
|
61
|
+
path: slicePath,
|
|
62
|
+
sliceName: sliceContent.name,
|
|
63
|
+
model: sliceModel && (0, customtypes_1.isCompositeSlice)(sliceModel)
|
|
64
|
+
? sliceModel
|
|
65
|
+
: undefined,
|
|
66
|
+
content: sliceContent.widget,
|
|
67
|
+
})(transform);
|
|
68
|
+
case "GroupContentType":
|
|
69
|
+
return (0, GroupContent_1.traverseGroupContent)({
|
|
70
|
+
path: slicePath,
|
|
71
|
+
model: sliceModel &&
|
|
72
|
+
(0, customtypes_1.isLegacySlice)(sliceModel) &&
|
|
73
|
+
sliceModel.type === "Group"
|
|
74
|
+
? sliceModel
|
|
75
|
+
: undefined,
|
|
76
|
+
content: sliceContent.widget,
|
|
77
|
+
})(transform);
|
|
78
|
+
default:
|
|
79
|
+
return sliceContent.widget;
|
|
80
|
+
}
|
|
81
|
+
})();
|
|
82
|
+
const convertedSlice = transform({
|
|
83
|
+
key: sliceContent.key,
|
|
84
|
+
apiId: sliceContent.name,
|
|
85
|
+
path: slicePath,
|
|
86
|
+
model: sliceModel,
|
|
87
|
+
content: convertedSliceWidget,
|
|
88
|
+
});
|
|
89
|
+
const convertedSliceParent = convertedSlice && {
|
|
90
|
+
...sliceContent,
|
|
91
|
+
widget: convertedSlice,
|
|
92
|
+
};
|
|
93
|
+
return convertedSliceParent ? acc.concat(convertedSliceParent) : acc;
|
|
94
|
+
}, []);
|
|
95
|
+
return {
|
|
96
|
+
__TYPE__: content.__TYPE__,
|
|
97
|
+
value,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
exports.traverseSlices = traverseSlices;
|