mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Our current `search_v2` solution currently ignore reference pages, since they are not in markdown format. ## Solution Use the source model from _"search_v1"_ to ingest the `search_v2` table. <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions _Sadly, this cannot be tested until re-ingestion happens on our CI._ But here are some local tests... <img width="666" height="278" alt="Screenshot 2026-10-28 at 16 59 45" src="https://github.com/user-attachments/assets/9be67cb7-2598-42ce-86f7-3947e607588d" /> <img width="725" height="269" alt="Screenshot 2026-10-28 at 16 58 38" src="https://github.com/user-attachments/assets/30a74c41-5a2e-48f8-8c82-24b40c80e738" /> --- Funny enough, with the same legacy source model, results are better since this search ranks up the JavaScript method correctly, which our current search doesn't. <img width="713" height="640" alt="Screenshot 2026-10-28 at 16 56 59" src="https://github.com/user-attachments/assets/e658ac24-7752-4e7b-baa4-b7fdca89de94" /> ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
187 lines
6.2 KiB
TypeScript
187 lines
6.2 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import {
|
|
ClientLibReferenceSource,
|
|
CliReferenceSource,
|
|
OpenApiReferenceSource,
|
|
} from '../search/sources/reference-doc'
|
|
import {
|
|
buildReferenceRows,
|
|
cleanMethodName,
|
|
splitIdentifier,
|
|
toSectionRow,
|
|
type Reference,
|
|
} from './reference-pages'
|
|
|
|
// the generated data is not in the repo: the sections each page renders are fixtures
|
|
vi.mock('../../features/docs/Reference.generated.singleton.js', () => ({
|
|
getApiEndpointById: vi.fn(),
|
|
getFlattenedSections: vi.fn(),
|
|
}))
|
|
const singleton = vi.mocked(await import('../../features/docs/Reference.generated.singleton.js'))
|
|
|
|
const csharp = { id: 'csharp', version: 'v8', title: 'C# Reference' }
|
|
|
|
const csharpSignUp = new ClientLibReferenceSource(
|
|
'csharp-lib',
|
|
'/reference/csharp/auth-signup',
|
|
{
|
|
id: 'sign-up',
|
|
type: 'function',
|
|
title: 'Create a new user',
|
|
slug: 'auth-signup',
|
|
product: 'auth',
|
|
},
|
|
{ id: 'sign-up', $ref: '', title: 'SignUp()', description: 'Creates a new user.' },
|
|
{ title: 'C# Reference' }
|
|
)
|
|
|
|
describe('splitIdentifier', () => {
|
|
it('splits camelCase, snake_case and dotted names into words', () => {
|
|
expect(splitIdentifier('signInWithPassword')).toBe('sign In With Password')
|
|
expect(splitIdentifier('sign_in_with_password')).toBe('sign in with password')
|
|
expect(splitIdentifier('Operator.Equals')).toBe('Operator Equals')
|
|
})
|
|
})
|
|
|
|
describe('cleanMethodName', () => {
|
|
it('keeps the method, drops the signature and the label', () => {
|
|
expect(cleanMethodName('SignUp()')).toBe('SignUp')
|
|
expect(cleanMethodName('SignIn(email, password)')).toBe('SignIn')
|
|
expect(cleanMethodName('Fetch data: select()')).toBe('select')
|
|
expect(cleanMethodName('from_.upload()')).toBe('from_.upload')
|
|
expect(cleanMethodName('Using Filters')).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('toSectionRow', () => {
|
|
it('names legacy SDK sections after the method, titled for humans', () => {
|
|
expect(toSectionRow({ ...csharp, load: vi.fn() }, csharpSignUp)).toMatchObject({
|
|
slug: 'reference/csharp/auth-signup',
|
|
page_title: 'SignUp',
|
|
heading: 'SignUp Create a new user',
|
|
heading_level: 1,
|
|
heading_path: ['C# Reference', 'SignUp'],
|
|
excerpt: 'Create a new user',
|
|
})
|
|
})
|
|
|
|
it('names new pipeline sections after their title, the method', () => {
|
|
const source = new ClientLibReferenceSource(
|
|
'js-lib',
|
|
'/reference/javascript/auth-getclaims',
|
|
{
|
|
id: 'auth-getclaims',
|
|
type: 'function',
|
|
title: 'getClaims',
|
|
slug: 'auth-getclaims',
|
|
product: 'auth',
|
|
},
|
|
{
|
|
id: 'auth-getclaims',
|
|
$ref: '',
|
|
title: '',
|
|
description: 'Extracts the JWT claims. Verifies the [JWT](/docs/guides/auth/jwts) first.',
|
|
},
|
|
{ title: 'JavaScript Reference' }
|
|
)
|
|
const reference = { id: 'javascript', version: 'v2', title: 'JavaScript Reference' }
|
|
const row = toSectionRow({ ...reference, load: vi.fn() }, source)
|
|
|
|
expect(row).toMatchObject({ page_title: 'getClaims', heading: 'getClaims' })
|
|
expect(row.excerpt).toBe('Extracts the JWT claims.')
|
|
expect(row.content).toContain('get Claims')
|
|
expect(row.content).toContain('Verifies the JWT first.')
|
|
})
|
|
|
|
it('names CLI sections after the command', () => {
|
|
const source = new CliReferenceSource(
|
|
'cli',
|
|
'/reference/cli/supabase-db-push',
|
|
{
|
|
id: 'supabase-db-push',
|
|
type: 'cli-command',
|
|
title: 'Push migration to remote database',
|
|
slug: 'supabase-db-push',
|
|
},
|
|
{
|
|
id: 'supabase-db-push',
|
|
title: 'supabase db push',
|
|
summary: 'Push new migrations to the remote database',
|
|
} as never,
|
|
{ title: 'CLI Reference' }
|
|
)
|
|
const reference = { id: 'cli', version: 'latest', title: 'CLI Reference' }
|
|
|
|
expect(toSectionRow({ ...reference, load: vi.fn() }, source)).toMatchObject({
|
|
page_title: 'supabase db push',
|
|
heading: 'supabase db push Push migration to remote database',
|
|
excerpt: 'Push migration to remote database',
|
|
})
|
|
})
|
|
|
|
it('describes Management API sections by their endpoint', () => {
|
|
const source = new OpenApiReferenceSource(
|
|
'api',
|
|
'/reference/api/v1-list-all-projects',
|
|
{
|
|
id: 'v1-list-all-projects',
|
|
type: 'operation',
|
|
title: 'List all projects',
|
|
slug: 'v1-list-all-projects',
|
|
},
|
|
{ operation: 'get', path: '/v1/projects', description: 'Returns a list of all projects.' },
|
|
{ title: 'Management API Reference' }
|
|
)
|
|
const reference = { id: 'api', version: 'latest', title: 'Management API Reference' }
|
|
|
|
expect(toSectionRow({ ...reference, load: vi.fn() }, source)).toMatchObject({
|
|
page_title: 'List all projects',
|
|
heading: 'List all projects',
|
|
excerpt: 'GET /v1/projects: Returns a list of all projects.',
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('buildReferenceRows', () => {
|
|
it('adds the page and keeps one row per section the page renders', async () => {
|
|
const mfaEnroll = new ClientLibReferenceSource(
|
|
'csharp-lib',
|
|
'/reference/csharp/auth-mfa-enroll',
|
|
{
|
|
id: 'mfa-enroll',
|
|
type: 'function',
|
|
title: 'Enroll a factor',
|
|
slug: 'auth-mfa-enroll',
|
|
product: 'auth',
|
|
},
|
|
{ id: 'mfa-enroll', $ref: '', title: 'Enroll()', description: '' },
|
|
{ title: 'C# Reference' }
|
|
)
|
|
singleton.getFlattenedSections.mockResolvedValue([
|
|
{ id: 'introduction', type: 'markdown', slug: 'introduction' },
|
|
{ id: 'sign-up', type: 'function', slug: 'auth-signup' },
|
|
])
|
|
const reference: Reference = {
|
|
...csharp,
|
|
load: async () => [csharpSignUp, csharpSignUp, mfaEnroll],
|
|
}
|
|
|
|
const rows = await buildReferenceRows(reference)
|
|
|
|
expect(rows.map((row) => row.slug)).toEqual([
|
|
'reference/csharp',
|
|
'reference/csharp/auth-signup',
|
|
])
|
|
expect(rows[0]).toMatchObject({ page_title: 'C# Reference', heading_path: ['C# Reference'] })
|
|
expect(rows[0].excerpt).toMatch(/^This reference documents every object and method/)
|
|
})
|
|
|
|
it('fails when the generated data is missing', async () => {
|
|
singleton.getFlattenedSections.mockResolvedValue([])
|
|
await expect(
|
|
buildReferenceRows({ ...csharp, load: async () => [csharpSignUp] })
|
|
).rejects.toThrow('codegen:references')
|
|
})
|
|
})
|