Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated linting, changed getCreatedByUserId #11

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

4 changes: 0 additions & 4 deletions .eslintrc

This file was deleted.

8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config = require('eslint-config-service-soft');

module.exports = [
{
ignores: ['showcase/']
},
...config
];
8,374 changes: 4,827 additions & 3,547 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lbx-change-sets",
"version": "1.1.0",
"version": "1.1.1",
"description": "lbx-change-sets",
"keywords": [
"loopback-extension",
Expand Down Expand Up @@ -57,7 +57,7 @@
"@types/lodash": "^4.14.197",
"@types/node": "^20.5.0",
"eslint": "^8.47.0",
"eslint-config-service-soft": "^1.1.0",
"eslint-config-service-soft": "^1.2.2",
"source-map-support": "^0.5.21",
"typescript": "~5.1.6"
}
Expand Down
18 changes: 10 additions & 8 deletions showcase/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"]
}
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": [
"src"
]
}
3 changes: 3 additions & 0 deletions src/__tests__/fixtures/test-db.datasource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { juggler } from '@loopback/repository';

/**
* An in memory database used for testing.
*/
export const testDb: juggler.DataSource = new juggler.DataSource({
name: 'db',
connector: 'memory'
Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/fixtures/test.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ export class TestChangeSetEntityRepository extends CrudChangeSetSoftDeleteReposi
}
}

