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 file support #164

Closed
wants to merge 17 commits into from
Closed

Conversation

harlos0517
Copy link

@harlos0517 harlos0517 commented Oct 23, 2023

Why

This is a proposal for providing multiple file support to ts-to-zod

Related issue: #71

Based on PR #118

The refactoring took place in the generate function, most notable changes:

  • the function becomes async because it has been delegated the responsibility of reading the type files
  • internally it uses a recursive method ( iterateToZod ) up to the transformation of the zodSchemas
  • changes elsewhere are just adjustments to the changes that affect generate

TODO

  • non-relative module imports
  • verify the following dependency scenarios
    • manage default exports
    • deep nesting, cross reference between modules
    • test scenarios with types, interfaces, enums
    • check to see if we can make generate simpler
    • relay exports, export * from 'asdf'
    • check modules aliasing extensively

This is still WIP so any feedback and ideas are welcome!

fracalo and others added 15 commits March 2, 2023 18:39
At the moment generate will run only skipping validation,
also importing of types from absolute module is still not working.
fix: Avoid crating schemas for non imported types
fix: Default imports/aliasing
* upstream/main:
  fix: support numeric literal keys (fabien0102#120)
  chore: release 3.0.0 (fabien0102#119)
  feat: Generate inferred types (fabien0102#85)
  feat!: Support circular dependencies with loops of length > 1 (fabien0102#114)
  build: add missing dependency on @oclif/errors (fabien0102#115)
@harlos0517 harlos0517 mentioned this pull request Oct 23, 2023
@harlos0517
Copy link
Author

harlos0517 commented Oct 25, 2023

For now, every test is currently passing.

But there is one case that hasn't been covered by the test.

// color.ts
export enum Secondary { Green, Orange, Violet }
// index.ts
import * as UtilsColor from "./colors/index";
type Enemy = {
  color: UtilsColor.Secondary
}

// index.zod.ts (Desired)
// Generated by ts-to-zod
import { z } from "zod";
import * as UtilsColor from "./colors/index";

export const utilsColorSecondarySchema = z.nativeEnum(UtilsColor.Secondary);

const enemySchema = z.object({
   color: utilsColorSecondarySchema,
});

// index.zod.ts (Current behvaior)
// Generated by ts-to-zod
import { z } from "zod";
import { utilsColorSecondary } from "./colors/index";

export const utilsColorSecondarySchema = z.nativeEnum(Secondary);

const enemySchema = z.object({
   color: utilsColorSecondarySchema,
});

@schiller-manuel
Copy link
Collaborator

schiller-manuel commented Nov 28, 2023

Can you please rebase? Will review then.

@schiller-manuel
Copy link
Collaborator

closing now that we merged #148 and #135

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

Successfully merging this pull request may close these issues.

None yet

3 participants