-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: integrate generated types into @prismicio/client
automatically
#14
Conversation
@prismicio/client
CreateClient interface@prismicio/client
CreateClient interface
@prismicio/client
CreateClient interface@prismicio/client
CreateClient interface
@prismicio/client
CreateClient interface@prismicio/client
automatically
size-limit report 📦
|
…on with global `string` integration
Codecov Report
@@ Coverage Diff @@
## main #14 +/- ##
==========================================
- Coverage 95.49% 95.31% -0.19%
==========================================
Files 20 20
Lines 311 320 +9
Branches 64 67 +3
==========================================
+ Hits 297 305 +8
Misses 2 2
- Partials 12 13 +1
Continue to review full report at Codecov.
|
@prismicio/client
automatically@prismicio/client
automatically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, however, I'm not a fan of having to manually disable the CreateClient
interface. It makes sense to have this option for prismic-ts-codegen
, but when looking at Slice Machine having to support it on a per-adapter-basis will be painful and confusing for users.
Would something like this allow override without disabling the functionality? (wild idea)
declare module "@prismicio/client" {
interface CreateClient {
<TDocuments extends prismicT.PrismicDocument = AllDocumentTypes>(
repositoryNameOrEndpoint: string,
options?: prismic.ClientConfig
): prismic.Client<TDocuments>;
}
}
@lihbr I just tested the current implementation and confirmed that document types are overridable per client via the type parameter. const client1 = prismic.createClient("foo") // Automatic generated types
const client2 = prismic.createClient<AllDocumentTypes1>("bar") // Uses AllDocumentTypes1
const client3 = prismic.createClient<AllDocumentTypes2>("baz") // Uses AllDocumentTypes2 This means consumers don't need to disable the Side note: I made the I think we're good to merge. 👍 |
Types of changes
Description
This PR adds the ability to generate a
@prismicio/client
module augmentation that automatically types a Prismic client. It does this by generating aCreateClient
interface that uses the Prismic repository's generated document types. For more details onCreateClient
, see the "Client type augmentation" section of prismicio/prismic-client#238.The generated
CreateClient
interface overrides all calls to@prismicio/client
'screateClient()
function to be typed with the generatedAllDocumentTypes
type. The output looks like this:Projects using multiple Prismic repositories: If a project queries content from multiple Prismic repositories, the automatic integration should be disabled and
AllDocumentTypes
should be passed tocreateClient()
manually.See the below sections for details on new CLI and library behaviors.
prismic-ts-codegen
CLIWhen using the
prismic-ts-codegen
CLI, this new functionality is enabled by default. The integration can be disabled using theclientIntegration.includeCreateClientInterface
.generateTypes()
APIWhen using the
generateTypes()
API, this new functionality is disabled by default. To enable it, passclientIntegration.includeCreateClientInterface: true
as an option.Checklist: