Skip to content

Conversation

@mikaelkaron
Copy link
Contributor

@mikaelkaron mikaelkaron commented Nov 4, 2025

This change modifies the type generation system to produce TypeScript source files (.ts) with embedded JSON schemas instead of declaration files (.d.ts). This enables runtime access to schema information while maintaining full type safety.

Changes:

  • Generate .ts files instead of .d.ts files for all entity types
  • Export JSON schema as const alongside TypeScript interfaces
  • Use type-only imports with explicit .ts extensions
  • Update all test fixtures to support ES modules
  • Add comprehensive tests for JSON schema validation
  • Convert fixture plugin files from CommonJS to ES modules

Benefits:

  • Runtime access to JSON schemas for validation and documentation
  • Better tree-shaking with type-only imports
  • Improved TypeScript compatibility with explicit file extensions
  • Maintains backward compatibility with existing type definitions

This change modifies the type generation system to produce TypeScript
source files (.ts) with embedded JSON schemas instead of declaration
files (.d.ts). This enables runtime access to schema information while
maintaining full type safety.

Changes:
- Generate .ts files instead of .d.ts files for all entity types
- Export JSON schema as const alongside TypeScript interfaces
- Use type-only imports with explicit .ts extensions
- Update all test fixtures to support ES modules
- Add comprehensive tests for JSON schema validation
- Convert fixture plugin files from CommonJS to ES modules

Benefits:
- Runtime access to JSON schemas for validation and documentation
- Better tree-shaking with type-only imports
- Improved TypeScript compatibility with explicit file extensions
- Maintains backward compatibility with existing type definitions

Signed-off-by: Mikael Karon <[email protected]>
@mikaelkaron mikaelkaron changed the title feat: generate .ts files with JSON schema exports instead of .d.ts files feat: generate .ts files with JSON schema exports instead of .d.ts files Nov 4, 2025
@mcollina
Copy link
Member

mcollina commented Nov 4, 2025

As it is, this is a semver-major change. Can you make it not breaking? One option would be it be keep the old behavior and add the new one behind a flag. Maybe there is another way, so that there is both a .d.ts and a .ts? I'm unsure.

@mikaelkaron
Copy link
Contributor Author

I think it could be possible to output the interface in a .d.ts and the schema in .ts?

@mcollina
Copy link
Member

mcollina commented Nov 4, 2025

Then it'd be ok if it's not breaking.

@mikaelkaron
Copy link
Contributor Author

having a file.ts and a file.d.ts in the same folder is creating some issue. What about putting just the schemas in /schemas?

@mcollina
Copy link
Member

mcollina commented Nov 4, 2025

If it doesn't break existing users, no problem.

@mikaelkaron mikaelkaron force-pushed the mikaelkaron-db-generate-jsonschema-as-const branch 4 times, most recently from fee4fab to dcbd763 Compare November 4, 2025 16:42
@mikaelkaron
Copy link
Contributor Author

I'm not sure what's best here. Now I'm generating this into the types folder with a -schema suffix. If we want this in a new folder we should add config.schemas?.dir and this MR gets bigger. However I can see a reason why you'd like all generated schemas in a new folder... WDYT?

@mikaelkaron mikaelkaron force-pushed the mikaelkaron-db-generate-jsonschema-as-const branch from dcbd763 to 7b1e6f7 Compare November 4, 2025 16:47
@mikaelkaron mikaelkaron changed the title feat: generate .ts files with JSON schema exports instead of .d.ts files feat: generate JSON schema exports Nov 4, 2025
@mikaelkaron
Copy link
Contributor Author

Know what, it will probably make more sense to have a schemas folder, and since I don't want to break this in the future I'll refactor to include that.

@mikaelkaron mikaelkaron marked this pull request as draft November 7, 2025 10:52
@mcollina
Copy link
Member

mcollina commented Nov 8, 2025

Yes!

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.

2 participants