npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lbx-change-sets

v1.1.2

Published

lbx-change-sets

Downloads

12

Readme

lbx-change-sets

This package helps you to track changes made on your entities automatically using a base repository class to extend from:

  • Automatically generate change sets containing information about WHO, WHEN and WHAT was changed on your entities.
  • Be able to rollback a single or multiple entities to the state of a specified change set or date. (The reset gets also tracked)
  • Be able to "softly" delete entities, which have a delete flag on them.
  • Be able to restore a single or multiple "softly" deleted entities.

Usage

Register the component

The minimum required code changes to use the library to its full extend is simply registering it in the application.ts constructor:

import { ChangeRepository, ChangeSetRepository, LbxChangeSetsComponent } from 'lbx-change-sets';

//...
this.component(LbxChangeSetsComponent);
this.repository(ChangeRepository);
this.repository(ChangeSetRepository);
//...

Change Set

Create an entity that should use change sets

All entities that should make use of the change set functionality need to extend ChangeSetEntity:

import { ChangeSetEntity } from 'lbx-change-sets';
// ...
@model()
export class TestChangeSetEntity extends ChangeSetEntity {
    @property({
        type: 'string',
        required: true
    })
    firstName: string;

    @property({
        type: 'string',
        required: true
    })
    lastName: string;

    constructor(data?: Partial<TestChangeSetEntity>) {
        super(data);
    }
}

Create the repository for that entity

The repository needs to extend CrudChangeSetRepository:

import { CrudChangeSetRepository } from 'lbx-change-sets';
// ...
export class TestChangeSetEntityRepository extends CrudChangeSetRepository<
    TestChangeSetEntity,
    typeof TestChangeSetEntity.prototype.id,
    TestRelations
> {
    constructor(
        @inject('datasources.db')
        dataSource: DbDataSource,
        @repository.getter('ChangeSetRepository')
        changeSetRepositoryGetter: Getter<ChangeSetRepository>,
        @repository(ChangeRepository)
        changeRepository: ChangeRepository,
        @repository(ChangeSetRepository)
        changeSetRepository: ChangeSetRepository,
        @inject.getter(SecurityBindings.USER)
        getUserProfile: Getter<UserProfile>
    ) {
        super(TestChangeSetEntity, dataSource, changeSetRepositoryGetter, changeRepository, changeSetRepository, getUserProfile);
    }
}

Enjoy!

That's it. Whenever you user the default actions of the repository like "create" or "updateById" a change set will be generated automatically.

If you use transactions they will be used to guarantee that change sets are only generated when the base operation worked.

INFO: If you have complex relations that should be tracked or rolled back you will probably need to override the corresponding methods.

Get change sets

All existing change sets are available via the normal @hasMany property "changeSets" on your entity and repository. You can however also get them via the ChangeSetRepository and ChangeRepository.

Rollback

To rollback you can simply call the methods rollback[ToDate | ToChangeSet...] on your repository.

Exclude properties from change set creation

If you have some properties that you don't want to have in your change sets, you can exlude them by overriding the keysToExcludeFromChangeSets array in your repository. By default this already doesn't track the entities id.

Change Set & Soft Delete

If you want to use the soft delete features aswell, you can basically follow the same steps above but extend from ChangeSetSoftDeleteEntity and CrudChangeSetSoftDeleteRepository.

They provide the same functionality mentionend above and some more:

soft delete

To softly delete a single or multiple entities you can use the respoitories softDelete[ById | All...] methods.

restore

To softly delete a single or multiple entities you can use the respoitories restore[ById | All...] methods.

convenience methods

Because most times you probably want to only return or update entities that aren't deleted, the repository provides some convenience methods for that:

  • findNonDeleted: find, but limited to not deleted entities
  • findDeleted: find, but limited to deleted entities
  • updateAllNonDeleted: updateAll, but limited to not deleted entities
  • updateAllDeleted: updateAll, but limited to deleted entities
  • rollbackAllNonDeletedToDate: rollbackAllToDate, but limited to not deleted entities
  • rollbackAllDeletedToDate: rollbackAllToDate, but limited to deleted entities
  • deleteAllDeleted: deleteAll, but limited to deleted entities