Repository navigation
tml-2834: extension-supabase M1 — package (/pack + PSL contract) + examples/supabase walking skeleton - #746
Conversation
Shape the M1 slice of the Supabase integration (TML-2834): scaffold @prisma-next/extension-supabase (/pack + PSL contract + stub /runtime) and the examples/supabase walking skeleton. The skeleton proves the framework handles the external Supabase contract correctly — the planner emits no DDL for the auth.*/storage.* tables and the verifier confirms they exist — while the app's own public schema migrates and round-trips on the stock Postgres runtime. - slice spec + 7-dispatch plan under projects/extension-supabase/slices/ - defer /contract typed handles + roles to cross-contract-refs / postgres-rls (they reinvent contract access; likely the wrong abstraction) - split bootstrapSupabaseShim: M1 ships the schemas+tables increment (the verifier fails on a missing external table); roles + auth.*() functions defer - update umbrella decisions C13/C14 and the project plan M1 section to match Refs: TML-2834 Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Stand up packages/3-extensions/supabase/ with the full build config
(package.json, tsdown, tsconfigs, biome, prisma-next.config) modelled on
pgvector. Exports ./pack (compiling placeholder stub for D3) and ./runtime
(M2 stub). Wires prismaContract('src/contract/contract.prisma',
{ target: postgres, defaultControlPolicy: 'external' }) in
prisma-next.config.ts. Registers the package in architecture.config.json
so pnpm lint:deps is green.
All D1 gates pass: build, typecheck, lint (--error-on-warnings), lint:deps.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Author src/contract/contract.prisma with auth (AuthUser, AuthIdentity) and storage (StorageBucket, StorageObject) namespaces, using named types for the uuid/timestamptz column types. HALT: contract emit fails because assertSingleDomainNamespaceForEmission throws for multi-namespace contracts (TML-2550). The contract.d.ts emitter supports only a single domain namespace. Both contract.json and contract.d.ts cannot be produced until the emitter is extended or the assertion is relaxed for extension packs. PSL parsing and JSON canonicalization succeed; only .d.ts generation throws. Unblocking this requires either extending the emitter to handle multi-namespace .d.ts or deciding extension packs skip .d.ts. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
… first-name-wins) Interim unblock for the Supabase extension contract, which declares two domain namespaces (auth + storage). The old assertSingleDomainNamespaceForEmission guard threw rather than silently dropping namespaces; now we flatten all namespace models into the emitted d.ts type map with first-bare-name-wins semantics (matching the documented ORM flatten behaviour). Single-namespace output is byte-identical — confirmed by pnpm fixtures:check showing zero drift across all committed contract.json / contract.d.ts fixtures. The proper per-namespace d.ts redesign remains explicit-namespace-dsl's job. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Runs prisma-next contract emit against the two-namespace Supabase PSL (auth + storage). Produces contract.json and contract.d.ts in src/contract/. The contract carries target: postgres, both namespaces with their four models (AuthUser, AuthIdentity, StorageBucket, StorageObject), defaultControlPolicy: 'external', and no roles block. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
….ts emission
Round-1 must-fix: `domainNamespacesType` in `generate-contract-dts.ts` was
emitting only `readonly <ns>: { readonly models: … }` per namespace, dropping
the `readonly valueObjects: …` block that the pre-503f7f334 single-namespace
template emitted when a namespace had value objects. This broke the stated
"single-namespace byte-identical" property for any contract carrying value
objects (sql-orm-client, retail-store, mongo-demo, mongo-blog-leaderboard).
Fix: compute a per-namespace `generateValueObjectsDescriptorType` alongside
the per-namespace `modelsType` and include `readonly valueObjects: …` in each
namespace block where the namespace has value objects — exactly matching the
prior single-namespace shape. The flattened top-level `valueObjects` map is
unchanged. Re-emitting the sql-orm-client fixture confirms zero git diff;
`fixtures:check` exits 0 (all re-emitted fixtures byte-identical).
Round-1 should-fix: add two tests to lock in the undercovered behaviours:
(a) first-name-wins collision semantics in the flattened top-level models map
when two namespaces share the same bare model name;
(b) per-namespace `valueObjects` block is present when a single namespace
declares value objects — this case would have caught the must-fix at unit
level before CI.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Replace the D1 placeholder with the real SqlControlExtensionDescriptor. supabasePack carries the emitted contract.json (imported as a value) in a ContractSpace with no migrations and headRef.hash = the contract's storageHash. supabasePackWith(options) replaces contractJson when a contractOverride is provided (for test use). The contractSpace is built inline without contractSpaceFromJson to avoid a shared-plane → migration-plane dep violation (lint:deps enforces shared cannot import migration). All type coercions use blindCast from @prisma-next/utils/casts (added as a dep). Gates: - build: pack.mjs 1.95 KB gzip (< 5 KB budget) - typecheck + tsc -p tsconfig.test.json: clean - lint (biome --error-on-warnings): clean - lint:deps: 1030 modules, no violations - fixtures:check: exit 0 Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Creates examples/supabase as a private workspace package
(@prisma-next/example-supabase). The app:
- Declares a PSL contract with Profile { id, username } in the public
namespace (src/contract.prisma), emitted to src/contract.json and
src/contract.d.ts.
- Wires the Supabase extension pack via extensionPacks: [supabasePack]
in prisma-next.config.ts. The emitted contract.json records the pack
as extensionPacks.supabase; the auth/storage namespaces live in the
pack's own contract space and do not appear in the app's domain.
- Builds the runtime client on the stock @prisma-next/postgres/runtime
(no extensions array — the pack composes at authoring time only).
- Provides one handler (insertAndReadProfile) that inserts a Profile
row and reads it back; this is the skeleton's public.profile walk.
All gates green: pnpm emit, pnpm typecheck, pnpm lint:deps, pnpm
fixtures:check.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… (D5) Adds examples/supabase/test/supabase-bootstrap.ts, the first increment of the shared Supabase test fixture. Seeds a Postgres/PGlite database with: - CREATE SCHEMA auth, storage - auth.users, auth.identities, storage.buckets, storage.objects Columns match the extension-supabase contract exactly so the framework verifier passes when a composed contract declares those tables as `external`. No roles and no auth.uid()/jwt()/role() functions — those are the postgres-rls increment. Location rationale: examples/supabase/test/ is the canonical home because all future constituents (cross-contract-refs, postgres-rls, explicit-namespace-dsl) grow the same example and its test directory. D6's test imports the shim via a local relative path; test/integration tests that need it can mirror the SQL. Gates: pnpm typecheck (example-supabase), biome lint, pnpm lint:deps all clean. Smoke: bootstrapSupabaseShim DDL runs against a PGlite DB; SELECT from auth.users returns 0 rows with all four tables present. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…gration + minimal /runtime descriptor (D5.5) Two framework-forced changes discovered at D6, both verified against the pgvector pattern: 1. The migration aggregate loader reads extension spaces from on-disk migrations/<space>/ — it needs at least one migration package to build a graph with a reachable head ref. The supabase pack now ships a zero-ops baseline migration (from=null → storageHash) that establishes the head ref without emitting any DDL. The auth.*/storage.* tables are external (Supabase-managed); this migration only records that the contract space has been "installed". 2. The stock postgres runtime checks that every extensionPacks entry in the emitted contract.json has a matching runtime component. A `never` stub export fails this check. /runtime is now a minimal SqlRuntimeExtensionDescriptor (no codecs, no ops) — just enough to pass the component-requirements check. This is NOT the real SupabaseRuntime (role-binding, asUser/asAnon) — that stays M2. Also: the regen-extension-migrations script is updated to support extensions with PSL-authored contracts at src/contract/contract.json (vs TypeScript-authored ones at src/contract.json directly). Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…(D6)
Walking skeleton integration test that proves the core M1 claim:
when a composed contract declares extensionPacks: [supabasePack], the
framework treats auth.* / storage.* tables as external — no DDL emitted
for them, verifier confirms they exist, and public.profile migrates and
round-trips normally.
Test flow:
1. Start PGlite; seed external tables via bootstrapSupabaseShim.
2. Materialise the supabase extension space on disk — emitContractSpaceArtefacts
(contract.json + refs/head.json) and materialiseMigrationPackage for the
zero-ops baseline migration so the aggregate loader can walk the graph.
3. Run db init (plan mode first): asserts plan has CREATE TABLE for
public.profile and zero ops targeting auth.* / storage.*.
4. Run db init (apply mode): applies the plan.
5. Run db verify: asserts all space schema results pass.
6. Run handler's public.profile insert + read-back; asserts the row.
7. Raw SQL confirms auth.users is reachable in the seeded DB.
Committed describe.skip because of a framework gap (surfaced to operator):
executeRun and executeDbVerify call familyInstance.introspect({ driver })
without passing a contract, so the Postgres adapter only introspects the
public schema. The supabase extension space declares tables in auth and
storage schemas — those are never read, so db verify reports them as
"missing" even when bootstrapSupabaseShim has seeded them.
Fix needed in packages/1-framework/3-tooling/cli/src/control-api/operations/
db-run.ts (~line 160) and db-verify.ts: pass the aggregate contracts to
familyInstance.introspect so the Postgres adapter walks all declared
namespaces. This is a second framework change; operator must approve before
proceeding. Test ungates at M3 once both the introspect fix and the full
example are green end-to-end.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
- projects/extension-supabase/trace.jsonl: Drive build-loop trace (44 events, 7 dispatches / 9 rounds; verify.ts --allow-open integrity-OK). Early events were back-filled after I wrongly skipped live emission — the drive-record-traces emitter works fine from inside the repo tree (the global-path arktype error was ESM resolution, not a real blocker). Live emission from here on. - spec.md: record the D1.5 emitter relax (Contract-impact) and the D6-discovered, framework-forced refinements — the pack ships a zero-ops baseline migration and /runtime is a minimal descriptor (both match the pgvector pattern). Refs: TML-2834 Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ti-namespace contracts)
`executeRun` (db init/update) and `executeDbVerify` called
`familyInstance.introspect({ driver })` without a contract, so the
Postgres adapter fell back to introspecting only the `public` schema.
This was correct for single-namespace contracts but wrong for composed
contracts that declare tables in additional schemas (e.g. the Supabase
extension's `auth` and `storage` namespaces).
Fix: after `buildContractSpaceAggregate` resolves, build a merged
synthetic contract whose `storage.namespaces` key set is the union of
every namespace declared across all members (app + extensions), then
pass it to `familyInstance.introspect`. The Postgres adapter's
`extractContractNamespaceIds` reads only `contract.storage.namespaces`
keys — no other fields are consumed — so a structurally minimal object
is sufficient.
Single-namespace contracts are unchanged: when all members share only
`public` (or `__unbound__`), the merged contract has exactly one key
and the adapter takes the same `introspectSchema` path as before.
Operator-approved second framework change for the Supabase M1 skeleton.
Regression-tested: cli.control-policy.postgres, cli.db-verify.*,
cli.db-init.*, cli.db-update.* — all green.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…anaged, auth/storage external) Adds `packages/3-extensions/supabase/test/classification.e2e.test.ts`, an integration test that seeds a PGlite database with the Supabase `auth`/`storage` external tables and then runs `db init` + `db verify` through the control client API. Specific assertions: - `public.profile` is app-managed: the migration plan includes a `CREATE TABLE` op attributed to the app contract space. - The supabase extension space carries **zero** plan ops (all tables in `auth.*`/`storage.*` have `defaultControlPolicy: external` — the planner suppresses DDL for them). - `db verify` passes for every space: the verifier confirms the external tables are present in the database and does not flag them as missing or as DDL drift. - The supabase space schema-verify result has zero issues. Also adds `vitest.config.ts` for the extension package and wires in `@prisma-next/driver-postgres` as a dev dependency (needed by `createControlClient`). The seed SQL is inlined in the test (same shape as the Supabase extension contract); `bootstrapSupabaseShim` in `examples/supabase` remains unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Adds test/pack.resolution.test-d.ts — a type-level smoke test that proves
the /pack subpath resolves and typechecks independently of the example app.
Seven vitest type assertions cover:
- supabasePack extends ControlExtensionDescriptor<'sql', 'postgres'>
- supabasePack.kind / .familyId / .targetId are the expected literals
- supabasePackWith() and supabasePackWith({ contractOverride }) return the
same type as supabasePack
- [supabasePack] is assignable to ControlExtensionDescriptor<'sql','postgres'>[]
(the extensionPacks array element type in PrismaNextConfig)
All slice-DoD gates green:
- /pack gzip bundle: 2.25 kB (< 5 kB budget)
- pnpm --filter @prisma-next/extension-supabase build: pass
- pnpm --filter @prisma-next/extension-supabase typecheck: pass
(tsc -p tsconfig.test.json --noEmit: pass)
- pnpm --filter @prisma-next/extension-supabase lint: pass
- pnpm lint:deps: pass
- pnpm fixtures:check: pass
- pnpm --filter @prisma-next/extension-supabase test: pass
(1 classification e2e + 7 type assertions with --typecheck)
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…pabase-m1-scaffold-package-pack-psl-contract-and
…enerate baseline migration (D8) Merged origin/main (76 commits: TML-2836 migration-vocabulary rename + read-command JSON redesign; TML-2808 emitted-contract shape changes). Adapted our slice: - re-emit the Supabase pack contract + the examples/supabase app contract with the merged emitter (storageHash + emitted shape updated to current) - regenerate the pack's zero-ops baseline migration with the current migration vocabulary so it matches the ContractSpace type - classification e2e adjusted accordingly All five changed packages typecheck clean; supabase package tests (classification e2e + /pack smoke) green; lint:deps clean. Single-namespace contracts unaffected. Refs: TML-2834 Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a Supabase extension and examples, updates emitter to emit multi-namespace contract DTS, threads aggregate namespaces into CLI introspection, synthesizes head refs for migration-less extension spaces, and adds generated contract artifacts plus tests and fixtures. ChangesMulti-namespace and migration-less extensions framework
Supabase extension package
Supabase example
Repository and discovery wiring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (2)
packages/1-framework/3-tooling/cli/src/control-api/operations/db-run.ts (1)
276-310: ⚡ Quick winExtract duplicated
buildAggregateIntrospectContractto a shared module.This function is identical to the one in
db-verify.ts(lines 368-389). Consider extracting it to a shared location (e.g.,migration-helpers.tsor a newaggregate-introspect.tsmodule) to avoid duplication and ensure consistent behavior.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/1-framework/3-tooling/cli/src/control-api/operations/db-run.ts` around lines 276 - 310, The buildAggregateIntrospectContract function is duplicated; extract it into a single shared module (e.g., migration-helpers or aggregate-introspect) and export it, then replace the local definitions in both db-run.ts and db-verify.ts with an import of that exported function; ensure you keep the same signature (buildAggregateIntrospectContract(aggregate: ContractSpaceAggregate): Record<string, unknown>), preserve the try/catch and namespace merging behavior, and update any imports so callers use the new shared symbol.examples/supabase/test/skeleton.integration.test.ts (1)
62-63: ⚡ Quick winAvoid a hard
describe.skipfor the only E2E proof path.This permanently removes regression coverage for migrate/verify/runtime integration. Prefer env-gating so it can run in CI lanes when enabled.
Suggested change
-describe.skip('supabase walking skeleton — external-contract migrate/verify + public round-trip', () => { +const runSupabaseSkeleton = process.env.RUN_SUPABASE_SKELETON_E2E === '1'; +(runSupabaseSkeleton ? describe : describe.skip)( + 'supabase walking skeleton — external-contract migrate/verify + public round-trip', + () => { let database: Awaited<ReturnType<typeof createDevDatabase>>; let migrationsDir: string; @@ -}); + }, +);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/supabase/test/skeleton.integration.test.ts` around lines 62 - 63, The test suite currently disables the only E2E path by using describe.skip; change this to an environment-gated describe so the integration tests run when explicitly enabled (e.g., check process.env.RUN_SUPABASE_E2E or similar) instead of always skipping. Locate the describe.skip block (the suite name 'supabase walking skeleton — external-contract migrate/verify + public round-trip') and the associated createDevDatabase usage, wrap or replace describe.skip with a conditional that calls describe only when the env var is truthy and otherwise calls describe.skip (or uses a helper like describeIfIntegration), and document the required env var in test setup so CI jobs can opt-in.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/supabase/src/prisma/db.ts`:
- Line 3: Update the import path for the Contract type in the module that
currently reads "import type { Contract } from '../contract.d';"—remove the ".d"
suffix so it matches the repository convention (i.e., import type { Contract }
from '../contract'). Ensure the import statement in
examples/supabase/src/prisma/db.ts references '../contract' (extensionless) and
that any tooling/type resolution still picks up the Contract type.
In `@examples/supabase/tsconfig.json`:
- Line 2: Update the tsconfig "extends" entry to use the repo-standard base
reference: replace the string "`@prisma-next/tsconfig/base`" with
"prisma-next/tsconfig/base" in the examples/supabase tsconfig.json so the
"extends" array points to the monorepo's shared config.
In `@packages/1-framework/3-tooling/cli/src/control-api/operations/db-run.ts`:
- Line 296: Replace the bare TypeScript assertion on contract.storage used to
derive namespaces with the project's safe cast utility: import castAs from
'`@prisma-next/utils/casts`' and use castAs<Record<string, unknown> |
undefined>(contract.storage).namespaces (or similar) to assign to namespaces;
update the statement that references contract.storage and the namespaces
variable to use castAs<T> instead of the bare "as" cast so the type compliance
is preserved (refer to symbols contract.storage, namespaces, and castAs<T>).
In `@packages/1-framework/3-tooling/cli/src/control-api/operations/db-verify.ts`:
- Line 375: Replace the bare "as" cast on contract.storage with the project cast
helper: import castAs from '`@prisma-next/utils/casts`' and use castAs<{
namespaces?: Record<string, unknown> }>(contract.storage) to extract .namespaces
(so the expression that produces namespaces uses castAs instead of
(contract.storage as ...)). Ensure the cast type matches the original shape ({
namespaces?: Record<string, unknown> }) and update any imports accordingly.
In `@packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts`:
- Line 71: Replace bare `as` assertions with the project's `castAs<T>` helper:
import castAs from '`@prisma-next/utils/casts`' and change usages like
`Object.entries(ns.models as Record<string, ContractModel>)` to
`Object.entries(castAs<Record<string, ContractModel>>(ns.models))`; do the same
for the other occurrences that currently use `as` (the casts involving
`ContractModel` at the other three sites) so all four raw `as` casts are
replaced with `castAs<T>` calls referencing the same target types.
---
Nitpick comments:
In `@examples/supabase/test/skeleton.integration.test.ts`:
- Around line 62-63: The test suite currently disables the only E2E path by
using describe.skip; change this to an environment-gated describe so the
integration tests run when explicitly enabled (e.g., check
process.env.RUN_SUPABASE_E2E or similar) instead of always skipping. Locate the
describe.skip block (the suite name 'supabase walking skeleton —
external-contract migrate/verify + public round-trip') and the associated
createDevDatabase usage, wrap or replace describe.skip with a conditional that
calls describe only when the env var is truthy and otherwise calls describe.skip
(or uses a helper like describeIfIntegration), and document the required env var
in test setup so CI jobs can opt-in.
In `@packages/1-framework/3-tooling/cli/src/control-api/operations/db-run.ts`:
- Around line 276-310: The buildAggregateIntrospectContract function is
duplicated; extract it into a single shared module (e.g., migration-helpers or
aggregate-introspect) and export it, then replace the local definitions in both
db-run.ts and db-verify.ts with an import of that exported function; ensure you
keep the same signature (buildAggregateIntrospectContract(aggregate:
ContractSpaceAggregate): Record<string, unknown>), preserve the try/catch and
namespace merging behavior, and update any imports so callers use the new shared
symbol.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 54ccc319-149c-41cb-9daf-e08ff9c3fa55
⛔ Files ignored due to path filters (6)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlprojects/extension-supabase/plan.mdis excluded by!projects/**projects/extension-supabase/slices/m1-scaffold-and-skeleton/plan.mdis excluded by!projects/**projects/extension-supabase/slices/m1-scaffold-and-skeleton/spec.mdis excluded by!projects/**projects/extension-supabase/trace.jsonlis excluded by!projects/**projects/supabase-integration/decisions.mdis excluded by!projects/**
📒 Files selected for processing (42)
architecture.config.jsonexamples/supabase/biome.jsoncexamples/supabase/package.jsonexamples/supabase/prisma-next.config.tsexamples/supabase/src/contract.d.tsexamples/supabase/src/contract.jsonexamples/supabase/src/contract.prismaexamples/supabase/src/handlers.tsexamples/supabase/src/prisma/db.tsexamples/supabase/test/skeleton.integration.test.tsexamples/supabase/test/supabase-bootstrap.tsexamples/supabase/tsconfig.jsonexamples/supabase/vitest.config.tspackages/1-framework/3-tooling/cli/src/control-api/operations/db-run.tspackages/1-framework/3-tooling/cli/src/control-api/operations/db-verify.tspackages/1-framework/3-tooling/emitter/src/assert-single-domain-namespace-for-emission.tspackages/1-framework/3-tooling/emitter/src/generate-contract-dts.tspackages/1-framework/3-tooling/emitter/test/assert-single-domain-namespace-for-emission.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/3-extensions/supabase/biome.jsoncpackages/3-extensions/supabase/migrations/20260605T0000_establish_external_supabase_tables/end-contract.d.tspackages/3-extensions/supabase/migrations/20260605T0000_establish_external_supabase_tables/end-contract.jsonpackages/3-extensions/supabase/migrations/20260605T0000_establish_external_supabase_tables/migration.jsonpackages/3-extensions/supabase/migrations/20260605T0000_establish_external_supabase_tables/migration.tspackages/3-extensions/supabase/migrations/20260605T0000_establish_external_supabase_tables/ops.jsonpackages/3-extensions/supabase/migrations/refs/head.jsonpackages/3-extensions/supabase/package.jsonpackages/3-extensions/supabase/prisma-next.config.tspackages/3-extensions/supabase/src/contract/contract.d.tspackages/3-extensions/supabase/src/contract/contract.jsonpackages/3-extensions/supabase/src/contract/contract.prismapackages/3-extensions/supabase/src/exports/pack.tspackages/3-extensions/supabase/src/exports/runtime.tspackages/3-extensions/supabase/src/pack/index.tspackages/3-extensions/supabase/test/classification.e2e.test.tspackages/3-extensions/supabase/test/pack.resolution.test-d.tspackages/3-extensions/supabase/tsconfig.jsonpackages/3-extensions/supabase/tsconfig.prod.jsonpackages/3-extensions/supabase/tsconfig.test.jsonpackages/3-extensions/supabase/tsdown.config.tspackages/3-extensions/supabase/vitest.config.tsscripts/regen-extension-migrations.mjs
💤 Files with no reviewable changes (1)
- packages/1-framework/3-tooling/emitter/src/assert-single-domain-namespace-for-emission.ts
…n CI The M1 proof (external-contract migrate/verify + public.profile round-trip) is green and stable, and examples/** is already part of test:examples — so the suite was running as "skipped", guarding nothing. A skipped green test defeats the walking skeleton's reason to exist: a continuous CI surface that catches cross-constituent regressions the day they're introduced. Un-skip it. It asserts M1 behaviour only; later constituents (cross-contract-refs, postgres-rls, explicit-namespace-dsl) extend the assertions in place. Spec gating notes updated. Refs: TML-2834 Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…, de-duplicate (PR#746) Replace the verbatim-duplicated `buildAggregateIntrospectContract` free function (which lived in both `db-run.ts` and `db-verify.ts`, swallowed errors, and cast `storage` as `Record<string,unknown>`) with a single `collectAggregateNamespaces` exported from `@prisma-next/migration-tools/aggregate`. The new helper calls `member.contract().storage.namespaces` directly — the field is typed `Readonly<Record<string, StorageNamespace>>` on `StorageBase`, so no casting is needed. The try/catch is gone: by the time either CLI command reaches introspection the aggregate has already passed `buildContractSpaceAggregate` with `checkContracts: true`, so every `member.contract()` call is safe. Behaviour is unchanged: introspection still walks all declared namespaces (app + composed extensions); single-namespace contracts still introspect only their namespace. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…p Supabase no-op baseline (PR#746) Extension spaces that declare only external schema (e.g. `auth.*` / `storage.*` tables owned by Supabase) have no DDL migrations to ship and no on-disk migration graph to walk. The previous workaround was a zero-ops baseline migration solely to give the loader an edge so the head ref appeared in the graph. The reviewer correctly flagged this as a smell. Loader (`loader.ts`): when `readMigrationsDir` returns zero packages AND zero load-time problems for an extension space, treat the space as migration-less. Synthesize its head ref from the on-disk `contract.json`'s `storage.storageHash` (the same approach `loadAppSpace` uses for the app), and mark the state with `hasSynthesizedHead: true`. Integrity check (`check-integrity.ts`): when `hasSynthesizedHead` is `true` for a space, skip the `headRefMissing` and `headRefNotInGraph` checks. The graph is empty by design for these spaces; the planner's synth strategy handles them (zero ops). Migration-backed spaces (pgvector etc.) are unaffected — the `isMigrationless` condition only triggers when both `packages.length === 0` AND `problems.length === 0`, so a space whose packages failed to load still goes through the full head-ref check. Pack (`extension-supabase/src/pack/index.ts`): set `migrations: []` and derive `headRef` directly from `contractJson.storage.storageHash`. Delete the entire `packages/3-extensions/supabase/migrations/` tree. Tests: update `classification.e2e.test.ts` and `examples/supabase/test/skeleton.integration.test.ts` to stop calling `materialiseMigrationPackage`. Add four loader tests that cover the new path: head-ref synthesis, no integrity violations for migration-less spaces, and correct non-migration-less behaviour for spaces with unloadable packages. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…n, share shim, slim /pack type test
③ Rename emitter test: assert-single-domain-namespace-for-emission.test.ts →
generate-contract-dts.multi-namespace.test.ts (the method in the old name
was deleted; the test now exercises generateContractDts multi-namespace emission).
⑤ Derive the supabase pack version from its own package.json via
`import packageJson from '../../package.json' with { type: 'json' }`
so it stays in sync automatically with the package version field.
⑥ Move bootstrapSupabaseShim into packages/3-extensions/supabase/test/supabase-bootstrap.ts
(uses pg directly; interface takes connectionString: string) and export it as
the @prisma-next/extension-supabase/test/utils subpath. Add pg + @types/pg as devDeps
and a tsdown entry so the dist is built. The example's supabase-bootstrap.ts now
re-exports from that subpath. The inlined seed SQL in classification.e2e.test.ts
is removed — both consumers share the single definition.
⑦ Consolidate pack.resolution.test-d.ts: drop the data-echo assertions (.kind,
.familyId, .targetId literal checks); keep one test with two toExtend assertions
that actually verify the assignability contract.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…pabase-m1-scaffold-package-pack-psl-contract-and
Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
examples/supabase/test/skeleton.integration.test.ts (1)
104-107:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse the real Supabase
contract.d.tsartifact here.
emitContractSpaceArtefacts()always writescontract.d.ts, but this test feeds it a stub string. That means the walking-skeleton still passes if the packaged Supabase DTS is missing or stale, which weakens the PR's “ships emitted contract artifacts” proof. Thread the generated DTS through from the pack descriptor or import the emitted file directly instead of hardcoding a placeholder.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/supabase/test/skeleton.integration.test.ts` around lines 104 - 107, The test currently passes a hardcoded stub for contractDts to emitContractSpaceArtefacts which hides missing/stale Supabase DTS; change the test to pass the real generated DTS instead of the placeholder. Locate where the pack descriptor or generated artifacts are produced in the test setup (or read the emitted contract.d.ts from the build output), and supply that value as the contractDts argument to emitContractSpaceArtefacts alongside space.contractJson and space.headRef so the real Supabase contract.d.ts is validated; ensure the test fails if the DTS is unavailable.
🧹 Nitpick comments (1)
examples/supabase/test/skeleton.integration.test.ts (1)
143-167: ⚡ Quick winTighten the plan assertions to the actual target object.
Line 146 lets any
createTableop satisfy thepublic.profilecheck, and the auth/storage guard only inspectsid/labelsubstrings. A planner regression can therefore still pass this test while routing DDL to the wrong object. Assert the exact target table/namespace from the operation metadata, or at minimum matchpublic.profileexplicitly in one place instead of relying on generic display strings.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/supabase/test/skeleton.integration.test.ts` around lines 143 - 167, The test currently allows any createTable op (via op.id substring) and only substring-matches auth/storage, so update the assertions to check the operation's explicit target metadata instead of display strings: when scanning operations (the operations array and existing hasProfileCreate logic), find a createTable op whose target/schema/name (e.g., op.target, op.object, or op.metadata fields that represent schema/name) exactly equals "public" and "profile" (or a single "public.profile" identifier) and assert that exists; likewise replace the auth/storage filter to check the operation's schema/namespace field for exact equality to "auth" or "storage" (not substring of id/label) before asserting zero such ops (adjust the expect calls that currently reference hasProfileCreate and authOrStorageOps to use these stricter checks).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@examples/supabase/test/skeleton.integration.test.ts`:
- Around line 104-107: The test currently passes a hardcoded stub for
contractDts to emitContractSpaceArtefacts which hides missing/stale Supabase
DTS; change the test to pass the real generated DTS instead of the placeholder.
Locate where the pack descriptor or generated artifacts are produced in the test
setup (or read the emitted contract.d.ts from the build output), and supply that
value as the contractDts argument to emitContractSpaceArtefacts alongside
space.contractJson and space.headRef so the real Supabase contract.d.ts is
validated; ensure the test fails if the DTS is unavailable.
---
Nitpick comments:
In `@examples/supabase/test/skeleton.integration.test.ts`:
- Around line 143-167: The test currently allows any createTable op (via op.id
substring) and only substring-matches auth/storage, so update the assertions to
check the operation's explicit target metadata instead of display strings: when
scanning operations (the operations array and existing hasProfileCreate logic),
find a createTable op whose target/schema/name (e.g., op.target, op.object, or
op.metadata fields that represent schema/name) exactly equals "public" and
"profile" (or a single "public.profile" identifier) and assert that exists;
likewise replace the auth/storage filter to check the operation's
schema/namespace field for exact equality to "auth" or "storage" (not substring
of id/label) before asserting zero such ops (adjust the expect calls that
currently reference hasProfileCreate and authOrStorageOps to use these stricter
checks).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 98de6bdc-0f94-46f3-9cae-ba1fdd4bb083
⛔ Files ignored due to path filters (2)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlprojects/extension-supabase/trace.jsonlis excluded by!projects/**
📒 Files selected for processing (17)
examples/supabase/test/skeleton.integration.test.tsexamples/supabase/test/supabase-bootstrap.tspackages/1-framework/3-tooling/cli/src/control-api/operations/db-run.tspackages/1-framework/3-tooling/cli/src/control-api/operations/db-verify.tspackages/1-framework/3-tooling/emitter/test/generate-contract-dts.multi-namespace.test.tspackages/1-framework/3-tooling/migration/src/aggregate/aggregate.tspackages/1-framework/3-tooling/migration/src/aggregate/check-integrity.tspackages/1-framework/3-tooling/migration/src/aggregate/loader.tspackages/1-framework/3-tooling/migration/src/exports/aggregate.tspackages/1-framework/3-tooling/migration/test/aggregate/check-integrity.test.tspackages/1-framework/3-tooling/migration/test/aggregate/loader.test.tspackages/3-extensions/supabase/package.jsonpackages/3-extensions/supabase/src/pack/index.tspackages/3-extensions/supabase/test/classification.e2e.test.tspackages/3-extensions/supabase/test/pack.resolution.test-d.tspackages/3-extensions/supabase/test/supabase-bootstrap.tspackages/3-extensions/supabase/tsdown.config.ts
💤 Files with no reviewable changes (1)
- packages/1-framework/3-tooling/emitter/test/generate-contract-dts.multi-namespace.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/3-extensions/supabase/package.json
- packages/3-extensions/supabase/test/classification.e2e.test.ts
… on graph emptiness (PR#746) Remove the `isMigrationless` branch from `loadExtensionSpace`: extension spaces now read `refs/head.json` uniformly from disk, the same as any migration-backed extension. The Supabase pack already writes its head ref via `emitContractSpaceArtefacts`, so the walking-skeleton test stays green without any test-side changes. Remove `hasSynthesizedHead` from `IntegritySpaceState`. The field conflated "how we got the head ref" with "is there a migration graph to check against", which are independent. Replace the integrity gate: - `headRefMissing` now fires for ALL non-app spaces when `head.json` is absent — a missing head ref is always an authoring error. - `headRefNotInGraph` is gated on `member.packages.length > 0`; empty-graph spaces (no packages) skip this check because the graph reachability test is meaningless with nothing to walk. Also delete the `extractStorageHashFromRaw` and `safeCallRaw` helpers that were only used by the removed branch. Update the four loader tests that asserted synthesis behaviour to instead assert uniform disk reads. Update the `check-integrity.test.ts` literals to drop `hasSynthesizedHead`. Fix the "rethrows on unexpected graph() failure" test to give the faulty member a package so the graph check is triggered. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…pabase-m1-scaffold-package-pack-psl-contract-and
…mitter bare casts
- examples/supabase/src/handlers.ts: drop the `db.sql['profile']` bracket
workaround + defensive nil-check. The typed surface has `profile` as a named
property (the contract.d.ts emits `roots: { profile: ... }`), so
`db.sql.profile` typechecks fine — the index-signature workaround was
unnecessary (D4 implementer's report was wrong).
- examples/supabase/src/prisma/db.ts: `'../contract.d'` → `'../contract'` to
match the modern repo convention (retail-store, mongo-demo).
- examples/supabase/test/skeleton.integration.test.ts: bump the per-`it`
timeout from `timeouts.spinUpPpgDev` (30s) to 4× that. The test does seed +
materialise + dbInit (plan + apply) + dbVerify + connect runtime + insert +
read — substantially more than a DB spin-up. 4× gives cold CI headroom.
- packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts: replace
the four bare `as` casts (CodeRabbit) with `blindCast<T, Reason>` per the
no-bare-casts repo policy. Emitter output is byte-identical (fixtures:check
green); emitter tests 162/162.
Refs: TML-2834
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/supabase/src/handlers.ts`:
- Around line 5-6: The handler currently does an unfiltered select after
inserting which will return all rows; update the logic in the function (where
you call db.sql.profile.insert and runtime.execute) to use the SQL builder's
returning(...) on db.sql.profile.insert([{ username }]) and return the
runtime.execute(...) of that insert with .returning('id', 'username').build()
instead of calling db.sql.profile.select('id', 'username') so only the newly
inserted row(s) are returned.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 65c83ddd-1c18-424e-83be-2720777f7842
⛔ Files ignored due to path filters (1)
projects/extension-supabase/trace.jsonlis excluded by!projects/**
📒 Files selected for processing (4)
examples/supabase/src/handlers.tsexamples/supabase/src/prisma/db.tsexamples/supabase/test/skeleton.integration.test.tspackages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- examples/supabase/src/prisma/db.ts
- examples/supabase/test/skeleton.integration.test.ts
- packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
…or upgrade instructions PR adds the new @prisma-next/extension-supabase package + examples/supabase. Two enabling framework changes (multi-namespace emit; introspect all declared namespaces) are forward-compatible — single-namespace contracts emit byte-identical output and existing extension packs are unaffected. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ile (PR#746) CodeRabbit caught that the prior insert + unfiltered select would return all profile rows once the table is non-empty — the integration test only passed by coincidence (table starts empty). Use the SQL builder's .returning(...) on the insert so only the newly-inserted row(s) come back, matching the prisma-next-demo idiom. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Clean up as we go — CodeRabbit flagged these in R5; I'd dismissed them as pre-existing (they predate this PR), but per repo policy bare `as` should not exist in production code. Three sites: the two `notOk(failure) as DbInitResult | DbUpdateResult` widenings in db-run.ts (failure-path return) and the `projectedSchema as never` opaque-IR pass-through in db-verify.ts. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ent (PR#746) Two review comments: 1) bootstrapSupabaseShim now takes 'client: Client' instead of 'connectionString: string'. The shim no longer owns the client lifecycle — callers pass their own (already-connected) client so it can be reused across other test setup steps (or bound to a transaction). Both consumers (classification.e2e + skeleton.integration) wrap with the test-utils 'withClient' helper. 2) Rewrote the 'synth strategy (zero ops)' comment in check-integrity.ts in plain English: 'When a space ships no migrations, the planner emits no DDL for it — the database is treated as already at the declared state.' Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Overview
Stands up the Supabase integration's walking skeleton: the
@prisma-next/extension-supabasepackage and a runnableexamples/supabaseapp. The skeleton proves the package's core claim end-to-end — the framework treats Supabase'sauth.*/storage.*tables asexternal(no DDL emitted, verified-present) while the app's ownpublicschema migrates and round-trips on the stock Postgres runtime.What changed
packages/3-extensions/supabase/(modeled on pgvector):/pack(realExtensionPackcarrying the contract +spaceId),/runtime(minimal descriptor — not the realSupabaseRuntime, which is M2), a PSL-authored contract (auth+storagenamespaces, 4 models,defaultControl: 'external', no roles), and a zero-ops baseline migration.examples/supabase/: composesextensionPacks: [supabasePack], apublic.Profilemodel, stock-runtimedb.ts, one handler; gated integration test (.skip) proving migrate/verify + round-trip.bootstrapSupabaseShim(schemas + 4 external tables; no roles/functions — those grow withpostgres-rls)..d.tsassert; flattens first-name-wins). Single-namespace output is byte-identical, locked by tests.db init/db verifyintrospect all declared namespaces (waspublic-only — a bug for composed contracts). Single-namespace behavior unchanged.packages/3-extensions/supabase/test/): proves introspecting a Supabase DB attributespublic.*to the app andauth.*/storage.*as external.Why
The integration is delivered as a walking skeleton grown one feature at a time; this is its starting state (M1). The two framework changes are operator-approved enablers discovered during the build — both align with existing patterns (pgvector ships migrations + a runtime export; introspection should read declared schemas).
Scope
In: the package, the example, the shim, the proof, the two framework enablers.
Out (deferred to their owning constituents):
/contracttyped handles + roles (cross-contract-refs/postgres-rls); the real/runtimerole-binding (M2); cross-contract FK, RLS, explicitauth.*queries.Verification
All changed packages typecheck;
pnpm lint:deps+pnpm fixtures:checkgreen; supabase package tests (classification e2e +/packtype smoke) green; full integration suite 1039/1039. Merged currentorigin/main(incl. TML-2836 migration-vocabulary rename + TML-2808 emitted-shape changes) and re-validated.Refs: TML-2834
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor
Tests