diff --git a/src/generateTypes.ts b/src/generateTypes.ts index 10759e3..8bf1537 100644 --- a/src/generateTypes.ts +++ b/src/generateTypes.ts @@ -81,7 +81,7 @@ export function generateTypes(config: GenerateTypesConfig = {}): string { allDocumentTypesTypeNames.push(customTypeType.name); contentTypeNames.push(customTypeType.name); - contentTypeNames.push(customTypeType.dataName); + contentTypeNames.push(...customTypeType.contentTypeNames); } if (config.customTypeModels.length > 0) { @@ -108,8 +108,7 @@ export function generateTypes(config: GenerateTypesConfig = {}): string { code = addSection(sharedSliceType.code, code); contentTypeNames.push(sharedSliceType.name); - contentTypeNames.push(sharedSliceType.variationUnionName); - contentTypeNames.push(...sharedSliceType.variationNames); + contentTypeNames.push(...sharedSliceType.contentTypeNames); } } diff --git a/src/lib/buildCustomTypeDataType.ts b/src/lib/buildCustomTypeDataType.ts index 01a9094..2512563 100644 --- a/src/lib/buildCustomTypeDataType.ts +++ b/src/lib/buildCustomTypeDataType.ts @@ -17,6 +17,7 @@ type BuildCustomTypeDataTypeReturnValue = { name: string; code: string; auxiliaryTypes: AuxiliaryType[]; + contentTypeNames: string[]; }; export function buildCustomTypeDataType( @@ -24,6 +25,7 @@ export function buildCustomTypeDataType( ): BuildCustomTypeDataTypeReturnValue { let code = ""; const auxiliaryTypes: AuxiliaryType[] = []; + const contentTypeNames: string[] = []; const name = buildTypeName(args.model.id, "Document", "Data"); const humanReadableName = getHumanReadableModelName({ @@ -51,6 +53,7 @@ export function buildCustomTypeDataType( fieldProperties += tabFieldProperties.code; auxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes); + contentTypeNames.push(...tabFieldProperties.contentTypeNames); } if (fieldProperties) { @@ -70,5 +73,6 @@ export function buildCustomTypeDataType( name, code, auxiliaryTypes, + contentTypeNames, }; } diff --git a/src/lib/buildCustomTypeType.ts b/src/lib/buildCustomTypeType.ts index fa8d4ff..b6b8768 100644 --- a/src/lib/buildCustomTypeType.ts +++ b/src/lib/buildCustomTypeType.ts @@ -23,9 +23,9 @@ type BuildCustomTypeTypesArgs = { type BuildCustomTypeTypeReturnValue = { name: string; - dataName: string; code: string; auxiliaryTypes: AuxiliaryType[]; + contentTypeNames: string[]; }; export function buildCustomTypeType( @@ -43,6 +43,7 @@ export function buildCustomTypeType( let code = ""; const auxiliaryTypes: AuxiliaryType[] = []; + const contentTypeNames: string[] = []; const name = buildTypeName(args.model.id, "Document"); const langDefault = @@ -63,6 +64,8 @@ export function buildCustomTypeType( }); auxiliaryTypes.push(...dataType.auxiliaryTypes); + contentTypeNames.push(dataType.name); + contentTypeNames.push(...dataType.contentTypeNames); code = addSection(dataType.code, code); @@ -86,9 +89,9 @@ export function buildCustomTypeType( const result = { name, - dataName: dataType.name, code, auxiliaryTypes, + contentTypeNames, }; if (args.cache) { diff --git a/src/lib/buildFieldProperties.ts b/src/lib/buildFieldProperties.ts index 51bca0d..b6c2256 100644 --- a/src/lib/buildFieldProperties.ts +++ b/src/lib/buildFieldProperties.ts @@ -21,6 +21,7 @@ type BuildFieldPropertyArgs = Pick< type BuildFieldPropertyReturnType = { code: string; auxiliaryTypes: AuxiliaryType[]; + contentTypeNames: string[]; }; function buildFieldProperty( @@ -34,6 +35,7 @@ function buildFieldProperty( }); const auxiliaryTypes: AuxiliaryType[] = []; + const contentTypeNames: string[] = []; const name = args.name.includes("-") || @@ -450,6 +452,7 @@ function buildFieldProperty( name: choiceUnionName, code: `type ${choiceUnionName} = ${choiceUnion}`, }); + contentTypeNames.push(choiceUnionName); code = addLine(`${name}: prismic.SliceZone<${choiceUnionName}>;`, code); @@ -464,6 +467,7 @@ function buildFieldProperty( return { code, auxiliaryTypes, + contentTypeNames, }; } @@ -477,6 +481,7 @@ type BuildFieldPropertiesArgs = { type BuildFieldPropertiesReturnType = { code: string; auxiliaryTypes: AuxiliaryType[]; + contentTypeNames: string[]; }; export function buildFieldProperties( @@ -485,6 +490,7 @@ export function buildFieldProperties( let code = ""; const auxiliaryTypes: AuxiliaryType[] = []; + const contentTypeNames: string[] = []; for (const name in args.fields) { const field = args.fields[name]; @@ -500,10 +506,12 @@ export function buildFieldProperties( code = addSection(fieldProperty.code, code); auxiliaryTypes.push(...fieldProperty.auxiliaryTypes); + contentTypeNames.push(...fieldProperty.contentTypeNames); } return { code, auxiliaryTypes, + contentTypeNames, }; } diff --git a/src/lib/buildSharedSliceType.ts b/src/lib/buildSharedSliceType.ts index bab8d2b..30d53a4 100644 --- a/src/lib/buildSharedSliceType.ts +++ b/src/lib/buildSharedSliceType.ts @@ -22,9 +22,9 @@ type BuildSharedSliceTypeArgs = { type BuildSharedSliceTypeReturnValue = { name: string; - variationUnionName: string; variationNames: string[]; code: string; + contentTypeNames: string[]; }; export function buildSharedSliceType( @@ -40,6 +40,7 @@ export function buildSharedSliceType( } let code = ""; + const contentTypeNames: string[] = []; const name = buildTypeName(args.model.id, "Slice"); const humanReadableName = getHumanReadableModelName({ @@ -76,6 +77,8 @@ export function buildSharedSliceType( path, }); + contentTypeNames.push(...primaryFieldProperties.contentTypeNames); + const docs = stripIndent` /** * Primary content in *${humanReadablePath}* @@ -120,6 +123,8 @@ export function buildSharedSliceType( path, }); + contentTypeNames.push(...itemFieldProperties.contentTypeNames); + const docs = stripIndent` /** * Primary content in *${humanReadablePath}* @@ -168,6 +173,9 @@ export function buildSharedSliceType( const variationUnionName = buildTypeName(name, "Variation"); const variationsUnion = buildUnion(variationNames); + contentTypeNames.push(variationUnionName); + contentTypeNames.push(...variationNames); + code = addSection( source` /** @@ -198,9 +206,9 @@ export function buildSharedSliceType( const result = { name, - variationUnionName, variationNames, code, + contentTypeNames, }; if (args.cache) { diff --git a/test/__snapshots__/generateTypes.test.ts.snap b/test/__snapshots__/generateTypes.test.ts.snap index 08499db..fea3655 100644 --- a/test/__snapshots__/generateTypes.test.ts.snap +++ b/test/__snapshots__/generateTypes.test.ts.snap @@ -2400,14 +2400,19 @@ declare module \\"@prismicio/client\\" { export type { MorbiDocument, MorbiDocumentData, + MorbiDocumentDataSliceZoneSlice, NetusDocument, NetusDocumentData, + NetusDocumentDataSliceZoneSlice, AliquamDocument, AliquamDocumentData, + AliquamDocumentDataSliceZoneSlice, ADocument, ADocumentData, + ADocumentDataSliceZoneSlice, ConsequatDocument, ConsequatDocumentData, + ConsequatDocumentDataSliceZoneSlice, AllDocumentTypes, InterdumSlice, InterdumSliceVariation,