Home / Class/ LintWarningsGuideLoader Class — supabase Architecture

LintWarningsGuideLoader Class — supabase Architecture

Architecture documentation for the LintWarningsGuideLoader class in lint-warnings-guide.ts from the supabase codebase.

Entity Profile

Relationship Graph

Source Code

apps/docs/scripts/search/sources/lint-warnings-guide.ts lines 7–78

export class LintWarningsGuideLoader extends BaseLoader {
  type = 'markdown' as const

  constructor(
    source: string,
    path: string,
    public org: string,
    public repo: string,
    public branch: string,
    public docsDir: string
  ) {
    super(source, path)
  }

  async load() {
    const octokit = new Octokit()

    const response = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
      owner: this.org,
      repo: this.repo,
      path: this.docsDir,
      ref: this.branch,
      headers: {
        'X-GitHub-Api-Version': '2022-11-28',
      },
    })

    if (response.status >= 400) {
      throw Error(`Could not get contents of repo ${this.org}/${this.repo}`)
    }

    if (!Array.isArray(response.data)) {
      throw Error(
        'Reading a directory, not a file. Should not reach this, solely to appease Typescript.'
      )
    }

    const lintsList = response.data.filter(({ path }) => /docs\/\d+.+\.md$/.test(path))

    // Fetch all lint files and combine them into a single guide
    const lints = await Promise.all(
      lintsList.map(async ({ path }) => {
        const fileResponse = await fetch(
          `https://raw.githubusercontent.com/${this.org}/${this.repo}/${this.branch}/${path}`
        )

        if (fileResponse.status >= 400) {
          throw Error(`Could not get contents of file ${this.org}/${this.repo}/${path}`)
        }

        const content = await fileResponse.text()
        const basename = getBasename(path)

        return {
          path: basename,
          content,
          originalPath: path,
        }
      })
    )

    // Create a separate source for each lint file
    return lints.map(
      (lint) =>
        new LintWarningsGuideSource(
          this.source,
          `${this.path}?queryGroups=lint&lint=${lint.path}`,
          lint
        )
    )
  }
}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free