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

loopback4-meta-info

v1.4.1

Published

A loopback-next extension for meta data include soft delete feature

Downloads

4

Readme

loopback4-soft-delete

LoopBack

Node version Dependencies Status Loopback Core Version Loopback Build Version npm vulnerabilities

Latest version License Downloads Total Downloads

Install

npm install loopback4-meta-info

NOTE - It only support loopback4.

npm install loopback4-meta-info

Quick Starter

For a quick starter guide, you can refer to our loopback 4 starter application which utilizes this package for soft-deletes in a multi-tenant application.

Transaction support

With version 3.0.0, transaction repository support has been added. In place of SoftCrudRepository, extend your repository with DefaultTransactionSoftCrudRepository. For further usage guidelines, refer below.

Usage

Right now, this extension exports three abstract classes which are actually helping with soft delete operations.

  • MetaEntity - An abstract base class for all models which require soft delete feature. This class is a wrapper over Entity class from @loopback/repository adding three attributes to the model class for handling soft-delete, namely, deleted, deletedOn, deletedBy, and some meta createdBy, updatedBy, createdOn, updatedOn The column names needed to be there in DB within that table are - 'created_on', 'created_by', 'updated_on', 'updated_by','deleted', 'deleted_on', 'deleted_by'. If you are using auto-migration of loopback 4, then, you may not need to do anything specific to add this column. If not, then please add these columns to the DB table.
  • SoftMetaCrudRepository - An abstract base class for all repositories which require soft delete feature. This class is going to be the one which handles soft delete operations and ensures soft deleted entries are not returned in responses, However if there is a need to query soft deleted entries as well,there is an options to achieve that and you can use findAll() in place of find() , findOneIncludeSoftDelete() in place of findOne() and findByIdIncludeSoftDelete() in place of findById(), these will give you the responses including soft deleted entries. This class is a wrapper over DefaultCrudRepository class from @loopback/repository.

In order to use this extension in your LB4 application, please follow below steps.

  1. Extend models with SoftDeleteEntity class replacing Entity. For example,
import {model, property} from '@loopback/repository';
import {SoftMetaCrudRepository} from 'loopback4-meta-info';

@model({
  name: 'users',
})
export class User extends SoftMetaCrudRepository {
  @property({
    type: 'number',
    id: true,
  })
  id?: number;

  // .... More properties
}
  1. Extend repositories with SoftMetaCrudRepository class replacing DefaultCrudRepository. For example,
import {Getter, inject} from '@loopback/core';
import {SoftCrudRepository} from 'loopback4-meta-info';
import {SecurityBindings, securityId, UserProfile} from '@loopback/security';

import {PgdbDataSource} from '../datasources';
import {User, UserRelations} from '../models';

export class UserRepository extends SoftMetaCrudRepository<
  User,
  typeof User.prototype.id,
  UserRelations
> {
  constructor(
    @inject('datasources.pgdb') dataSource: PgdbDataSource,
    @inject.getter(SecurityBindings.USER, {optional: true})
    protected readonly getCurrentUser: Getter< UserProfile | undefined>,
  ) {
    super(User, dataSource, getCurrentUser);
  }
}

License

MIT