UNPKG

@prismicio/mock

Version:

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

64 lines (63 loc) 2.63 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const prismic = require("@prismicio/client"); const buildContentRelationshipField = require("../lib/buildContentRelationshipField.cjs"); const createFaker = require("../lib/createFaker.cjs"); const generateCustomTypeId = require("../lib/generateCustomTypeId.cjs"); const generateTags = require("../lib/generateTags.cjs"); const customType = require("./customType.cjs"); const contentRelationship$1 = require("../model/contentRelationship.cjs"); function _interopNamespaceDefault(e) { const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } }); if (e) { for (const k in e) { if (k !== "default") { const d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: () => e[k] }); } } } n.default = e; return Object.freeze(n); } const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic); const contentRelationship = (config) => { var _a, _b; const faker = config.faker || createFaker.createFaker(config.seed); if (config.state === "empty") { return { link_type: prismic__namespace.LinkType.Document }; } else { const model = config.model || contentRelationship$1.contentRelationship({ 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.customType({ faker }), type: ((_a = model.config) == null ? void 0 : _a.customtypes) ? faker.randomElement(model.config.customtypes) : generateCustomTypeId.generateCustomTypeId({ faker }), tags: ((_b = model.config) == null ? void 0 : _b.tags) ? faker.randomElements(model.config.tags) : generateTags.generateTags({ faker }) } ]; const document = faker.randomElement(linkableDocuments); if (!document) { throw new Error("A linkable document could not be found."); } return buildContentRelationshipField.buildContentRelationshipField({ document }); } }; exports.contentRelationship = contentRelationship; //# sourceMappingURL=contentRelationship.cjs.map