Skip to content

Commit 225da52

Browse files
committed
feat(core): upgrade to latest lb4 and manage new attributes in transaction repo
BREAKING CHANGE: New columns added for deleted_on and delete_by attributes
1 parent 13290a6 commit 225da52

8 files changed

+8356
-1319
lines changed

.cz-config.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module.exports = {
2+
types: [
3+
{value: 'feat', name: 'feat: A new feature'},
4+
{value: 'fix', name: 'fix: A bug fix'},
5+
{value: 'docs', name: 'docs: Documentation only changes'},
6+
{
7+
value: 'style',
8+
name:
9+
'style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)',
10+
},
11+
{
12+
value: 'refactor',
13+
name:
14+
'refactor: A code change that neither fixes a bug nor adds a feature',
15+
},
16+
{
17+
value: 'perf',
18+
name: 'perf: A code change that improves performance',
19+
},
20+
{value: 'test', name: 'test: Adding missing tests'},
21+
{
22+
value: 'chore',
23+
name:
24+
'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation',
25+
},
26+
{value: 'revert', name: 'revert: Reverting a commit'},
27+
{value: 'WIP', name: 'WIP: Work in progress'},
28+
],
29+
30+
scopes: [
31+
{name: 'chore'},
32+
{name: 'ci-cd'},
33+
{name: 'repository'},
34+
{name: 'entity'},
35+
],
36+
37+
appendBranchNameToCommitMessage: false,
38+
allowTicketNumber: false,
39+
isTicketNumberRequired: false,
40+
ticketNumberPrefix: 'Fixes - ',
41+
42+
// override the messages, defaults are as follows
43+
messages: {
44+
type: "Select the type of change that you're committing:",
45+
scope: 'Denote the SCOPE of this change:',
46+
// used if allowCustomScopes is true
47+
customScope: 'Mention the SCOPE of this change:',
48+
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
49+
body:
50+
'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
51+
breaking: 'List any BREAKING CHANGES (optional):\n',
52+
footer:
53+
'List any ISSUES CLOSED by this change (optional). E.g.: #31, #34:\n',
54+
confirmCommit: 'Are you sure you want to proceed with the commit above?',
55+
},
56+
57+
allowCustomScopes: true,
58+
allowBreakingChanges: ['feat', 'fix'],
59+
60+
// limit subject length
61+
subjectLimit: 100,
62+
breaklineChar: '|', // It is supported for fields body and footer.
63+
footerPrefix: '',
64+
askForBreakingChangeFirst: true, // default is false
65+
};

README.md

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,38 @@
1919
npm install loopback4-soft-delete
2020
```
2121

22+
**NOTE** - With latest version 3.0.0, you also need to install [loopback4-authentication](https://github.com/sourcefuse/loopback4-authentication) for using deleted_by feature added.
23+
24+
```sh
25+
npm install loopback4-soft-delete
26+
```
27+
2228
## Quick Starter
2329

2430
For a quick starter guide, you can refer to our [loopback 4 starter](https://github.com/sourcefuse/loopback4-starter) application which utilizes this package for soft-deletes in a multi-tenant application.
2531

32+
## Transaction support
33+
34+
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.
35+
2636
## Usage
2737

28-
Right now, this extension exports two abstract classes which are actually helping with soft delete operations.
38+
Right now, this extension exports three abstract classes which are actually helping with soft delete operations.
2939

3040
- **SoftDeleteEntity** -
3141
An abstract base class for all models which require soft delete feature.
32-
This class is a wrapper over Entity class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository) adding a new attribute 'deleted' (boolean) to the model class.
33-
Same column is needed to be there in DB within that table.
42+
This class is a wrapper over Entity class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository) adding three attributes to the model class for handling soft-delete, namely, deleted, deletedOn, deletedBy.
43+
The column names needed to be there in DB within that table are - 'deleted', 'deleted_on', 'deleted_by'.
3444
If you are using auto-migration of loopback 4, then, you may not need to do anything specific to add this column.
35-
If not, then please add this column to the DB table.
45+
If not, then please add these columns to the DB table.
3646
- **SoftCrudRepository** -
3747
An abstract base class for all repositories which require soft delete feature.
3848
This class is going to be the one which handles soft delete operations and ensures soft deleted entries are not returned in responses at all.
3949
This class is a wrapper over DefaultCrudRepository class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository).
50+
- **DefaultTransactionSoftCrudRepository** -
51+
An abstract base class for all repositories which require soft delete feature with transaction support.
52+
This class is going to be the one which handles soft delete operations and ensures soft deleted entries are not returned in responses at all.
53+
This class is a wrapper over DefaultTransactionalRepository class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository).
4054

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

@@ -63,18 +77,49 @@ export class User extends SoftDeleteEntity {
6377
2. Extend repositories with SoftCrudRepository class replacing DefaultCrudRepository. For example,
6478

6579
```ts
66-
import {inject} from '@loopback/core';
80+
import {Getter, inject} from '@loopback/core';
6781
import {SoftCrudRepository} from 'loopback4-soft-delete';
82+
import {AuthenticationBindings, IAuthUser} from 'loopback4-authentication';
6883

6984
import {PgdbDataSource} from '../datasources';
70-
import {User} from '../models';
85+
import {User, UserRelations} from '../models';
7186

7287
export class UserRepository extends SoftCrudRepository<
7388
User,
74-
typeof User.prototype.id
89+
typeof User.prototype.id,
90+
UserRelations
91+
> {
92+
constructor(
93+
@inject('datasources.pgdb') dataSource: PgdbDataSource,
94+
@inject.getter(AuthenticationBindings.CURRENT_USER, {optional: true})
95+
protected readonly getCurrentUser: Getter<IAuthUser | undefined>,
96+
) {
97+
super(User, dataSource, getCurrentUser);
98+
}
99+
}
100+
```
101+
102+
3. For transaction support, extend repositories with DefaultTransactionSoftCrudRepository class replacing DefaultTransactionalRepository. For example,
103+
104+
```ts
105+
import {Getter, inject} from '@loopback/core';
106+
import {SoftCrudRepository} from 'loopback4-soft-delete';
107+
import {AuthenticationBindings, IAuthUser} from 'loopback4-authentication';
108+
109+
import {PgdbDataSource} from '../datasources';
110+
import {User, UserRelations} from '../models';
111+
112+
export class UserRepository extends DefaultTransactionSoftCrudRepository<
113+
User,
114+
typeof User.prototype.id,
115+
UserRelations
75116
> {
76-
constructor(@inject('datasources.pgdb') dataSource: PgdbDataSource) {
77-
super(User, dataSource);
117+
constructor(
118+
@inject('datasources.pgdb') dataSource: PgdbDataSource,
119+
@inject.getter(AuthenticationBindings.CURRENT_USER, {optional: true})
120+
protected readonly getCurrentUser: Getter<IAuthUser | undefined>,
121+
) {
122+
super(User, dataSource, getCurrentUser);
78123
}
79124
}
80125
```

commitlint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
rules: {
4+
'header-max-length': [2, 'always', 100],
5+
'body-leading-blank': [2, 'always'],
6+
'footer-leading-blank': [0, 'always'],
7+
},
8+
};

0 commit comments

Comments
 (0)