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

Multiple Exports #63

Open
nkooman-bzs opened this issue Nov 1, 2024 · 3 comments
Open

Multiple Exports #63

nkooman-bzs opened this issue Nov 1, 2024 · 3 comments
Assignees
Labels

Comments

@nkooman-bzs
Copy link

Brief bug description

When using v8.0.0-8 of the model generator, it is possible to create conflicting type names.

Repro steps

  1. Create a content type and content type snippet with the same name
  2. Generate delivery models
  3. See that those names will conflict in the barrel file exporting all delivery types.

Expected behavior

Export all snippets/types/taxonomies/etc under a unique name.
e.g. ContentTypes.Banner and ContentTypeSnippets.Banner

Test environment

  • Version 8.0.0-8

Screenshots

Error in barrel file:
image

Conflicting types:
image

@Enngage Enngage self-assigned this Feb 7, 2025
@Enngage
Copy link
Member

Enngage commented Feb 7, 2025

Hi @nkooman-bzs,

sorry the late reply. I've missed this issue completely :)

You're right that this conflict may happen, though I'm not sure if we want to enforce any prefix/suffix to prevent that from happening. You can quite easily modify the names of the objects in Delivery models in the way you mentioned by using the nameResolvers option:

await generateDeliveryModelsAsync({
        addTimestamp: false,
        environmentId: x,
        apiKey: y,
        moduleFileExtension: 'js',
        nameResolvers: {
            contentType: (item) => `ContentType_${resolveCase(item.name, 'pascalCase')}`,
            snippet: (item) => `ContentTypeSnippet_${resolveCase(item.name, 'pascalCase')}`,
            taxonomy: (item) => `Taxonomy_${resolveCase(item.name, 'pascalCase')}`
        }
    });

I think this should be enough for most people :) We could expose prefix/suffix in a config for the CLI usage, but that seems rather unnecessary.

Are you able to solve your issue with the above? ;)

@nkooman-bzs
Copy link
Author

This would fix the issue yes. However, I'm looking to not prefix the actual type but rather namespace the types themselves.
I think a potential solution would be to have a toggle to choose whether the barrel files generate export * from '...' vs export * as ContentTypes from '...'

@Enngage
Copy link
Member

Enngage commented Feb 18, 2025

That makes sense although it would mean you can import the same type either with/without namespace.

I'm keeping it open as we might add an option for using namespaces in future, but we don't plan it for the next major release.

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

No branches or pull requests

2 participants