// eslint-disable-next-line max-len
export function createTestRepositories(): { changeRepository: ChangeRepository, changeSetRepository: ChangeSetRepository, userProfile: UserProfile, testRepository: TestChangeSetEntityRepository } {
const testDb: juggler.DataSource = new juggler.DataSource({
name: `db-${Date.now()}`,
connector: 'memory'
});
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line typescript/no-use-before-define
const changeRepository: ChangeRepository = new ChangeRepository(testDb, (async () => changeSetRepository));
const changeSetRepository: ChangeSetRepository = new ChangeSetRepository(testDb, async () => changeRepository);
const userProfile: UserProfile = { [securityId]: '42' };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable max-len */

import { Count } from '@loopback/repository';
import { expect } from '@loopback/testlab';
import { Change, ChangeSet, ChangeSetType } from '../../models';
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/unit/crud-change-set.repository.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable max-len */

import { expect } from '@loopback/testlab';
import { Change, ChangeSet, ChangeSetType } from '../../models';
import { TestChangeSetEntity } from '../fixtures/test.model';
Expand Down
5 changes: 4 additions & 1 deletion src/keys.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable typescript/no-namespace */
import { BindingKey, CoreBindings } from '@loopback/core';
import { LbxChangeSetsComponent } from './component';

/**
* Binding keys used by this component.
*/
export namespace LbxChangeSetsBindings {
/**
* Binding of the Component.
*/
export const COMPONENT: BindingKey<LbxChangeSetsComponent> = BindingKey.create<LbxChangeSetsComponent>(
`${CoreBindings.COMPONENTS}.LbxChangeSetsComponent`
);
Expand Down
16 changes: 1 addition & 15 deletions src/repositories/crud-change-set-soft-delete.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti

/**
* Delete matching records that have been softly deleted including all of their change sets.
*
* @param where - An additional filter.
* @param options - Additional options, eg. Transaction.
* @returns The amount of deleted entities.
Expand All @@ -50,7 +49,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti

/**
* Find matching records that are deleted.
*
* @param filter - Query filter.
* @param options - Options for the operations.
* @returns A promise of an array of records found.
Expand All @@ -64,21 +62,19 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti

/**
* Find matching records that are not deleted.
*
* @param filter - Query filter.
* @param options - Options for the operations.
* @returns A promise of an array of records found.
*/
async findNonDeleted(filter?: Filter<T>, options?: AnyObject): Promise<T[]> {
filter = new FilterBuilder(filter)
.where({ ...filter?.where, deleted: false } as Where<T>)
.where(whereWithDeleted(false, filter?.where))
.build();
return super.find(filter, options);
}

/**
* Updating matching records that are deleted with attributes from the data object.
*
* @param data - The data to update the entities with.
* @param where - A filter to only update some entities.
* @param options - Additional options, eg. Transaction.
Expand All @@ -91,7 +87,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti

/**
* Updating matching records that are not deleted with attributes from the data object.
*
* @param data - The data to update the entities with.
* @param where - A filter to only update some entities.
* @param options - Additional options, eg. Transaction.
Expand All @@ -107,7 +102,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti
*
* This DOES NOT preserve any changes that happened after the date.
* Any change sets after the given date will be deleted in the end.
*
* @param date - The date to which the rollback should happen.
* @param where - A filter to only rollback some entities.
* @param createChangeSet - Whether or not a change set should be created.
Expand All @@ -132,7 +126,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti
*
* This DOES NOT preserve any changes that happened after the date.
* Any change sets after the given date will be deleted in the end.
*
* @param date - The date to which the rollback should happen.
* @param where - A filter to only rollback some entities.
* @param createChangeSet - Whether or not a change set should be created.
Expand All @@ -156,7 +149,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti
/**
* Softly deletes the given entity and creates a change set.
* This simply sets the deleted flag to true.
*
* @param entity - The entity that should be softly deleted.
* @param options - Additional options, eg. Transaction.
*/
Expand All @@ -174,7 +166,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti
/**
* Softly deletes the entity with the given id and creates a change set.
* This simply sets the deleted flag to true.
*
* @param id - The entity that should be softly deleted.
* @param options - Additional options, eg. Transaction.
*/
Expand All @@ -185,7 +176,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti

/**
* Softly deletes all entities found for the given filter that are not already deleted.
*
* @param where - A where filter.
* @param options - Additional options, eg. Transaction.
* @returns The amount of softly deleted entities.
Expand All @@ -200,7 +190,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti
// eslint-disable-next-line jsdoc/require-returns
/**
* Restores the given entity.
*
* @param entity - The entity to restore.
* @param options - Additional options, eg. Transaction.
*/
Expand All @@ -217,7 +206,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti
// eslint-disable-next-line jsdoc/require-returns
/**
* Restores the entity with the given id.
*
* @param id - The id of the entity to restore.
* @param options - Additional options, eg. Transaction.
*/
Expand All @@ -228,7 +216,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti

/**
* Restores all entities found for the given filter that were deleted.
*
* @param where - A where filter.
* @param options - Additional options, eg. Transaction.
* @returns The amount of restored entities.
Expand All @@ -243,7 +230,6 @@ export class CrudChangeSetSoftDeleteRepository<T extends ChangeSetSoftDeleteEnti

/**
* Adds a delete condition for the given filter.
*
* @param value - Whether to filter for { deleted: true } or { deleted: false }.
* @param where - An existing where clause that should be modified.
* @returns A where condition with either { deleted: true } or { deleted: false }.
Expand Down
24 changes: 3 additions & 21 deletions src/repositories/crud-change-set.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex

/**
* Delete matching records including all of their change sets.
*
* @param where - An additional filter.
* @param options - Additional options, eg. Transaction.
* @returns The amount of deleted entities.
Expand All @@ -86,7 +85,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
/**
* Delete an entity by id.
* Also handles the deletion of all change sets.
*
* @param id - Value for the entity id.
* @param options - Options for the operations.
* @returns A promise that will be resolve if the operation succeeded or will be rejected if the entity was not found.
Expand All @@ -100,7 +98,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
* Resets the changes of a single change set on the given entity to the state before the change set.
* This DOES preserve any changes that happened after the change set.
* The given change set gets deleted afterwards.
*
* @param entity - The entity that should be reset.
* @param changeSet - The change set which changes should be reset.
* @param createChangeSet - Whether or not a change set should be created.
Expand All @@ -117,7 +114,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
options?: AnyObject
): Promise<{entity: T, changedValues: DataObject<T>}> {
if (changeSet.changeSetEntityId !== entity.id) {
// eslint-disable-next-line max-len
throw new HttpErrors.BadRequest('Could not reset the changes from the change set: The changeSet doesn\'t belong to the entity with the given id.');
}
const data: DataObject<T> = {};
Expand Down Expand Up @@ -145,7 +141,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex

/**
* Update an entity by id with property/value pairs in the data object.
*
* @param id - Value for the entity id.
* @param data - Data attributes to be updated.
* @param options - Options for the operations.
Expand All @@ -169,7 +164,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
* Resets the changes of a single change set on the entity with the given id to the state before the oldest change set.
* This DOES preserve any changes that happened after the change set.
* The given change set gets deleted afterwards.
*
* @param id - The id of the entity that should be reset.
* @param changeSet - The change set which changes should be reset.
* @param createChangeSet - Whether or not a change set should be created.
Expand All @@ -194,7 +188,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
* This DOES NOT preserve any changes that happened after the change set.
* The given change set and any change sets after that will be deleted in the end.
* Calls rollbackByDate on the change set date internally.
*
* @param entity - The entity to rollback.
* @param changeSet - The change set that should be rolled back to.
* @param createChangeSet - Whether or not a change set should be created.
Expand All @@ -218,7 +211,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
* This DOES NOT preserve any changes that happened after the change set.
* The given change set and any change sets after that will be deleted in the end.
* Calls rollbackByDate on the change set date internally.
*
* @param id - The id of the entity to rollback.
* @param changeSet - The change set that should be rolled back to.
* @param createChangeSet - Whether or not a change set should be created.
Expand Down Expand Up @@ -246,7 +238,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
* Rolls back all changes on the given entity that have happened since the given date.
* This DOES NOT preserve any changes that happened after the date.
* Any change sets after the given date will be deleted in the end.
*
* @param entity - The entity to rollback.
* @param date - The date to which the rollback should happen.
* @param createChangeSet - Whether or not a change set should be created.
Expand Down Expand Up @@ -289,7 +280,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
* Rolls back all changes on the entity with the given id that have happened since the given date.
* This DOES NOT preserve any changes that happened after the date.
* Any change sets after the given date will be deleted in the end.
*
* @param id - The id of the entity to rollback.
* @param date - The date to which the rollback should happen.
* @param createChangeSet - Whether or not a change set should be created.
Expand All @@ -313,7 +303,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
* Rolls back all changes on the entities found with the given where filter to the state of the given date.
* This DOES NOT preserve any changes that happened after the date.
* Any change sets after the given date will be deleted in the end.
*
* @param date - The date to which the rollback should happen.
* @param where - A filter to only rollback some entities.
* @param createChangeSet - Whether or not a change set should be created.
Expand All @@ -336,7 +325,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex

/**
* Deletes all change sets with their changes for the entity with the given id.
*
* @param id - The id of the entity that should be deleted.
* @param options - Additional options (e.g. Transaction etc.).
*/
Expand All @@ -351,7 +339,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
/**
* Creates a change set for the related entity id.
* Also generates the changes from the given data.
*
* @param entity - The entity for which the change set gets created.
* @param data - The data of the operation eg. The update body.
* @param type - Whether the change set is for create, update or delete.
Expand All @@ -378,7 +365,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex

/**
* Get all changes from the given data that should be added to a new change set.
*
* @param entity - The entity that has been changed.
* @param data - The changed data.
* @param type - The type of the change set to create.
Expand All @@ -403,7 +389,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
/**
* Checks whether or not a value has actually changed.
* This is used to determine whether or not a change should be created or not.
*
* @param previousValue - The value before any changes.
* @param newValue - The value after changes.
* @returns Whether or not the given values are not equal.
Expand All @@ -417,7 +402,6 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex

/**
* Gets the keys of values that should be included in change sets.
*
* @param data - The new values.
* @returns The keys that should be included in the change set.
*/
Expand All @@ -433,12 +417,12 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex

/**
* Tries to get a currently logged in user using @loopback/security.
*
* @returns The id of the currently logged in user or undefined if that didn't work.
*/
protected async getCreatedByUserId(): Promise<string | undefined> {
try {
return (await this.getUserProfile())[securityId];
const userProfile: UserProfile = await this.getUserProfile();
return userProfile[securityId] ?? userProfile['id'];
}
catch (error) {
return undefined;
Expand All @@ -447,13 +431,11 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex

/**
* Creates the changes for the given change set from the given data.
*
* @param keys - The keys to create changes for.
* @param changeSet - The changeset to create the changes for.
* @param data - The data to get the changed values from.
* @param options - Additional options (e.g. Transaction etc.).
*/
// eslint-disable-next-line max-len
protected async createChangesFromData(keys: (keyof T)[], changeSet: ChangeSet, data: DataObject<T>, options?: AnyObject): Promise<void> {
const entity: T = await this.findById(changeSet.changeSetEntityId as ID, undefined, options);
for (const key of keys) {
Expand All @@ -471,8 +453,8 @@ export class CrudChangeSetRepository<T extends ChangeSetEntity, ID, Relations ex
/**
* Sleeps for the given amount of milliseconds.
* You need to await this to work.
*
* @param ms - The amount of milliseconds everything should sleep.
* @returns When the amount of milliseconds have passed.
*/
async function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
Expand Down
Loading