Skip to content

Commit

Permalink
API: Update eslint
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Daniel Arnauer committed Mar 28, 2022
1 parent 1dbba92 commit c780be8
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 49 deletions.
7 changes: 4 additions & 3 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions api/src/service/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class RpcMultichainClient implements MultichainClient {
object: any,
): Promise<TxId> {
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<boolean> {
Expand All @@ -130,7 +130,7 @@ export class RpcMultichainClient implements MultichainClient {
}

public async getInfo(): Promise<any> {
return await this.rpcClient.invoke("getinfo");
return this.rpcClient.invoke("getinfo");
}

public async getValues(
Expand Down
2 changes: 1 addition & 1 deletion api/src/service/RpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export class RpcClient {

public async retrieveItems(streamName: string, start: number, count: number): Promise<Item[]> {
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<Result.Type<StreamItem>[]> {
Expand Down
1 change: 1 addition & 0 deletions api/src/service/cache2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export async function withCache<T>(
await updateCache(ctx, conn);
}

// eslint-disable-next-line @typescript-eslint/return-await
return transaction(cacheInstance);
} finally {
releaseWriteLock(cache);
Expand Down
2 changes: 1 addition & 1 deletion api/src/service/document_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function getDocuments(
conn: ConnToken,
ctx: Ctx,
): Promise<Result.Type<DocumentUploaded.Document[]>> {
return await Cache.withCache(conn, ctx, async (cache) =>
return Cache.withCache(conn, ctx, async (cache) =>
DocumentGet.getAllDocumentInfos(ctx, {
getDocumentsEvents: async () => {
return cache.getDocumentUploadedEvents();
Expand Down
4 changes: 2 additions & 2 deletions api/src/service/global_permission_grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions api/src/service/global_permission_revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
15 changes: 6 additions & 9 deletions api/src/service/global_permissions_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ export async function getGlobalPermissions(
serviceUser: ServiceUser,
): Promise<Result.Type<GlobalPermissions.GlobalPermissions>> {
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();
},
}),
);
}
2 changes: 1 addition & 1 deletion api/src/service/notification_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getNotificationsForUser(
): Promise<Result.Type<Notification.Notification[]>> {
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);
Expand Down
2 changes: 1 addition & 1 deletion api/src/service/public_key_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function getPublicKey(
): Promise<Result.Type<PublicKeyBase64>> {
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(),
}),
Expand Down
2 changes: 1 addition & 1 deletion api/src/service/subproject_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
}),
);
Expand Down
35 changes: 13 additions & 22 deletions api/src/service/user_assignments_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,19 @@ export async function getUserAssignments(
): Promise<Result.Type<UserAssignments.UserAssignments>> {
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,
Expand Down
2 changes: 1 addition & 1 deletion api/src/service/workflowitem_permission_grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion api/src/service/workflowitem_permission_revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
},
),
Expand Down
2 changes: 1 addition & 1 deletion api/src/service/workflowitem_permissions_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
}),
);
Expand Down
2 changes: 1 addition & 1 deletion api/src/system/getVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const multichainVersionMetaData = async (

const storageServiceMetaData = async (
storageServiceClient: StorageServiceClient,
): Promise<Version> => await storageServiceClient.getVersion();
): Promise<Version> => storageServiceClient.getVersion();

export const getVersion = async (
multichainHost: string,
Expand Down

0 comments on commit c780be8

Please sign in to comment.