@flotiq/flotiq-astro-sdk
Version:
Astro collection generator for connecting with Flotiq CMS
21 lines (20 loc) • 705 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateCollections = generateCollections;
const zod_schema_1 = require("./field-processors/zod-schema");
/**
* Generates loaders and schemas for types
*/
function generateCollections(schemas, propertiesConfig, required, order, name) {
const schema = (0, zod_schema_1.generateZodSchema)(schemas, propertiesConfig, required, order);
return `
const ${name} = defineCollection({
loader: async () => {
const response = (await api.content.${name}.list()).data;
response.map((object: any) => mapReferences(object));
return response;
},
schema: ${schema},
});
`;
}