chore: Move to Typescript (#2783)

This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
This commit is contained in:
Tom Moor
2021-11-29 06:40:55 -08:00
committed by GitHub
parent 25ccfb5d04
commit 15b1069bcc
1017 changed files with 17410 additions and 54942 deletions

View File

@@ -1,12 +1,10 @@
// @flow
import chalk from "chalk";
import winston from "winston";
import env from "../env";
import Metrics from "../logging/metrics";
import Sentry from "../logging/sentry";
import env from "@server/env";
import Metrics from "@server/logging/metrics";
import Sentry from "@server/logging/sentry";
const isProduction = env.NODE_ENV === "production";
type LogCategory =
| "lifecycle"
| "hocuspocus"
@@ -17,8 +15,7 @@ type LogCategory =
| "queue"
| "database"
| "utils";
type Extra = { [key: string]: any };
type Extra = Record<string, any>;
class Logger {
output: any;
@@ -77,6 +74,7 @@ class Logger {
scope.setExtra(key, extra[key]);
scope.setLevel(Sentry.Severity.Warning);
}
Sentry.captureMessage(message);
});
}
@@ -106,14 +104,21 @@ class Logger {
scope.setExtra(key, extra[key]);
scope.setLevel(Sentry.Severity.Error);
}
Sentry.captureException(error);
});
}
if (isProduction) {
this.output.error(message, { error: error.message, stack: error.stack });
this.output.error(message, {
error: error.message,
stack: error.stack,
});
} else {
console.error(message, { error, extra });
console.error(message, {
error,
extra,
});
}
}
}

View File

@@ -1,8 +1,7 @@
// @flow
import ddMetrics from "datadog-metrics";
class Metrics {
enabled: boolean = !!process.env.DD_API_KEY;
enabled = !!process.env.DD_API_KEY;
constructor() {
if (!this.enabled) {
@@ -24,12 +23,13 @@ class Metrics {
return ddMetrics.gauge(key, value, tags);
}
gaugePerInstance(key: string, value: number, tags?: string[] = []): void {
gaugePerInstance(key: string, value: number, tags: string[] = []): void {
if (!this.enabled) {
return;
}
const instanceId = process.env.INSTANCE_ID || process.env.HEROKU_DYNO_ID;
if (!instanceId) {
throw new Error(
"INSTANCE_ID or HEROKU_DYNO_ID must be set when using DataDog"
@@ -39,12 +39,12 @@ class Metrics {
return ddMetrics.gauge(key, value, [...tags, `instance:${instanceId}`]);
}
increment(key: string, tags?: { [string]: string }): void {
increment(key: string, tags?: Record<string, string>): void {
if (!this.enabled) {
return;
}
return ddMetrics.increment(key, tags);
return ddMetrics.increment(key);
}
}

View File

@@ -1,7 +1,6 @@
// @flow
import * as Sentry from "@sentry/node";
import env from "../env";
import type { ContextWithState } from "../types";
import env from "@server/env";
import { ContextWithState } from "../types";
if (env.SENTRY_DSN) {
Sentry.init({
@@ -22,26 +21,33 @@ if (env.SENTRY_DSN) {
export function requestErrorHandler(error: any, ctx: ContextWithState) {
// we don't need to report every time a request stops to the bug tracker
if (error.code === "EPIPE" || error.code === "ECONNRESET") {
console.warn("Connection error", { error });
console.warn("Connection error", {
error,
});
return;
}
if (process.env.SENTRY_DSN) {
Sentry.withScope(function (scope) {
const requestId = ctx.headers["x-request-id"];
if (requestId) {
scope.setTag("request_id", requestId);
scope.setTag("request_id", requestId as string);
}
const authType = ctx.state ? ctx.state.authType : undefined;
if (authType) {
scope.setTag("auth_type", authType);
}
const userId =
ctx.state && ctx.state.user ? ctx.state.user.id : undefined;
if (userId) {
scope.setUser({ id: userId });
scope.setUser({
id: userId,
});
}
scope.addEventProcessor(function (event) {