UNPKG

gatsby-source-prismic

Version:

Gatsby source plugin for building websites using Prismic as a data source

58 lines (57 loc) 2.09 kB
import * as prismicCustomTypesClient from "@prismicio/custom-types-client"; const resolveModels = async (args) => { const keyedCustomTypeModels = {}; const keyedSharedSliceModels = {}; if (args.pluginOptions.customTypesApiToken) { const client = prismicCustomTypesClient.createClient({ repositoryName: args.pluginOptions.repositoryName, token: args.pluginOptions.customTypesApiToken, fetch: args.pluginOptions.fetch || (await import("node-fetch")).default, endpoint: args.pluginOptions.customTypesApiEndpoint }); const [customTypeModels, sharedSliceModels] = await Promise.all([ client.getAllCustomTypes(), client.getAllSharedSlices() ]); for (const customTypeModel of customTypeModels) { keyedCustomTypeModels[customTypeModel.id] = customTypeModel; } for (const sharedSliceModel of sharedSliceModels) { keyedSharedSliceModels[sharedSliceModel.id] = sharedSliceModel; } } if (args.pluginOptions.schemas) { for (const id in args.pluginOptions.schemas) { const customTypeModel = { id, json: args.pluginOptions.schemas[id], // The following values are "fake". They are // not part of the given definition so we must // fill them in to promote the type to a Custom // Type model. label: "label", status: true, repeatable: true }; keyedCustomTypeModels[customTypeModel.id] = customTypeModel; } } if (args.pluginOptions.customTypeModels) { for (const customTypeModel of args.pluginOptions.customTypeModels) { keyedCustomTypeModels[customTypeModel.id] = customTypeModel; } } if (args.pluginOptions.sharedSliceModels) { for (const sharedSliceModel of args.pluginOptions.sharedSliceModels) { keyedSharedSliceModels[sharedSliceModel.id] = sharedSliceModel; } } return { customTypeModels: Object.values(keyedCustomTypeModels), sharedSliceModels: Object.values(keyedSharedSliceModels) }; }; export { resolveModels }; //# sourceMappingURL=resolveModels.js.map