Supabase adapter

artifactkit/adapters/supabase runs artifactkit on an existing Supabase project through the Data API (PostgREST). No direct database connection, no pg, and no SDK dependency: you inject a client that has rpc(name, args) — a @supabase/supabase-js service-role client satisfies it as is.

import { createClient } from '@supabase/supabase-js';
import { createSupabaseAdapter } from '@artifactkitdev/core/adapters/supabase';

const adapter = createSupabaseAdapter(
  createClient(url, serviceRoleKey, { auth: { persistSession: false, autoRefreshToken: false } }),
);
const deps = { store: adapter.store, bodies: adapter.bodies, comments: adapter.comments, runtime };

Provides ArtifactStore, BodyStore and CommentStore. Artifact state and the event log are not part of this adapter (leave deps.state unset). Capabilities are all true, because each write is one RPC and therefore one transaction.

The core commits each operation through the optional ArtifactStore.putWithBodies method. Its body bundle stays paired with that operation's metadata through the atomic RPC, so concurrent updates can safely share an adapter instance. Metadata-only operations pass an empty body bundle and cannot flush another operation's staged body. Reads return committed database bodies only.

The low-level bodies.put + store.put staging protocol remains available for existing sequential callers. Do not interleave that protocol across operations; use putWithBodies or the core use cases for concurrent writes.

What the migration creates

SUPABASE_SCHEMA_SQL (also adapter.schema) is idempotent and creates:

artifactkit_put writes the metadata, enforces the expected version (create / cas / replace) and inserts the new version bodies in one call. A stale write returns a conflict and changes nothing; a failure while storing a body rolls the metadata write back.

One-time setup needs a privileged connection

The Data API cannot run DDL, so the service-role key cannot install this. That key is a runtime credential; installing needs a management credential, any one of:

After that, runtime needs only the project URL and the service-role key.

node --input-type=module -e "import('@artifactkitdev/core/adapters/supabase').then(m => console.log(m.SUPABASE_SCHEMA_SQL))" > artifactkit.sql

If the RPCs are missing, calls fail with artifactkit schema is not installed.

Tests

tests/supabase.test.ts and the shared conformance suite run the real SQL in PGlite (Postgres in WASM), calling each RPC as service_role, and check anon/authenticated are refused. They cover version conflicts, rollback on a failed body write, comments, share/delete, and the permission model. PGlite serialises statements, so these show the guard is correct, not behaviour under a real multi-connection load.