2.0.0 • Published 3 years ago

@kittgen/nestjs-typeorm-history v2.0.0

Weekly downloads
36
License
MIT
Repository
github
Last release
3 years ago

Kittgen TypeORM History

TypeORM based module for keeping a histories of an entities.

Check the main page for Kittgen for further information.

Feature Overview

  • Keep a history of your entities
  • Customization of history properties
  • Lightweight

Usage

Installation

npm i @kittgen/nestjs-typeorm-history

Declare your history entity

import {
  HistoryFor,
  HistoryActionType,
  HistoryActionColumn,
  MappedColumn,
  SnapshotColumn,
} from '@kittgen/nestjs-typeorm-history';

@Entity()
@HistoryFor(User) 
export class UserHistory {

  @SnapshotColumn({ type: 'jsonb' })
  payload: User

  @HistoryActionColumn()
  action: HistoryActionType

  // optional, map payload properties as column
  @MappedColumn<User>((user: User) => user.firstName, { name: 'nickname' })
  nickname: string

  // any other properties
  // ...
}

Properties decorated with @SnapshotColumn and @HistoryActionColumn are required. HistoryActionType supports three possible values: CREATED, UPDATED and DELETED.

The MappedColumn decorator can be used to map properties of an entity directly to a column. You don't need to use jsonb, alternatively you can also use embedded entities:

@Column(() => User, { prefix: 'user' })
payload: User;

Dont't forget to make your history entities known to TypeORM by adding them to the entities property.

// other TypeORM config properties
entities: [User, UserHistory],
// ...

Register the module

In the imports array of your module, add the TypeOrmHistoryModule. You have to provide the TypeORM connection.

TypeOrmHistoryModule.registerAsync({
  inject: [Connection],
  useFactory: (connection: Connection) => {
    return {
      connection,
    };
  },
})

Local Development

Local Library Development

Important Commands

# start in watcher mode
npm start

# builds to the 'dist' folder
npm run build

# runs the tests
npm test

Commits

We use conventional commits for nice commit messages and automated versioning/changelog.

This packages uses TSDX.

Credits

This package is based on https://github.com/anchan828/typeorm-helpers

License

Kittgen is licensed under MIT. See LICENSE.

Authors

Kittgen is developed by Otto von Wesendonk and Edgar Müller.

0.0.0-8d8c2ee

3 years ago

0.0.0-611613c

3 years ago

0.0.0-744a1de

3 years ago

0.0.0-9800f8f

3 years ago

0.0.0-8dd3613

3 years ago

0.0.0-855a009

3 years ago

0.0.0-fb3dde4

3 years ago

0.0.0-0b49dd4

3 years ago

0.0.0-7f3031b

3 years ago

0.0.0-3da0a2f

3 years ago

0.0.0-fbe3b4d

3 years ago

0.0.0-780c3dc

3 years ago

0.0.0-b71ba8d

3 years ago

0.0.0-589d695

3 years ago

0.0.0-ab340bb

3 years ago

0.0.0-a247ac9

3 years ago

0.0.0-3e15093

3 years ago

0.0.0-0e1fe14

3 years ago

0.0.0-3cc7124

3 years ago

0.0.0-775e640

4 years ago

0.0.0-ddcdd12

4 years ago

0.0.0-f76970e

4 years ago

0.0.0-4a5520e

4 years ago

0.0.0-777772c

4 years ago

0.0.0-de55f93

4 years ago

2.0.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago