diff --git a/api/oauth/sso/:issuer/callback/index.ts b/api/oauth/sso/:issuer/callback/index.ts index 1bad8535..dd7d891f 100644 --- a/api/oauth/sso/:issuer/callback/index.ts +++ b/api/oauth/sso/:issuer/callback/index.ts @@ -113,7 +113,7 @@ export default apiRoute((app) => (error, message, app) => returnError( context, - manager.processOAuth2Error(app), + OAuthManager.processOAuth2Error(app), error, message, ), diff --git a/classes/media/preprocessors/image-conversion.ts b/classes/media/preprocessors/image-conversion.ts index cfb1bceb..a4f94b8f 100644 --- a/classes/media/preprocessors/image-conversion.ts +++ b/classes/media/preprocessors/image-conversion.ts @@ -104,10 +104,9 @@ export class ImageConversionPreprocessor implements MediaPreprocessor { fileName: string, newExtension: string, ): string { - return this.extractFilenameFromPath(fileName).replace( - /\.[^/.]+$/, - `.${newExtension}`, - ); + return ImageConversionPreprocessor.extractFilenameFromPath( + fileName, + ).replace(/\.[^/.]+$/, `.${newExtension}`); } /** @@ -115,7 +114,7 @@ export class ImageConversionPreprocessor implements MediaPreprocessor { * @param path - The path to extract the filename from. * @returns The extracted filename. */ - private extractFilenameFromPath(path: string): string { + private static extractFilenameFromPath(path: string): string { const pathParts = path.split(/(? { ]); // biome-ignore lint/complexity/useLiteralKeys: Private method - const directories = await pluginLoader["getDirectories"]("/some/path"); + const directories = await PluginLoader["getDirectories"]("/some/path"); expect(directories).toEqual(["dir1", "dir2"]); }); @@ -65,7 +65,7 @@ describe("PluginLoader", () => { const manifestFile = // biome-ignore lint/complexity/useLiteralKeys: Private method - await pluginLoader["findManifestFile"]("/some/path"); + await PluginLoader["findManifestFile"]("/some/path"); expect(manifestFile).toBe("manifest.json"); }); @@ -73,7 +73,7 @@ describe("PluginLoader", () => { mockReaddir.mockResolvedValue(["index.ts", "otherfile.txt"]); // biome-ignore lint/complexity/useLiteralKeys: Private method - const hasEntrypoint = await pluginLoader["hasEntrypoint"]("/some/path"); + const hasEntrypoint = await PluginLoader["hasEntrypoint"]("/some/path"); expect(hasEntrypoint).toBe(true); }); diff --git a/classes/plugin/loader.ts b/classes/plugin/loader.ts index 928bffb8..e03edbf4 100644 --- a/classes/plugin/loader.ts +++ b/classes/plugin/loader.ts @@ -18,7 +18,7 @@ export class PluginLoader { * @param {string} dir - The directory to search. * @returns {Promise} - An array of directory names. */ - private async getDirectories(dir: string): Promise { + private static async getDirectories(dir: string): Promise { const files = await readdir(dir, { withFileTypes: true }); return files.filter((f) => f.isDirectory()).map((f) => f.name); } @@ -28,7 +28,9 @@ export class PluginLoader { * @param {string} dir - The directory to search. * @returns {Promise} - The manifest file name if found, otherwise undefined. */ - private async findManifestFile(dir: string): Promise { + private static async findManifestFile( + dir: string, + ): Promise { const files = await readdir(dir); return files.find((f) => f.match(/^manifest\.(json|json5|jsonc)$/)); } @@ -38,7 +40,7 @@ export class PluginLoader { * @param {string} dir - The directory to search. * @returns {Promise} - True if the entrypoint file is found, otherwise false. */ - private async hasEntrypoint(dir: string): Promise { + private static async hasEntrypoint(dir: string): Promise { const files = await readdir(dir); return files.includes("index.ts") || files.includes("index.js"); } @@ -79,16 +81,16 @@ export class PluginLoader { * @returns {Promise} - An array of plugin directories. */ public async findPlugins(dir: string): Promise { - const directories = await this.getDirectories(dir); + const directories = await PluginLoader.getDirectories(dir); const plugins: string[] = []; for (const directory of directories) { - const manifestFile = await this.findManifestFile( + const manifestFile = await PluginLoader.findManifestFile( `${dir}/${directory}`, ); if ( manifestFile && - (await this.hasEntrypoint(`${dir}/${directory}`)) + (await PluginLoader.hasEntrypoint(`${dir}/${directory}`)) ) { plugins.push(directory); } @@ -105,7 +107,9 @@ export class PluginLoader { * @throws Will throw an error if the manifest file is missing or invalid. */ public async parseManifest(dir: string, plugin: string): Promise { - const manifestFile = await this.findManifestFile(`${dir}/${plugin}`); + const manifestFile = await PluginLoader.findManifestFile( + `${dir}/${plugin}`, + ); if (!manifestFile) { throw new Error(`Plugin ${plugin} is missing a manifest file`); diff --git a/classes/search/search-manager.ts b/classes/search/search-manager.ts index a07bb427..b30a36cd 100644 --- a/classes/search/search-manager.ts +++ b/classes/search/search-manager.ts @@ -149,7 +149,7 @@ export class SonicSearchManager { * @param n Batch number * @param batchSize Size of the batch */ - private getNthDatabaseAccountBatch( + private static getNthDatabaseAccountBatch( n: number, batchSize = 1000, ): Promise[]> { @@ -172,7 +172,7 @@ export class SonicSearchManager { * @param n Batch number * @param batchSize Size of the batch */ - private getNthDatabaseStatusBatch( + private static getNthDatabaseStatusBatch( n: number, batchSize = 1000, ): Promise[]> { @@ -221,10 +221,11 @@ export class SonicSearchManager { const batchCount = Math.ceil(accountCount / batchSize); for (let i = 0; i < batchCount; i++) { - const accounts = await this.getNthDatabaseAccountBatch( - i, - batchSize, - ); + const accounts = + await SonicSearchManager.getNthDatabaseAccountBatch( + i, + batchSize, + ); await Promise.all( accounts.map((account) => this.ingestChannel.push( @@ -252,7 +253,10 @@ export class SonicSearchManager { const batchCount = Math.ceil(statusCount / batchSize); for (let i = 0; i < batchCount; i++) { - const statuses = await this.getNthDatabaseStatusBatch(i, batchSize); + const statuses = await SonicSearchManager.getNthDatabaseStatusBatch( + i, + batchSize, + ); await Promise.all( statuses.map((status) => this.ingestChannel.push( diff --git a/packages/database-interface/oauth.ts b/packages/database-interface/oauth.ts index 7d5d3798..a3aa8671 100644 --- a/packages/database-interface/oauth.ts +++ b/packages/database-interface/oauth.ts @@ -33,7 +33,7 @@ export class OAuthManager { this.issuer = found; } - async getFlow(flowId: string) { + static async getFlow(flowId: string) { return await db.query.OpenIdLoginFlows.findFirst({ where: (flow, { eq }) => eq(flow.id, flowId), with: { @@ -42,13 +42,13 @@ export class OAuthManager { }); } - async getAuthServer(issuerUrl: URL) { + static async getAuthServer(issuerUrl: URL) { return await discoveryRequest(issuerUrl, { algorithm: "oidc", }).then((res) => processDiscoveryResponse(issuerUrl, res)); } - getParameters( + static getParameters( authServer: AuthorizationServer, issuer: (typeof config.oidc.providers)[0], currentUrl: URL, @@ -64,7 +64,7 @@ export class OAuthManager { ); } - async getOIDCResponse( + static async getOIDCResponse( authServer: AuthorizationServer, issuer: (typeof config.oidc.providers)[0], redirectUri: string, @@ -83,7 +83,7 @@ export class OAuthManager { ); } - async processOIDCResponse( + static async processOIDCResponse( authServer: AuthorizationServer, issuer: (typeof config.oidc.providers)[0], oidcResponse: Response, @@ -98,7 +98,7 @@ export class OAuthManager { ); } - async getUserInfo( + static async getUserInfo( authServer: AuthorizationServer, issuer: (typeof config.oidc.providers)[0], accessToken: string, @@ -125,7 +125,7 @@ export class OAuthManager { ); } - processOAuth2Error( + static processOAuth2Error( application: InferInsertModel | null, ) { return { @@ -212,7 +212,7 @@ export class OAuthManager { app: Application | null, ) => Response, ) { - const flow = await this.getFlow(flowId); + const flow = await OAuthManager.getFlow(flowId); if (!flow) { return errorFn("invalid_request", "Invalid flow", null); @@ -220,9 +220,9 @@ export class OAuthManager { const issuerUrl = new URL(this.issuer.url); - const authServer = await this.getAuthServer(issuerUrl); + const authServer = await OAuthManager.getAuthServer(issuerUrl); - const parameters = await this.getParameters( + const parameters = await OAuthManager.getParameters( authServer, this.issuer, currentUrl, @@ -236,7 +236,7 @@ export class OAuthManager { ); } - const oidcResponse = await this.getOIDCResponse( + const oidcResponse = await OAuthManager.getOIDCResponse( authServer, this.issuer, redirectUrl.toString(), @@ -244,7 +244,7 @@ export class OAuthManager { parameters, ); - const result = await this.processOIDCResponse( + const result = await OAuthManager.processOIDCResponse( authServer, this.issuer, oidcResponse, @@ -265,7 +265,7 @@ export class OAuthManager { // Validate `sub` // Later, we'll use this to automatically set the user's data - const userInfo = await this.getUserInfo( + const userInfo = await OAuthManager.getUserInfo( authServer, this.issuer, access_token, diff --git a/packages/database-interface/timeline.ts b/packages/database-interface/timeline.ts index 11313751..1976d6a1 100644 --- a/packages/database-interface/timeline.ts +++ b/packages/database-interface/timeline.ts @@ -76,7 +76,7 @@ export class Timeline { switch (this.type) { case TimelineType.Note: linkHeader.push( - ...(await this.fetchNoteLinkHeader( + ...(await Timeline.fetchNoteLinkHeader( objects as Note[], urlWithoutQuery, limit, @@ -85,7 +85,7 @@ export class Timeline { break; case TimelineType.User: linkHeader.push( - ...(await this.fetchUserLinkHeader( + ...(await Timeline.fetchUserLinkHeader( objects as User[], urlWithoutQuery, limit, @@ -98,7 +98,7 @@ export class Timeline { return linkHeader.join(", "); } - private async fetchNoteLinkHeader( + private static async fetchNoteLinkHeader( notes: Note[], urlWithoutQuery: string, limit: number, @@ -126,7 +126,7 @@ export class Timeline { return linkHeader; } - private async fetchUserLinkHeader( + private static async fetchUserLinkHeader( users: User[], urlWithoutQuery: string, limit: number,