2.0.0 • Published 2 years ago

@kittgen/nestjs-typeorm-history v2.0.0

Weekly downloads
36
License
MIT
Repository
github
Last release
2 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

2 years ago

0.0.0-611613c

2 years ago

0.0.0-744a1de

2 years ago

0.0.0-9800f8f

2 years ago

0.0.0-8dd3613

2 years ago

0.0.0-855a009

2 years ago

0.0.0-fb3dde4

2 years ago

0.0.0-0b49dd4

2 years ago

0.0.0-7f3031b

2 years ago

0.0.0-3da0a2f

2 years ago

0.0.0-fbe3b4d

2 years ago

0.0.0-780c3dc

2 years ago

0.0.0-b71ba8d

2 years ago

0.0.0-589d695

2 years ago

0.0.0-ab340bb

2 years ago

0.0.0-a247ac9

2 years ago

0.0.0-3e15093

2 years ago

0.0.0-0e1fe14

2 years ago

0.0.0-3cc7124

2 years ago

0.0.0-775e640

2 years ago

0.0.0-ddcdd12

2 years ago

0.0.0-f76970e

2 years ago

0.0.0-4a5520e

2 years ago

0.0.0-777772c

2 years ago

0.0.0-de55f93

2 years ago

2.0.0

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago