dependencies dependencies cluster_AppModule cluster_AppModule_imports AuthModule AuthModule AppModule AppModule AuthModule->AppModule BlogSummaryModule BlogSummaryModule BlogSummaryModule->AppModule ContributorModule ContributorModule ContributorModule->AppModule EmojiModule EmojiModule EmojiModule->AppModule EndorsementModule EndorsementModule EndorsementModule->AppModule HealthModule HealthModule HealthModule->AppModule HighlightModule HighlightModule HighlightModule->AppModule HistogramModule HistogramModule HistogramModule->AppModule InsightsModule InsightsModule InsightsModule->AppModule IssueSummaryModule IssueSummaryModule IssueSummaryModule->AppModule OpenAIWrappedModule OpenAIWrappedModule OpenAIWrappedModule->AppModule PullRequestModule PullRequestModule PullRequestModule->AppModule RepoModule RepoModule RepoModule->AppModule StarModule StarModule StarModule->AppModule StarSearchModule StarSearchModule StarSearchModule->AppModule StargazeModule StargazeModule StargazeModule->AppModule SubmitModule SubmitModule SubmitModule->AppModule TimescaleModule TimescaleModule TimescaleModule->AppModule UrlModule UrlModule UrlModule->AppModule UserListModule UserListModule UserListModule->AppModule UserModule UserModule UserModule->AppModule UserReposModule UserReposModule UserReposModule->AppModule VoteModule VoteModule VoteModule->AppModule WorkspaceModule WorkspaceModule WorkspaceModule->AppModule
import { MiddlewareConsumer, Module } from "@nestjs/common";
import { InjectDataSource, TypeOrmModule } from "@nestjs/typeorm";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { HttpModule } from "@nestjs/axios";
import { TerminusModule } from "@nestjs/terminus";
import { DataSource } from "typeorm";
import { TypeOrmModuleOptions } from "@nestjs/typeorm/dist/interfaces/typeorm-options.interface";

import {
  ApiConfig,
  DbApiConfig,
  EndpointConfig,
  OpenAIConfig,
  BingConfig,
  DbTimescaleConfig,
  GitHubConfig,
  DubConfig,
  StarSearchConfig,
  envSchema,
} from "./config";
import { RepoModule } from "./repo/repo.module";
import { HealthModule } from "./health/health.module";
import { DbRepoWithStats } from "./repo/entities/repo.entity";
import { DbUser } from "./user/user.entity";
import { DbRepoToUserVotes } from "./repo/entities/repo.to.user.votes.entity";
import { DbRepoToUserStars } from "./repo/entities/repo.to.user.stars.entity";
import { DbRepoToUserSubmissions } from "./repo/entities/repo.to.user.submissions.entity";
import { DbRepoToUserStargazers } from "./repo/entities/repo.to.user.stargazers.entity";
import { AuthModule } from "./auth/auth.module";
import { VoteModule } from "./vote/vote.module";
import { StarModule } from "./star/star.module";
import { StargazeModule } from "./stargaze/stargaze.module";
import { SubmitModule } from "./submit/submit.module";
import { UserModule } from "./user/user.module";
import { HttpLoggerMiddleware } from "./common/middleware/http-logger.middleware";
import { DatabaseLoggerMiddleware } from "./common/middleware/database-logger.middleware";
import { InsightsModule } from "./insight/insights.module";
import { DbInsight } from "./insight/entities/insight.entity";
import { DbInsightRepo } from "./insight/entities/insight-repo.entity";
import { UserReposModule } from "./user-repo/user-repos.module";
import { DbUserRepo } from "./user-repo/user-repo.entity";
import { EmojiModule } from "./emoji/emoji.module";
import { PullRequestModule } from "./pull-requests/pull-request.module";
import { DbUserHighlight } from "./user/entities/user-highlight.entity";
import { HighlightModule } from "./highlight/highlight.module";
import { DbUserToUserFollows } from "./user/entities/user-follows.entity";
import { DbInsightMember } from "./insight/entities/insight-member.entity";
import { DbEmoji } from "./emoji/entities/emoji.entity";
import { DbUserHighlightReaction } from "./user/entities/user-highlight-reaction.entity";
import { DbUserTopRepo } from "./user/entities/user-top-repo.entity";
import { DbUserNotification } from "./user/entities/user-notification.entity";
import { DbUserCollaboration } from "./user/entities/user-collaboration.entity";
import { DbUserOrganization } from "./user/entities/user-organization.entity";
import { EndorsementModule } from "./endorsement/endorsement.module";
import { DbEndorsement } from "./endorsement/entities/endorsement.entity";
import { ContributorModule } from "./contributor/contributor.module";
import { OpenAIWrappedModule } from "./openai-wrapped/openai-wrapped.module";
import { IssueSummaryModule } from "./issues/issue-summary.module";
import { BlogSummaryModule } from "./blogs/issue-summary.module";
import { UserListModule } from "./user-lists/user-list.module";
import { DbUserList } from "./user-lists/entities/user-list.entity";
import { DbUserListContributor } from "./user-lists/entities/user-list-contributor.entity";
import { TimescaleModule } from "./timescale/timescale.module";
import { DbPullRequestGitHubEvents } from "./timescale/entities/pull_request_github_event.entity";
import { DbPullRequestReviewGitHubEvents } from "./timescale/entities/pull_request_review_github_event.entity";
import { DbWorkspace } from "./workspace/entities/workspace.entity";
import { DbWorkspaceMember } from "./workspace/entities/workspace-member.entity";
import { DbWorkspaceOrg } from "./workspace/entities/workspace-org.entity";
import { DbWorkspaceRepo } from "./workspace/entities/workspace-repos.entity";
import { DbWorkspaceInsight } from "./workspace/entities/workspace-insights.entity";
import { WorkspaceModule } from "./workspace/workspace.module";
import { HistogramModule } from "./histogram/histogram.module";
import { DbWorkspaceContributor } from "./workspace/entities/workspace-contributors.entity";
import { DbIssuesGitHubEvents } from "./timescale/entities/issues_github_event.entity";
import { DbPushGitHubEvents } from "./timescale/entities/push_github_events.entity";
import { DbWorkspaceUserLists } from "./workspace/entities/workspace-user-list.entity";
import { UrlModule } from "./url/url.module";
import { StarSearchModule } from "./star-search/star-search.module";
import { DbCommitCommentGitHubEvents } from "./timescale/entities/commit_comment_github_events.entity";
import { DbPullRequestReviewCommentGitHubEvents } from "./timescale/entities/pull_request_review_comment_github_events.entity";
import { DbIssueCommentGitHubEvents } from "./timescale/entities/issue_comment_github_events.entity";
import { DbStarSearchThread } from "./star-search/entities/thread.entity";
import { DbStarSearchThreadHistory } from "./star-search/entities/thread-history.entity";
import { DbStarSearchUserThread } from "./star-search/entities/user-thread.entity";
import { DbStarSearchWorkspaceThread } from "./star-search/entities/worspace-thread.entity";

