{"version":3,"file":"buildCustomTypeType.cjs","names":["getCacheKey","buildTypeName","buildUnion","checkHasUIDField","getHumanReadableModelName","buildCustomTypeDataType","addSection","CUSTOM_TYPES_DOCUMENTATION_URL"],"sources":["../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport type QuickLRU from \"quick-lru\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeType(\n\targs: BuildCustomTypeTypesArgs\n): BuildCustomTypeTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildCustomTypeTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\");\n\tconst langDefault =\n\t\targs.localeIDs && args.localeIDs.length > 0\n\t\t\t? buildUnion(args.localeIDs.map((localeID) => `\"${localeID}\"`))\n\t\t\t: \"string\";\n\tconst baseDocumentType = checkHasUIDField(args.model)\n\t\t? \"PrismicDocumentWithUID\"\n\t\t: \"PrismicDocumentWithoutUID\";\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst dataType = buildCustomTypeDataType({\n\t\tmodel: args.model,\n\t\tfieldConfigs: args.fieldConfigs,\n\t});\n\n\tauxiliaryTypes.push(...dataType.auxiliaryTypes);\n\tcontentTypeNames.push(dataType.name);\n\tcontentTypeNames.push(...dataType.contentTypeNames);\n\n\tcode = addSection(dataType.code, code);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} document from Prismic\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Repeatable**: \\`${args.model.repeatable.toString()}\\`\n\t\t\t * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}\n\t\t\t *\n\t\t\t * @typeParam Lang - Language API ID of the document.\n\t\t\t */\n\t\t\texport type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${\n\t\t\tdataType.name\n\t\t}>, \"${args.model.id}\", Lang>;\n\t\t`,\n\t\tcode\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;AA4BA,SAAgB,oBACf,MACiC;AACjC,KAAI,KAAK,OAAO;EACf,MAAM,MAAMA,oBAAAA,YAAY,KAAK,MAAM;EACnC,MAAM,SAAS,KAAK,MAAM,IAAI,IAAI;AAElC,MAAI,OACH,QAAO;;CAIT,IAAI,OAAO;CAEX,MAAM,iBAAkC,EAAE;CAC1C,MAAM,mBAA6B,EAAE;CAErC,MAAM,OAAOC,sBAAAA,cAAc,KAAK,MAAM,IAAI,WAAW;CACrD,MAAM,cACL,K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