1.0.3 • Published 2 months ago

@ifjkt/typeorm-revisions v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@ifjkt/typeorm-revisions

npm NPM

Description

Provides a Revision History Subscriber for TypeORM Entities

Tested: MySQL 8, MariaDB and Postgres

Installation

$ npm i --save typeorm @ifjkt/typeorm-revisions

Quick Start

1. Create your own Entity

@Entity()
class MyModel extends BaseEntity {
  @PrimaryGeneratedColumn()
  public id!: number;
  
  @Column()
  public name!: string;
  
  @Column()
  public email!: string;
}

2. Create an Entity for your Audit table

@Entity()
class MyModelHistory extends MyModel implements HistoryEntityInterface {
  @Column({
    name: 'record_id',
    type: 'int',
  })
  recordId: number;

  @Column({
    name: 'revision_timestamp',
  })
  revisionTime: Date;

  @Column({
    name: 'revision_type',
  })
  revisionType: RevisionActionType;
}

3. Annotate your Audit table with the @AuditTable decorator and specify your audit fields

@Entity()
@AuditTable({
  recordIdProperty: 'recordId',
  revisionTypeProperty: 'revisionType',
  revisionTimestampProperty: 'revisionTime',
})
class MyModelHistory extends MyModel implements HistoryEntityInterface {
  @Column({
    name: 'record_id',
    type: 'int',
  })
  recordId: number;

  @Column({
    name: 'revision_timestamp',
  })
  revisionTime: Date;

  @Column({
    name: 'revision_type',
  })
  revisionType: RevisionActionType;
}

4. Create an Entity Subscriber for your entity to process Audit events

@EventSubscriber()
class MyModelHistorySubscriber extends HistorySubscriber<MyModel, MyModelHistory> {
  public entity = MyModel;
  public historyEntity = MyModelHistory;
}

License

MIT

Forked from https://github.com/ephillipe/typeorm-revisions

1.0.3

2 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago