SoftwareBrothers / adminjs-mikroorm

MIT License
3 stars 6 forks source link

Unhandled type warnigns #8

Open yackinn opened 2 years ago

yackinn commented 2 years ago

Describe the bug We can see a lot of unhandled type warnigns in the terminal output on load of any resource in the admin panel.

Installed libraries and their versions "@adminjs/express": "^4.1.0" "@adminjs/mikroorm": "^1.1.0" "@adminjs/nestjs": "^4.0.0" "@mikro-orm/core": "^5.0.5"

To Reproduce Steps to reproduce the behavior:

  1. Login
  2. Click on resource

Expected behavior No unhandled type warning.

Screenshots That's the console output.

Unhandled type: string
Unhandled type: string
Unhandled type: Date
Unhandled type: Date
Unhandled type: Date
Unhandled type: Date
Unhandled type: string
Unhandled type: string
Unhandled type: object
Unhandled type: object
Unhandled type: string
Unhandled type: string
Unhandled type: string
Unhandled type: string
Unhandled type: string
Unhandled type: string
Unhandled type: Date
Unhandled type: Date
Unhandled type: Date

AdminJSOptions with schema

@Entity({ customRepository: () => UserRepository })
export class User extends OmputBaseEntity {
  [EntityRepositoryType]?: UserRepository;

  @Property({ unique: true, columnType: 'varchar(255)' })
  @IsEmail()
  email: string;

  @Property({ hidden: true, columnType: 'varchar(255)' })
  password: ComparablePassword;

  @Property({ nullable: true })
  age?: number;

}

Desktop (please complete the following information if relevant):

Additional context Add any other context about the problem here. That's our module setup using Nestjs.

AdminModule.createAdminAsync({
      inject: [MikroORM],
      useFactory: async (orm: MikroORM) => {
        return {
          adminJsOptions: {
            rootPath: '/admin',
            resources: [
              {
                resource: {
                  model: User,
                  orm,
                },
              }
            ]
          }
        };
      }
    }),
dziraf commented 2 years ago

Your model doesn't seem to have Date or object data types, where do they come from?

yackinn commented 2 years ago
@Entity({ abstract: true })
export abstract class OmputBaseEntity {
  @PrimaryKey()
  id: string = v4();

  @Property({ hidden: true })
  createdAt: Date = new Date();

  @Property({ hidden: true, nullable: true, onUpdate: () => new Date() })
  updatedAt?: Date;

@dziraf That's what the base entity looks like. Are the types incorrect for adminjs?

dziraf commented 2 years ago

Transferring to adminjs-mikroorm repository. The types might be correct but they need to be mapped for a specific ORM adapter. I'm not sure why MikroORM uses Javascript types for columns now while it used database types previously e. g. timestamptz so I'll have to take a look.

You should be able to set a specific type in your resource options for each property in the meantime

rubiin commented 2 years ago

Similar to ArrayType . For fixing date type, I can do a pr

    let type: PropertyType = DATA_TYPES[this.column.columnTypes[0].toLowerCase()]
      || DATA_TYPES[this.column.type.toLowerCase()];

This should fix for date. I just checked locally

dziraf commented 2 years ago

@rubiin Go ahead. Unfortuantely I don't have any active project with MikroORM at the moment to investigate those issues. We do have a dev repo: https://github.com/SoftwareBrothers/adminjs-dev but it would still require a lot of work to reproduce various ORM-specific types. I personally prefer if ORMs provide database types since it's easier to map across packages

vincentwinkel commented 2 years ago

What about this issue? I also have plenty of errors like that (only with Date).

adminjs 5.10.0
@adminjs/mikroorm 1.1.1

[EDIT] The solution proposed by @rubiin works like a charm in my case.

vincentwinkel commented 1 year ago

Still no PR?