UNPKG

@prismicio/mock

Version:

Generate mock Prismic documents, fields, Slices, and models for development and testing environments

32 lines (31 loc) 1.68 kB
import { createFaker } from "../lib/createFaker.js"; import { generateTags } from "../lib/generateTags.js"; import { contentRelationship as contentRelationship$1 } from "../model/contentRelationship.js"; import { customType } from "./customType.js"; import { buildContentRelationshipField } from "../lib/buildContentRelationshipField.js"; import { generateCustomTypeId } from "../lib/generateCustomTypeId.js"; import * as prismic from "@prismicio/client"; //#region src/value/contentRelationship.ts const contentRelationship = (config) => { const faker = config.faker || createFaker(config.seed); if (config.state === "empty") return { link_type: prismic.LinkType.Document }; else { const model = config.model || contentRelationship$1({ faker }); const linkableDocuments = config.linkableDocuments ? config.linkableDocuments.filter((document) => { let shouldKeep = true; if (model.config?.customtypes) shouldKeep = shouldKeep && model.config.customtypes.includes(document.type); if (model.config?.tags) shouldKeep = shouldKeep && model.config.tags.some((tag) => document.tags.includes(tag)); return shouldKeep; }) : [{ ...customType({ faker }), type: model.config?.customtypes ? faker.randomElement(model.config.customtypes) : generateCustomTypeId({ faker }), tags: model.config?.tags ? faker.randomElements(model.config.tags) : generateTags({ faker }) }]; const document = faker.randomElement(linkableDocuments); if (!document) throw new Error("A linkable document could not be found."); return buildContentRelationshipField({ document }); } }; //#endregion export { contentRelationship }; //# sourceMappingURL=contentRelationship.js.map