Remove useless async from functions

This commit is contained in:
Jesse Wierzbinski 2023-11-19 16:42:40 -10:00
parent 50fc4dbcf4
commit b9efd093a6
24 changed files with 28 additions and 42 deletions

View file

@ -15,6 +15,6 @@ module.exports = {
rules: {
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
},
};

View file

@ -30,10 +30,7 @@ export const getFromToken = async (
* Converts this application to an API application.
* @returns The API application representation of this application.
*/
export const applicationToAPI = async (
app: Application
// eslint-disable-next-line @typescript-eslint/require-await
): Promise<APIApplication> => {
export const applicationToAPI = (app: Application): APIApplication => {
return {
name: app.name,
website: app.website,

View file

@ -54,8 +54,7 @@ export const addEmojiIfNotExists = async (emoji: LysandEmoji) => {
* Converts the emoji to an APIEmoji object.
* @returns The APIEmoji object.
*/
// eslint-disable-next-line @typescript-eslint/require-await
export const emojiToAPI = async (emoji: Emoji): Promise<APIEmoji> => {
export const emojiToAPI = (emoji: Emoji): APIEmoji => {
return {
shortcode: emoji.shortcode,
static_url: emoji.url, // TODO: Add static version

View file

@ -41,10 +41,7 @@ export const createNewRelationship = async (
* Converts the relationship to an API-friendly format.
* @returns The API-friendly relationship.
*/
export const relationshipToAPI = async (
rel: Relationship
// eslint-disable-next-line @typescript-eslint/require-await
): Promise<APIRelationship> => {
export const relationshipToAPI = (rel: Relationship): APIRelationship => {
return {
blocked_by: rel.blockedBy,
blocking: rel.blocking,

View file

@ -450,16 +450,14 @@ export const statusToAPI = async (
id: status.id,
in_reply_to_id: status.inReplyToPostId || null,
in_reply_to_account_id: status.inReplyToPost?.authorId || null,
account: await userToAPI(status.author),
account: userToAPI(status.author),
created_at: new Date(status.createdAt).toISOString(),
application: status.application
? await applicationToAPI(status.application)
? applicationToAPI(status.application)
: null,
card: null,
content: status.content,
emojis: await Promise.all(
status.emojis.map(emoji => emojiToAPI(emoji))
),
emojis: status.emojis.map(emoji => emojiToAPI(emoji)),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
favourited: !!(status.likes ?? []).find(
like => like.likerId === user?.id

View file

@ -343,11 +343,10 @@ export const generateUserKeys = async () => {
};
};
// eslint-disable-next-line @typescript-eslint/require-await
export const userToAPI = async (
export const userToAPI = (
user: UserWithRelations,
isOwnAccount = false
): Promise<APIAccount> => {
): APIAccount => {
const config = getConfig();
return {
@ -364,7 +363,7 @@ export const userToAPI = async (
.length,
following_count: user.relationships.filter(r => r.following).length,
statuses_count: user._count.statuses,
emojis: await Promise.all(user.emojis.map(emoji => emojiToAPI(emoji))),
emojis: user.emojis.map(emoji => emojiToAPI(emoji)),
// TODO: Add fields
fields: [],
bot: user.isBot,

View file

@ -83,5 +83,5 @@ export default async (
},
});
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -102,5 +102,5 @@ export default async (
},
});
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -44,5 +44,5 @@ export default async (
if (!foundUser) return errorResponse("User not found", 404);
return jsonResponse(await userToAPI(foundUser, user?.id === foundUser.id));
return jsonResponse(userToAPI(foundUser, user?.id === foundUser.id));
};

View file

@ -96,5 +96,5 @@ export default async (
// TODO: Implement duration
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -86,5 +86,5 @@ export default async (
},
});
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -83,5 +83,5 @@ export default async (
},
});
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -97,5 +97,5 @@ export default async (
});
}
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -83,5 +83,5 @@ export default async (
},
});
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -83,5 +83,5 @@ export default async (
},
});
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -85,5 +85,5 @@ export default async (
},
});
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -83,5 +83,5 @@ export default async (
},
});
return jsonResponse(await relationshipToAPI(relationship));
return jsonResponse(relationshipToAPI(relationship));
};

View file

@ -63,9 +63,5 @@ export default async (req: Request): Promise<Response> => {
(a, b) => ids.indexOf(a.subjectId) - ids.indexOf(b.subjectId)
);
return jsonResponse(
await Promise.all(
relationships.map(async r => await relationshipToAPI(r))
)
);
return jsonResponse(relationships.map(r => relationshipToAPI(r)));
};

View file

@ -242,5 +242,5 @@ export default async (req: Request): Promise<Response> => {
},
});
return jsonResponse(await userToAPI(user));
return jsonResponse(userToAPI(user));
};

View file

@ -22,7 +22,7 @@ export default async (req: Request): Promise<Response> => {
if (!user) return errorResponse("Unauthorized", 401);
return jsonResponse({
...(await userToAPI(user, true)),
...userToAPI(user, true),
// TODO: Add role support
role: {
id: 0,

View file

@ -39,5 +39,5 @@ export default async (req: Request): Promise<Response> => {
include: userRelations,
});
return jsonResponse(await userToAPI(newUser));
return jsonResponse(userToAPI(newUser));
};

View file

@ -39,5 +39,5 @@ export default async (req: Request): Promise<Response> => {
include: userRelations,
});
return jsonResponse(await userToAPI(newUser));
return jsonResponse(userToAPI(newUser));
};

View file

@ -105,7 +105,7 @@ export default async (
}
return jsonResponse(
await Promise.all(objects.map(async user => userToAPI(user))),
objects.map(user => userToAPI(user)),
200,
{
Link: linkHeader.join(", "),

View file

@ -106,7 +106,7 @@ export default async (
}
return jsonResponse(
await Promise.all(objects.map(async user => userToAPI(user))),
objects.map(user => userToAPI(user)),
200,
{
Link: linkHeader.join(", "),