I have a Vite library using Zod. I want to parse configurations and my folder structure is similiar to the configuration object structure. index.ts
files always export all files in their own directory and everything from their subdirectories e.g. export * from './subDir';
so the root file exports "the whole lib".
The following setup shows a single configuration branch
.
├── src
│ ├── api
│ │ ├── dataSources
| | | ├── dataSource
| | | | ├── following
| | | | | ├── computed
| | | | | | ├── followingComputedDataSourceConfigurationSchema.ts ( extends dataSourceConfigurationSchema )
| │ │ | | | └── index.ts
| | | | | ├── entity
| | | | | | ├── followingEntityDataSourceConfigurationSchema.ts ( extends leadingDataSourceConfigurationSchema )
| │ │ | | | └── index.ts
| │ │ | | └── index.ts
| | | | ├── leading
| | | | | ├── leadingDataSourceConfigurationSchema.ts ( extends dataSourceConfigurationSchema )
| │ │ | | └── index.ts
| | | | ├── dataSourceConfigurationSchema.ts ( base schema )
│ │ | | └── index.ts
| | | ├── dataSourcesConfigurationSchema.ts ( expects leading and array of followings )
│ │ | └── index.ts
| | ├── apiConfigurationSchema.ts ( expects dataSources )
│ │ └── index.ts
│ └── index.ts
└── test
└── basic.test.ts
The problem is that I think I'm running into circular dependency imports. I checked the schema with a test using Vitest
it('fails.', () => {
expect(() => apiConfigurationSchema.parse({})).not.toThrow();
});
By doing so I get the following error
TypeError: Cannot read properties of undefined (reading '_parse')
I don't want to merge the schemas into a single big file because subdirectories might also contain custom validation functions for this specific section.
Do you have any ideas how to fix this setup?