fix: circular dependency

This commit is contained in:
Vyacheslav Matyukhin 2022-05-12 18:59:07 +04:00
parent 2d5e73dd8b
commit fad619385c
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
8 changed files with 60 additions and 54 deletions

View File

@ -1,4 +1,4 @@
import { platforms } from "../platforms"; import { platforms } from "../platforms/registry";
import { executeJobByName } from "./jobs"; import { executeJobByName } from "./jobs";
/* Do everything */ /* Do everything */

View File

@ -1,6 +1,7 @@
import { doEverything } from "../flow/doEverything"; import { doEverything } from "../flow/doEverything";
import { rebuildFrontpage } from "../frontpage"; import { rebuildFrontpage } from "../frontpage";
import { platforms, processPlatform } from "../platforms"; import { processPlatform } from "../platforms";
import { platforms } from "../platforms/registry";
import { rebuildAlgoliaDatabase } from "../utils/algolia"; import { rebuildAlgoliaDatabase } from "../utils/algolia";
import { sleep } from "../utils/sleep"; import { sleep } from "../utils/sleep";

View File

@ -2,23 +2,9 @@ import { Question } from "@prisma/client";
import { QuestionOption } from "../../common/types"; import { QuestionOption } from "../../common/types";
import { prisma } from "../database/prisma"; import { prisma } from "../database/prisma";
import { betfair } from "./betfair";
import { fantasyscotus } from "./fantasyscotus"; // This file includes comon types and functions for working with platforms.
import { foretold } from "./foretold"; // The registry of all platforms is in a separate file, ./registry.ts, to avoid circular dependencies.
import { givewellopenphil } from "./givewellopenphil";
import { goodjudgment } from "./goodjudgment";
import { goodjudgmentopen } from "./goodjudgmentopen";
import { guesstimate } from "./guesstimate";
import { infer } from "./infer";
import { kalshi } from "./kalshi";
import { manifold } from "./manifold";
import { metaculus } from "./metaculus";
import { polymarket } from "./polymarket";
import { predictit } from "./predictit";
import { rootclaim } from "./rootclaim";
import { smarkets } from "./smarkets";
import { wildeford } from "./wildeford";
import { xrisk } from "./xrisk";
export interface QualityIndicators { export interface QualityIndicators {
stars: number; stars: number;
@ -86,26 +72,6 @@ export type Platform<ArgNames extends string = ""> = {
} }
); );
export const platforms: Platform<string>[] = [
betfair,
fantasyscotus,
foretold,
givewellopenphil,
goodjudgment,
goodjudgmentopen,
guesstimate,
infer,
kalshi,
manifold,
metaculus,
polymarket,
predictit,
rootclaim,
smarkets,
wildeford,
xrisk,
];
// Typing notes: // Typing notes:
// There's a difference between prisma's Question type (type returned from `find` and `findMany`) and its input types due to JsonValue vs InputJsonValue mismatch. // There's a difference between prisma's Question type (type returned from `find` and `findMany`) and its input types due to JsonValue vs InputJsonValue mismatch.
// On the other hand, we can't use Prisma.QuestionUpdateInput or Prisma.QuestionCreateManyInput either, because we use this question in guesstimate's code for preparing questions from guesstimate models... // On the other hand, we can't use Prisma.QuestionUpdateInput or Prisma.QuestionCreateManyInput either, because we use this question in guesstimate's code for preparing questions from guesstimate models...
@ -232,14 +198,3 @@ export interface PlatformConfig {
label: string; label: string;
color: string; color: string;
} }
// get frontend-safe version of platforms data
export const getPlatformsConfig = (): PlatformConfig[] => {
const platformsConfig = platforms.map((platform) => ({
name: platform.name,
label: platform.label,
color: platform.color,
}));
return platformsConfig;
};

View File

@ -0,0 +1,50 @@
import { betfair } from "./betfair";
import { fantasyscotus } from "./fantasyscotus";
import { foretold } from "./foretold";
import { givewellopenphil } from "./givewellopenphil";
import { goodjudgment } from "./goodjudgment";
import { goodjudgmentopen } from "./goodjudgmentopen";
import { guesstimate } from "./guesstimate";
import { Platform, PlatformConfig } from "./index";
import { infer } from "./infer";
import { kalshi } from "./kalshi";
import { manifold } from "./manifold";
import { metaculus } from "./metaculus";
import { polymarket } from "./polymarket";
import { predictit } from "./predictit";
import { rootclaim } from "./rootclaim";
import { smarkets } from "./smarkets";
import { wildeford } from "./wildeford";
import { xrisk } from "./xrisk";
export const platforms: Platform<string>[] = [
betfair,
fantasyscotus,
foretold,
givewellopenphil,
goodjudgment,
goodjudgmentopen,
guesstimate,
infer,
kalshi,
manifold,
metaculus,
polymarket,
predictit,
rootclaim,
smarkets,
wildeford,
xrisk,
];
// get frontend-safe version of platforms data
export const getPlatformsConfig = (): PlatformConfig[] => {
const platformsConfig = platforms.map((platform) => ({
name: platform.name,
label: platform.label,
color: platform.color,
}));
return platformsConfig;
};

View File

@ -3,7 +3,7 @@ import algoliasearch from "algoliasearch";
import { Question } from "@prisma/client"; import { Question } from "@prisma/client";
import { prisma } from "../database/prisma"; import { prisma } from "../database/prisma";
import { platforms } from "../platforms"; import { platforms } from "../platforms/registry";
let cookie = process.env.ALGOLIA_MASTER_API_KEY || ""; let cookie = process.env.ALGOLIA_MASTER_API_KEY || "";
const algoliaAppId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID || ""; const algoliaAppId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID || "";

View File

@ -1,5 +1,5 @@
import { prisma } from "../../backend/database/prisma"; import { prisma } from "../../backend/database/prisma";
import { platforms } from "../../backend/platforms"; import { platforms } from "../../backend/platforms/registry";
import { builder } from "../builder"; import { builder } from "../builder";
export const PlatformObj = builder.objectRef<string>("Platform").implement({ export const PlatformObj = builder.objectRef<string>("Platform").implement({

View File

@ -1,7 +1,7 @@
import { GetServerSideProps, NextPage } from "next"; import { GetServerSideProps, NextPage } from "next";
import React from "react"; import React from "react";
import { getPlatformsConfig, platforms } from "../backend/platforms"; import { getPlatformsConfig, platforms } from "../backend/platforms/registry";
import { Layout } from "../web/common/Layout"; import { Layout } from "../web/common/Layout";
import { Props, QueryParameters, SearchScreen } from "../web/search/components/SearchScreen"; import { Props, QueryParameters, SearchScreen } from "../web/search/components/SearchScreen";
import { FrontpageDocument, SearchDocument } from "../web/search/queries.generated"; import { FrontpageDocument, SearchDocument } from "../web/search/queries.generated";

View File

@ -3,7 +3,7 @@
import { GetServerSideProps, NextPage } from "next"; import { GetServerSideProps, NextPage } from "next";
import React from "react"; import React from "react";
import { platforms } from "../backend/platforms"; import { platforms } from "../backend/platforms/registry";
import { QuestionFragment } from "../web/fragments.generated"; import { QuestionFragment } from "../web/fragments.generated";
import { QuestionCard } from "../web/questions/components/QuestionCard"; import { QuestionCard } from "../web/questions/components/QuestionCard";
import { SearchDocument } from "../web/search/queries.generated"; import { SearchDocument } from "../web/search/queries.generated";