UNPKG

@prismicio/mock

Version:

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

47 lines (46 loc) 1.92 kB
import * as prismic from "@prismicio/client"; import { buildContentRelationshipField } from "../lib/buildContentRelationshipField.js"; import { createFaker } from "../lib/createFaker.js"; import { generateCustomTypeId } from "../lib/generateCustomTypeId.js"; import { generateTags } from "../lib/generateTags.js"; import { customType } from "./customType.js"; import { contentRelationship as contentRelationship$1 } from "../model/contentRelationship.js"; const contentRelationship = (config) => { var _a, _b; 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((document2) => { var _a2, _b2; let shouldKeep = true; if ((_a2 = model.config) == null ? void 0 : _a2.customtypes) { shouldKeep = shouldKeep && model.config.customtypes.includes(document2.type); } if ((_b2 = model.config) == null ? void 0 : _b2.tags) { shouldKeep = shouldKeep && model.config.tags.some((tag) => document2.tags.includes(tag)); } return shouldKeep; }) : [ { ...customType({ faker }), type: ((_a = model.config) == null ? void 0 : _a.customtypes) ? faker.randomElement(model.config.customtypes) : generateCustomTypeId({ faker }), tags: ((_b = model.config) == null ? void 0 : _b.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 }); } }; export { contentRelationship }; //# sourceMappingURL=contentRelationship.js.map