Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prismicio/types-internal

Package Overview
Dependencies
Maintainers
30
Versions
166
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prismicio/types-internal - npm Package Compare versions

Comparing version 2.4.0-alpha.3 to 2.4.0-alpha.4

lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts

4

lib/content/Document.js

@@ -16,2 +16,6 @@ "use strict";

const legacyDocReader = t.record(common_1.WidgetKey, t.unknown);
/**
* `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
* format used by Prismic DB, therefore, this function itself is not "legacy".
*/
const DocumentLegacyCodec = (allTypes) => {

@@ -18,0 +22,0 @@ return new t.Type("Document", (u) => !!u && typeof u === "object", (doc) => {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupContentDefaultValue = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
const tslib_1 = require("tslib");

@@ -85,2 +85,6 @@ const fp_ts_1 = require("fp-ts");

});
exports.GroupContentDefaultValue = {
__TYPE__: exports.GroupContentType,
value: [],
};
function groupContentWithDefaultValues(customType, content) {

@@ -87,0 +91,0 @@ var _a;

33

lib/content/fields/slices/Slice/SharedSliceContent.js

@@ -10,2 +10,3 @@ "use strict";

const io_ts_types_1 = require("io-ts-types");
const customtypes_1 = require("../../../../customtypes");
const LegacyContentCtx_1 = require("../../../LegacyContentCtx");

@@ -17,2 +18,3 @@ const utils_1 = require("../../../utils");

const RepeatableContent_1 = require("./RepeatableContent");
const SlicePrimaryContent_1 = require("./SlicePrimaryContent");
exports.SharedSliceContentType = "SharedSliceContent";

@@ -45,3 +47,3 @@ const isSharedSliceContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.SharedSliceContentType;

]);
const result = (0, nestable_1.NestableLegacy)(FieldCtx).decode(value);
const result = (0, SlicePrimaryContent_1.SlicePrimaryLegacy)(FieldCtx).decode(value);
if (!result)

@@ -67,3 +69,3 @@ return acc;

]);
const result = (0, nestable_1.NestableLegacy)(FieldCtx).encode(value);
const result = (0, SlicePrimaryContent_1.SlicePrimaryLegacy)(FieldCtx).encode(value);
if (!result)

@@ -102,3 +104,3 @@ return acc;

variation: t.string,
primary: t.record(t.string, nestable_1.NestableContent),
primary: t.record(t.string, SlicePrimaryContent_1.SlicePrimaryContent),
items: RepeatableContent_1.RepeatableWidgets,

@@ -109,7 +111,5 @@ });

const variationConfig = customType.variations.find((v) => v.id === content.variation);
// Temporarily filtering out group fields and casting to NestableWidget until
// we support group fields in primary
const primaryConfig = Object.fromEntries(Object.entries((_a = variationConfig === null || variationConfig === void 0 ? void 0 : variationConfig.primary) !== null && _a !== void 0 ? _a : {}).filter(([_, value]) => value.type !== "Group"));
const primaryConfig = (_a = variationConfig === null || variationConfig === void 0 ? void 0 : variationConfig.primary) !== null && _a !== void 0 ? _a : {};
const itemsConfig = (_b = variationConfig === null || variationConfig === void 0 ? void 0 : variationConfig.items) !== null && _b !== void 0 ? _b : {};
const updatedPrimaryContent = (0, withDefaultValues_1.withDefaultNestableContentValues)(primaryConfig, content.primary);
const updatedPrimaryContent = (0, withDefaultValues_1.withDefaultSlicePrimaryContentValues)(primaryConfig, content.primary);
const updatedItemsContent = (0, withDefaultValues_1.repeatableContentWithDefaultNestableContentValues)(itemsConfig, content.items);

