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

KyselifyEntity skips json attribute #219

Open
terion-name opened this issue Jan 14, 2025 · 1 comment
Open

KyselifyEntity skips json attribute #219

terion-name opened this issue Jan 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@terion-name
Copy link

model:

import {
    BaseEntity,
    Column,
    CreateDateColumn,
    Entity,
    Index,
    ManyToOne,
    PrimaryGeneratedColumn,
    UpdateDateColumn
} from 'typeorm';
import type {Insertable, Selectable, Updateable} from 'kysely';
import {AccountEntity} from '../account';
import {InboxEntity} from "../inbox";
import type {Generated, NonAttribute} from 'kysely-typeorm';

export interface ChannelApiTable {
    id: Generated<number>;
    account_id: number;
    identifier: string;
    hmac_token: string;
    hmac_mandatory: boolean;
    webhook_url: string | null;
    additional_attributes: Record<string, any> | null;
    created_at: Date;
    updated_at: Date;
}

export type ChannelApi = Selectable<ChannelApiTable>;
export type NewChannelApi = Insertable<ChannelApiTable>;
export type ChannelApiUpdate = Updateable<ChannelApiTable>;

@Entity('channel_api')
@Index(['hmac_token'], {unique: true})
@Index(['identifier'], {unique: true})
export class ChannelApiEntity extends BaseEntity {
    @PrimaryGeneratedColumn()
    id: Generated<number>;

    @ManyToOne(() => AccountEntity)
    account: NonAttribute<AccountEntity>;

    @Column()
    account_id: number;

    @Column()
    identifier: string;

    @Column()
    hmac_token: string;

    @Column({default: false})
    hmac_mandatory: boolean;

    @Column({nullable: true})
    webhook_url: string;

    @Column({type: 'jsonb', nullable: true})
    additional_attributes: Record<string, any>;

    @ManyToOne(() => InboxEntity)
    inbox: NonAttribute<InboxEntity>;

    @CreateDateColumn()
    created_at: Date;

    @UpdateDateColumn()
    updated_at: Date;
}

If in database definition I use manuallly created interface:

interface Database {
    // ...
    channel_api: Entities.ChannelApiTable;
}

Then everything works fine and types are ok. But If I use:

interface Database {
    // ...
    channel_api: KyselifyEntity<Entities.ChannelApiEntity>;
}

Then channel_api's type has no prop additional_attributes

@igalklebanov igalklebanov added the bug Something isn't working label Jan 14, 2025
@igalklebanov
Copy link
Member

Hey 👋

Thanks for raising this! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants