@prismicio/types-internal
Version:
Prismic types for Custom Types and Prismic Data
44 lines (43 loc) • 2.06 kB
TypeScript
import * as t from "io-ts";
import type { CompositeSlice, Group, NestableWidget, StaticSlices, UID, VariationFields } from "../customtypes";
import { FieldType, SharedSliceItemContent, SliceItemContent, WidgetContent } from "./fields";
declare type WithFieldType = WithContentType & {
type: FieldType;
};
export declare function hasFieldContentType(obj: unknown): obj is WithFieldType;
declare type WithContentType = {
__TYPE__: string;
};
export declare function hasContentType(obj: unknown): obj is WithContentType;
export declare function withKey<C extends t.Mixed>(codec: C): t.IntersectionC<[t.ExactC<t.TypeC<{
key: t.Type<string, string, unknown>;
}>>, C]>;
export declare type TraverseSliceContentFn = <S extends SliceItemContent | SharedSliceItemContent, D extends VariationFields | CompositeSlice | Group | NestableWidget>({ path, key, apiId, model, content, }: {
path: ContentPath;
key: string;
apiId: string;
model?: D | undefined;
content: S;
}) => S | SharedSliceItemContent | undefined;
export declare type TraverseWidgetContentFn<ContentTransformMode extends "preserve" | "widen" = "preserve"> = <C extends WidgetContent, D extends NestableWidget | StaticSlices | Group | UID>({ path, key, apiId, model, content, }: {
path: ContentPath;
key: string;
apiId: string;
model?: D | undefined;
content: C;
}) => ([ContentTransformMode] extends ["preserve"] ? C : WidgetContent) | undefined;
export declare type ContentPathEntry = {
type: "CustomType" | "Widget" | "SharedSlice" | "Slice" | "LegacySlice" | "GroupItem" | "primary" | "items" | "RepeatableItem";
key: string;
};
export declare type ContentPath = ReadonlyArray<ContentPathEntry>;
export declare const ContentPath: {
serialize(path: ContentPath): string;
current(path: ContentPath): ContentPathEntry | undefined;
append(path: string, strElement: string): string;
make(entries: Array<{
key?: ContentPathEntry["key"] | undefined;
type: ContentPathEntry["type"];
}>): ContentPath;
};
export {};