You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To increase type-safety and minimize errors when querying for content items by their codename.
Adding an option to output some, or all, content item codenames would allow us to further constrain the codenames of content items by letting us specify that content item codenames can't be just any string, but instead one of many very specific strings.
Proposed solution
One solution may be to add a property to the existing IExportProjectSettings interface so that users can choose to generate types for their content item codenames, like so:
constconfig: IGenerateModelsConfig={sdkType: 'delivery',projectId: '<project id>',apiKey: '<api key>',exportProjectSettings: {/** set to true to generate a `contentItems.ts` file alongside the existing `contentTypes.ts` file. */exportContentItemCodenames: true,/** or perhaps a function to allow the user to specify only certain content types / items ? */exportContentItemCodenames: (content_type,content_item)=>true,},
Then, given a project with a content type called Hyperlink, having 3 content items whose codenames are: contact_us, warranty_and_repair, and returns, the output file could look something like:
If a content type has more than a certain number of content items, the proposed solution may not be ideal; as it could lead to very large file(s) that are difficult to navigate and may slow the performance of the IDE.
It might be good to allow additional configuration in the IGenerateModelsConfig to adjust the limit on the number of generated codenames.
The text was updated successfully, but these errors were encountered:
I had similar thoughts in the past and while it would definitely be beneficial in some scenarios, it didn't make it into our backlog yet ;) It generally doesn't make sense to generate codenames for all content items so we would have to introduce new config for both type & number of content items.
I will likely implement this at some point, but I can't give any estimates at the moment.
I think this needs to be closed. The generator currently exports a contentTypes const which supplies this functionality.
This was more about generating codenames of content items which is a valid point imho. My only concern is that it could be a very large file if you had say 100k content items in your project :)
Motivation
To increase type-safety and minimize errors when querying for content items by their codename.
Adding an option to output some, or all, content item codenames would allow us to further constrain the codenames of content items by letting us specify that content item codenames can't be just any string, but instead one of many very specific strings.
Proposed solution
One solution may be to add a property to the existing
IExportProjectSettings
interface so that users can choose to generate types for their content item codenames, like so:Then, given a project with a content type called
Hyperlink
, having 3 content items whose codenames are:contact_us
,warranty_and_repair
, andreturns
, the output file could look something like:We could then use these types to constrain a function like this:
Additional considerations
If a content type has more than a certain number of content items, the proposed solution may not be ideal; as it could lead to very large file(s) that are difficult to navigate and may slow the performance of the IDE.
It might be good to allow additional configuration in the
IGenerateModelsConfig
to adjust the limit on the number of generated codenames.The text was updated successfully, but these errors were encountered: