xddq / ts2typebox

Creating TypeBox code from Typescript types
MIT License
43 stars 3 forks source link

Parsing classes with imports #25

Closed d9k closed 6 months ago

d9k commented 8 months ago

Seems ts2typebox can't parse class and doesn't process imports

import { Column, DataType, Default, Model, Table } from 'sequelize-typescript';

@Table
export class CarBrand extends Model<CarBrand> {
  @Column
  name: string;

  @Default(true)
  @Column(DataType.BOOLEAN)
  isCertified: boolean;

  @Column
  imgUrl: string;

  @Column
  orderNo: number;

  @Column
  carsCount: number;
}

(example from sequelize-typescript-migration-lts/README)

> ts2typebox -i carBrand.ts --output-stdout
Unhandled: ImportDeclaration import { Column, DataType, Default, Model, Table } from 'sequelize-typescript';
/**
 * ATTENTION. This code was AUTO GENERATED by ts2typebox. While I don't know
 * your use case, there is a high chance that direct changes to this file get
 * lost. Consider making changes to the underlying Typescript code you use to
 * generate this file instead. The default file is called "types.ts", perhaps
 * have a look there! :]
 */

It would be very nice to be able to create skeleton of TypeBox validators from database models code.

xddq commented 8 months ago

hey @d9k !

Sounds like a handy use case. However, this package is nowadays just a simple wrapper around https://github.com/sinclairzx81/typebox-codegen . I think you should mention the issue there. Once it is fixed updating the dependencies here is no problem.

Will probably close this in a couple of weeks in case there is no response.

d9k commented 8 months ago

@xddq, thanks for the answer, I opened an issue at typebox-codegen too.

xddq commented 6 months ago

closing, for more info see the mentioned issue at typebox-codegen