UNPKG

@kontent-ai/model-generator

Version:

This utility generates strongly-typed models for Delivery JS SDK, Migration toolkit or just general scripting to improve the experience when referencing Kontent.ai related objects.

45 lines (43 loc) 2.07 kB
import { syncConfig } from "../../config.js"; import { wrapComment } from "../../core/comment.utils.js"; import { sortAlphabetically, uniqueFilter } from "../../core/core.utils.js"; import { getImporter } from "../../core/importer.js"; export function getSyncGenerator(config) { const importer = getImporter(config.moduleFileExtension); return { getSyncFiles() { return { folderName: undefined, files: [ { filename: `${syncConfig.coreTypesFilename}.ts`, text: ` ${importer.importType({ filePathOrPackage: syncConfig.npmPackageName, importValue: [syncConfig.sdkTypes.syncClientTypes, syncConfig.sdkTypes.syncClient], })} ${wrapComment("Use as generic type when creating a sync client for increased type safety")} export type ${syncConfig.coreClientTypesTypeName} = ${syncConfig.sdkTypes.syncClientTypes} & { readonly languageCodenames: ${getCodenames(config.environmentData.languages)}, readonly typeCodenames: ${getCodenames(config.environmentData.types)}, readonly workflowCodenames: ${getCodenames(config.environmentData.workflows)}, readonly workflowStepCodenames: ${getCodenames(config.environmentData.workflows.flatMap((workflow) => workflow.steps))}, readonly collectionCodenames: ${getCodenames(config.environmentData.collections)}, readonly taxonomyCodenames: ${getCodenames(config.environmentData.taxonomies)}, }; ${wrapComment("Type safe sync client")} export type ${syncConfig.coreClientTypeName} = SyncClient<${syncConfig.coreClientTypesTypeName}>; `, }, ], }; }, }; } function getCodenames(items) { if (!items.length) { return "never"; } return sortAlphabetically(items.map((item) => `'${item.codename}'`).filter(uniqueFilter), (m) => m).join(" | "); } //# sourceMappingURL=sync.generator.js.map