prismic-ts-codegen
Advanced tools
Comparing version 0.1.3-alpha.0 to 0.1.3
@@ -19,3 +19,2 @@ import { CustomTypeModel, SharedSliceModel } from '@prismicio/types'; | ||
includeCreateClientInterface?: boolean; | ||
includeContentNamespace?: boolean; | ||
}; | ||
@@ -35,3 +34,4 @@ }; | ||
* The access token for the Prismic repository. If the repository is private | ||
* and `locales.fetchFromRepository` is `true`, providing a token is required. | ||
* and `locales.fetchFromRepository` is `true`, providing a token is | ||
* required. | ||
*/ | ||
@@ -68,16 +68,2 @@ accessToken?: string; | ||
includeCreateClientInterface?: boolean; | ||
/** | ||
* Determines if a `@prismicio/client` namespace named `Content` containing | ||
* all Document and Slice types should be included in the output. | ||
* | ||
* If set to `true`, a `Content` namespace from `@prismicio/client` will be | ||
* available to import to easily access types for your Prismic repository content. | ||
* | ||
* **Note**: If your project queries content from multiple Prismic | ||
* repositories, set `includeContentNamespace` to `false` and manually | ||
* import the content types instead. | ||
* | ||
* @defaultValue `true` | ||
*/ | ||
includeContentNamespace?: boolean; | ||
}; | ||
@@ -131,3 +117,4 @@ /** | ||
/** | ||
* A list of file paths to Custom Type and Slice models. Globs are supported. | ||
* A list of file paths to Custom Type and Slice models. Globs are | ||
* supported. | ||
*/ | ||
@@ -134,0 +121,0 @@ files?: string[]; |
@@ -201,6 +201,14 @@ import { Project, ModuleDeclarationKind } from 'ts-morph'; | ||
const buildSharedSliceInterfaceName = (config) => { | ||
const buildSharedSliceInterfaceNamePart = (config) => { | ||
return pascalCase(`${config.id} Slice`); | ||
}; | ||
const buildTypeName = (...parts) => { | ||
let name = pascalCase(parts.filter(Boolean).join(" ")); | ||
if (/^[0-9]/.test(name) ? "_" : "") { | ||
name = `_${name}`; | ||
} | ||
return name; | ||
}; | ||
const addInterfacePropertyForField = (config) => { | ||
@@ -255,3 +263,5 @@ switch (config.model.type) { | ||
const configuredProviderType = config.fieldConfigs.embed?.providerTypes[providerType]; | ||
providerTypes.push(`({ provider_name: "${providerType}" } & ${configuredProviderType})`); | ||
providerTypes.push( | ||
`({ provider_name: "${providerType}" } & ${configuredProviderType})` | ||
); | ||
} | ||
@@ -261,3 +271,5 @@ } | ||
name: config.id, | ||
type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(" | ")})>` : "prismicT.EmbedField", | ||
type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join( | ||
" | " | ||
)})>` : "prismicT.EmbedField", | ||
docs: buildFieldDocs({ | ||
@@ -466,3 +478,9 @@ id: config.id, | ||
const itemInterface = config.sourceFile.addInterface({ | ||
name: pascalCase(`${config.path[0].id} Document Data ${config.id} Item`), | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
"Item" | ||
), | ||
docs: [ | ||
@@ -519,3 +537,5 @@ { | ||
if (choice.type === CustomTypeModelSliceType.SharedSlice) { | ||
choiceInterfaceNames.push(buildSharedSliceInterfaceName({ id: choiceId })); | ||
choiceInterfaceNames.push( | ||
buildSharedSliceInterfaceNamePart({ id: choiceId }) | ||
); | ||
} else if (choice.type === CustomTypeModelSliceType.Slice) { | ||
@@ -525,3 +545,11 @@ let primaryInterface; | ||
primaryInterface = config.sourceFile.addInterface({ | ||
name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice Primary`), | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
choiceId, | ||
"Slice", | ||
"Primary" | ||
), | ||
docs: [ | ||
@@ -547,3 +575,5 @@ { | ||
}); | ||
writer.writeLine(`Primary content in ${humanReadablePath}`); | ||
writer.writeLine( | ||
`Primary content in ${humanReadablePath}` | ||
); | ||
} | ||
@@ -578,3 +608,11 @@ } | ||
itemInterface = config.sourceFile.addInterface({ | ||
name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice Item`), | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
choiceId, | ||
"Slice", | ||
"Item" | ||
), | ||
docs: [ | ||
@@ -629,3 +667,10 @@ { | ||
const sliceType = config.sourceFile.addTypeAlias({ | ||
name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice`), | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
choiceId, | ||
"Slice" | ||
), | ||
type: `prismicT.Slice<"${choiceId}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`, | ||
@@ -639,3 +684,9 @@ isExported: true | ||
const slicesType = config.sourceFile.addTypeAlias({ | ||
name: pascalCase(`${config.path[0].id} Document Data ${config.id} Slice`), | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
"Slice" | ||
), | ||
type: choiceInterfaceNames.length > 0 ? choiceInterfaceNames.join(" | ") : "never", | ||
@@ -711,3 +762,3 @@ docs: [ | ||
dataInterface = sourceFile.addInterface({ | ||
name: pascalCase(`${model.id} Document Data`), | ||
name: buildTypeName(model.id, "Document", "Data"), | ||
docs: [ | ||
@@ -737,3 +788,3 @@ { | ||
dataInterface = sourceFile.addTypeAlias({ | ||
name: pascalCase(`${model.id} Document Data`), | ||
name: buildTypeName(model.id, "Document", "Data"), | ||
type: `Record<string, never>`, | ||
@@ -748,3 +799,3 @@ docs: [ | ||
return sourceFile.addTypeAlias({ | ||
name: pascalCase(`${model.id} Document`), | ||
name: buildTypeName(model.id, "Document"), | ||
typeParameters: [ | ||
@@ -765,3 +816,5 @@ { | ||
writer.writeLine(`- **Repeatable**: \`${model.repeatable}\``); | ||
writer.writeLine(`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`); | ||
writer.writeLine( | ||
`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}` | ||
); | ||
}, | ||
@@ -786,3 +839,7 @@ tags: [ | ||
primaryInterface = config.sourceFile.addInterface({ | ||
name: pascalCase(`${buildSharedSliceInterfaceName({ id: config.model.id })} ${variation.id} Primary`), | ||
name: buildTypeName( | ||
buildSharedSliceInterfaceNamePart({ id: config.model.id }), | ||
variation.id, | ||
"Primary" | ||
), | ||
docs: [ | ||
@@ -828,3 +885,7 @@ { | ||
itemInterface = config.sourceFile.addInterface({ | ||
name: pascalCase(`${buildSharedSliceInterfaceName({ id: config.model.id })} ${variation.id} Item`), | ||
name: buildTypeName( | ||
buildSharedSliceInterfaceNamePart({ id: config.model.id }), | ||
variation.id, | ||
"Item" | ||
), | ||
docs: [ | ||
@@ -869,5 +930,6 @@ { | ||
const variationType = config.sourceFile.addTypeAlias({ | ||
name: pascalCase(`${buildSharedSliceInterfaceName({ | ||
id: config.model.id | ||
})} ${variation.id}`), | ||
name: buildTypeName( | ||
buildSharedSliceInterfaceNamePart({ id: config.model.id }), | ||
variation.id | ||
), | ||
type: `prismicT.SharedSliceVariation<"${variation.id}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`, | ||
@@ -877,7 +939,11 @@ docs: [ | ||
description: (writer) => { | ||
writer.writeLine(`${variation.name} variation for ${config.model.name} Slice`); | ||
writer.writeLine( | ||
`${variation.name} variation for ${config.model.name} Slice` | ||
); | ||
writer.blankLine(); | ||
writer.writeLine(`- **API ID**: \`${variation.id}\``); | ||
writer.writeLine(`- **Description**: \`${variation.description}\``); | ||
writer.writeLine(`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`); | ||
writer.writeLine( | ||
`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}` | ||
); | ||
} | ||
@@ -891,3 +957,3 @@ } | ||
const variationsType = config.sourceFile.addTypeAlias({ | ||
name: pascalCase(`${config.model.id} Slice Variation`), | ||
name: buildTypeName(config.model.id, "Slice", "Variation"), | ||
type: variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never", | ||
@@ -911,5 +977,5 @@ docs: [ | ||
return config.sourceFile.addTypeAlias({ | ||
name: pascalCase(buildSharedSliceInterfaceName({ | ||
id: config.model.id | ||
})), | ||
name: buildTypeName( | ||
buildSharedSliceInterfaceNamePart({ id: config.model.id }) | ||
), | ||
type: `prismicT.SharedSlice<"${config.model.id}", ${variationsType.getName()}>`, | ||
@@ -922,4 +988,8 @@ docs: [ | ||
writer.writeLine(`- **API ID**: \`${config.model.id}\``); | ||
writer.writeLine(`- **Description**: \`${config.model.description}\``); | ||
writer.writeLine(`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`); | ||
writer.writeLine( | ||
`- **Description**: \`${config.model.description}\`` | ||
); | ||
writer.writeLine( | ||
`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}` | ||
); | ||
} | ||
@@ -949,3 +1019,3 @@ } | ||
sourceFile.addStatements(BLANK_LINE_IDENTIFIER); | ||
const simplifyTypeAlias = sourceFile.addTypeAlias({ | ||
sourceFile.addTypeAlias({ | ||
name: "Simplify", | ||
@@ -971,3 +1041,5 @@ typeParameters: [ | ||
name: "AllDocumentTypes", | ||
type: config.customTypeModels.map((customTypeModel) => pascalCase(`${customTypeModel.id} Document`)).join(" | "), | ||
type: config.customTypeModels.map( | ||
(customTypeModel) => buildTypeName(customTypeModel.id, "Document") | ||
).join(" | "), | ||
isExported: true | ||
@@ -986,3 +1058,3 @@ }); | ||
} | ||
if (config.clientIntegration?.includeCreateClientInterface || config.clientIntegration?.includeContentNamespace) { | ||
if (config.clientIntegration?.includeCreateClientInterface) { | ||
sourceFile.addImportDeclaration({ | ||
@@ -998,40 +1070,21 @@ moduleSpecifier: "@prismicio/client", | ||
}); | ||
if (config.clientIntegration.includeCreateClientInterface) { | ||
clientModuleDeclaration.addInterface({ | ||
name: "CreateClient", | ||
callSignatures: [ | ||
{ | ||
parameters: [ | ||
{ | ||
name: "repositoryNameOrEndpoint", | ||
type: "string" | ||
}, | ||
{ | ||
name: "options", | ||
type: "prismic.ClientConfig", | ||
hasQuestionToken: true | ||
} | ||
], | ||
returnType: (config.customTypeModels?.length || 0) > 0 ? "prismic.Client<AllDocumentTypes>" : "prismic.Client" | ||
} | ||
] | ||
}); | ||
} | ||
if (config.clientIntegration.includeContentNamespace) { | ||
const contentNamespaceDeclaration = clientModuleDeclaration.addModule({ | ||
name: "Content", | ||
declarationKind: ModuleDeclarationKind.Namespace | ||
}); | ||
const exportSymbols = sourceFile.getExportSymbols().filter((exportSymbol) => { | ||
return exportSymbol.getName() !== simplifyTypeAlias.getName(); | ||
}); | ||
contentNamespaceDeclaration.addExportDeclaration({ | ||
isTypeOnly: true, | ||
namedExports: exportSymbols.map((exportSymbol) => { | ||
return { | ||
name: exportSymbol.getName() | ||
}; | ||
}) | ||
}); | ||
} | ||
clientModuleDeclaration.addInterface({ | ||
name: "CreateClient", | ||
callSignatures: [ | ||
{ | ||
parameters: [ | ||
{ | ||
name: "repositoryNameOrEndpoint", | ||
type: "string" | ||
}, | ||
{ | ||
name: "options", | ||
type: "prismic.ClientConfig", | ||
hasQuestionToken: true | ||
} | ||
], | ||
returnType: (config.customTypeModels?.length || 0) > 0 ? "prismic.Client<AllDocumentTypes>" : "prismic.Client" | ||
} | ||
] | ||
}); | ||
} | ||
@@ -1038,0 +1091,0 @@ return getSourceFileText(sourceFile); |
{ | ||
"name": "prismic-ts-codegen", | ||
"version": "0.1.3-alpha.0", | ||
"version": "0.1.3", | ||
"description": "An experimental Prismic model-to-TypeScript-type generator", | ||
@@ -48,3 +48,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@prismicio/client": "^6.4.3", | ||
"@prismicio/client": "^6.7.0", | ||
"@prismicio/custom-types-client": "^0.0.7", | ||
@@ -56,3 +56,3 @@ "common-tags": "^1.8.2", | ||
"meow": "^10.1.3", | ||
"node-fetch": "^3.2.6", | ||
"node-fetch": "^3.2.10", | ||
"pascal-case": "^3.1.2", | ||
@@ -63,12 +63,12 @@ "prettier": "^2.7.1", | ||
"devDependencies": { | ||
"@prismicio/mock": "^0.1.0", | ||
"@prismicio/mock": "^0.1.1", | ||
"@prismicio/types": "^0.2.0", | ||
"@size-limit/preset-small-lib": "^7.0.8", | ||
"@size-limit/preset-small-lib": "^8.0.1", | ||
"@types/common-tags": "^1.8.1", | ||
"@types/prettier": "^2.6.3", | ||
"@typescript-eslint/eslint-plugin": "^5.30.5", | ||
"@typescript-eslint/parser": "^5.30.5", | ||
"ava": "^4.3.0", | ||
"@types/prettier": "^2.7.0", | ||
"@typescript-eslint/eslint-plugin": "^5.35.1", | ||
"@typescript-eslint/parser": "^5.35.1", | ||
"ava": "^4.3.3", | ||
"esbuild-register": "^3.3.3", | ||
"eslint": "^8.19.0", | ||
"eslint": "^8.22.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
@@ -78,7 +78,7 @@ "eslint-plugin-prettier": "^4.2.1", | ||
"nyc": "^15.1.0", | ||
"prettier-plugin-jsdoc": "^0.3.38", | ||
"prettier-plugin-jsdoc": "^0.4.2", | ||
"siroc": "^0.16.0", | ||
"size-limit": "^7.0.8", | ||
"size-limit": "^8.0.1", | ||
"standard-version": "^9.5.0", | ||
"typescript": "^4.7.4" | ||
"typescript": "^4.8.2" | ||
}, | ||
@@ -85,0 +85,0 @@ "peerDependencies": { |
@@ -22,3 +22,2 @@ import Joi from "joi"; | ||
includeCreateClientInterface: Joi.boolean(), | ||
includeContentNamespace: Joi.boolean(), | ||
}), | ||
@@ -25,0 +24,0 @@ |
@@ -114,4 +114,2 @@ import { existsSync, writeFileSync } from "fs"; | ||
: false, | ||
includeContentNamespace: | ||
config.clientIntegration?.includeContentNamespace ?? true, | ||
}, | ||
@@ -125,3 +123,3 @@ }); | ||
console.info( | ||
"[INFO]: prismic-ts-codegen was configured to automatically integrate with `@prismicio/client`, but the integration was not generated because no Custom Type models were found. Automatic integration requires at least one Custom Type model.", | ||
"[INFO]: prismic-ts-codegen was configured to automatically integrate with `@prismicio/client`, but the integration was generated because no Custom Type models were found. Automatic integration requires at least one Custom Type model.", | ||
); | ||
@@ -128,0 +126,0 @@ } |
@@ -12,3 +12,4 @@ /** | ||
* The access token for the Prismic repository. If the repository is private | ||
* and `locales.fetchFromRepository` is `true`, providing a token is required. | ||
* and `locales.fetchFromRepository` is `true`, providing a token is | ||
* required. | ||
*/ | ||
@@ -48,17 +49,2 @@ accessToken?: string; | ||
includeCreateClientInterface?: boolean; | ||
/** | ||
* Determines if a `@prismicio/client` namespace named `Content` containing | ||
* all Document and Slice types should be included in the output. | ||
* | ||
* If set to `true`, a `Content` namespace from `@prismicio/client` will be | ||
* available to import to easily access types for your Prismic repository content. | ||
* | ||
* **Note**: If your project queries content from multiple Prismic | ||
* repositories, set `includeContentNamespace` to `false` and manually | ||
* import the content types instead. | ||
* | ||
* @defaultValue `true` | ||
*/ | ||
includeContentNamespace?: boolean; | ||
}; | ||
@@ -119,3 +105,4 @@ | ||
/** | ||
* A list of file paths to Custom Type and Slice models. Globs are supported. | ||
* A list of file paths to Custom Type and Slice models. Globs are | ||
* supported. | ||
*/ | ||
@@ -122,0 +109,0 @@ files?: string[]; |
@@ -9,3 +9,3 @@ import { Project, ModuleDeclarationKind } from "ts-morph"; | ||
import { FieldConfigs } from "./types"; | ||
import { pascalCase } from "./lib/pascalCase"; | ||
import { buildTypeName } from "./lib/buildTypeName"; | ||
@@ -19,3 +19,2 @@ export type GenerateTypesConfig = { | ||
includeCreateClientInterface?: boolean; | ||
includeContentNamespace?: boolean; | ||
}; | ||
@@ -40,3 +39,3 @@ }; | ||
const simplifyTypeAlias = sourceFile.addTypeAlias({ | ||
sourceFile.addTypeAlias({ | ||
name: "Simplify", | ||
@@ -66,3 +65,3 @@ typeParameters: [ | ||
.map((customTypeModel) => | ||
pascalCase(`${customTypeModel.id} Document`), | ||
buildTypeName(customTypeModel.id, "Document"), | ||
) | ||
@@ -85,6 +84,3 @@ .join(" | "), | ||
if ( | ||
config.clientIntegration?.includeCreateClientInterface || | ||
config.clientIntegration?.includeContentNamespace | ||
) { | ||
if (config.clientIntegration?.includeCreateClientInterface) { | ||
sourceFile.addImportDeclaration({ | ||
@@ -102,51 +98,24 @@ moduleSpecifier: "@prismicio/client", | ||
if (config.clientIntegration.includeCreateClientInterface) { | ||
clientModuleDeclaration.addInterface({ | ||
name: "CreateClient", | ||
callSignatures: [ | ||
{ | ||
parameters: [ | ||
{ | ||
name: "repositoryNameOrEndpoint", | ||
type: "string", | ||
}, | ||
{ | ||
name: "options", | ||
type: "prismic.ClientConfig", | ||
hasQuestionToken: true, | ||
}, | ||
], | ||
returnType: | ||
(config.customTypeModels?.length || 0) > 0 | ||
? "prismic.Client<AllDocumentTypes>" | ||
: "prismic.Client", | ||
}, | ||
], | ||
}); | ||
} | ||
if (config.clientIntegration.includeContentNamespace) { | ||
const contentNamespaceDeclaration = clientModuleDeclaration.addModule({ | ||
name: "Content", | ||
declarationKind: ModuleDeclarationKind.Namespace, | ||
}); | ||
const exportSymbols = sourceFile | ||
.getExportSymbols() | ||
.filter((exportSymbol) => { | ||
// The Simplify utility type should not | ||
// be exported, but it is included in | ||
// `getExportSymbols()`'s result. | ||
return exportSymbol.getName() !== simplifyTypeAlias.getName(); | ||
}); | ||
contentNamespaceDeclaration.addExportDeclaration({ | ||
isTypeOnly: true, | ||
namedExports: exportSymbols.map((exportSymbol) => { | ||
return { | ||
name: exportSymbol.getName(), | ||
}; | ||
}), | ||
}); | ||
} | ||
clientModuleDeclaration.addInterface({ | ||
name: "CreateClient", | ||
callSignatures: [ | ||
{ | ||
parameters: [ | ||
{ | ||
name: "repositoryNameOrEndpoint", | ||
type: "string", | ||
}, | ||
{ | ||
name: "options", | ||
type: "prismic.ClientConfig", | ||
hasQuestionToken: true, | ||
}, | ||
], | ||
returnType: | ||
(config.customTypeModels?.length || 0) > 0 | ||
? "prismic.Client<AllDocumentTypes>" | ||
: "prismic.Client", | ||
}, | ||
], | ||
}); | ||
} | ||
@@ -153,0 +122,0 @@ |
@@ -14,6 +14,7 @@ import type { | ||
import { FieldConfigs, PathElement } from "../types"; | ||
import { buildFieldDocs } from "./buildFieldDocs"; | ||
import { buildSharedSliceInterfaceName } from "./buildSharedSliceInterfaceName"; | ||
import { buildSharedSliceInterfaceNamePart } from "./buildSharedSliceInterfaceNamePart"; | ||
import { buildTypeName } from "./buildTypeName"; | ||
import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath"; | ||
import { pascalCase } from "./pascalCase"; | ||
@@ -366,4 +367,8 @@ type AddInterfacePropertyFromFieldConfig = { | ||
const itemInterface = config.sourceFile.addInterface({ | ||
name: pascalCase( | ||
`${config.path[0].id} Document Data ${config.id} Item`, | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
"Item", | ||
), | ||
@@ -429,3 +434,3 @@ docs: [ | ||
choiceInterfaceNames.push( | ||
buildSharedSliceInterfaceName({ id: choiceId }), | ||
buildSharedSliceInterfaceNamePart({ id: choiceId }), | ||
); | ||
@@ -439,4 +444,10 @@ } else if (choice.type === CustomTypeModelSliceType.Slice) { | ||
primaryInterface = config.sourceFile.addInterface({ | ||
name: pascalCase( | ||
`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice Primary`, | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
choiceId, | ||
"Slice", | ||
"Primary", | ||
), | ||
@@ -497,4 +508,10 @@ docs: [ | ||
itemInterface = config.sourceFile.addInterface({ | ||
name: pascalCase( | ||
`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice Item`, | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
choiceId, | ||
"Slice", | ||
"Item", | ||
), | ||
@@ -552,4 +569,9 @@ docs: [ | ||
const sliceType = config.sourceFile.addTypeAlias({ | ||
name: pascalCase( | ||
`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice`, | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
choiceId, | ||
"Slice", | ||
), | ||
@@ -572,4 +594,8 @@ type: `prismicT.Slice<"${choiceId}", ${ | ||
const slicesType = config.sourceFile.addTypeAlias({ | ||
name: pascalCase( | ||
`${config.path[0].id} Document Data ${config.id} Slice`, | ||
name: buildTypeName( | ||
config.path[0].id, | ||
"Document", | ||
"Data", | ||
config.id, | ||
"Slice", | ||
), | ||
@@ -576,0 +602,0 @@ type: |
@@ -11,3 +11,3 @@ import type { CustomTypeModel, CustomTypeModelField } from "@prismicio/types"; | ||
import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields"; | ||
import { pascalCase } from "./pascalCase"; | ||
import { buildTypeName } from "./buildTypeName"; | ||
@@ -40,3 +40,3 @@ const collectCustomTypeFields = ( | ||
dataInterface = sourceFile.addInterface({ | ||
name: pascalCase(`${model.id} Document Data`), | ||
name: buildTypeName(model.id, "Document", "Data"), | ||
docs: [ | ||
@@ -70,3 +70,3 @@ { | ||
dataInterface = sourceFile.addTypeAlias({ | ||
name: pascalCase(`${model.id} Document Data`), | ||
name: buildTypeName(model.id, "Document", "Data"), | ||
type: `Record<string, never>`, | ||
@@ -82,3 +82,3 @@ docs: [ | ||
return sourceFile.addTypeAlias({ | ||
name: pascalCase(`${model.id} Document`), | ||
name: buildTypeName(model.id, "Document"), | ||
typeParameters: [ | ||
@@ -85,0 +85,0 @@ { |
@@ -8,9 +8,10 @@ import type { SharedSliceModel } from "@prismicio/types"; | ||
import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields"; | ||
import { buildSharedSliceInterfaceName } from "./buildSharedSliceInterfaceName"; | ||
import { pascalCase } from "./pascalCase"; | ||
import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath"; | ||
import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants"; | ||
import { FieldConfigs } from "../types"; | ||
import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields"; | ||
import { buildSharedSliceInterfaceNamePart } from "./buildSharedSliceInterfaceNamePart"; | ||
import { buildTypeName } from "./buildTypeName"; | ||
import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath"; | ||
type AddTypeAliasForSharedSliceConfig = { | ||
@@ -31,6 +32,6 @@ model: SharedSliceModel; | ||
primaryInterface = config.sourceFile.addInterface({ | ||
name: pascalCase( | ||
`${buildSharedSliceInterfaceName({ id: config.model.id })} ${ | ||
variation.id | ||
} Primary`, | ||
name: buildTypeName( | ||
buildSharedSliceInterfaceNamePart({ id: config.model.id }), | ||
variation.id, | ||
"Primary", | ||
), | ||
@@ -79,6 +80,6 @@ docs: [ | ||
itemInterface = config.sourceFile.addInterface({ | ||
name: pascalCase( | ||
`${buildSharedSliceInterfaceName({ id: config.model.id })} ${ | ||
variation.id | ||
} Item`, | ||
name: buildTypeName( | ||
buildSharedSliceInterfaceNamePart({ id: config.model.id }), | ||
variation.id, | ||
"Item", | ||
), | ||
@@ -126,6 +127,5 @@ docs: [ | ||
const variationType = config.sourceFile.addTypeAlias({ | ||
name: pascalCase( | ||
`${buildSharedSliceInterfaceName({ | ||
id: config.model.id, | ||
})} ${variation.id}`, | ||
name: buildTypeName( | ||
buildSharedSliceInterfaceNamePart({ id: config.model.id }), | ||
variation.id, | ||
), | ||
@@ -159,3 +159,3 @@ type: `prismicT.SharedSliceVariation<"${variation.id}", ${ | ||
const variationsType = config.sourceFile.addTypeAlias({ | ||
name: pascalCase(`${config.model.id} Slice Variation`), | ||
name: buildTypeName(config.model.id, "Slice", "Variation"), | ||
type: | ||
@@ -182,6 +182,4 @@ variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never", | ||
return config.sourceFile.addTypeAlias({ | ||
name: pascalCase( | ||
buildSharedSliceInterfaceName({ | ||
id: config.model.id, | ||
}), | ||
name: buildTypeName( | ||
buildSharedSliceInterfaceNamePart({ id: config.model.id }), | ||
), | ||
@@ -188,0 +186,0 @@ type: `prismicT.SharedSlice<"${ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
38
5436
344370
Updated@prismicio/client@^6.7.0
Updatednode-fetch@^3.2.10