UNPKG

@prismicio/mock

Version:

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

1 lines 2.44 kB
{"version":3,"file":"repository.cjs","sources":["../../../src/api/repository.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nimport { capitalCase } from \"../lib/changeCase\";\nimport { createFaker } from \"../lib/createFaker\";\nimport { generateTags } from \"../lib/generateTags\";\n\nimport { MockRestApiConfig } from \"../types\";\nimport { ref } from \"./ref\";\n\nexport type MockRestApiRepositoryConfig = {\n\tcustomTypeModels?: prismic.CustomTypeModel[];\n\twithReleases?: boolean;\n} & MockRestApiConfig;\n\nexport const repository = (\n\tconfig: MockRestApiRepositoryConfig,\n): prismic.Repository => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tconst types = (config.customTypeModels || []).reduce(\n\t\t(acc, model) => {\n\t\t\tacc[model.id] = model.label || model.id;\n\n\t\t\treturn acc;\n\t\t},\n\t\t{} as prismic.Repository[\"types\"],\n\t);\n\n\treturn {\n\t\trefs: [\n\t\t\tref({ faker, isMasterRef: true }),\n\t\t\t...(config.withReleases ? [ref({ faker }), ref({ faker })] : []),\n\t\t],\n\t\tintegrationFieldsRef: ref({ faker }).ref,\n\t\ttypes,\n\t\tlanguages: [\n\t\t\t{\n\t\t\t\tid: faker.word(),\n\t\t\t\tname: capitalCase(faker.word()),\n\t\t\t\tis_master: true,\n\t\t\t},\n\t\t],\n\t\ttags: generateTags({\n\t\t\tfaker,\n\t\t\tmin: 1,\n\t\t\tmax: 10,\n\t\t}),\n\t\tforms: {},\n\t\tlicense: \"All Rights Reserved\",\n\t\tversion: faker.hash(7),\n\t\tbookmarks: {},\n\t\texperiments: {},\n\t\toauth_token: faker.url(),\n\t\toauth_initiate: faker.url(),\n\t};\n};\n"],"names":["createFaker","ref","capitalCase","generateTags"],"mappings":";;;;;;AAca,MAAA,aAAa,CACzB,WACuB;AACvB,QAAM,QAAQ,OAAO,SAASA,YAAAA,YAAY,OAAO,IAAI;AAE/C,QAAA,SAAS,OAAO,oBAAoB,IAAI,OAC7C,CAAC,KAAK,UAAS;AACd,QAAI,MAAM,EAAE,IAAI,MAAM,SAAS,MAAM;AAE9B,WAAA;AAAA,EACR,GACA,CAAiC,CAAA;AAG3B,SAAA;AAAA,IACN,MAAM;AAAA,MACLC,IAAAA,IAAI,EAAE,OAAO,aAAa,MAAM;AAAA,MAChC,GAAI,OAAO,eAAe,CAACA,IAAAA,IAAI,EAAE,OAAO,GAAGA,QAAI,EAAE,MAAO,CAAA,CAAC,IAAI,CAAA;AAAA,IAC7D;AAAA,IACD,sBAAsBA,IAAA,IAAI,EAAE,MAAA,CAAO,EAAE;AAAA,IACrC;AAAA,IACA,WAAW;AAAA,MACV;AAAA,QACC,IAAI,MAAM,KAAM;AAAA,QAChB,MAAMC,WAAA,YAAY,MAAM,MAAM;AAAA,QAC9B,WAAW;AAAA,MACX;AAAA,IACD;AAAA,IACD,MAAMC,aAAAA,aAAa;AAAA,MAClB;AAAA,MACA,KAAK;AAAA,MACL,KAAK;AAAA,IAAA,CACL;AAAA,IACD,OAAO,CAAE;AAAA,IACT,SAAS;AAAA,IACT,SAAS,MAAM,KAAK,CAAC;AAAA,IACrB,WAAW,CAAE;AAAA,IACb,aAAa,CAAE;AAAA,IACf,aAAa,MAAM,IAAK;AAAA,IACxB,gBAAgB,MAAM,IAAK;AAAA,EAAA;AAE7B;;"}