UNPKG

@spotable/attio-sdk

Version:
41 lines (38 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateSdkUtilityTypes = generateSdkUtilityTypes; const fs_1 = require("../../helpers/fs"); const logger_1 = require("../../helpers/logger"); const fileHeader_1 = require("./fileHeader"); const FILE_NAME = "sdk-utilities.ts"; function generateSdkUtilityTypes(objects, standardTypes = false, outputDir) { logger_1.default.debug(`Generating SDK utility types file: ${FILE_NAME}`); const imports = `${objects.map(({ singular_noun }) => singular_noun).join(", ")}, ${standardTypes ? "AttioList, AttioEntry, AttioNote, AttioTask" : ""}`; const entityNames = [...objects.map(({ api_slug }) => `'${api_slug}'`), ...(standardTypes ? [`'list'`, `'entry'`, `'note'`, `'task'`] : [])]; const entityTypes = [ ...objects.map(({ api_slug, singular_noun }) => ` '${api_slug}': ${singular_noun};`), ...(standardTypes ? [` 'list': AttioList;`, ` 'entry': AttioEntry;`, ` 'note': AttioNote;`, ` 'task': AttioTask;`] : []), ]; const utilityTypes = ` ${(0, fileHeader_1.generateFileHeader)(FILE_NAME)} import { ${imports} } from "."; /** * All available entity names in your Attio workspace. * Use this type for type-safe entity access with the SDK. */ export type EntityName = ${entityNames.join(" | ")}; /** * Maps entity names to their corresponding types. * Use this for type-safe entity access in your SDK. */ export interface EntityTypes { ${entityTypes.join("\n")} } /** * Type utility to get the entity type from an entity name. */ export type GetEntityType<K extends EntityName> = EntityTypes[K]; `; (0, fs_1.writeGeneratedFile)(outputDir, FILE_NAME, utilityTypes); } //# sourceMappingURL=sdkUtilityTypes.js.map