Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .agents/skills/api-types/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: api-types
description: Maintain Supabase API types. Use when changing generated API type declarations, OpenAPI schemas, or investigating API type deployment drift.
---

# API types

The generated API contract has three specs: API v1, API v2, and Platform. Their committed outputs are `packages/api-types/types/api-v1.d.ts`, `packages/api-types/types/api-v2.d.ts`, and `packages/api-types/types/platform.d.ts`.

## Update types

1. Make the API/schema change and ensure it is deployed to production before relying on a type PR. Production is the merge-gate source of truth.
2. Run `pnpm api:codegen` against a running local API environment. It fetches all three local OpenAPI specs and updates the committed files.
3. Inspect and commit only the intended generated type changes.
4. Run `pnpm api:verify-types`. It fetches the three production OpenAPI specs, regenerates types with the repository tooling, and compares them with the committed files.

Complete the update only when `pnpm api:verify-types` passes after the production deployment is available.

## Interpret verification

- A pass means the committed generated declarations match all three production specs at the time of the check.
- A mismatch means production and the committed files differ. If the API is not deployed, deploy it and rerun the check. If production is correct, regenerate and review the changed files.
- A fetch failure means the production schema endpoint could not be read; fix or retry the endpoint before treating the result as a type mismatch.

## Pull requests

The `Verify production API types` CI job runs when `packages/api-types/types/**` changes and performs the same production comparison. It is currently observational, not a required merge check. The `api-deploy-required` label is informational only. Still run the local verifier before requesting review and treat a failed CI verification as production drift that must be resolved.
2 changes: 1 addition & 1 deletion .github/workflows/label_prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: 'The `api-deploy-required` label was auto-applied to this PR because it updates the API types. Ensure that the new or updated API, if any, is deployed on production before **removing the label** and merging this PR.',
body: 'The `api-deploy-required` label was auto-applied to this PR because it updates the API types. The `Verify production API types` check reports whether the committed types match production; it is currently observational and does not block merging.',
})
6 changes: 0 additions & 6 deletions .github/workflows/validate-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ jobs:
echo "PR blocked: [tag: do not merge]"
exit 1

- name: Tagged with 'api-deploy-required'
if: contains( github.event.pull_request.labels.*.name, 'api-deploy-required')
run: |
echo "PR blocked: [tag: api-deploy-required] — confirm the API is deployed in production, then remove the label."
exit 1

- name: All good
if: ${{ success() }}
run: |
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/verify-production-api-types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Verify production API types

on:
pull_request:
types: [opened, reopened, synchronize]

permissions:
contents: read
pull-requests: read

jobs:
verify-production-api-types:
runs-on: ubuntu-latest
steps:
- id: changes
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" --paginate --jq '.[].filename' | grep -q '^packages/api-types/types/'; then
echo "api_types_changed=true" >> "$GITHUB_OUTPUT"
else
echo "api_types_changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Check out pull request
if: steps.changes.outputs.api_types_changed == 'true'
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
persist-credentials: false

- name: Install pnpm
if: steps.changes.outputs.api_types_changed == 'true'
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271
with:
run_install: false

- name: Set up Node.js
if: steps.changes.outputs.api_types_changed == 'true'
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version-file: '.nvmrc'
cache: pnpm

- name: Install API types dependencies
if: steps.changes.outputs.api_types_changed == 'true'
run: pnpm install --frozen-lockfile --filter=api-types...

- name: Verify production API types
if: steps.changes.outputs.api_types_changed == 'true'
run: pnpm --filter=api-types run verify-production-types
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ tmp
*.swp

coverage
# vitest reporter output (json/junit/html/attachments)
.vitest
allure-results
allure-report
.nyc_output
Expand Down
1 change: 0 additions & 1 deletion apps/docs/app/api/graphql/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('/api/graphql POST basic error statuses', () => {
})

beforeEach(() => {
vi.clearAllMocks()
vi.spyOn(console, 'error').mockImplementation(() => {})
})

Expand Down
1 change: 0 additions & 1 deletion apps/docs/app/api/revalidate/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ describe('_handleRevalidateRequest', () => {

afterEach(() => {
process.env = originalEnv
vi.clearAllMocks()
vi.useRealTimers()
})

Expand Down
6 changes: 1 addition & 5 deletions apps/docs/app/api/search/embeddings/route.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest } from 'next/server'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { describe, expect, it, vi } from 'vitest'

import { POST } from './route'

Expand All @@ -19,10 +19,6 @@ function makeRequest(body: unknown) {
}

describe('/api/search/embeddings', () => {
afterEach(() => {
vi.clearAllMocks()
})

it('returns 400 when query is missing', async () => {
const response = await POST(makeRequest({}))
expect(response.status).toBe(400)
Expand Down
6 changes: 1 addition & 5 deletions apps/docs/app/api/search/fts/route.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest } from 'next/server'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { describe, expect, it, vi } from 'vitest'

import { POST } from './route'

Expand All @@ -21,10 +21,6 @@ function makeRequest(body: unknown) {
}

describe('/api/search/fts', () => {
afterEach(() => {
vi.clearAllMocks()
})

it('returns 400 when query is missing', async () => {
const response = await POST(makeRequest({}))
expect(response.status).toBe(400)
Expand Down
16 changes: 8 additions & 8 deletions apps/docs/content/guides/database/prisma.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t
yarn add prisma tsx @types/pg --save-dev
yarn add @prisma/client @prisma/adapter-pg dotenv pg

npx tsc --init
yarn tsc --init

npx prisma init
yarn prisma init
```
</TabPanel>
<TabPanel id="bun_initiate" label="bun">
Expand Down Expand Up @@ -285,8 +285,8 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t
</TabPanel>
<TabPanel id="yarn_migrate" label="yarn">
```bash
npx prisma migrate dev --name first_prisma_migration
npx prisma generate
yarn prisma migrate dev --name first_prisma_migration
yarn prisma generate
```
</TabPanel>
<TabPanel id="bun_migrate" label="bun">
Expand Down Expand Up @@ -368,7 +368,7 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t

<TabPanel id="yarn_sync" label="yarn">
```bash
npx prisma db pull
yarn prisma db pull
```

Create a migration file
Expand All @@ -378,7 +378,7 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t

Synchronize the migrations
```bash
npx prisma migrate diff \
yarn prisma migrate diff \
--from-empty \
--to-schema prisma/schema.prisma \
--script > prisma/migrations/0_init_supabase/migration.sql
Expand All @@ -390,8 +390,8 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t
</Admonition>

```bash
npx prisma migrate resolve --applied 0_init_supabase
npx prisma generate
yarn prisma migrate resolve --applied 0_init_supabase
yarn prisma generate
```
</TabPanel>

Expand Down
6 changes: 1 addition & 5 deletions apps/docs/features/directives/Show.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mdxToMarkdown } from 'mdast-util-mdx'
import { toMarkdown } from 'mdast-util-to-markdown'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'

import { type Feature } from 'common'
import { showRemark } from './Show'
Expand All @@ -14,10 +14,6 @@ vi.mock('common/enabled-features', () => ({
const { isFeatureEnabled } = await import('common/enabled-features')

describe('$Show', () => {
beforeEach(() => {
vi.clearAllMocks()
})

afterEach(() => {
vi.restoreAllMocks()
})
Expand Down
7 changes: 5 additions & 2 deletions apps/docs/features/docs/Reference.mdx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ const getRefMarkdown = cache_fullProcess_withDevCacheBust(

interface MDXRemoteRefsProps {
source: string
codeBlockProps?: Partial<ComponentProps<typeof CodeBlock>>
}

function MDXRemoteRefs({ source }: MDXRemoteRefsProps) {
function MDXRemoteRefs({ source, codeBlockProps }: MDXRemoteRefsProps) {
const refComponents = {
...components,
// Override the CodeBlock used for normal guides to skip type generation
// because it is too resource-intensive
pre: (props: ComponentProps<typeof CodeBlock>) => <CodeBlock {...props} skipTypeGeneration />,
pre: (props: ComponentProps<typeof CodeBlock>) => (
<CodeBlock {...props} {...codeBlockProps} skipTypeGeneration />
),
RefSubLayout,
CliGlobalFlagsHandler,
}
Expand Down
10 changes: 9 additions & 1 deletion apps/docs/features/docs/Reference.sections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,15 @@ async function FunctionSection({
</TabsList>
{examples.map((example) => (
<TabsContent key={example.id} value={example.id}>
<MDXRemoteRefs source={example.code} />
<div
className={cn(
'prose wrap-break-word max-w-none',
'[&_.shiki]:!my-0 [&_.shiki:not(:last-child)]:!mb-4',
'[&_p]:!whitespace-normal'
)}
>
<MDXRemoteRefs source={example.code} />
</div>
<div className="flex flex-col gap-2 mt-2">
{'data' in example && !!example.data?.sql && (
<CollapsibleDetails title="Data source" content={example.data.sql} />
Expand Down
54 changes: 40 additions & 14 deletions apps/docs/features/docs/Reference.ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ReferenceSectionWrapper } from '~/features/docs/Reference.ui.client'
import { normalizeMarkdown } from '~/features/docs/Reference.utils'
import { isEqual } from 'lodash-es'
import { ChevronRight, XCircle } from 'lucide-react'
import { fromMarkdown } from 'mdast-util-from-markdown'
import type { HTMLAttributes, PropsWithChildren } from 'react'
import ReactMarkdown from 'react-markdown'
import { Badge, cn, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui'
Expand Down Expand Up @@ -115,32 +116,57 @@ export function StickyHeader({ title, monoFont = false, className }: StickyHeade
}

export function CollapsibleDetails({ title, content }: { title: string; content: string }) {
const blocks = fromMarkdown(content).children
const isCodeOnly = blocks.length === 1 && blocks[0].type === 'code'

return (
<Collapsible>
<Collapsible
className={cn(
'overflow-hidden',
'border border-default rounded-lg bg-surface-100',
'has-[:focus-visible]:outline-solid has-[:focus-visible]:outline-2',
'has-[:focus-visible]:outline-offset-[-2px] has-[:focus-visible]:outline-[var(--ring)]'
)}
>
<CollapsibleTrigger
className={cn(
'group',
'w-full h-8',
'border bg-surface-100 rounded-sm',
'px-5',
'flex items-center gap-3',
'group/trigger',
'w-full min-h-8',
'px-2 py-1.5',
'flex items-center gap-2',
'text-xs text-foreground-light',
'data-open:bg-surface-200',
'data-open:rounded-b-none data-open:border-b-0',
'transition motion-reduce:duration-1 ease-out'
'cursor-pointer hover:bg-surface-200 hover:text-foreground',
'focus-visible:outline-none',
'transition-[background-color,color] duration-150 ease-out'
)}
>
<ChevronRight size={12} className="group-data-open:rotate-90 transition-transform" />
{title}
<ChevronRight
size={12}
strokeWidth={2}
aria-hidden
className="ms-auto shrink-0 text-foreground-muted group-data-open/trigger:rotate-90 transition-transform duration-200 ease-out motion-reduce:transition-none"
/>
</CollapsibleTrigger>
<CollapsibleContent
className={cn(
'border border-default bg-surface-100 rounded-b',
'px-5 py-2',
'prose max-w-none text-sm'
'overflow-hidden',
'data-open:animate-collapsible-down data-closed:animate-collapsible-up',
'motion-reduce:animate-none'
)}
>
<MDXRemoteRefs source={content} />
<div
className={cn(
'border-t border-default',
'prose max-w-none text-sm',
!isCodeOnly && 'px-4 py-3 [&_:where(p,li)]:text-sm [&_:where(p,li)]:leading-6'
)}
>
<MDXRemoteRefs
source={content}
codeBlockProps={isCodeOnly ? { compact: true } : undefined}
/>
</div>
</CollapsibleContent>
</Collapsible>
)
Expand Down
9 changes: 6 additions & 3 deletions apps/docs/features/ui/CodeBlock/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export async function CodeBlock({
children,
skipTypeGeneration,
hideControls = false,
compact = false,
}: PropsWithChildren<{
className?: string
lang?: string
lineNumbers?: boolean
contents?: string
skipTypeGeneration?: boolean
hideControls?: boolean
compact?: boolean
}>) {
let code = (contents || extractCode(children)).trim()
const lang = tryToBundledLanguage(langSetting || '') || extractLang(children)
Expand Down Expand Up @@ -63,16 +65,17 @@ export async function CodeBlock({
'relative',
'not-prose',
'w-full',
'border border-default rounded-lg',
'bg-200 shadow-codeblock',
compact ? 'border-0 my-0!' : 'border border-default rounded-lg shadow-codeblock',
'bg-200',
'text-sm',
className
)}
>
<div
className={cn(
'code-scroll',
'w-full overflow-x-auto overscroll-x-none rounded-lg',
'w-full overflow-x-auto overscroll-x-none',
!compact && 'rounded-lg',
'focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring'
)}
role="group"
Expand Down
1 change: 0 additions & 1 deletion apps/docs/lib/custom-content/getCustomContent.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'

beforeEach(() => {
vi.clearAllMocks()
vi.resetModules()
})

Expand Down
Loading
Loading