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,15 +1,13 @@
// @flow
import {
User,
Team,
UserAuthentication,
AuthenticationProvider,
} from "../models";
import { flushdb } from "../test/support";
} from "@server/models";
import { flushdb } from "@server/test/support";
import script from "./20210226232041-migrate-authentication";
beforeEach(() => flushdb());
describe("#work", () => {
it("should create authentication record for users", async () => {
const team = await Team.create({
@@ -22,15 +20,12 @@ describe("#work", () => {
serviceId: "U123",
teamId: team.id,
});
await script();
const authProvider = await AuthenticationProvider.findOne({
where: {
providerId: "T123",
},
});
const auth = await UserAuthentication.findOne({
where: {
providerId: "U123",
@@ -53,15 +48,12 @@ describe("#work", () => {
teamId: team.id,
deletedAt: new Date(),
});
await script();
const authProvider = await AuthenticationProvider.findOne({
where: {
providerId: "domain.com",
},
});
const auth = await UserAuthentication.findOne({
where: {
providerId: "123456789",
@@ -84,15 +76,12 @@ describe("#work", () => {
teamId: team.id,
suspendedAt: new Date(),
});
await script();
const authProvider = await AuthenticationProvider.findOne({
where: {
providerId: "example.com",
},
});
const auth = await UserAuthentication.findOne({
where: {
providerId: "123456789",
@@ -115,15 +104,12 @@ describe("#work", () => {
serviceId: "U456",
teamId: team.id,
});
await script();
const authProvider = await AuthenticationProvider.findOne({
where: {
providerId: "T456",
},
});
const auth = await UserAuthentication.findOne({
where: {
providerId: "U456",
@@ -143,9 +129,7 @@ describe("#work", () => {
name: `Test`,
teamId: team.id,
});
await script();
const count = await UserAuthentication.count();
expect(count).toEqual(0);
});

View File

@@ -1,22 +1,21 @@
// @flow
import "./bootstrap";
import Logger from "../logging/logger";
import Logger from "@server/logging/logger";
import {
Team,
User,
AuthenticationProvider,
UserAuthentication,
} from "../models";
} from "@server/models";
import { Op } from "../sequelize";
const cache = {};
let page = 0;
let limit = 100;
const page = 0;
const limit = 100;
export default async function main(exit = false) {
// @ts-expect-error ts-migrate(7024) FIXME: Function implicitly has return type 'any' because ... Remove this comment to see the full error message
const work = async (page: number) => {
Logger.info("database", "Starting authentication migration");
const users = await User.findAll({
limit,
offset: page * limit,
@@ -40,6 +39,7 @@ export default async function main(exit = false) {
for (const user of users) {
const provider = user.service;
const providerId = user.team[`${provider}Id`];
if (!providerId) {
Logger.info(
"database",
@@ -47,6 +47,7 @@ export default async function main(exit = false) {
);
continue;
}
if (providerId.startsWith("transferred")) {
Logger.info(
"database",
@@ -56,6 +57,7 @@ export default async function main(exit = false) {
}
let authenticationProviderId = cache[providerId];
if (!authenticationProviderId) {
const [
authenticationProvider,
@@ -66,7 +68,6 @@ export default async function main(exit = false) {
teamId: user.teamId,
},
});
cache[providerId] = authenticationProviderId =
authenticationProvider.id;
}
@@ -96,9 +97,8 @@ export default async function main(exit = false) {
Logger.info("database", "Migration complete");
process.exit(0);
}
}
} // In the test suite we import the script rather than run via node CLI
// In the test suite we import the script rather than run via node CLI
if (process.env.NODE_ENV !== "test") {
main(true);
}

View File

@@ -1,20 +1,15 @@
// @flow
import { Revision, Event } from "../models";
import { buildDocument } from "../test/factories";
import { flushdb } from "../test/support";
import { Revision, Event } from "@server/models";
import { buildDocument } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import script from "./20210716000000-backfill-revisions";
beforeEach(() => flushdb());
describe("#work", () => {
it("should create events for revisions", async () => {
const document = await buildDocument();
const revision = await Revision.createFromDocument(document);
await script();
const event = await Event.findOne();
expect(event.name).toEqual("revisions.create");
expect(event.modelId).toEqual(revision.id);
expect(event.documentId).toEqual(document.id);
@@ -25,13 +20,9 @@ describe("#work", () => {
it("should create events for revisions of deleted documents", async () => {
const document = await buildDocument();
const revision = await Revision.createFromDocument(document);
await document.destroy();
await script();
const event = await Event.findOne();
expect(event.name).toEqual("revisions.create");
expect(event.modelId).toEqual(revision.id);
expect(event.documentId).toEqual(document.id);
@@ -42,10 +33,8 @@ describe("#work", () => {
it("should be idempotent", async () => {
const document = await buildDocument();
await Revision.createFromDocument(document);
await script();
await script();
const count = await Event.count();
expect(count).toEqual(1);
});

View File

@@ -1,15 +1,14 @@
// @flow
import "./bootstrap";
import { Revision, Document, Event } from "../models";
import { Revision, Document, Event } from "@server/models";
let limit = 100;
const limit = 100;
let page = parseInt(process.argv[2], 10);
page = Number.isNaN(page) ? 0 : page;
export default async function main(exit = false) {
// @ts-expect-error ts-migrate(7024) FIXME: Function implicitly has return type 'any' because ... Remove this comment to see the full error message
const work = async (page: number) => {
console.log(`Backfill revision events… page ${page}`);
const revisions = await Revision.findAll({
limit,
offset: page * limit,
@@ -53,9 +52,8 @@ export default async function main(exit = false) {
console.log("Backfill complete");
process.exit(0);
}
}
} // In the test suite we import the script rather than run via node CLI
// In the test suite we import the script rather than run via node CLI
if (process.env.NODE_ENV !== "test") {
main(true);
}

View File

@@ -1,6 +0,0 @@
// @flow
if (process.env.NODE_ENV !== "test") {
require("dotenv").config({ silent: true });
}
process.env.SINGLE_RUN = true;

View File

@@ -0,0 +1,11 @@
if (process.env.NODE_ENV !== "test") {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("dotenv").config({
silent: true,
});
}
// @ts-expect-error ts-migrate(2322) FIXME: Type 'true' is not assignable to type 'string | un... Remove this comment to see the full error message
process.env.SINGLE_RUN = true;
export {};