From fad619385ccfce0ce392cd691196bd11a464bd5d Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Thu, 12 May 2022 18:59:07 +0400 Subject: [PATCH] fix: circular dependency --- src/backend/flow/doEverything.ts | 2 +- src/backend/flow/jobs.ts | 3 +- src/backend/platforms/index.ts | 51 ++----------------------------- src/backend/platforms/registry.ts | 50 ++++++++++++++++++++++++++++++ src/backend/utils/algolia.ts | 2 +- src/graphql/schema/platforms.ts | 2 +- src/pages/index.tsx | 2 +- src/pages/secretEmbed.tsx | 2 +- 8 files changed, 60 insertions(+), 54 deletions(-) create mode 100644 src/backend/platforms/registry.ts diff --git a/src/backend/flow/doEverything.ts b/src/backend/flow/doEverything.ts index 64835d0..8e2da5d 100644 --- a/src/backend/flow/doEverything.ts +++ b/src/backend/flow/doEverything.ts @@ -1,4 +1,4 @@ -import { platforms } from "../platforms"; +import { platforms } from "../platforms/registry"; import { executeJobByName } from "./jobs"; /* Do everything */ diff --git a/src/backend/flow/jobs.ts b/src/backend/flow/jobs.ts index 58d289c..61a3d2b 100644 --- a/src/backend/flow/jobs.ts +++ b/src/backend/flow/jobs.ts @@ -1,6 +1,7 @@ import { doEverything } from "../flow/doEverything"; import { rebuildFrontpage } from "../frontpage"; -import { platforms, processPlatform } from "../platforms"; +import { processPlatform } from "../platforms"; +import { platforms } from "../platforms/registry"; import { rebuildAlgoliaDatabase } from "../utils/algolia"; import { sleep } from "../utils/sleep"; diff --git a/src/backend/platforms/index.ts b/src/backend/platforms/index.ts index cba1a58..384ab92 100644 --- a/src/backend/platforms/index.ts +++ b/src/backend/platforms/index.ts @@ -2,23 +2,9 @@ import { Question } from "@prisma/client"; import { QuestionOption } from "../../common/types"; import { prisma } from "../database/prisma"; -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 { 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"; + +// This file includes comon types and functions for working with platforms. +// The registry of all platforms is in a separate file, ./registry.ts, to avoid circular dependencies. export interface QualityIndicators { stars: number; @@ -86,26 +72,6 @@ export type Platform = { } ); -export const platforms: Platform[] = [ - betfair, - fantasyscotus, - foretold, - givewellopenphil, - goodjudgment, - goodjudgmentopen, - guesstimate, - infer, - kalshi, - manifold, - metaculus, - polymarket, - predictit, - rootclaim, - smarkets, - wildeford, - xrisk, -]; - // 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. // 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; 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; -}; diff --git a/src/backend/platforms/registry.ts b/src/backend/platforms/registry.ts new file mode 100644 index 0000000..ed6d902 --- /dev/null +++ b/src/backend/platforms/registry.ts @@ -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[] = [ + 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; +}; diff --git a/src/backend/utils/algolia.ts b/src/backend/utils/algolia.ts index 40efeb7..f2cc38d 100644 --- a/src/backend/utils/algolia.ts +++ b/src/backend/utils/algolia.ts @@ -3,7 +3,7 @@ import algoliasearch from "algoliasearch"; import { Question } from "@prisma/client"; import { prisma } from "../database/prisma"; -import { platforms } from "../platforms"; +import { platforms } from "../platforms/registry"; let cookie = process.env.ALGOLIA_MASTER_API_KEY || ""; const algoliaAppId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID || ""; diff --git a/src/graphql/schema/platforms.ts b/src/graphql/schema/platforms.ts index ebde3ed..10dc2b4 100644 --- a/src/graphql/schema/platforms.ts +++ b/src/graphql/schema/platforms.ts @@ -1,5 +1,5 @@ import { prisma } from "../../backend/database/prisma"; -import { platforms } from "../../backend/platforms"; +import { platforms } from "../../backend/platforms/registry"; import { builder } from "../builder"; export const PlatformObj = builder.objectRef("Platform").implement({ diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 1ea9ad9..5814c91 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,7 +1,7 @@ import { GetServerSideProps, NextPage } from "next"; import React from "react"; -import { getPlatformsConfig, platforms } from "../backend/platforms"; +import { getPlatformsConfig, platforms } from "../backend/platforms/registry"; import { Layout } from "../web/common/Layout"; import { Props, QueryParameters, SearchScreen } from "../web/search/components/SearchScreen"; import { FrontpageDocument, SearchDocument } from "../web/search/queries.generated"; diff --git a/src/pages/secretEmbed.tsx b/src/pages/secretEmbed.tsx index 7420734..039af0d 100644 --- a/src/pages/secretEmbed.tsx +++ b/src/pages/secretEmbed.tsx @@ -3,7 +3,7 @@ import { GetServerSideProps, NextPage } from "next"; import React from "react"; -import { platforms } from "../backend/platforms"; +import { platforms } from "../backend/platforms/registry"; import { QuestionFragment } from "../web/fragments.generated"; import { QuestionCard } from "../web/questions/components/QuestionCard"; import { SearchDocument } from "../web/search/queries.generated";