Files
supabase/apps/docs/scripts/search/sources/index.ts
Lukas Klingsbo 833d3cb1d7 docs: migrate Dart/Flutter reference to the new reference pipeline (#47224)
## What

Routes the **Dart/Flutter v2** reference through the new
reference-content pipeline (`scripts/build-reference-content.ts` +
`spec/reference/dart/v2/`), the same one JavaScript v2 already uses.
Dart v1 stays on the legacy YAML pipeline.

## How

Dart has no upstream TypeDoc dump, so this follows the reference
README's "adapt other formats as a pre-step" approach:

- **`scripts/generate-dart-reference.ts`** converts the committed legacy
spec (`spec/supabase_dart_v2.yml`) plus the shared section tree into a
TypeDoc-shaped dump at `spec/reference/dart/v2/supabase_flutter.json`
(gitignored, like every other dump). Each Dart method becomes a
`variant: 'declaration'` node tagged with `@category`/`@subcategory` and
carries the legacy function shape (description, notes, params, examples)
on a non-TypeDoc `content` field.
- **`build-reference-content.ts`** gains a small, backward-compatible
addition: it spreads a declaration's `content` straight onto the
`functions.json` entry. The renderer then shows params/examples/notes
exactly as the legacy YAML did, with no typeSpec round-trip. The field
is absent for real TypeDoc dumps, so **JavaScript output is unchanged**
(existing JS snapshot still passes).
- `dart-v2` added to `SUPPORTS_NEW_REFERENCE_PROCESS`; the v2 `specFile`
is dropped from the nav entry so the legacy generator skips it.
- Dart search ingest switched to the new-pipeline loader.
- `config.json` + hand-authored partials (intro markdown,
`initializing`, and subcategory overviews like `using-filters`,
`auth-mfa`) added under `spec/reference/dart/v2/partials/`, mirroring
the JS lib.
- The dart dump is regenerated in `codegen:references:new` and in CI; a
self-contained `dart/v2` snapshot test covers the full YAML → dump →
content path.

## Verification

- `vitest run scripts/build-reference-content.test.ts` — both JS and
Dart snapshots pass.
- 112 function sections all resolve to renderable `functions.json`
entries (104 methods + 7 subcategory overviews + `initializing`).
- `tsc --noEmit` clean for all changed files.
- Legacy generator confirmed to skip dart v2 (only `dart.v1.*`
regenerated).

> Note: the live dev server (which needs the Supabase backend) was not
run; verification was done at the data-pipeline level plus parity with
the production JS pipeline behavior.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added Dart v2 reference documentation sections, including Installing,
Initializing, Filters, Modifiers, Auth Admin, MFA, Passkeys, File
Buckets, Introduction, and Upgrade guidance.
* Expanded the Dart v2 reference pipeline so Dart API pages are
generated from the newer reference content flow.
* **Bug Fixes**
* Improved Dart reference rendering by preserving legacy descriptions,
notes, params, and examples in generated function entries.
* Updated Dart v2 reference search to use the new pipeline’s generated
content so results and navigation stay in sync.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Jeremias Menichelli <jmenichelli@gmail.com>
2026-07-03 15:09:56 +02:00

181 lines
5.9 KiB
TypeScript

import { type GuideModel } from '../../../resources/guide/guideModel.js'
import { GuideModelLoader } from '../../../resources/guide/guideModelLoader.js'
import { LintWarningsGuideLoader, type LintWarningsGuideSource } from './lint-warnings-guide.js'
import { MarkdownLoader, type MarkdownSource } from './markdown.js'
import { fetchPartners, IntegrationLoader, type IntegrationSource } from './partner-integrations.js'
import {
ClientLibReferenceLoader,
CliReferenceLoader,
loadClientLibReferenceFromNewPipeline,
OpenApiReferenceLoader,
type ClientLibReferenceSource,
type CliReferenceSource,
type OpenApiReferenceSource,
} from './reference-doc.js'
import { fetchTroubleshootingSources, type TroubleshootingSource } from './troubleshooting.js'
export type SearchSource =
| MarkdownSource
| OpenApiReferenceSource
| ClientLibReferenceSource
| CliReferenceSource
| TroubleshootingSource
| IntegrationSource
| LintWarningsGuideSource
export async function fetchGuideSources() {
const guides = (await GuideModelLoader.allFromFs()).unwrapLeft()
return guides.map((guide: GuideModel) => MarkdownLoader.fromGuideModel('guide', guide))
}
export async function fetchOpenApiReferenceSource() {
return new OpenApiReferenceLoader(
'api',
'/reference/api',
{ title: 'Management API Reference' },
'spec/transforms/api_v1_openapi_deparsed.json',
'spec/common-api-sections.json'
).load()
}
export async function fetchJsLibReferenceSource() {
// JS v2 is driven by the new reference pipeline. Ingest search sources from
// the generated `content/reference/javascript/v2/` outputs so embeddings
// never drift from what the renderer shows.
return loadClientLibReferenceFromNewPipeline({
source: 'js-lib',
path: '/reference/javascript',
meta: { title: 'JavaScript Reference', language: 'JavaScript' },
contentDir: 'content/reference/javascript/v2',
})
}
export async function fetchDartLibReferenceSource() {
// Dart v2 is driven by the new reference pipeline. Ingest search sources from
// the generated `content/reference/dart/v2/` outputs so embeddings never
// drift from what the renderer shows.
return loadClientLibReferenceFromNewPipeline({
source: 'dart-lib',
path: '/reference/dart',
meta: { title: 'Dart Reference', language: 'Dart' },
contentDir: 'content/reference/dart/v2',
})
}
export async function fetchPythonLibReferenceSource() {
return new ClientLibReferenceLoader(
'python-lib',
'/reference/python',
{ title: 'Python Reference', language: 'Python' },
'spec/supabase_py_v2.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchCSharpLibReferenceSource() {
return new ClientLibReferenceLoader(
'csharp-lib',
'/reference/csharp',
{ title: 'C# Reference', language: 'C#' },
'spec/supabase_csharp_v0.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchSwiftLibReferenceSource() {
return new ClientLibReferenceLoader(
'swift-lib',
'/reference/swift',
{ title: 'Swift Reference', language: 'Swift' },
'spec/supabase_swift_v2.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchKtLibReferenceSource() {
return new ClientLibReferenceLoader(
'kt-lib',
'/reference/kotlin',
{ title: 'Kotlin Reference', language: 'Kotlin' },
'spec/supabase_kt_v1.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchCliLibReferenceSource() {
return new CliReferenceLoader(
'cli',
'/reference/cli',
{ title: 'CLI Reference', platform: 'cli' },
'spec/cli_v1_commands.yaml',
'spec/common-cli-sections.json'
).load()
}
export async function fetchLintWarningsGuideSources() {
return new LintWarningsGuideLoader(
'guide',
'/guides/database/database-advisors',
'supabase',
'splinter',
'main',
'docs'
).load()
}
/**
* Fetches all the sources we want to index for search
*/
export async function fetchAllSources(fullIndex: boolean) {
const guideSources = fetchGuideSources()
const lintWarningsGuideSources = fetchLintWarningsGuideSources()
const openApiReferenceSource = fetchOpenApiReferenceSource()
const jsLibReferenceSource = fetchJsLibReferenceSource()
const dartLibReferenceSource = fullIndex ? fetchDartLibReferenceSource() : []
const pythonLibReferenceSource = fullIndex ? fetchPythonLibReferenceSource() : []
const cSharpLibReferenceSource = fullIndex ? fetchCSharpLibReferenceSource() : []
const swiftLibReferenceSource = fullIndex ? fetchSwiftLibReferenceSource() : []
const ktLibReferenceSource = fullIndex ? fetchKtLibReferenceSource() : []
const cliReferenceSource = fullIndex ? fetchCliLibReferenceSource() : []
const partnerIntegrationSources = fullIndex
? fetchPartners()
.then((partners) =>
partners
? Promise.all(
partners.map((partner) => new IntegrationLoader(partner.slug, partner).load())
)
: []
)
.then((data) => data.flat())
: []
// Load troubleshooting articles from local MDX files
const troubleshootingSources = fetchTroubleshootingSources()
.then((loaders) => Promise.all(loaders.map((loader) => loader.load())))
.then((data) => data.flat())
// Type assertion required because ReferenceLoader.load() returns Promise<BaseSource[]>
// which widens the inferred union type. All concrete sources in this array are valid
// SearchSource types (MarkdownSource, OpenApiReferenceSource, etc.).
const sources = (
await Promise.all([
guideSources,
lintWarningsGuideSources,
openApiReferenceSource,
jsLibReferenceSource,
dartLibReferenceSource,
pythonLibReferenceSource,
cSharpLibReferenceSource,
swiftLibReferenceSource,
ktLibReferenceSource,
cliReferenceSource,
partnerIntegrationSources,
troubleshootingSources,
])
).flat() as SearchSource[]
return sources
}