mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
fix: 🚨 Fix Deepsource warnings
This commit is contained in:
parent
2fffbcbede
commit
870b6dbe85
|
|
@ -125,6 +125,7 @@
|
||||||
"noGlobalDirnameFilename": "error",
|
"noGlobalDirnameFilename": "error",
|
||||||
"noProcessGlobal": "warn",
|
"noProcessGlobal": "warn",
|
||||||
"noTsIgnore": "warn",
|
"noTsIgnore": "warn",
|
||||||
|
"useReadonlyClassProperties": "error",
|
||||||
"useConsistentObjectDefinition": {
|
"useConsistentObjectDefinition": {
|
||||||
"level": "warn",
|
"level": "warn",
|
||||||
"options": {
|
"options": {
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ await build({
|
||||||
"@bull-board/ui",
|
"@bull-board/ui",
|
||||||
// Excluded because Standard Schema imports those, but the code is never executed
|
// Excluded because Standard Schema imports those, but the code is never executed
|
||||||
"@valibot/to-json-schema",
|
"@valibot/to-json-schema",
|
||||||
"effect"
|
"effect",
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ export class PluginLoader {
|
||||||
* @returns {Promise<unknown>} - The parsed manifest content.
|
* @returns {Promise<unknown>} - The parsed manifest content.
|
||||||
* @throws Will throw an error if the manifest file cannot be parsed.
|
* @throws Will throw an error if the manifest file cannot be parsed.
|
||||||
*/
|
*/
|
||||||
private async parseManifestFile(
|
private static async parseManifestFile(
|
||||||
manifestPath: string,
|
manifestPath: string,
|
||||||
manifestFile: string,
|
manifestFile: string,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
|
|
@ -118,7 +118,7 @@ export class PluginLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
const manifestPath = `${dir}/${plugin}/${manifestFile}`;
|
const manifestPath = `${dir}/${plugin}/${manifestFile}`;
|
||||||
const manifest = await this.parseManifestFile(
|
const manifest = await PluginLoader.parseManifestFile(
|
||||||
manifestPath,
|
manifestPath,
|
||||||
manifestFile,
|
manifestFile,
|
||||||
);
|
);
|
||||||
|
|
@ -140,7 +140,7 @@ export class PluginLoader {
|
||||||
* @returns {Promise<Plugin<ZodTypeAny>>} - The loaded Plugin instance.
|
* @returns {Promise<Plugin<ZodTypeAny>>} - The loaded Plugin instance.
|
||||||
* @throws Will throw an error if the entrypoint's default export is not a Plugin.
|
* @throws Will throw an error if the entrypoint's default export is not a Plugin.
|
||||||
*/
|
*/
|
||||||
public async loadPlugin(
|
public static async loadPlugin(
|
||||||
dir: string,
|
dir: string,
|
||||||
entrypoint: string,
|
entrypoint: string,
|
||||||
): Promise<Plugin<ZodTypeAny>> {
|
): Promise<Plugin<ZodTypeAny>> {
|
||||||
|
|
@ -197,7 +197,7 @@ export class PluginLoader {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pluginInstance = await this.loadPlugin(
|
const pluginInstance = await PluginLoader.loadPlugin(
|
||||||
dir,
|
dir,
|
||||||
`${plugin}/index`,
|
`${plugin}/index`,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,8 @@ export class ResponseError<
|
||||||
export class BaseClient {
|
export class BaseClient {
|
||||||
public constructor(
|
public constructor(
|
||||||
protected baseUrl: URL,
|
protected baseUrl: URL,
|
||||||
private accessToken?: string,
|
private readonly accessToken?: string,
|
||||||
private options: {
|
private readonly options: {
|
||||||
globalCatch?: (error: ResponseError) => void;
|
globalCatch?: (error: ResponseError) => void;
|
||||||
throwOnError?: boolean;
|
throwOnError?: boolean;
|
||||||
} = {},
|
} = {},
|
||||||
|
|
@ -103,6 +103,7 @@ export class BaseClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Overridable by testing */
|
/** Overridable by testing */
|
||||||
|
// biome-ignore lint/nursery/useReadonlyClassProperties: Overridable by testing
|
||||||
private fetch = (...args: Parameters<typeof fetch>) => fetch(...args);
|
private fetch = (...args: Parameters<typeof fetch>) => fetch(...args);
|
||||||
|
|
||||||
private async request<ReturnType>(
|
private async request<ReturnType>(
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ await build({
|
||||||
"acorn",
|
"acorn",
|
||||||
// Excluded because Standard Schema imports those, but the code is never executed
|
// Excluded because Standard Schema imports those, but the code is never executed
|
||||||
"@valibot/to-json-schema",
|
"@valibot/to-json-schema",
|
||||||
"effect"
|
"effect",
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -180,19 +180,19 @@ export class Instance extends BaseInterface<typeof Instances> {
|
||||||
|
|
||||||
// Go to endpoint, then follow the links to the actual metadata
|
// Go to endpoint, then follow the links to the actual metadata
|
||||||
try {
|
try {
|
||||||
const { json, ok, status } = await fetch(wellKnownUrl, {
|
const result = await fetch(wellKnownUrl, {
|
||||||
// @ts-expect-error Bun extension
|
// @ts-expect-error Bun extension
|
||||||
proxy: config.http.proxy_address,
|
proxy: config.http.proxy_address,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!ok) {
|
if (!result.ok) {
|
||||||
federationResolversLogger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
federationResolversLogger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
||||||
origin,
|
origin,
|
||||||
)} - HTTP ${status}`;
|
)} - HTTP ${result.status}`;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wellKnown = (await json()) as {
|
const wellKnown = (await result.json()) as {
|
||||||
links: { rel: string; href: string }[];
|
links: { rel: string; href: string }[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -216,23 +216,19 @@ export class Instance extends BaseInterface<typeof Instances> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const result2 = await fetch(metadataUrl.href, {
|
||||||
json: json2,
|
|
||||||
ok: ok2,
|
|
||||||
status: status2,
|
|
||||||
} = await fetch(metadataUrl.href, {
|
|
||||||
// @ts-expect-error Bun extension
|
// @ts-expect-error Bun extension
|
||||||
proxy: config.http.proxy_address,
|
proxy: config.http.proxy_address,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!ok2) {
|
if (!result2.ok) {
|
||||||
federationResolversLogger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
federationResolversLogger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
||||||
origin,
|
origin,
|
||||||
)} - HTTP ${status2}`;
|
)} - HTTP ${result2.status}`;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const metadata = (await json2()) as {
|
const metadata = (await result2.json()) as {
|
||||||
metadata: {
|
metadata: {
|
||||||
nodeName?: string;
|
nodeName?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ enum TimelineType {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Timeline<Type extends Note | User | Notification> {
|
export class Timeline<Type extends Note | User | Notification> {
|
||||||
public constructor(private type: TimelineType) {}
|
public constructor(private readonly type: TimelineType) {}
|
||||||
|
|
||||||
public static getNoteTimeline(
|
public static getNoteTimeline(
|
||||||
sql: SQL<unknown> | undefined,
|
sql: SQL<unknown> | undefined,
|
||||||
|
|
|
||||||
|
|
@ -55,14 +55,14 @@ export class InboxProcessor {
|
||||||
* @param requestIp Request IP address. Grabs it from the Hono context if not provided.
|
* @param requestIp Request IP address. Grabs it from the Hono context if not provided.
|
||||||
*/
|
*/
|
||||||
public constructor(
|
public constructor(
|
||||||
private request: Request,
|
private readonly request: Request,
|
||||||
private body: JSONObject,
|
private readonly body: JSONObject,
|
||||||
private sender: {
|
private readonly sender: {
|
||||||
instance: Instance;
|
instance: Instance;
|
||||||
key: CryptoKey;
|
key: CryptoKey;
|
||||||
} | null,
|
} | null,
|
||||||
private authorizationHeader?: string,
|
private readonly authorizationHeader?: string,
|
||||||
private requestIp: SocketAddress | null = null,
|
private readonly requestIp: SocketAddress | null = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -208,7 +208,7 @@ export class InboxProcessor {
|
||||||
throw new ApiError(400, "Unknown entity type");
|
throw new ApiError(400, "Unknown entity type");
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return this.handleError(e as Error);
|
return InboxProcessor.handleError(e as Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -589,7 +589,7 @@ export class InboxProcessor {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
* @throws {ApiError} - The error response.
|
* @throws {ApiError} - The error response.
|
||||||
*/
|
*/
|
||||||
private handleError(e: Error): void {
|
private static handleError(e: Error): void {
|
||||||
if (isValidationError(e)) {
|
if (isValidationError(e)) {
|
||||||
throw new ApiError(400, "Failed to process request", e.message);
|
throw new ApiError(400, "Failed to process request", e.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,15 @@ export type HonoPluginEnv<ConfigType extends z.ZodTypeAny> = HonoEnv & {
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Plugin<ConfigSchema extends z.ZodTypeAny> {
|
export class Plugin<ConfigSchema extends z.ZodTypeAny> {
|
||||||
private handlers: Partial<ServerHooks> = {};
|
private readonly handlers: Partial<ServerHooks> = {};
|
||||||
|
// biome-ignore lint/nursery/useReadonlyClassProperties: biome is wrong lol
|
||||||
private store: z.infer<ConfigSchema> | null = null;
|
private store: z.infer<ConfigSchema> | null = null;
|
||||||
private routes: {
|
private readonly routes: {
|
||||||
path: string;
|
path: string;
|
||||||
fn: (app: Hono<HonoPluginEnv<ConfigSchema>>) => void;
|
fn: (app: Hono<HonoPluginEnv<ConfigSchema>>) => void;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
public constructor(private configSchema: ConfigSchema) {}
|
public constructor(private readonly configSchema: ConfigSchema) {}
|
||||||
|
|
||||||
public get middleware(): MiddlewareHandler<HonoPluginEnv<ConfigSchema>> {
|
public get middleware(): MiddlewareHandler<HonoPluginEnv<ConfigSchema>> {
|
||||||
// Middleware that adds the plugin's configuration to the request object
|
// Middleware that adds the plugin's configuration to the request object
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,9 @@ export enum SonicIndexType {
|
||||||
* Class for managing Sonic search operations
|
* Class for managing Sonic search operations
|
||||||
*/
|
*/
|
||||||
export class SonicSearchManager {
|
export class SonicSearchManager {
|
||||||
private searchChannel: SonicChannelSearch;
|
private readonly searchChannel: SonicChannelSearch;
|
||||||
private ingestChannel: SonicChannelIngest;
|
private readonly ingestChannel: SonicChannelIngest;
|
||||||
|
// biome-ignore lint/nursery/useReadonlyClassProperties: biome is wrong lol
|
||||||
private connected = false;
|
private connected = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,10 @@ export class StreamingTimeline {
|
||||||
return `timeline:${this.timeline}`;
|
return `timeline:${this.timeline}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private messageHandler = (channel: string, message: string): void => {
|
private readonly messageHandler = (
|
||||||
|
channel: string,
|
||||||
|
message: string,
|
||||||
|
): void => {
|
||||||
if (channel === this.channelName) {
|
if (channel === this.channelName) {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(message);
|
const parsed = JSON.parse(message);
|
||||||
|
|
|
||||||
|
|
@ -44,35 +44,31 @@ const getSinks = (): Record<"file" | "console" | "sentry", Sink> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.logging.sentry) {
|
if (config.logging.sentry) {
|
||||||
sinks.sentry = getSentrySink(
|
|
||||||
Sentry.init({
|
|
||||||
dsn: config.logging.sentry.dsn.origin,
|
|
||||||
debug: config.logging.sentry.debug,
|
|
||||||
sampleRate: config.logging.sentry.sample_rate,
|
|
||||||
maxBreadcrumbs: config.logging.sentry.max_breadcrumbs,
|
|
||||||
tracesSampleRate: config.logging.sentry.traces_sample_rate,
|
|
||||||
environment: config.logging.sentry.environment,
|
|
||||||
tracePropagationTargets:
|
|
||||||
config.logging.sentry.trace_propagation_targets,
|
|
||||||
release: env.GIT_COMMIT
|
|
||||||
? `${pkg.version}-${env.GIT_COMMIT}`
|
|
||||||
: pkg.version,
|
|
||||||
integrations: [Sentry.extraErrorDataIntegration()],
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
sinks.sentry = withFilter(
|
sinks.sentry = withFilter(
|
||||||
sinks.sentry,
|
getSentrySink(
|
||||||
|
Sentry.init({
|
||||||
|
dsn: config.logging.sentry.dsn.origin,
|
||||||
|
debug: config.logging.sentry.debug,
|
||||||
|
sampleRate: config.logging.sentry.sample_rate,
|
||||||
|
maxBreadcrumbs: config.logging.sentry.max_breadcrumbs,
|
||||||
|
tracesSampleRate: config.logging.sentry.traces_sample_rate,
|
||||||
|
environment: config.logging.sentry.environment,
|
||||||
|
tracePropagationTargets:
|
||||||
|
config.logging.sentry.trace_propagation_targets,
|
||||||
|
release: env.GIT_COMMIT
|
||||||
|
? `${pkg.version}-${env.GIT_COMMIT}`
|
||||||
|
: pkg.version,
|
||||||
|
integrations: [Sentry.extraErrorDataIntegration()],
|
||||||
|
}),
|
||||||
|
),
|
||||||
getLevelFilter(config.logging.sentry.log_level),
|
getLevelFilter(config.logging.sentry.log_level),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sinks.console = getConsoleSink({
|
|
||||||
formatter: consoleFormatter,
|
|
||||||
});
|
|
||||||
|
|
||||||
sinks.console = withFilter(
|
sinks.console = withFilter(
|
||||||
sinks.console,
|
getConsoleSink({
|
||||||
|
formatter: consoleFormatter,
|
||||||
|
}),
|
||||||
getLevelFilter(config.logging.log_level),
|
getLevelFilter(config.logging.log_level),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ type MaybePromise<T> = T | Promise<T>;
|
||||||
* .sort();
|
* .sort();
|
||||||
*/
|
*/
|
||||||
export class EntitySorter {
|
export class EntitySorter {
|
||||||
private handlers: EntitySorterHandlers = new Map();
|
private readonly handlers: EntitySorterHandlers = new Map();
|
||||||
|
|
||||||
public constructor(private jsonData: JSONObject) {}
|
public constructor(private readonly jsonData: JSONObject) {}
|
||||||
|
|
||||||
public on<T extends typeof Entity>(
|
public on<T extends typeof Entity>(
|
||||||
entity: T,
|
entity: T,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue