From c780be8a59240b24a7c2f68823003d400a01c437 Mon Sep 17 00:00:00 2001 From: Daniel Arnauer Date: Mon, 28 Mar 2022 12:45:40 +0200 Subject: [PATCH] API: Update eslint Resolve eslint rule @typescript-eslint/return-await If there is no try-catch block, an async function can return the Promise directly instead of awaiting it. See https://stackoverflow.com/questions/38708550/difference-between-return-await-promise-and-return-promise for further explanation. --- api/package.json | 7 ++-- api/src/service/Client.ts | 4 +-- api/src/service/RpcClient.ts | 2 +- api/src/service/cache2.ts | 1 + api/src/service/document_get.ts | 2 +- api/src/service/global_permission_grant.ts | 4 +-- api/src/service/global_permission_revoke.ts | 4 +-- api/src/service/global_permissions_get.ts | 15 ++++---- api/src/service/notification_list.ts | 2 +- api/src/service/public_key_get.ts | 2 +- api/src/service/subproject_list.ts | 2 +- api/src/service/user_assignments_get.ts | 35 +++++++------------ .../service/workflowitem_permission_grant.ts | 2 +- .../service/workflowitem_permission_revoke.ts | 2 +- .../service/workflowitem_permissions_list.ts | 2 +- api/src/system/getVersion.ts | 2 +- 16 files changed, 39 insertions(+), 49 deletions(-) diff --git a/api/package.json b/api/package.json index 369b128f7a..0593175a68 100644 --- a/api/package.json +++ b/api/package.json @@ -81,6 +81,7 @@ "fastify-swagger": "^4.12.4", "joi": "^14.3.1", "jsonwebtoken": "^8.5.0", + "lodash": "^4.17.21", "lodash.isequal": "^4.5.0", "module-alias": "^2.2.2", "raw-body": "^2.3.3", @@ -100,8 +101,8 @@ "@types/pino": "^6.3.11", "@types/uuid": "^3.4.3", "@types/verror": "^1.10.3", - "@typescript-eslint/eslint-plugin": "4.28.5", - "@typescript-eslint/parser": "4.28.5", + "@typescript-eslint/eslint-plugin": "5.16.0", + "@typescript-eslint/parser": "5.16.0", "chai": "^4.1.2", "colors": "^1.4.0", "coveralls": "^3.0.3", @@ -123,7 +124,7 @@ "ts-node-dev": "^1.1.8", "tsconfig-paths": "^3.11.0", "tslint": "*", - "typescript": "^4.0.2" + "typescript": "^4.6.2" }, "_moduleAliases": { "lib": "dist/lib" diff --git a/api/src/service/Client.ts b/api/src/service/Client.ts index 0ef5a0f2d4..eadf201b02 100644 --- a/api/src/service/Client.ts +++ b/api/src/service/Client.ts @@ -121,7 +121,7 @@ export class RpcMultichainClient implements MultichainClient { object: any, ): Promise { const data = objectToHex(object); - return await this.rpcClient.invokePublish(streamId, key, data); + return this.rpcClient.invokePublish(streamId, key, data); } public async isValidAddress(address: string): Promise { @@ -130,7 +130,7 @@ export class RpcMultichainClient implements MultichainClient { } public async getInfo(): Promise { - return await this.rpcClient.invoke("getinfo"); + return this.rpcClient.invoke("getinfo"); } public async getValues( diff --git a/api/src/service/RpcClient.ts b/api/src/service/RpcClient.ts index 67d3c4575c..14f24e420b 100644 --- a/api/src/service/RpcClient.ts +++ b/api/src/service/RpcClient.ts @@ -334,7 +334,7 @@ export class RpcClient { public async retrieveItems(streamName: string, start: number, count: number): Promise { const verbose: boolean = false; - return await this.invoke("liststreamitems", streamName, verbose, count, start); + return this.invoke("liststreamitems", streamName, verbose, count, start); } private async convertToReadableItems(items: StreamItem[]): Promise[]> { diff --git a/api/src/service/cache2.ts b/api/src/service/cache2.ts index 1f3e47aaac..2fe6168e74 100644 --- a/api/src/service/cache2.ts +++ b/api/src/service/cache2.ts @@ -346,6 +346,7 @@ export async function withCache( await updateCache(ctx, conn); } + // eslint-disable-next-line @typescript-eslint/return-await return transaction(cacheInstance); } finally { releaseWriteLock(cache); diff --git a/api/src/service/document_get.ts b/api/src/service/document_get.ts index 94c184661f..9e6859ab0b 100644 --- a/api/src/service/document_get.ts +++ b/api/src/service/document_get.ts @@ -9,7 +9,7 @@ export async function getDocuments( conn: ConnToken, ctx: Ctx, ): Promise> { - return await Cache.withCache(conn, ctx, async (cache) => + return Cache.withCache(conn, ctx, async (cache) => DocumentGet.getAllDocumentInfos(ctx, { getDocumentsEvents: async () => { return cache.getDocumentUploadedEvents(); diff --git a/api/src/service/global_permission_grant.ts b/api/src/service/global_permission_grant.ts index bb672a6951..141c77bf6a 100644 --- a/api/src/service/global_permission_grant.ts +++ b/api/src/service/global_permission_grant.ts @@ -29,8 +29,8 @@ export async function grantGlobalPermission( permission, { getGlobalPermissions: async () => getGlobalPermissions(conn, ctx, serviceUser), - isGroup: async (granteeId) => await GroupQuery.groupExists(conn, ctx, serviceUser, granteeId), - getUser: async (userId) => await UserQuery.getUser(conn, ctx, serviceUser, userId), + isGroup: async (granteeId) => GroupQuery.groupExists(conn, ctx, serviceUser, granteeId), + getUser: async (userId) => UserQuery.getUser(conn, ctx, serviceUser, userId), }, ); if (Result.isErr(result)) return new VError(result, "failed to grant global permission"); diff --git a/api/src/service/global_permission_revoke.ts b/api/src/service/global_permission_revoke.ts index 7167676f60..12e98f53b5 100644 --- a/api/src/service/global_permission_revoke.ts +++ b/api/src/service/global_permission_revoke.ts @@ -29,8 +29,8 @@ export async function revokeGlobalPermission( permission, { getGlobalPermissions: async () => getGlobalPermissions(conn, ctx, serviceUser), - isGroup: async (revokeeId) => await GroupQuery.groupExists(conn, ctx, serviceUser, revokeeId), - getUser: async (userId) => await UserQuery.getUser(conn, ctx, serviceUser, userId), + isGroup: async (revokeeId) => GroupQuery.groupExists(conn, ctx, serviceUser, revokeeId), + getUser: async (userId) => UserQuery.getUser(conn, ctx, serviceUser, userId), }, ); if (Result.isErr(result)) return new VError(result, "failed to revoke global permission"); diff --git a/api/src/service/global_permissions_get.ts b/api/src/service/global_permissions_get.ts index 92003db5e6..64e218d961 100644 --- a/api/src/service/global_permissions_get.ts +++ b/api/src/service/global_permissions_get.ts @@ -13,14 +13,11 @@ export async function getGlobalPermissions( serviceUser: ServiceUser, ): Promise> { logger.debug("Getting Global Permissions"); - return Cache.withCache( - conn, - ctx, - async (cache) => - await GlobalPermissionsGet.getGlobalPermissions(ctx, serviceUser, { - getGlobalPermissionsEvents: async () => { - return cache.getGlobalEvents(); - }, - }), + return Cache.withCache(conn, ctx, async (cache) => + GlobalPermissionsGet.getGlobalPermissions(ctx, serviceUser, { + getGlobalPermissionsEvents: async () => { + return cache.getGlobalEvents(); + }, + }), ); } diff --git a/api/src/service/notification_list.ts b/api/src/service/notification_list.ts index a8ce71dbf2..f122ff9a0e 100644 --- a/api/src/service/notification_list.ts +++ b/api/src/service/notification_list.ts @@ -15,7 +15,7 @@ export async function getNotificationsForUser( ): Promise> { logger.debug({ user }, "Getting notifications for user"); - return await Cache.withCache(conn, ctx, (cache) => + return Cache.withCache(conn, ctx, (cache) => NotificationList.getUserNotifications(ctx, user, { getUserNotificationEvents: async (userId: UserRecord.Id) => { return cache.getNotificationEvents(userId); diff --git a/api/src/service/public_key_get.ts b/api/src/service/public_key_get.ts index 53faeebf80..dbced41d76 100644 --- a/api/src/service/public_key_get.ts +++ b/api/src/service/public_key_get.ts @@ -13,7 +13,7 @@ export async function getPublicKey( ): Promise> { logger.debug("Getting public key"); - return await Cache.withCache(conn, ctx, async (cache) => + return Cache.withCache(conn, ctx, async (cache) => PublicKeyGet.getPublicKey(ctx, organization, { getPublicKeysEvents: async () => cache.getPublicKeyEvents(), }), diff --git a/api/src/service/subproject_list.ts b/api/src/service/subproject_list.ts index 1404ef47cd..4d6c150f52 100644 --- a/api/src/service/subproject_list.ts +++ b/api/src/service/subproject_list.ts @@ -20,7 +20,7 @@ export async function listSubprojects( const visibleSubprojectsResult = await Cache.withCache(conn, ctx, async (cache) => SubprojectList.getAllVisible(ctx, serviceUser, { getAllSubprojects: async () => { - return await cache.getSubprojects(projectId); + return cache.getSubprojects(projectId); }, }), ); diff --git a/api/src/service/user_assignments_get.ts b/api/src/service/user_assignments_get.ts index 91ac3fe85c..5bb0c153cc 100644 --- a/api/src/service/user_assignments_get.ts +++ b/api/src/service/user_assignments_get.ts @@ -18,28 +18,19 @@ export async function getUserAssignments( ): Promise> { logger.debug({ req: requestData }, "Get user assignments"); - const userAssignmentResult = await Cache.withCache( - conn, - ctx, - async (cache) => - await UserAssignmentsGet.getUserAssignments( - ctx, - requestData.userId, - issuer, - issuerOrganization, - { - getAllProjects: async () => { - return cache.getProjects(); - }, - getSubprojects: async (pId) => { - return cache.getSubprojects(pId); - }, - getWorkflowitems: async (pId, spId) => { - return cache.getWorkflowitems(pId, spId); - }, - getUser: () => UserQuery.getUser(conn, ctx, issuer, requestData.userId), - }, - ), + const userAssignmentResult = await Cache.withCache(conn, ctx, async (cache) => + UserAssignmentsGet.getUserAssignments(ctx, requestData.userId, issuer, issuerOrganization, { + getAllProjects: async () => { + return cache.getProjects(); + }, + getSubprojects: async (pId) => { + return cache.getSubprojects(pId); + }, + getWorkflowitems: async (pId, spId) => { + return cache.getWorkflowitems(pId, spId); + }, + getUser: () => UserQuery.getUser(conn, ctx, issuer, requestData.userId), + }), ); return Result.mapErr( userAssignmentResult, diff --git a/api/src/service/workflowitem_permission_grant.ts b/api/src/service/workflowitem_permission_grant.ts index 82aca0bfe1..72baaa2d65 100644 --- a/api/src/service/workflowitem_permission_grant.ts +++ b/api/src/service/workflowitem_permission_grant.ts @@ -49,7 +49,7 @@ export async function grantWorkflowitemPermission( intent, { getWorkflowitem: async (pId, spId, wId) => { - return await cache.getWorkflowitem(pId, spId, wId); + return cache.getWorkflowitem(pId, spId, wId); }, userExists: async (user) => UserQuery.userExists(conn, ctx, serviceUser, user), getUser: async (user) => UserQuery.getUser(conn, ctx, serviceUser, user), diff --git a/api/src/service/workflowitem_permission_revoke.ts b/api/src/service/workflowitem_permission_revoke.ts index 9d243c4ae4..4e041abd90 100644 --- a/api/src/service/workflowitem_permission_revoke.ts +++ b/api/src/service/workflowitem_permission_revoke.ts @@ -41,7 +41,7 @@ export async function revokeWorkflowitemPermission( intent, { getWorkflowitem: async (pId, spId, wId) => { - return await cache.getWorkflowitem(pId, spId, wId); + return cache.getWorkflowitem(pId, spId, wId); }, }, ), diff --git a/api/src/service/workflowitem_permissions_list.ts b/api/src/service/workflowitem_permissions_list.ts index 32d2876cb6..3249081e58 100644 --- a/api/src/service/workflowitem_permissions_list.ts +++ b/api/src/service/workflowitem_permissions_list.ts @@ -26,7 +26,7 @@ export async function listWorkflowitemPermissions( const permissionsResult = await Cache.withCache(conn, ctx, async (cache) => WorkflowitemPermissionsList.getAll(ctx, serviceUser, projectId, subprojectId, workflowitemId, { getWorkflowitem: async (pId, spId, wId) => { - return await cache.getWorkflowitem(pId, spId, wId); + return cache.getWorkflowitem(pId, spId, wId); }, }), ); diff --git a/api/src/system/getVersion.ts b/api/src/system/getVersion.ts index 6a691eca88..7931fabc4a 100644 --- a/api/src/system/getVersion.ts +++ b/api/src/system/getVersion.ts @@ -42,7 +42,7 @@ const multichainVersionMetaData = async ( const storageServiceMetaData = async ( storageServiceClient: StorageServiceClient, -): Promise => await storageServiceClient.getVersion(); +): Promise => storageServiceClient.getVersion(); export const getVersion = async ( multichainHost: string,