@Module({
  imports: [
    ConfigModule.forRoot({
      load: [
        ApiConfig,
        DbApiConfig,
        EndpointConfig,
        OpenAIConfig,
        StarSearchConfig,
        BingConfig,
        DbTimescaleConfig,
        GitHubConfig,
        DubConfig,
      ],
      isGlobal: true,
      validate: (config) => {
        const parsed = envSchema.safeParse(config);

        if (!parsed.success) {
          throw new Error(parsed.error.issues.map((issue) => `${issue.path.join(".")} ${issue.message}`).join(", "));
        }

        /*
         * todo - in the future, we will want to return parsed.data from the validated
         * Zod environment schema. This way, we only pass in a validated
         * and runtime type safe object. For now, just returning the raw env config
         * works fine.
         */
        return config;
      },
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      name: "ApiConnection",
      useFactory: (configService: ConfigService) =>
        ({
          parseInt8: true,
          type: configService.get("db-api.connection"),
          host: configService.get("db-api.host"),
          port: configService.get("db-api.port"),
          username: configService.get("db-api.username"),
          password: configService.get("db-api.password"),
          database: configService.get("db-api.database"),
          autoLoadEntities: false,
          entities: [
            DbUser,
            DbUserRepo,
            DbUserHighlight,
            DbUserHighlightReaction,
            DbUserNotification,
            DbUserCollaboration,
            DbRepoWithStats,
            DbRepoToUserVotes,
            DbRepoToUserStars,
            DbRepoToUserSubmissions,
            DbRepoToUserStargazers,
            DbInsight,
            DbInsightMember,
            DbInsightRepo,
            DbUserToUserFollows,
            DbEmoji,
            DbUserTopRepo,
            DbEndorsement,
            DbUserOrganization,
            DbUserList,
            DbUserListContributor,
            DbWorkspace,
            DbWorkspaceMember,
            DbWorkspaceOrg,
            DbWorkspaceRepo,
            DbWorkspaceInsight,
            DbWorkspaceUserLists,
            DbWorkspaceContributor,
            DbStarSearchThread,
            DbStarSearchThreadHistory,
            DbStarSearchUserThread,
            DbStarSearchWorkspaceThread,
          ],
          synchronize: false,
          logger: new DatabaseLoggerMiddleware("OS"),
          ssl: {
            ca: configService.get("db-api.certificate"),
            rejectUnauthorized: false,
          },
          maxQueryExecutionTime: configService.get("db-api.maxQueryExecutionTime"),
        } as TypeOrmModuleOptions),
      inject: [ConfigService],
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      name: "TimescaleConnection",
      useFactory: (configService: ConfigService) =>
        ({
          type: configService.get("db-timescale.connection"),
          host: configService.get("db-timescale.host"),
          port: configService.get("db-timescale.port"),
          username: configService.get("db-timescale.username"),
          password: configService.get("db-timescale.password"),
          database: configService.get("db-timescale.database"),
          autoLoadEntities: false,
          entities: [
            DbPushGitHubEvents,
            DbPullRequestGitHubEvents,
            DbIssuesGitHubEvents,
            DbPullRequestReviewGitHubEvents,
            DbCommitCommentGitHubEvents,
            DbPullRequestReviewCommentGitHubEvents,
            DbIssueCommentGitHubEvents,
          ],
          synchronize: false,
          logger: new DatabaseLoggerMiddleware("OS"),
          ssl: {
            ca: configService.get("db-timescale.certificate"),
            rejectUnauthorized: false,
          },
        } as TypeOrmModuleOptions),
      inject: [ConfigService],
    }),
    TerminusModule,
    HttpModule,
    AuthModule,
    HealthModule,
    RepoModule,
    VoteModule,
    StarModule,
    StargazeModule,
    SubmitModule,
    UserModule,
    InsightsModule,
    IssueSummaryModule,
    BlogSummaryModule,
    UserReposModule,
    PullRequestModule,
    HighlightModule,
    EmojiModule,
    EndorsementModule,
    ContributorModule,
    OpenAIWrappedModule,
    UserListModule,
    TimescaleModule,
    WorkspaceModule,
    HistogramModule,
    UrlModule,
    StarSearchModule,
  ],
  providers: [],
})
export class AppModule {
  constructor(
    @InjectDataSource("ApiConnection")
    private readonly apiConnection: DataSource,

    @InjectDataSource("TimescaleConnection")
    private readonly timescaleConnection: DataSource
  ) {}

  configure(consumer: MiddlewareConsumer) {
    consumer.apply(HttpLoggerMiddleware).forRoutes(`v1`);
    consumer.apply(HttpLoggerMiddleware).forRoutes(`v2`);
  }
}

results matching ""

    No results matching ""