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,4 +1,3 @@
// @flow
import { v4 as uuidv4 } from "uuid";
import {
Share,
@@ -14,19 +13,23 @@ import {
Integration,
AuthenticationProvider,
FileOperation,
} from "../models";
} from "@server/models";
let count = 1;
export async function buildShare(overrides: Object = {}) {
export async function buildShare(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
if (!overrides.userId) {
const user = await buildUser({ teamId: overrides.teamId });
const user = await buildUser({
teamId: overrides.teamId,
});
overrides.userId = user.id;
}
if (!overrides.documentId) {
const document = await buildDocument({
createdById: overrides.userId,
@@ -41,9 +44,8 @@ export async function buildShare(overrides: Object = {}) {
});
}
export function buildTeam(overrides: Object = {}) {
export function buildTeam(overrides: Record<string, any> = {}) {
count++;
return Team.create(
{
name: `Team ${count}`,
@@ -62,7 +64,7 @@ export function buildTeam(overrides: Object = {}) {
);
}
export function buildEvent(overrides: Object = {}) {
export function buildEvent(overrides: Record<string, any> = {}) {
return Event.create({
name: "documents.publish",
ip: "127.0.0.1",
@@ -70,14 +72,13 @@ export function buildEvent(overrides: Object = {}) {
});
}
export async function buildGuestUser(overrides: Object = {}) {
export async function buildGuestUser(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
count++;
return User.create({
email: `user${count}@example.com`,
name: `User ${count}`,
@@ -87,7 +88,7 @@ export async function buildGuestUser(overrides: Object = {}) {
});
}
export async function buildUser(overrides: Object = {}) {
export async function buildUser(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
@@ -98,9 +99,7 @@ export async function buildUser(overrides: Object = {}) {
teamId: overrides.teamId,
},
});
count++;
return User.create(
{
email: `user${count}@example.com`,
@@ -122,18 +121,17 @@ export async function buildUser(overrides: Object = {}) {
);
}
export async function buildAdmin(overrides: Object = {}) {
export async function buildAdmin(overrides: Record<string, any> = {}) {
return buildUser({ ...overrides, isAdmin: true });
}
export async function buildInvite(overrides: Object = {}) {
export async function buildInvite(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
count++;
return User.create({
email: `user${count}@example.com`,
name: `User ${count}`,
@@ -142,14 +140,15 @@ export async function buildInvite(overrides: Object = {}) {
});
}
export async function buildIntegration(overrides: Object = {}) {
export async function buildIntegration(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
const user = await buildUser({ teamId: overrides.teamId });
const user = await buildUser({
teamId: overrides.teamId,
});
const authentication = await IntegrationAuthentication.create({
service: "slack",
userId: user.id,
@@ -157,7 +156,6 @@ export async function buildIntegration(overrides: Object = {}) {
token: "fake-access-token",
scopes: ["example", "scopes", "here"],
});
return Integration.create({
type: "post",
service: "slack",
@@ -169,19 +167,20 @@ export async function buildIntegration(overrides: Object = {}) {
});
}
export async function buildCollection(overrides: Object = {}) {
export async function buildCollection(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
if (!overrides.userId) {
const user = await buildUser({ teamId: overrides.teamId });
const user = await buildUser({
teamId: overrides.teamId,
});
overrides.userId = user.id;
}
count++;
return Collection.create({
name: `Test Collection ${count}`,
description: "Test collection description",
@@ -191,19 +190,20 @@ export async function buildCollection(overrides: Object = {}) {
});
}
export async function buildGroup(overrides: Object = {}) {
export async function buildGroup(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
if (!overrides.userId) {
const user = await buildUser({ teamId: overrides.teamId });
const user = await buildUser({
teamId: overrides.teamId,
});
overrides.userId = user.id;
}
count++;
return Group.create({
name: `Test Group ${count}`,
createdById: overrides.userId,
@@ -211,26 +211,27 @@ export async function buildGroup(overrides: Object = {}) {
});
}
export async function buildGroupUser(overrides: Object = {}) {
export async function buildGroupUser(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
if (!overrides.userId) {
const user = await buildUser({ teamId: overrides.teamId });
const user = await buildUser({
teamId: overrides.teamId,
});
overrides.userId = user.id;
}
count++;
return GroupUser.create({
createdById: overrides.userId,
...overrides,
});
}
export async function buildDocument(overrides: Object = {}) {
export async function buildDocument(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
@@ -247,7 +248,6 @@ export async function buildDocument(overrides: Object = {}) {
}
count++;
return Document.create({
title: `Document ${count}`,
text: "This is the text in an example document",
@@ -258,14 +258,16 @@ export async function buildDocument(overrides: Object = {}) {
});
}
export async function buildFileOperation(overrides: Object = {}) {
export async function buildFileOperation(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
if (!overrides.userId) {
const user = await buildAdmin({ teamId: overrides.teamId });
const user = await buildAdmin({
teamId: overrides.teamId,
});
overrides.userId = user.id;
}
@@ -280,14 +282,16 @@ export async function buildFileOperation(overrides: Object = {}) {
});
}
export async function buildAttachment(overrides: Object = {}) {
export async function buildAttachment(overrides: Record<string, any> = {}) {
if (!overrides.teamId) {
const team = await buildTeam();
overrides.teamId = team.id;
}
if (!overrides.userId) {
const user = await buildUser({ teamId: overrides.teamId });
const user = await buildUser({
teamId: overrides.teamId,
});
overrides.userId = user.id;
}
@@ -297,7 +301,6 @@ export async function buildAttachment(overrides: Object = {}) {
}
count++;
return Attachment.create({
key: `uploads/key/to/file ${count}.png`,
url: `https://redirect.url.com/uploads/key/to/file ${count}.png`,

View File

@@ -1,4 +1,3 @@
// @flow
import "../env";
// test environment variables
@@ -8,6 +7,5 @@ process.env.GOOGLE_CLIENT_ID = "123";
process.env.SLACK_KEY = "123";
process.env.DEPLOYMENT = "";
process.env.ALLOWED_DOMAINS = "allowed-domain.com";
// This is needed for the relative manual mock to be picked up
jest.mock("../queues");

View File

@@ -1,6 +1,5 @@
// @flow
import { v4 as uuidv4 } from "uuid";
import { User, Document, Collection, Team } from "../models";
import { User, Document, Collection, Team } from "@server/models";
import { sequelize } from "../sequelize";
const sql = sequelize.getQueryInterface();
@@ -30,9 +29,7 @@ export const seed = async () => {
include: "authenticationProviders",
}
);
const authenticationProvider = team.authenticationProviders[0];
const admin = await User.create(
{
email: "admin@example.com",
@@ -52,7 +49,6 @@ export const seed = async () => {
include: "authentications",
}
);
const user = await User.create(
{
id: "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
@@ -71,7 +67,6 @@ export const seed = async () => {
include: "authentications",
}
);
const collection = await Collection.create({
name: "Collection",
urlId: "collection",
@@ -79,7 +74,6 @@ export const seed = async () => {
createdById: user.id,
permission: "read_write",
});
const document = await Document.create({
parentDocumentId: null,
collectionId: collection.id,
@@ -92,7 +86,6 @@ export const seed = async () => {
});
await document.publish(collection.createdById);
await collection.reload();
return {
user,
admin,