@@ -128,2 +128,21 @@ return {

const fieldDef = (_b = (_a = model === null || model === void 0 ? void 0 : model.fields) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b[fieldKey];
if ((0, GroupContent_1.isGroupContent)(fieldContent) && (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) {
const transformedGroupField = (0, GroupContent_1.traverseGroupContent)({
path: path.concat([
{ key: "primary", type: "primary" },
{ key: fieldKey, type: "Widget" },
]),
key: fieldKey,
apiId: sliceName,
content: fieldContent,
model: fieldDef,
})(transformWidget);
// Can happen if the transform function returns undefined to filter out a field
if (!transformedGroupField)
return acc;
return {
...acc,
[fieldKey]: transformedGroupField,
};
}
const transformedField = transformWidget({

@@ -130,0 +149,0 @@ path: path.concat([

@@ -1,3 +0,5 @@

import type { NestableWidget } from "../../customtypes";
import { type NestableWidget, type SlicePrimaryWidget } from "../../customtypes";
import type { NestableContent } from "./nestable";
import type { SlicePrimaryContent } from "./slices/Slice/SlicePrimaryContent";
export declare function withDefaultSlicePrimaryContentValues(customType: Record<string, SlicePrimaryWidget>, content: Partial<Record<string, SlicePrimaryContent>>): Record<string, SlicePrimaryContent>;
export declare function withDefaultNestableContentValues(customType: Record<string, NestableWidget>, content: Record<string, NestableContent>): Record<string, NestableContent>;

@@ -4,0 +6,0 @@ export declare function repeatableContentWithDefaultNestableContentValues<T extends {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.repeatableContentWithDefaultNestableContentValues = exports.withDefaultNestableContentValues = void 0;
exports.repeatableContentWithDefaultNestableContentValues = exports.withDefaultNestableContentValues = exports.withDefaultSlicePrimaryContentValues = void 0;
const customtypes_1 = require("../../customtypes");
const GroupContent_1 = require("./GroupContent");
const nestable_1 = require("./nestable");
function withDefaultSlicePrimaryContentValues(customType, content) {
const updatedContent = content;
for (const [widgetKey, widgetDef] of Object.entries(customType)) {
const widgetContent = content[widgetKey];
if (widgetContent === undefined) {
if (widgetDef.type === customtypes_1.GroupFieldType) {
updatedContent[widgetKey] = (0, GroupContent_1.groupContentWithDefaultValues)(widgetDef, GroupContent_1.GroupContentDefaultValue);
}
else {
const defaultValue = (0, nestable_1.NestableContentDefaultValue)(widgetDef);
if (defaultValue) {
updatedContent[widgetKey] = defaultValue;
}
}
continue;
}
if (widgetDef.type === customtypes_1.GroupFieldType && (0, GroupContent_1.isGroupContent)(widgetContent)) {
updatedContent[widgetKey] = (0, GroupContent_1.groupContentWithDefaultValues)(widgetDef, widgetContent);
}
}
return updatedContent;
}
exports.withDefaultSlicePrimaryContentValues = withDefaultSlicePrimaryContentValues;
function withDefaultNestableContentValues(customType, content) {

@@ -6,0 +31,0 @@ return Object.entries(customType).reduce((updatedContent, [widgetKey, widgetDef]) => {

{
"name": "@prismicio/types-internal",
"version": "2.4.0-alpha.3",
"version": "2.4.0-alpha.4",
"description": "Prismic types for Custom Types and Prismic Data",

@@ -5,0 +5,0 @@ "keywords": [

@@ -44,2 +44,6 @@ import { either } from "fp-ts"

/**
* `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
* format used by Prismic DB, therefore, this function itself is not "legacy".
*/
const DocumentLegacyCodec = (allTypes?: LegacyContentCtx["allTypes"]) => {

@@ -46,0 +50,0 @@ return new t.Type<Document, WithTypes<DocumentLegacy>, unknown>(

@@ -127,2 +127,7 @@ import { either } from "fp-ts"

export const GroupContentDefaultValue: GroupContent = {
__TYPE__: GroupContentType,
value: [],
}
export function groupContentWithDefaultValues(

@@ -129,0 +134,0 @@ customType: Group,

@@ -12,6 +12,6 @@ import { either } from "fp-ts"

} from "../../../../_internal/utils"
import type {
NestableWidget,
SharedSlice,
VariationFields,
import {
type SharedSlice,
type VariationFields,
GroupFieldType,
} from "../../../../customtypes"

@@ -24,14 +24,15 @@ import {

import { hasContentType } from "../../../utils"
import { traverseGroupItemsContent } from "../../GroupContent"
import {
isNestableContent,
NestableContent,
NestableLegacy,
} from "../../nestable"
isGroupContent,
traverseGroupContent,
traverseGroupItemsContent,
} from "../../GroupContent"
import { isNestableContent } from "../../nestable"
import {
repeatableContentWithDefaultNestableContentValues,
withDefaultNestableContentValues,
withDefaultSlicePrimaryContentValues,
} from "../../withDefaultValues"
import type { SharedSliceItemContent } from "../SliceItem"
import { RepeatableWidgets, RepeatableWidgetsLegacy } from "./RepeatableContent"
import { SlicePrimaryContent, SlicePrimaryLegacy } from "./SlicePrimaryContent"

@@ -74,3 +75,3 @@ export const SharedSliceContentType = "SharedSliceContent"

const primary = Object.entries(parsedSlice.primary).reduce<
Record<string, NestableContent>
Record<string, SlicePrimaryContent>
>((acc, [key, value]) => {

@@ -83,3 +84,3 @@ const FieldCtx = getFieldCtx(key, ctx, [

const result = NestableLegacy(FieldCtx).decode(value)
const result = SlicePrimaryLegacy(FieldCtx).decode(value)
if (!result) return acc

@@ -111,3 +112,3 @@

const result = NestableLegacy(FieldCtx).encode(value)
const result = SlicePrimaryLegacy(FieldCtx).encode(value)
if (!result) return acc

@@ -152,3 +153,3 @@

variation: t.string,
primary: t.record(t.string, NestableContent),
primary: t.record(t.string, SlicePrimaryContent),
items: RepeatableWidgets,

@@ -166,12 +167,6 @@ })

// Temporarily filtering out group fields and casting to NestableWidget until
// we support group fields in primary
const primaryConfig = Object.fromEntries(
Object.entries(variationConfig?.primary ?? {}).filter(
([_, value]) => value.type !== "Group",
),
) as Record<string, NestableWidget>
const primaryConfig = variationConfig?.primary ?? {}
const itemsConfig = variationConfig?.items ?? {}
const updatedPrimaryContent = withDefaultNestableContentValues(
const updatedPrimaryContent = withDefaultSlicePrimaryContentValues(
primaryConfig,

@@ -214,2 +209,23 @@ content.primary,

if (isGroupContent(fieldContent) && fieldDef?.type === GroupFieldType) {
const transformedGroupField = traverseGroupContent({
path: path.concat([
{ key: "primary", type: "primary" },
{ key: fieldKey, type: "Widget" },
]),
key: fieldKey,
apiId: sliceName,
content: fieldContent,
model: fieldDef,
})(transformWidget)
// Can happen if the transform function returns undefined to filter out a field
if (!transformedGroupField) return acc
return {
...acc,
[fieldKey]: transformedGroupField,
}
}
const transformedField = transformWidget({

@@ -216,0 +232,0 @@ path: path.concat([

@@ -1,5 +0,52 @@

import type { NestableWidget } from "../../customtypes"
import {
type NestableWidget,
type SlicePrimaryWidget,
GroupFieldType,
} from "../../customtypes"
import {
GroupContentDefaultValue,
groupContentWithDefaultValues,
isGroupContent,
} from "./GroupContent"
import type { NestableContent } from "./nestable"
import { NestableContentDefaultValue } from "./nestable"
import type { SlicePrimaryContent } from "./slices/Slice/SlicePrimaryContent"
export function withDefaultSlicePrimaryContentValues(
customType: Record<string, SlicePrimaryWidget>,
content: Partial<Record<string, SlicePrimaryContent>>,
): Record<string, SlicePrimaryContent> {
const updatedContent = content as Record<string, SlicePrimaryContent>
for (const [widgetKey, widgetDef] of Object.entries(customType)) {
const widgetContent = content[widgetKey]
if (widgetContent === undefined) {
if (widgetDef.type === GroupFieldType) {
updatedContent[widgetKey] = groupContentWithDefaultValues(
widgetDef,
GroupContentDefaultValue,
)
} else {
const defaultValue = NestableContentDefaultValue(widgetDef)
if (defaultValue) {
updatedContent[widgetKey] = defaultValue
}
}
continue
}
if (widgetDef.type === GroupFieldType && isGroupContent(widgetContent)) {
updatedContent[widgetKey] = groupContentWithDefaultValues(
widgetDef,
widgetContent,
)
}
}
return updatedContent
}
export function withDefaultNestableContentValues(

@@ -6,0 +53,0 @@ customType: Record<string, NestableWidget>,

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc