sdk / typegen
CLAUDE.md52 starsChanged 8 days agoMITView on GitHub
The language registry for supabase gen types --lang <language>. It exports languages, a list of TypegenLanguage entries mapping a --lang name to the generator that renders it, so new languages need a pull request here and a dependency bump in the CLI, never CLI code. See SDK-1955 for the decision and SDK-1956 for the CLI adapter that replaces the CLI's hardcoded switch. Introspection is NOT implemented here: the consumer calls introspect() and passes the GeneratorMetadata in. introspect, Queryable, IntrospectOptions, GeneratorMetadata…
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- packages/postgrest-typegen/CLAUDE.mdCLAUDE.md
- capability-matrixSkill
The file
We split this CLAUDE.md into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 79
Keep the dependency list minimal.
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md -- @supabase/typegen
What This Package Does
The language registry for supabase gen types --lang <language>. It exports
languages, a list of TypegenLanguage entries mapping a --lang name to the
generator that renders it, so new languages need a pull request here and a
dependency bump in the CLI, never CLI code. See SDK-1955 for the decision and
SDK-1956 for the CLI adapter that replaces the CLI's hardcoded switch.
Introspection is NOT implemented here: the consumer calls introspect() and
passes the GeneratorMetadata in. introspect, Queryable,
IntrospectOptions, GeneratorMetadata and GENERATOR_METADATA_VERSION are
re-exported from @supabase/postgrest-typegen so the CLI depends on this
package alone and cannot end up with two postgrest-typegen versions. The
contract's compatibility rule, how GENERATOR_METADATA_VERSION relates to the
package version and who reviews contract changes are in
packages/postgrest-typegen/README.md under "Contract compatibility". The
registry sits above postgrest-typegen and the future per-SDK generator
packages (SDK-1641) to avoid a dependency cycle once TypeScript's generator
lives in supabase-js.
Architecture
src/contract.ts-- the public contract with the CLI:Host(cwd, env, signal, optionalspawn, optionalformat),OptionSpec/OptionValues,TypegenLanguage. Changing these is a semver-relevant change for the CLI.src/errors.ts--TypegenErrorand its subclasses (InvalidOptionError,SpawnUnavailableError,ToolNotInstalledError,ToolFailedError,MetadataRejectedError). The CLI maps these to its actionability model generically; keep the fields stable.src/options.ts--resolveOptions: defaults plus validation, run at the start of everygenerate.src/languages/in-process.ts--inProcessLanguage: wraps a generator function; sorts the metadata first.src/languages/external.ts--externalLanguage: runs a command in the host'scwdwithserializeGeneratorMetadata(sortGeneratorMetadata(m))on stdin, returns stdout, classifies failures through the entry'sclassify.src/languages/dart.ts-- the first out-of-process entry:dart run supabase_typegen --output -. No--schemaflag: the document on stdin already holds the schemas the consumer introspected.src/languages/swift.ts--supabase-typegen --access-control <level>, a prebuilt binary from supabase-swift's releases (SDK-2199). It downloads the release the nearestPackage.resolvedpins into the user cache, then falls back to PATH;SUPABASE_TYPEGENoverrides both. The only entry that touches the network or the file system;createSwifttakesfetchand the platform so tests stay offline.swift-access-controlmaps to--access-controland accepts onlyinternalandpublic. Exit65is a rejected document.src/languages/index.ts-- the three in-process entries and thelanguageslist.typescripthas no user options;detect-one-to-one-relationships(default true; the CLI's deprecated--postgrest-v9-compatsets it false),postgrest-versionanddefault-schemaare consumer options that the CLI and postgres-meta's hosted route set from what they know about the target. It honorshost.format.src/node-host.ts--createNodeHost, aHostonnode:child_process, plus the exported Windows pieces (resolveWindowsCommand,isWindowsScript,quoteForCmd,planSpawn) the Supabase CLI's own host reuses so both hosts start a.batthrough cmd.exe with the same command line.
Invariants
- User option
names are the CLI flag names verbatim (swift-access-control).audience: "user"options are flags;"consumer"options are set by the calling program and never rendered.--postgrest-v9-compatstopped being a registry option on purpose: it targets PostgREST 9 (2022) and only ever worked with--db-url, so the CLI adapter keeps it as a deprecated alias. generatealways sorts before generating and returns complete file contents for every language. The bundled generators end their output with a single newline and in-process entries pass it on verbatim, adding a newline only when aHost.formatimplementation dropped it; out-of-process entries return the tool's stdout verbatim. The CLI writes the result as-is.- In-process TypeScript formats through
host.formatwhen given. The CLI passes identity to keepoxfmtout of its bundle and its output unchanged. - Out-of-process tools: stdout is code, stderr is diagnostics, exit 0 is
success.
dart runkeeps stdout clean when it is not a terminal. inProcessmust be accurate: hosted consumers (postgres-meta) filter on it.- Keep the dependency list minimal; everything here lands in the CLI bundle.
@supabase/postgrest-typegenis pinned exactly, not a caret range: the registry promises consumers one postgrest-typegen version for introspection and generation alike. TheRelease postgrest-typegenworkflow opens a typegen release pull request that bumps the pin after each release; dependabot ignores this dependency.
Commands
bun run test # bun:test with a fake host; the node-host test spawns a shell script
bun run check-types
bun run check-types:consumer # tsc --project tsconfig.consumer.json
bun run format-and-lint
bun run knip
bun run build # tsc --project tsconfig.build.json, emits dist/check-types:consumer compiles src/ with @tsconfig/bun plus
customConditions: ["bun"], which is how the Supabase CLI type-checks this
package and, through it, @supabase/postgrest-typegen: both packages' bun
exports conditions hand the CLI src/*.ts rather than dist/*.d.ts, so the
pinned postgrest-typegen source must also pass stricter flags such as
noUncheckedIndexedAccess. A pin bump that fails this check must wait for a
postgrest-typegen fix.
Tests
test/fixtures.ts holds a deliberately unsorted GeneratorMetadata validated
with parseGeneratorMetadata. test/in-process.test.ts asserts each bundled
language's output equals the direct generator call on sorted input (the
byte-identity acceptance criterion, without Docker). test/dart.test.ts and test/swift.test.ts
cover the handoff and every error classification with the fake host from
test/helpers.ts; test/node-host.test.ts runs a fake dart shell script
on PATH.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

