@prismicio/types-internal
Advanced tools
Comparing version 2.9.0-alpha.0 to 2.9.0-alpha.1
@@ -161,2 +161,3 @@ "use strict"; | ||
const transformedWidget = (() => { | ||
var _a; | ||
switch (content.__TYPE__) { | ||
@@ -180,2 +181,12 @@ case "SliceContentType": | ||
})(transformWidget); | ||
case "RepeatableContent": | ||
return (0, fields_1.traverseRepeatableContent)({ | ||
path, | ||
key, | ||
apiId: key, | ||
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Link" && ((_a = fieldModel.config) === null || _a === void 0 ? void 0 : _a.repeat) | ||
? fieldModel | ||
: undefined, | ||
content, | ||
})(transformWidget); | ||
default: | ||
@@ -182,0 +193,0 @@ return transformWidget({ |
@@ -13,2 +13,3 @@ "use strict"; | ||
const nestable_1 = require("./nestable"); | ||
const RepeatableContent_1 = require("./RepeatableContent"); | ||
const withDefaultValues_1 = require("./withDefaultValues"); | ||
@@ -133,2 +134,3 @@ exports.GroupItemContentType = "GroupItemContent"; | ||
const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => { | ||
var _a; | ||
const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey]; | ||
@@ -146,2 +148,13 @@ let transformedField; | ||
} | ||
else if ((!fieldDef || | ||
((fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Link" && ((_a = fieldDef.config) === null || _a === void 0 ? void 0 : _a.repeat))) && | ||
fieldContent.__TYPE__ === "RepeatableContent") { | ||
transformedField = (0, RepeatableContent_1.traverseRepeatableContent)({ | ||
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]), | ||
key: fieldKey, | ||
apiId: fieldKey, | ||
model: fieldDef, | ||
content: fieldContent, | ||
})(transform); | ||
} | ||
else { | ||
@@ -148,0 +161,0 @@ transformedField = transform({ |
export * from "./EmptyContent"; | ||
export * from "./GroupContent"; | ||
export * from "./nestable"; | ||
export * from "./RepeatableContent"; | ||
export * from "./slices"; | ||
export * from "./UIDContent"; | ||
export * from "./WidgetContent"; |
@@ -7,4 +7,5 @@ "use strict"; | ||
(0, tslib_1.__exportStar)(require("./nestable"), exports); | ||
(0, tslib_1.__exportStar)(require("./RepeatableContent"), exports); | ||
(0, tslib_1.__exportStar)(require("./slices"), exports); | ||
(0, tslib_1.__exportStar)(require("./UIDContent"), exports); | ||
(0, tslib_1.__exportStar)(require("./WidgetContent"), exports); |
import * as t from "io-ts"; | ||
import { type NestableWidget } from "../../../customtypes"; | ||
import type { NestableWidget } from "../../../customtypes"; | ||
import type { LegacyContentCtx } from "../../LegacyContentCtx"; | ||
@@ -427,3 +427,3 @@ export declare const NestableContent: t.UnionC<[t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"RepeatableContent">; | ||
type: t.UnionC<[t.LiteralC<"Color">, t.LiteralC<"Boolean">, t.LiteralC<"Embed">, t.LiteralC<"GeoPoint">, t.LiteralC<"Date">, t.LiteralC<"Number">, t.LiteralC<"Range">, t.LiteralC<"StructuredText">, t.LiteralC<"Select">, t.LiteralC<"Separator">, t.LiteralC<"Text">, t.LiteralC<"Timestamp">, t.LiteralC<"Link">, t.LiteralC<"Image">, t.LiteralC<"IntegrationFields">]>; | ||
type: t.LiteralC<"Link">; | ||
value: t.ArrayC<t.ExactC<t.TypeC<{ | ||
@@ -686,3 +686,3 @@ __TYPE__: t.LiteralC<"LinkContent">; | ||
__TYPE__: "RepeatableContent"; | ||
type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp"; | ||
type: "Link"; | ||
value: { | ||
@@ -914,3 +914,3 @@ __TYPE__: "LinkContent"; | ||
export declare const NestableLegacy: (ctx: LegacyContentCtx) => { | ||
decode(value: unknown): import("fp-ts/lib/Either").Right<{ | ||
decode(value: unknown): import("fp-ts/lib/Either").Left<t.Errors> | import("fp-ts/lib/Either").Right<{ | ||
type: string; | ||
@@ -1095,5 +1095,5 @@ __TYPE__: "EmptyContent"; | ||
}); | ||
}> | t.Validation<{ | ||
}> | import("fp-ts/lib/Either").Right<{ | ||
__TYPE__: "RepeatableContent"; | ||
type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp"; | ||
type: "Link"; | ||
value: { | ||
@@ -1100,0 +1100,0 @@ __TYPE__: "LinkContent"; |
@@ -7,3 +7,2 @@ "use strict"; | ||
const t = (0, tslib_1.__importStar)(require("io-ts")); | ||
const customtypes_1 = require("../../../customtypes"); | ||
const EmptyContent_1 = require("../EmptyContent"); | ||
@@ -72,3 +71,2 @@ const RepeatableContent_1 = require("../RepeatableContent"); | ||
decode(value) { | ||
var _a, _b; | ||
if (!ctx.fieldType) | ||
@@ -79,8 +77,4 @@ return; | ||
return nullValue; | ||
const fieldTypeSplit = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.fieldType) === null || _a === void 0 ? void 0 : _a.split("."); | ||
const fieldType = (_b = fieldTypeSplit === null || fieldTypeSplit === void 0 ? void 0 : fieldTypeSplit[1]) !== null && _b !== void 0 ? _b : ctx.fieldType; | ||
if (!customtypes_1.NestableFieldTypes.is(fieldType)) | ||
return; | ||
const codec = (() => { | ||
switch (fieldType) { | ||
switch (ctx.fieldType) { | ||
case "Text": | ||
@@ -116,2 +110,4 @@ return (0, FieldContent_1.TextLegacy)(ctx); | ||
return (0, SeparatorContent_1.SeparatorLegacy)(ctx); | ||
case "Repeatable.Link": | ||
return (0, RepeatableContent_1.RepeatableLegacy)(ctx, "Link"); | ||
default: | ||
@@ -123,15 +119,5 @@ return; | ||
return; | ||
// We check if the Nestable Content is repeated. If so, we decode each | ||
// item in the array using the specific codec for the repeated content. | ||
if ((fieldTypeSplit === null || fieldTypeSplit === void 0 ? void 0 : fieldTypeSplit[0]) === "Repeatable") { | ||
return (0, RepeatableContent_1.RepeatableLegacy)(ctx, fieldType).decode(value); | ||
} | ||
return codec.decode(value); | ||
}, | ||
encode(value) { | ||
// We check if the Nestable Content is repeated. If so, we decode each | ||
// item in the array using the specific codec for the repeated content. | ||
if (value.__TYPE__ === RepeatableContent_1.RepeatableContentType) { | ||
return (0, RepeatableContent_1.RepeatableLegacy)(ctx, value.type).encode(value); | ||
} | ||
switch (value.__TYPE__) { | ||
@@ -171,2 +157,4 @@ case common_1.FieldContentType: { | ||
return (0, SeparatorContent_1.SeparatorLegacy)(ctx).encode(value); | ||
case "RepeatableContent": | ||
return (0, RepeatableContent_1.RepeatableLegacy)(ctx, value.type).encode(value); | ||
default: | ||
@@ -173,0 +161,0 @@ return; |
import * as t from "io-ts"; | ||
import type { ContentPath, TraverseWidgetContentFn } from "../../_internal/utils"; | ||
import { type Link, NestableFieldTypes, NestableWidget } from "../../customtypes"; | ||
import type { Link, NestableWidget } from "../../customtypes"; | ||
import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx"; | ||
export declare const RepeatableContentType: "RepeatableContent"; | ||
export declare const RepeatableFieldType: "Repeatable"; | ||
export declare const RepeatableItemContent: t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"LinkContent">; | ||
value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"ImageLink">; | ||
}>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
kind: t.StringC; | ||
id: t.StringC; | ||
url: t.StringC; | ||
height: t.StringC; | ||
width: t.StringC; | ||
size: t.StringC; | ||
name: t.StringC; | ||
}>>, t.ExactC<t.PartialC<{ | ||
date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>; | ||
}>>]>, t.ExactC<t.PartialC<{ | ||
text: t.StringC; | ||
}>>]>, t.ExactC<t.TypeC<{ | ||
kind: t.LiteralC<"image">; | ||
text: t.StringC; | ||
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"FileLink">; | ||
}>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{ | ||
kind: t.StringC; | ||
id: t.StringC; | ||
url: t.StringC; | ||
name: t.StringC; | ||
size: t.StringC; | ||
}>, t.PartialC<{ | ||
date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>; | ||
}>]>>, t.ExactC<t.PartialC<{ | ||
text: t.StringC; | ||
}>>]>, t.ExactC<t.TypeC<{ | ||
kind: t.LiteralC<"file">; | ||
text: t.StringC; | ||
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"DocumentLink">; | ||
}>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
id: t.Type<string, string, unknown>; | ||
}>>, t.ExactC<t.PartialC<{ | ||
text: t.StringC; | ||
}>>]>, t.ExactC<t.TypeC<{ | ||
kind: t.LiteralC<"document">; | ||
text: t.StringC; | ||
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"ExternalLink">; | ||
}>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{ | ||
url: t.StringC; | ||
}>, t.PartialC<{ | ||
kind: t.LiteralC<"web">; | ||
target: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>; | ||
preview: t.UnionC<[t.Type<{ | ||
title?: string; | ||
}, { | ||
title?: string; | ||
}, unknown>, t.NullC, t.UndefinedC]>; | ||
}>]>>, t.ExactC<t.PartialC<{ | ||
text: t.StringC; | ||
}>>]>, t.ExactC<t.TypeC<{ | ||
kind: t.LiteralC<"web">; | ||
text: t.StringC; | ||
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"MediaLink">; | ||
}>>, t.ExactC<t.TypeC<{ | ||
kind: t.LiteralC<"media">; | ||
text: t.StringC; | ||
}>>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"AnyLink">; | ||
}>>, t.ExactC<t.TypeC<{ | ||
text: t.StringC; | ||
}>>]>]>; | ||
}>>; | ||
export declare type RepeatableItemContent = t.TypeOf<typeof RepeatableItemContent>; | ||
export declare const RepeatableContent: t.ExactC<t.TypeC<{ | ||
__TYPE__: t.LiteralC<"RepeatableContent">; | ||
type: t.UnionC<[t.LiteralC<"Color">, t.LiteralC<"Boolean">, t.LiteralC<"Embed">, t.LiteralC<"GeoPoint">, t.LiteralC<"Date">, t.LiteralC<"Number">, t.LiteralC<"Range">, t.LiteralC<"StructuredText">, t.LiteralC<"Select">, t.LiteralC<"Separator">, t.LiteralC<"Text">, t.LiteralC<"Timestamp">, t.LiteralC<"Link">, t.LiteralC<"Image">, t.LiteralC<"IntegrationFields">]>; | ||
type: t.LiteralC<"Link">; | ||
value: t.ArrayC<t.ExactC<t.TypeC<{ | ||
@@ -157,3 +83,3 @@ __TYPE__: t.LiteralC<"LinkContent">; | ||
__TYPE__: "RepeatableContent"; | ||
type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp"; | ||
type: "Link"; | ||
value: { | ||
@@ -229,3 +155,3 @@ __TYPE__: "LinkContent"; | ||
}>; | ||
export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: NestableFieldTypes) => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>; | ||
export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: "Link") => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>; | ||
export declare type RepeatableCustomType = Link; | ||
@@ -232,0 +158,0 @@ export declare function traverseRepeatableContent({ path, key, apiId, model, content, }: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = exports.RepeatableItemContent = exports.RepeatableFieldType = exports.RepeatableContentType = void 0; | ||
exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -9,19 +9,12 @@ const fp_ts_1 = require("fp-ts"); | ||
const t = (0, tslib_1.__importStar)(require("io-ts")); | ||
const customtypes_1 = require("../../customtypes"); | ||
const nestable_1 = require("./nestable"); | ||
exports.RepeatableContentType = "RepeatableContent"; | ||
exports.RepeatableFieldType = "Repeatable"; | ||
exports.RepeatableItemContent = nestable_1.LinkContent; | ||
exports.RepeatableContent = t.strict({ | ||
__TYPE__: t.literal(exports.RepeatableContentType), | ||
type: customtypes_1.NestableFieldTypes, | ||
// TODO: How to ensure it's an array of only one type | ||
value: t.array(exports.RepeatableItemContent), | ||
__TYPE__: t.literal("RepeatableContent"), | ||
type: t.literal("Link"), | ||
value: t.array(nestable_1.LinkContent), | ||
}); | ||
exports.isRepeatableContent = exports.RepeatableContent.is; | ||
const RepeatableLegacy = (ctx, fieldType) => { | ||
const codecDecode = t.array(t.unknown); | ||
const codecEncode = t.array(exports.RepeatableItemContent); | ||
return new t.Type("RepeatableLegacy", exports.isRepeatableContent, (items) => { | ||
const parsed = (0, function_1.pipe)(codecDecode.decode(items), fp_ts_1.either.map((items) => { | ||
const parsed = (0, function_1.pipe)(t.array(t.unknown).decode(items), fp_ts_1.either.map((items) => { | ||
const parsedItems = items.reduce((acc, item) => { | ||
@@ -43,3 +36,3 @@ let result; | ||
type: fieldType, | ||
__TYPE__: exports.RepeatableContentType, | ||
__TYPE__: "RepeatableContent", | ||
}; | ||
@@ -49,3 +42,3 @@ })); | ||
}, (r) => { | ||
const res = codecEncode.encode(r.value); | ||
const res = t.array(nestable_1.LinkContent).encode(r.value); | ||
const encodedItems = res.reduce((acc, item) => { | ||
@@ -85,2 +78,5 @@ let encoded; | ||
return acc; | ||
// If the transformed field is not a link content, we don't include it | ||
if (!(0, nestable_1.isLinkContent)(transformedField)) | ||
return acc; | ||
return acc.concat(transformedField); | ||
@@ -87,0 +83,0 @@ }, []); |
@@ -432,3 +432,3 @@ import * as t from "io-ts"; | ||
__TYPE__: t.LiteralC<"RepeatableContent">; | ||
type: t.UnionC<[t.LiteralC<"Color">, t.LiteralC<"Boolean">, t.LiteralC<"Embed">, t.LiteralC<"GeoPoint">, t.LiteralC<"Date">, t.LiteralC<"Number">, t.LiteralC<"Range">, t.LiteralC<"StructuredText">, t.LiteralC<"Select">, t.LiteralC<"Separator">, t.LiteralC<"Text">, t.LiteralC<"Timestamp">, t.LiteralC<"Link">, t.LiteralC<"Image">, t.LiteralC<"IntegrationFields">]>; | ||
type: t.LiteralC<"Link">; | ||
value: t.ArrayC<t.ExactC<t.TypeC<{ | ||
@@ -435,0 +435,0 @@ __TYPE__: t.LiteralC<"LinkContent">; |
@@ -15,4 +15,5 @@ "use strict"; | ||
const nestable_1 = require("../../nestable"); | ||
const RepeatableContent_1 = require("../../RepeatableContent"); | ||
const withDefaultValues_1 = require("../../withDefaultValues"); | ||
const RepeatableContent_1 = require("./RepeatableContent"); | ||
const RepeatableContent_2 = require("./RepeatableContent"); | ||
const SlicePrimaryContent_1 = require("./SlicePrimaryContent"); | ||
@@ -35,3 +36,3 @@ exports.SharedSliceContentType = "SharedSliceContent"; | ||
]); | ||
const result = (0, RepeatableContent_1.RepeatableWidgetsLegacy)(itemsCtx).decode(parsedSlice.items); | ||
const result = (0, RepeatableContent_2.RepeatableWidgetsLegacy)(itemsCtx).decode(parsedSlice.items); | ||
if (!result || (0, Either_1.isLeft)(result)) | ||
@@ -81,3 +82,3 @@ return; | ||
]); | ||
const result = (0, RepeatableContent_1.RepeatableWidgetsLegacy)(itemsCtx).encode(s.items); | ||
const result = (0, RepeatableContent_2.RepeatableWidgetsLegacy)(itemsCtx).encode(s.items); | ||
return result; | ||
@@ -104,3 +105,3 @@ })() || []; | ||
primary: t.record(t.string, SlicePrimaryContent_1.SlicePrimaryContent), | ||
items: RepeatableContent_1.RepeatableWidgets, | ||
items: RepeatableContent_2.RepeatableWidgets, | ||
}); | ||
@@ -127,2 +128,3 @@ function sharedSliceContentWithDefaultValues(customType, content) { | ||
const transformedField = (() => { | ||
var _a; | ||
if ((0, GroupContent_1.isGroupContent)(fieldContent)) { | ||
@@ -140,2 +142,16 @@ return (0, GroupContent_1.traverseGroupContent)({ | ||
} | ||
else if ((0, RepeatableContent_1.isRepeatableContent)(fieldContent)) { | ||
return (0, RepeatableContent_1.traverseRepeatableContent)({ | ||
path: path.concat([ | ||
{ key: "primary", type: "primary" }, | ||
{ key: fieldKey, type: "Widget" }, | ||
]), | ||
key: fieldKey, | ||
apiId: fieldKey, | ||
content: fieldContent, | ||
model: (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Link" && ((_a = fieldDef.config) === null || _a === void 0 ? void 0 : _a.repeat) | ||
? fieldDef | ||
: undefined, | ||
})(transformWidget); | ||
} | ||
else if ((0, nestable_1.isNestableContent)(fieldContent)) { | ||
@@ -142,0 +158,0 @@ return transformWidget({ |
@@ -430,3 +430,3 @@ import * as t from "io-ts"; | ||
__TYPE__: t.LiteralC<"RepeatableContent">; | ||
type: t.UnionC<[t.LiteralC<"Color">, t.LiteralC<"Boolean">, t.LiteralC<"Embed">, t.LiteralC<"GeoPoint">, t.LiteralC<"Date">, t.LiteralC<"Number">, t.LiteralC<"Range">, t.LiteralC<"StructuredText">, t.LiteralC<"Select">, t.LiteralC<"Separator">, t.LiteralC<"Text">, t.LiteralC<"Timestamp">, t.LiteralC<"Link">, t.LiteralC<"Image">, t.LiteralC<"IntegrationFields">]>; | ||
type: t.LiteralC<"Link">; | ||
value: t.ArrayC<t.ExactC<t.TypeC<{ | ||
@@ -687,3 +687,3 @@ __TYPE__: t.LiteralC<"LinkContent">; | ||
__TYPE__: "RepeatableContent"; | ||
type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp"; | ||
type: "Link"; | ||
value: { | ||
@@ -915,3 +915,3 @@ __TYPE__: "LinkContent"; | ||
export declare const SimpleSliceLegacy: (ctx: LegacyContentCtx) => { | ||
decode: ((value: unknown) => import("fp-ts/lib/Either").Right<{ | ||
decode: ((value: unknown) => import("fp-ts/lib/Either").Left<t.Errors> | import("fp-ts/lib/Either").Right<{ | ||
type: string; | ||
@@ -1096,5 +1096,5 @@ __TYPE__: "EmptyContent"; | ||
}); | ||
}> | t.Validation<{ | ||
}> | import("fp-ts/lib/Either").Right<{ | ||
__TYPE__: "RepeatableContent"; | ||
type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp"; | ||
type: "Link"; | ||
value: { | ||
@@ -1101,0 +1101,0 @@ __TYPE__: "LinkContent"; |
@@ -427,3 +427,3 @@ import * as t from "io-ts"; | ||
__TYPE__: t.LiteralC<"RepeatableContent">; | ||
type: t.UnionC<[t.LiteralC<"Color">, t.LiteralC<"Boolean">, t.LiteralC<"Embed">, t.LiteralC<"GeoPoint">, t.LiteralC<"Date">, t.LiteralC<"Number">, t.LiteralC<"Range">, t.LiteralC<"StructuredText">, t.LiteralC<"Select">, t.LiteralC<"Separator">, t.LiteralC<"Text">, t.LiteralC<"Timestamp">, t.LiteralC<"Link">, t.LiteralC<"Image">, t.LiteralC<"IntegrationFields">]>; | ||
type: t.LiteralC<"Link">; | ||
value: t.ArrayC<t.ExactC<t.TypeC<{ | ||
@@ -504,3 +504,3 @@ __TYPE__: t.LiteralC<"LinkContent">; | ||
export declare const SlicePrimaryLegacy: (ctx: LegacyContentCtx) => { | ||
decode(value: unknown): import("fp-ts/lib/Either").Left<t.Errors> | import("fp-ts/lib/Either").Right<{ | ||
decode(value: unknown): import("fp-ts/lib/Either").Right<{ | ||
type: string; | ||
@@ -687,3 +687,3 @@ __TYPE__: "EmptyContent"; | ||
__TYPE__: "RepeatableContent"; | ||
type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp"; | ||
type: "Link"; | ||
value: { | ||
@@ -913,3 +913,3 @@ __TYPE__: "LinkContent"; | ||
__TYPE__: "SeparatorContent"; | ||
}> | import("fp-ts/lib/Either").Right<GroupContent> | undefined; | ||
}> | t.Validation<GroupContent> | undefined; | ||
encode(value: SlicePrimaryContent): import("../../../LegacyContentCtx").WithTypes<unknown> | undefined; | ||
@@ -1099,3 +1099,3 @@ }; | ||
__TYPE__: "RepeatableContent"; | ||
type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp"; | ||
type: "Link"; | ||
value: { | ||
@@ -1102,0 +1102,0 @@ __TYPE__: "LinkContent"; |
import * as t from "io-ts"; | ||
export declare const FieldOrSliceType: t.UnionC<[t.KeyofC<{ | ||
export declare const FieldOrSliceType: t.UnionC<[t.UnionC<[t.KeyofC<{ | ||
Color: null; | ||
@@ -22,21 +22,6 @@ Boolean: null; | ||
Choice: null; | ||
"Repeatable.Color": null; | ||
"Repeatable.Boolean": null; | ||
"Repeatable.Number": null; | ||
"Repeatable.Embed": null; | ||
"Repeatable.GeoPoint": null; | ||
"Repeatable.Date": null; | ||
"Repeatable.Range": null; | ||
"Repeatable.StructuredText": null; | ||
"Repeatable.Select": null; | ||
"Repeatable.Separator": null; | ||
"Repeatable.Text": null; | ||
"Repeatable.Timestamp": null; | ||
"Repeatable.Link": null; | ||
"Repeatable.Image": null; | ||
"Repeatable.IntegrationFields": null; | ||
}>, t.KeyofC<{ | ||
Slice: null; | ||
SharedSlice: null; | ||
}>]>; | ||
}>]>, t.LiteralC<"Repeatable.Link">]>; | ||
export declare type FieldOrSliceType = t.TypeOf<typeof FieldOrSliceType>; | ||
@@ -43,0 +28,0 @@ export declare class LegacyContentCtx { |
@@ -7,3 +7,6 @@ "use strict"; | ||
const widgets_1 = require("../customtypes/widgets"); | ||
exports.FieldOrSliceType = t.union([widgets_1.FieldType, widgets_1.SlicesTypes]); | ||
exports.FieldOrSliceType = t.union([ | ||
t.union([widgets_1.FieldType, widgets_1.SlicesTypes]), | ||
t.literal("Repeatable.Link"), | ||
]); | ||
class LegacyContentCtx { | ||
@@ -10,0 +13,0 @@ constructor(fieldKey, fieldPath, allTypes) { |
@@ -162,3 +162,2 @@ import * as t from "io-ts"; | ||
export declare type NestableWidget = t.TypeOf<typeof NestableWidget>; | ||
export declare const NestableFieldTypes: t.UnionC<[t.LiteralC<"Color">, t.LiteralC<"Boolean">, t.LiteralC<"Embed">, t.LiteralC<"GeoPoint">, t.LiteralC<"Date">, t.LiteralC<"Number">, t.LiteralC<"Range">, t.LiteralC<"StructuredText">, t.LiteralC<"Select">, t.LiteralC<"Separator">, t.LiteralC<"Text">, t.LiteralC<"Timestamp">, t.LiteralC<"Link">, t.LiteralC<"Image">, t.LiteralC<"IntegrationFields">]>; | ||
export declare type NestableFieldTypes = t.TypeOf<typeof NestableFieldTypes>; | ||
export declare type NestableFieldTypes = NestableWidget["type"]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NestableFieldTypes = exports.NestableWidget = void 0; | ||
exports.NestableWidget = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -38,18 +38,1 @@ const t = (0, tslib_1.__importStar)(require("io-ts")); | ||
]); | ||
exports.NestableFieldTypes = t.union([ | ||
t.literal(Color_1.ColorFieldType), | ||
t.literal(BooleanField_1.BooleanFieldType), | ||
t.literal(Embed_1.EmbedFieldType), | ||
t.literal(GeoPoint_1.GeoPointFieldType), | ||
t.literal(Date_1.DateFieldType), | ||
t.literal(Number_1.NumberFieldType), | ||
t.literal(Range_1.RangeFieldType), | ||
t.literal(RichText_1.RichTextFieldType), | ||
t.literal(Select_1.SelectFieldType), | ||
t.literal(Separator_1.SeparatorFieldType), | ||
t.literal(Text_1.TextFieldType), | ||
t.literal(Timestamp_1.TimestampFieldType), | ||
t.literal(Link_1.LinkFieldType), | ||
t.literal(Image_1.ImageFieldType), | ||
t.literal(IntegrationField_1.IntegrationFieldType), | ||
]); |
@@ -37,17 +37,2 @@ "use strict"; | ||
[Slices_1.LegacySlicesFieldType]: null, | ||
[`Repeatable.Color`]: null, | ||
[`Repeatable.Boolean`]: null, | ||
[`Repeatable.Number`]: null, | ||
[`Repeatable.Embed`]: null, | ||
[`Repeatable.GeoPoint`]: null, | ||
[`Repeatable.Date`]: null, | ||
[`Repeatable.Range`]: null, | ||
[`Repeatable.StructuredText`]: null, | ||
[`Repeatable.Select`]: null, | ||
[`Repeatable.Separator`]: null, | ||
[`Repeatable.Text`]: null, | ||
[`Repeatable.Timestamp`]: null, | ||
[`Repeatable.Link`]: null, | ||
[`Repeatable.Image`]: null, | ||
[`Repeatable.IntegrationFields`]: null, | ||
}); | ||
@@ -54,0 +39,0 @@ exports.Widgets = { |
{ | ||
"name": "@prismicio/types-internal", | ||
"version": "2.9.0-alpha.0", | ||
"version": "2.9.0-alpha.1", | ||
"description": "Prismic types for Custom Types and Prismic Data", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -27,2 +27,3 @@ import { either } from "fp-ts" | ||
traverseGroupContent, | ||
traverseRepeatableContent, | ||
traverseSlices, | ||
@@ -297,2 +298,13 @@ WidgetContent, | ||
})(transformWidget) | ||
case "RepeatableContent": | ||
return traverseRepeatableContent({ | ||
path, | ||
key, | ||
apiId: key, | ||
model: | ||
fieldModel?.type === "Link" && fieldModel.config?.repeat | ||
? fieldModel | ||
: undefined, | ||
content, | ||
})(transformWidget) | ||
default: | ||
@@ -299,0 +311,0 @@ return transformWidget({ |
@@ -23,2 +23,3 @@ import { either } from "fp-ts" | ||
import { isNestableContent, NestableContent, NestableLegacy } from "./nestable" | ||
import { traverseRepeatableContent } from "./RepeatableContent" | ||
import { repeatableContentWithDefaultNestableContentValues } from "./withDefaultValues" | ||
@@ -239,2 +240,14 @@ | ||
})(transform) | ||
} else if ( | ||
(!fieldDef || | ||
(fieldDef?.type === "Link" && fieldDef.config?.repeat)) && | ||
fieldContent.__TYPE__ === "RepeatableContent" | ||
) { | ||
transformedField = traverseRepeatableContent({ | ||
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]), | ||
key: fieldKey, | ||
apiId: fieldKey, | ||
model: fieldDef, | ||
content: fieldContent, | ||
})(transform) | ||
} else { | ||
@@ -241,0 +254,0 @@ transformedField = transform({ |
export * from "./EmptyContent" | ||
export * from "./GroupContent" | ||
export * from "./nestable" | ||
export * from "./RepeatableContent" | ||
export * from "./slices" | ||
export * from "./UIDContent" | ||
export * from "./WidgetContent" |
import { isRight } from "fp-ts/lib/Either" | ||
import * as t from "io-ts" | ||
import { type NestableWidget, NestableFieldTypes } from "../../../customtypes" | ||
import type { NestableWidget } from "../../../customtypes" | ||
import type { LegacyContentCtx } from "../../LegacyContentCtx" | ||
@@ -10,3 +10,2 @@ import { EmptyContent, EmptyLegacy, isEmptyContent } from "../EmptyContent" | ||
RepeatableContent, | ||
RepeatableContentType, | ||
RepeatableLegacy, | ||
@@ -151,9 +150,4 @@ } from "../RepeatableContent" | ||
const fieldTypeSplit = ctx?.fieldType?.split(".") | ||
const fieldType = fieldTypeSplit?.[1] ?? ctx.fieldType | ||
if (!NestableFieldTypes.is(fieldType)) return | ||
const codec = (() => { | ||
switch (fieldType) { | ||
switch (ctx.fieldType) { | ||
case "Text": | ||
@@ -189,2 +183,4 @@ return TextLegacy(ctx) | ||
return SeparatorLegacy(ctx) | ||
case "Repeatable.Link": | ||
return RepeatableLegacy(ctx, "Link") | ||
default: | ||
@@ -197,17 +193,5 @@ return | ||
// We check if the Nestable Content is repeated. If so, we decode each | ||
// item in the array using the specific codec for the repeated content. | ||
if (fieldTypeSplit?.[0] === "Repeatable") { | ||
return RepeatableLegacy(ctx, fieldType).decode(value) | ||
} | ||
return codec.decode(value) | ||
}, | ||
encode(value: NestableContent) { | ||
// We check if the Nestable Content is repeated. If so, we decode each | ||
// item in the array using the specific codec for the repeated content. | ||
if (value.__TYPE__ === RepeatableContentType) { | ||
return RepeatableLegacy(ctx, value.type).encode(value) | ||
} | ||
switch (value.__TYPE__) { | ||
@@ -241,2 +225,4 @@ case FieldContentType: { | ||
return SeparatorLegacy(ctx).encode(value) | ||
case "RepeatableContent": | ||
return RepeatableLegacy(ctx, value.type).encode(value) | ||
@@ -243,0 +229,0 @@ default: |
@@ -10,21 +10,15 @@ import { either } from "fp-ts" | ||
} from "../../_internal/utils" | ||
import type { Link, NestableWidget } from "../../customtypes" | ||
import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx" | ||
import { | ||
type Link, | ||
NestableFieldTypes, | ||
NestableWidget, | ||
} from "../../customtypes" | ||
import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx" | ||
import { LinkContent, LinkContentLegacy, LinkContentType } from "./nestable" | ||
isLinkContent, | ||
LinkContent, | ||
LinkContentLegacy, | ||
LinkContentType, | ||
} from "./nestable" | ||
export const RepeatableContentType = "RepeatableContent" as const | ||
export const RepeatableFieldType = "Repeatable" as const | ||
export const RepeatableItemContent = LinkContent | ||
export type RepeatableItemContent = t.TypeOf<typeof RepeatableItemContent> | ||
export const RepeatableContent = t.strict({ | ||
__TYPE__: t.literal(RepeatableContentType), | ||
type: NestableFieldTypes, | ||
// TODO: How to ensure it's an array of only one type | ||
value: t.array(RepeatableItemContent), | ||
__TYPE__: t.literal("RepeatableContent"), | ||
type: t.literal("Link"), | ||
value: t.array(LinkContent), | ||
}) | ||
@@ -38,7 +32,4 @@ | ||
ctx: LegacyContentCtx, | ||
fieldType: NestableFieldTypes, | ||
fieldType: "Link", | ||
): t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown> => { | ||
const codecDecode = t.array(t.unknown) | ||
const codecEncode = t.array(RepeatableItemContent) | ||
return new t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>( | ||
@@ -49,21 +40,18 @@ "RepeatableLegacy", | ||
const parsed = pipe( | ||
codecDecode.decode(items), | ||
t.array(t.unknown).decode(items), | ||
either.map((items) => { | ||
const parsedItems = items.reduce<Array<RepeatableItemContent>>( | ||
(acc, item) => { | ||
let result | ||
const parsedItems = items.reduce<Array<LinkContent>>((acc, item) => { | ||
let result | ||
switch (fieldType) { | ||
case "Link": | ||
result = LinkContentLegacy(ctx).decode(item) | ||
break | ||
} | ||
switch (fieldType) { | ||
case "Link": | ||
result = LinkContentLegacy(ctx).decode(item) | ||
break | ||
} | ||
if (!result) return acc | ||
if (isLeft(result)) return acc | ||
if (!result) return acc | ||
if (isLeft(result)) return acc | ||
return [...acc, result.right] | ||
}, | ||
[], | ||
) | ||
return [...acc, result.right] | ||
}, []) | ||
@@ -73,3 +61,3 @@ return { | ||
type: fieldType, | ||
__TYPE__: RepeatableContentType, | ||
__TYPE__: "RepeatableContent" as const, | ||
} | ||
@@ -82,3 +70,3 @@ }), | ||
(r: RepeatableContent) => { | ||
const res = codecEncode.encode(r.value) | ||
const res = t.array(LinkContent).encode(r.value) | ||
const encodedItems = res.reduce<Array<WithTypes<unknown>>>( | ||
@@ -127,3 +115,3 @@ (acc, item) => { | ||
): RepeatableContent | undefined => { | ||
const items = content.value.reduce<Array<RepeatableItemContent>>( | ||
const items = content.value.reduce<Array<LinkContent>>( | ||
(acc, fieldContent, index) => { | ||
@@ -145,2 +133,5 @@ const itemPath = path.concat([ | ||
// If the transformed field is not a link content, we don't include it | ||
if (!isLinkContent(transformedField)) return acc | ||
return acc.concat(transformedField) | ||
@@ -147,0 +138,0 @@ }, |
@@ -30,2 +30,6 @@ import { either } from "fp-ts" | ||
import { | ||
isRepeatableContent, | ||
traverseRepeatableContent, | ||
} from "../../RepeatableContent" | ||
import { | ||
repeatableContentWithDefaultNestableContentValues, | ||
@@ -219,2 +223,16 @@ withDefaultSlicePrimaryContentValues, | ||
})(transformWidget) | ||
} else if (isRepeatableContent(fieldContent)) { | ||
return traverseRepeatableContent({ | ||
path: path.concat([ | ||
{ key: "primary", type: "primary" }, | ||
{ key: fieldKey, type: "Widget" }, | ||
]), | ||
key: fieldKey, | ||
apiId: fieldKey, | ||
content: fieldContent, | ||
model: | ||
fieldDef?.type === "Link" && fieldDef.config?.repeat | ||
? fieldDef | ||
: undefined, | ||
})(transformWidget) | ||
} else if (isNestableContent(fieldContent)) { | ||
@@ -221,0 +239,0 @@ return transformWidget({ |
@@ -5,3 +5,6 @@ import * as t from "io-ts" | ||
export const FieldOrSliceType = t.union([FieldType, SlicesTypes]) | ||
export const FieldOrSliceType = t.union([ | ||
t.union([FieldType, SlicesTypes]), | ||
t.literal("Repeatable.Link"), | ||
]) | ||
export type FieldOrSliceType = t.TypeOf<typeof FieldOrSliceType> | ||
@@ -8,0 +11,0 @@ export class LegacyContentCtx { |
import * as t from "io-ts" | ||
import { BooleanField, BooleanFieldType } from "./BooleanField" | ||
import { Color, ColorFieldType } from "./Color" | ||
import { Date, DateFieldType } from "./Date" | ||
import { Embed, EmbedFieldType } from "./Embed" | ||
import { GeoPoint, GeoPointFieldType } from "./GeoPoint" | ||
import { Image, ImageFieldType } from "./Image" | ||
import { IntegrationField, IntegrationFieldType } from "./IntegrationField" | ||
import { Link, LinkFieldType } from "./Link" | ||
import { Number, NumberFieldType } from "./Number" | ||
import { Range, RangeFieldType } from "./Range" | ||
import { RichText, RichTextFieldType } from "./RichText" | ||
import { Select, SelectFieldType } from "./Select" | ||
import { Separator, SeparatorFieldType } from "./Separator" | ||
import { Text, TextFieldType } from "./Text" | ||
import { Timestamp, TimestampFieldType } from "./Timestamp" | ||
import { BooleanField } from "./BooleanField" | ||
import { Color } from "./Color" | ||
import { Date } from "./Date" | ||
import { Embed } from "./Embed" | ||
import { GeoPoint } from "./GeoPoint" | ||
import { Image } from "./Image" | ||
import { IntegrationField } from "./IntegrationField" | ||
import { Link } from "./Link" | ||
import { Number } from "./Number" | ||
import { Range } from "./Range" | ||
import { RichText } from "./RichText" | ||
import { Select } from "./Select" | ||
import { Separator } from "./Separator" | ||
import { Text } from "./Text" | ||
import { Timestamp } from "./Timestamp" | ||
@@ -38,20 +38,2 @@ export const NestableWidget = t.union([ | ||
export type NestableWidget = t.TypeOf<typeof NestableWidget> | ||
export const NestableFieldTypes = t.union([ | ||
t.literal(ColorFieldType), | ||
t.literal(BooleanFieldType), | ||
t.literal(EmbedFieldType), | ||
t.literal(GeoPointFieldType), | ||
t.literal(DateFieldType), | ||
t.literal(NumberFieldType), | ||
t.literal(RangeFieldType), | ||
t.literal(RichTextFieldType), | ||
t.literal(SelectFieldType), | ||
t.literal(SeparatorFieldType), | ||
t.literal(TextFieldType), | ||
t.literal(TimestampFieldType), | ||
t.literal(LinkFieldType), | ||
t.literal(ImageFieldType), | ||
t.literal(IntegrationFieldType), | ||
]) | ||
export type NestableFieldTypes = t.TypeOf<typeof NestableFieldTypes> | ||
export type NestableFieldTypes = NestableWidget["type"] |
@@ -64,17 +64,2 @@ import * as t from "io-ts" | ||
[LegacySlicesFieldType]: null, | ||
[`Repeatable.Color`]: null, | ||
[`Repeatable.Boolean`]: null, | ||
[`Repeatable.Number`]: null, | ||
[`Repeatable.Embed`]: null, | ||
[`Repeatable.GeoPoint`]: null, | ||
[`Repeatable.Date`]: null, | ||
[`Repeatable.Range`]: null, | ||
[`Repeatable.StructuredText`]: null, | ||
[`Repeatable.Select`]: null, | ||
[`Repeatable.Separator`]: null, | ||
[`Repeatable.Text`]: null, | ||
[`Repeatable.Timestamp`]: null, | ||
[`Repeatable.Link`]: null, | ||
[`Repeatable.Image`]: null, | ||
[`Repeatable.IntegrationFields`]: null, | ||
}) | ||
@@ -81,0 +66,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3306228
331
79414
0