Skip to content
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

Thoughts on adding some-sort of output customisation #109

Closed
AndrewLeedham opened this issue Mar 4, 2021 · 4 comments
Closed

Thoughts on adding some-sort of output customisation #109

AndrewLeedham opened this issue Mar 4, 2021 · 4 comments

Comments

@AndrewLeedham
Copy link
Contributor

I have been working on adding this package to one of our internal projects, and in order to facilitate the needs there I have forked this package and some modifications: AndrewLeedham@5a4c117. The main change is exporting to the type CMSEntry<ContentTypeId, Fields> instead of Entry<Fields>, as well as exporting a Union of all the types and some other minor tweaks. I am curious on your thoughts on a first class way of supporting something like this, ideas I have been considering:

  1. Put a PR in to the contentful.js repo to add the strongly typed Entry as an option, something like:
export interface Entry<Fields, ContentTypeID extends string = string> {
    sys: Sys<ContentTypeID>;
    fields: Fields;
    toPlainObject(): object;
    update(): Promise<Entry<T, ContentTypeID>>;
}

and extend this repo to export things in the format I am after.

  1. Add a method to the CFDefinitionsBuilder which exposes the ts-morph project, so it can be modified before generating the types.

  2. Integrate https://github.com/webpack/tapable into the package so the rendering can be modified as needed.

@marcolink
Copy link
Collaborator

  1. Put a PR in to the contentful.js repo to add the strongly typed Entry as an option, something like:

I'm not sure how urgent these changes are for you, but if you can wait, this might be something for you!

  1. Add a method to the CFDefinitionsBuilder which exposes the ts-morph project, so it can be modified before generating the types.

I'd be fine with exposing the ts-morph project 👍

3.Integrate https://github.com/webpack/tapable into the package so the rendering can be modified as needed.

I think tapable is a great and powerfull tool. But it comes with a complex API that we would add on top.

A general question, are you using it as CLI, or do you interact with CFDefinitionsBuilder builder directly?
I could imagine that we can register different types of render callbacks, to transform the input in different situations and for different prop renderers. Would that help to solve your problem?

@AndrewLeedham
Copy link
Contributor Author

I'm not sure how urgent these changes are for you

Not an immediate rush, I have things working with my custom fork. But it is not an ideal solution, as updates to the main repo will be difficult to back-port.

this might be something for you!

This seems to be specific to queries against field data right? What I am wanting is sys.contentType.sys.id to be strongly typed as part of Entry, e.g. instead of string it is a literal type of the relevant ID.

A general question, are you using it as CLI, or do you interact with CFDefinitionsBuilder builder directly?

Directly interacting with CFDefinitionsBuilder.

I could imagine that we can register different types of render callbacks, to transform the input in different situations and for different prop renderers. Would that help to solve your problem?

That is essentially what I was getting at with tapable, callbacks would work just as well 👍

@marcolink
Copy link
Collaborator

@AndrewLeedham I created a new PR #123 addressing this issue.

Would your case be covered with this? (still WIP though)

@marcolink
Copy link
Collaborator

version 2.0.0 which features custom rendering just got released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants