tinbase 0.2.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +64 -31
  2. package/dist/admin/api.d.ts +8 -1
  3. package/dist/admin/api.js +94 -1
  4. package/dist/admin/api.js.map +1 -1
  5. package/dist/admin/ui.d.ts +1 -1
  6. package/dist/admin/ui.js +16 -16
  7. package/dist/auth/handler.d.ts +13 -1
  8. package/dist/auth/handler.js +173 -6
  9. package/dist/auth/handler.js.map +1 -1
  10. package/dist/auth/inbox.d.ts +31 -0
  11. package/dist/auth/inbox.js +112 -0
  12. package/dist/auth/inbox.js.map +1 -0
  13. package/dist/auth/oauth.d.ts +59 -0
  14. package/dist/auth/oauth.js +209 -0
  15. package/dist/auth/oauth.js.map +1 -0
  16. package/dist/auth/qr.d.ts +8 -0
  17. package/dist/auth/qr.js +376 -0
  18. package/dist/auth/qr.js.map +1 -0
  19. package/dist/auth/totp.d.ts +19 -0
  20. package/dist/auth/totp.js +101 -0
  21. package/dist/auth/totp.js.map +1 -0
  22. package/dist/cli.js +168 -10
  23. package/dist/cli.js.map +1 -1
  24. package/dist/cron/service.d.ts +29 -0
  25. package/dist/cron/service.js +134 -0
  26. package/dist/cron/service.js.map +1 -0
  27. package/dist/db/bootstrap.d.ts +8 -1
  28. package/dist/db/bootstrap.js +240 -1
  29. package/dist/db/bootstrap.js.map +1 -1
  30. package/dist/db/database.d.ts +24 -0
  31. package/dist/db/database.js +61 -2
  32. package/dist/db/database.js.map +1 -1
  33. package/dist/db/emulated.d.ts +12 -0
  34. package/dist/db/emulated.js +156 -0
  35. package/dist/db/emulated.js.map +1 -0
  36. package/dist/db/engine.d.ts +2 -0
  37. package/dist/db/engine.js.map +1 -1
  38. package/dist/db/inspect.d.ts +13 -0
  39. package/dist/db/inspect.js +22 -0
  40. package/dist/db/inspect.js.map +1 -0
  41. package/dist/db/pgmem-engine.d.ts +22 -0
  42. package/dist/db/pgmem-engine.js +135 -0
  43. package/dist/db/pgmem-engine.js.map +1 -0
  44. package/dist/db/schema-diff.d.ts +23 -0
  45. package/dist/db/schema-diff.js +182 -0
  46. package/dist/db/schema-diff.js.map +1 -0
  47. package/dist/functions/deno-shim.d.ts +24 -0
  48. package/dist/functions/deno-shim.js +47 -0
  49. package/dist/functions/deno-shim.js.map +1 -0
  50. package/dist/functions/handler.d.ts +3 -1
  51. package/dist/functions/handler.js.map +1 -1
  52. package/dist/gen-types.d.ts +17 -0
  53. package/dist/gen-types.js +222 -0
  54. package/dist/gen-types.js.map +1 -0
  55. package/dist/index.d.ts +20 -0
  56. package/dist/index.js +83 -15
  57. package/dist/index.js.map +1 -1
  58. package/dist/jwt.d.ts +7 -0
  59. package/dist/jwt.js.map +1 -1
  60. package/dist/log-buffer.d.ts +21 -0
  61. package/dist/log-buffer.js +20 -0
  62. package/dist/log-buffer.js.map +1 -0
  63. package/dist/node/bundle-function.d.ts +7 -0
  64. package/dist/node/bundle-function.js +90 -0
  65. package/dist/node/bundle-function.js.map +1 -0
  66. package/dist/node/db-diff.d.ts +34 -0
  67. package/dist/node/db-diff.js +82 -0
  68. package/dist/node/db-diff.js.map +1 -0
  69. package/dist/node/index.d.ts +4 -1
  70. package/dist/node/index.js +4 -1
  71. package/dist/node/index.js.map +1 -1
  72. package/dist/node/load-functions.d.ts +6 -0
  73. package/dist/node/load-functions.js +60 -8
  74. package/dist/node/load-functions.js.map +1 -1
  75. package/dist/node/load-oauth.d.ts +4 -0
  76. package/dist/node/load-oauth.js +126 -0
  77. package/dist/node/load-oauth.js.map +1 -0
  78. package/dist/node/native/engine.d.ts +1 -1
  79. package/dist/node/native/engine.js +45 -14
  80. package/dist/node/native/engine.js.map +1 -1
  81. package/dist/realtime/engine.d.ts +24 -1
  82. package/dist/realtime/engine.js +154 -2
  83. package/dist/realtime/engine.js.map +1 -1
  84. package/dist/rest/build.d.ts +5 -1
  85. package/dist/rest/build.js +17 -8
  86. package/dist/rest/build.js.map +1 -1
  87. package/dist/rest/handler.js +22 -9
  88. package/dist/rest/handler.js.map +1 -1
  89. package/dist/types.d.ts +10 -0
  90. package/dist/types.js.map +1 -1
  91. package/dist/webhooks/service.d.ts +47 -0
  92. package/dist/webhooks/service.js +86 -0
  93. package/dist/webhooks/service.js.map +1 -0
  94. package/package.json +7 -2
@@ -3,4 +3,11 @@
3
3
  * Supabase project: roles, auth schema, storage schema, helper functions,
4
4
  * migration bookkeeping, and the realtime CDC plumbing.
5
5
  */
6
- export declare const BOOTSTRAP_SQL = "\n-- \u2500\u2500 Extensions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n-- Supabase enables these by default and migrations lean on them\n-- (uuid_generate_v4(), crypt(), citext, pg_trgm, \u2026). Each is created into the\n-- 'extensions' schema like hosted Supabase; any not available in this engine\n-- build is skipped rather than aborting the whole bootstrap.\ncreate schema if not exists extensions;\ndo $$\ndeclare ext text;\nbegin\n foreach ext in array array['uuid-ossp','pgcrypto','citext','pg_trgm','ltree','hstore','fuzzystrmatch'] loop\n begin\n execute format('create extension if not exists %I with schema extensions', ext);\n exception when others then\n -- extension not bundled in this engine; continue\n end;\n end loop;\nend $$;\n\n-- Make extension functions resolvable unqualified (uuid_generate_v4(), \u2026) on\n-- the current session (migrations run here) and for future connections.\ndo $$\nbegin\n execute 'alter database ' || quote_ident(current_database()) ||\n ' set search_path to \"$user\", public, extensions';\nexception when others then\n -- some engines disallow altering the current database; session SET below still applies\nend $$;\nset search_path to \"$user\", public, extensions;\n\n-- \u2500\u2500 Roles \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ndo $$\nbegin\n if not exists (select from pg_roles where rolname = 'anon') then\n create role anon nologin noinherit;\n end if;\n if not exists (select from pg_roles where rolname = 'authenticated') then\n create role authenticated nologin noinherit;\n end if;\n if not exists (select from pg_roles where rolname = 'service_role') then\n create role service_role nologin noinherit bypassrls;\n end if;\nend $$;\n\ngrant usage on schema extensions to anon, authenticated, service_role;\nalter role anon set search_path to \"$user\", public, extensions;\nalter role authenticated set search_path to \"$user\", public, extensions;\nalter role service_role set search_path to \"$user\", public, extensions;\n\ngrant usage on schema public to anon, authenticated, service_role;\ngrant all on all tables in schema public to anon, authenticated, service_role;\ngrant all on all sequences in schema public to anon, authenticated, service_role;\ngrant execute on all functions in schema public to anon, authenticated, service_role;\n\nalter default privileges in schema public\n grant all on tables to anon, authenticated, service_role;\nalter default privileges in schema public\n grant all on sequences to anon, authenticated, service_role;\nalter default privileges in schema public\n grant execute on functions to anon, authenticated, service_role;\n\n-- \u2500\u2500 Auth schema (GoTrue-compatible subset) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists auth;\n\ncreate table if not exists auth.users (\n id uuid primary key default gen_random_uuid(),\n aud text default 'authenticated',\n role text default 'authenticated',\n email text unique,\n encrypted_password text,\n email_confirmed_at timestamptz,\n invited_at timestamptz,\n confirmation_token text,\n recovery_token text,\n last_sign_in_at timestamptz,\n raw_app_meta_data jsonb default '{}'::jsonb,\n raw_user_meta_data jsonb default '{}'::jsonb,\n is_super_admin boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n phone text unique,\n phone_confirmed_at timestamptz,\n banned_until timestamptz,\n deleted_at timestamptz,\n is_anonymous boolean default false\n);\n\ncreate table if not exists auth.refresh_tokens (\n id bigint generated by default as identity primary key,\n token text unique not null,\n user_id uuid not null references auth.users(id) on delete cascade,\n parent text,\n session_id uuid,\n revoked boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate index if not exists refresh_tokens_user_id_idx on auth.refresh_tokens(user_id);\n\ncreate table if not exists auth.one_time_tokens (\n id uuid primary key default gen_random_uuid(),\n user_id uuid references auth.users(id) on delete cascade,\n email text not null,\n token_type text not null, -- otp | magiclink | recovery\n token text not null,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ngrant usage on schema auth to anon, authenticated, service_role;\n\ncreate or replace function auth.jwt() returns jsonb\nlanguage sql stable as $$\n select coalesce(\n nullif(current_setting('request.jwt.claims', true), ''),\n '{}'\n )::jsonb\n$$;\n\ncreate or replace function auth.uid() returns uuid\nlanguage sql stable as $$\n select nullif(auth.jwt() ->> 'sub', '')::uuid\n$$;\n\ncreate or replace function auth.role() returns text\nlanguage sql stable as $$\n select coalesce(auth.jwt() ->> 'role', 'anon')\n$$;\n\ncreate or replace function auth.email() returns text\nlanguage sql stable as $$\n select auth.jwt() ->> 'email'\n$$;\n\ngrant execute on function auth.jwt(), auth.uid(), auth.role(), auth.email()\n to anon, authenticated, service_role;\n\n-- \u2500\u2500 Storage schema (storage-api-compatible subset) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists storage;\n\ncreate table if not exists storage.buckets (\n id text primary key,\n name text not null unique,\n owner uuid,\n public boolean default false,\n file_size_limit bigint,\n allowed_mime_types text[],\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists storage.objects (\n id uuid primary key default gen_random_uuid(),\n bucket_id text not null references storage.buckets(id),\n name text not null,\n owner uuid,\n version text,\n metadata jsonb default '{}'::jsonb,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n last_accessed_at timestamptz default now(),\n unique (bucket_id, name)\n);\n\ncreate index if not exists objects_bucket_name_idx on storage.objects(bucket_id, name);\n\ngrant usage on schema storage to anon, authenticated, service_role;\ngrant select on storage.buckets to anon, authenticated, service_role;\ngrant all on storage.buckets to service_role;\ngrant all on storage.objects to anon, authenticated, service_role;\n\ncreate or replace function storage.foldername(name text) returns text[]\nlanguage sql immutable as $$\n select (string_to_array(name, '/'))[1 : array_length(string_to_array(name, '/'), 1) - 1]\n$$;\n\ncreate or replace function storage.filename(name text) returns text\nlanguage sql immutable as $$\n select (string_to_array(name, '/'))[array_length(string_to_array(name, '/'), 1)]\n$$;\n\ncreate or replace function storage.extension(name text) returns text\nlanguage sql immutable as $$\n select reverse(split_part(reverse(storage.filename(name)), '.', 1))\n$$;\n\nalter table storage.objects enable row level security;\n\n-- Dev-friendly default policies. Replace them in your migrations to lock down.\ndo $$\nbegin\n if not exists (select from pg_policies where schemaname = 'storage' and tablename = 'objects' and policyname = 'tinbase_authenticated_all') then\n create policy tinbase_authenticated_all on storage.objects\n for all to authenticated using (true) with check (true);\n end if;\n if not exists (select from pg_policies where schemaname = 'storage' and tablename = 'objects' and policyname = 'tinbase_public_read') then\n create policy tinbase_public_read on storage.objects\n for select to anon\n using (bucket_id in (select id from storage.buckets where public));\n end if;\nend $$;\n\n-- \u2500\u2500 Migration bookkeeping (same table the Supabase CLI uses) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists supabase_migrations;\n\ncreate table if not exists supabase_migrations.schema_migrations (\n version text primary key,\n name text,\n statements text[],\n applied_at timestamptz default now()\n);\n\ncreate table if not exists supabase_migrations.seed_files (\n path text primary key,\n hash text,\n applied_at timestamptz default now()\n);\n\n-- \u2500\u2500 Realtime CDC plumbing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists tinbase;\n\ncreate or replace function tinbase.cdc_notify() returns trigger\nlanguage plpgsql security definer as $$\ndeclare\n payload text;\nbegin\n payload := json_build_object(\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'type', TG_OP,\n 'commit_timestamp', to_char(now() at time zone 'utc', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"'),\n 'record', case when TG_OP in ('INSERT', 'UPDATE') then row_to_json(NEW) else null end,\n 'old_record', case when TG_OP in ('UPDATE', 'DELETE') then row_to_json(OLD) else null end\n )::text;\n -- pg_notify payloads are capped at ~8kB; degrade like Supabase does.\n if octet_length(payload) > 7500 then\n payload := json_build_object(\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'type', TG_OP,\n 'commit_timestamp', to_char(now() at time zone 'utc', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"'),\n 'record', null,\n 'old_record', null,\n 'errors', json_build_array('Payload too large')\n )::text;\n end if;\n perform pg_notify('tinbase_cdc', payload);\n return coalesce(NEW, OLD);\nend $$;\n";
6
+ /**
7
+ * Reduced bootstrap for subset engines (pg-mem) that can't run plpgsql, RLS
8
+ * policies, extensions, or LISTEN/NOTIFY. Just the schemas, core tables, and
9
+ * SQL-language auth helpers needed for the REST + auth CRUD surface. No RLS is
10
+ * enforced here — this path is for local-dev/preview only.
11
+ */
12
+ export declare const MINIMAL_BOOTSTRAP_SQL = "\ncreate schema if not exists auth;\ncreate schema if not exists storage;\ncreate schema if not exists supabase_migrations;\n\ncreate table if not exists auth.users (\n id uuid primary key default gen_random_uuid(),\n aud text default 'authenticated',\n role text default 'authenticated',\n email text unique,\n encrypted_password text,\n email_confirmed_at timestamptz,\n last_sign_in_at timestamptz,\n raw_app_meta_data jsonb default '{}'::jsonb,\n raw_user_meta_data jsonb default '{}'::jsonb,\n is_super_admin boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n phone text unique,\n phone_confirmed_at timestamptz,\n banned_until timestamptz,\n deleted_at timestamptz,\n is_anonymous boolean default false\n);\n\ncreate table if not exists auth.refresh_tokens (\n id bigserial primary key,\n token text unique not null,\n user_id uuid not null,\n parent text,\n session_id uuid,\n revoked boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists auth.one_time_tokens (\n id uuid primary key default gen_random_uuid(),\n user_id uuid,\n email text not null,\n token_type text not null,\n token text not null,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.identities (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null,\n provider text not null,\n provider_id text not null,\n identity_data jsonb default '{}'::jsonb,\n last_sign_in_at timestamptz default now(),\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n unique (provider, provider_id)\n);\n\ncreate table if not exists auth.flow_state (\n id uuid primary key default gen_random_uuid(),\n provider text not null,\n provider_state text not null unique,\n redirect_to text,\n code_challenge text,\n code_challenge_method text,\n auth_code text unique,\n user_id uuid,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.mfa_factors (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null,\n friendly_name text,\n factor_type text not null default 'totp',\n status text not null default 'unverified',\n secret text,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists auth.mfa_challenges (\n id uuid primary key default gen_random_uuid(),\n factor_id uuid not null,\n verified_at timestamptz,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists storage.buckets (\n id text primary key,\n name text not null unique,\n owner uuid,\n public boolean default false,\n file_size_limit bigint,\n allowed_mime_types text[],\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists storage.objects (\n id uuid primary key default gen_random_uuid(),\n bucket_id text not null,\n name text not null,\n owner uuid,\n version text,\n metadata jsonb default '{}'::jsonb,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n last_accessed_at timestamptz default now(),\n unique (bucket_id, name)\n);\n\ncreate table if not exists supabase_migrations.schema_migrations (\n version text primary key,\n name text,\n statements text[],\n applied_at timestamptz default now()\n);\n\ncreate table if not exists supabase_migrations.seed_files (\n path text primary key,\n hash text,\n applied_at timestamptz default now()\n);\n";
13
+ export declare const BOOTSTRAP_SQL = "\n-- \u2500\u2500 Extensions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n-- Supabase enables these by default and migrations lean on them\n-- (uuid_generate_v4(), crypt(), citext, pg_trgm, \u2026). Each is created into the\n-- 'extensions' schema like hosted Supabase; any not available in this engine\n-- build is skipped rather than aborting the whole bootstrap.\ncreate schema if not exists extensions;\ndo $$\ndeclare ext text;\nbegin\n foreach ext in array array['uuid-ossp','pgcrypto','citext','pg_trgm','ltree','hstore','fuzzystrmatch'] loop\n begin\n execute format('create extension if not exists %I with schema extensions', ext);\n exception when others then\n -- extension not bundled in this engine build; continue\n end;\n end loop;\nend $$;\n\n-- uuid-ossp isn't in every Postgres build (it needs an external UUID lib at\n-- build time \u2014 e.g. the theseus Linux binaries omit it). uuid_generate_v4() is\n-- the single most-used function from it, so shim it onto core gen_random_uuid()\n-- (also a v4 UUID) whenever the real extension isn't present, so migrations\n-- that call it work identically on every engine and platform.\ndo $$\nbegin\n if not exists (\n select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace\n where p.proname = 'uuid_generate_v4' and n.nspname in ('public', 'extensions')\n ) then\n create function extensions.uuid_generate_v4() returns uuid\n language sql volatile as 'select gen_random_uuid()';\n end if;\nend $$;\n\n-- Make extension functions resolvable unqualified (uuid_generate_v4(), \u2026) on\n-- the current session (migrations run here) and for future connections.\ndo $$\nbegin\n execute 'alter database ' || quote_ident(current_database()) ||\n ' set search_path to \"$user\", public, extensions';\nexception when others then\n -- some engines disallow altering the current database; session SET below still applies\nend $$;\nset search_path to \"$user\", public, extensions;\n\n-- \u2500\u2500 Roles \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ndo $$\nbegin\n if not exists (select from pg_roles where rolname = 'anon') then\n create role anon nologin noinherit;\n end if;\n if not exists (select from pg_roles where rolname = 'authenticated') then\n create role authenticated nologin noinherit;\n end if;\n if not exists (select from pg_roles where rolname = 'service_role') then\n create role service_role nologin noinherit bypassrls;\n end if;\nend $$;\n\ngrant usage on schema extensions to anon, authenticated, service_role;\nalter role anon set search_path to \"$user\", public, extensions;\nalter role authenticated set search_path to \"$user\", public, extensions;\nalter role service_role set search_path to \"$user\", public, extensions;\n\ngrant usage on schema public to anon, authenticated, service_role;\ngrant all on all tables in schema public to anon, authenticated, service_role;\ngrant all on all sequences in schema public to anon, authenticated, service_role;\ngrant execute on all functions in schema public to anon, authenticated, service_role;\n\nalter default privileges in schema public\n grant all on tables to anon, authenticated, service_role;\nalter default privileges in schema public\n grant all on sequences to anon, authenticated, service_role;\nalter default privileges in schema public\n grant execute on functions to anon, authenticated, service_role;\n\n-- \u2500\u2500 Auth schema (GoTrue-compatible subset) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists auth;\n\ncreate table if not exists auth.users (\n id uuid primary key default gen_random_uuid(),\n aud text default 'authenticated',\n role text default 'authenticated',\n email text unique,\n encrypted_password text,\n email_confirmed_at timestamptz,\n invited_at timestamptz,\n confirmation_token text,\n recovery_token text,\n last_sign_in_at timestamptz,\n raw_app_meta_data jsonb default '{}'::jsonb,\n raw_user_meta_data jsonb default '{}'::jsonb,\n is_super_admin boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n phone text unique,\n phone_confirmed_at timestamptz,\n banned_until timestamptz,\n deleted_at timestamptz,\n is_anonymous boolean default false\n);\n\ncreate table if not exists auth.refresh_tokens (\n id bigint generated by default as identity primary key,\n token text unique not null,\n user_id uuid not null references auth.users(id) on delete cascade,\n parent text,\n session_id uuid,\n revoked boolean default false,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate index if not exists refresh_tokens_user_id_idx on auth.refresh_tokens(user_id);\n\ncreate table if not exists auth.one_time_tokens (\n id uuid primary key default gen_random_uuid(),\n user_id uuid references auth.users(id) on delete cascade,\n email text not null,\n token_type text not null, -- otp | magiclink | recovery\n token text not null,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.identities (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null references auth.users(id) on delete cascade,\n provider text not null,\n provider_id text not null,\n identity_data jsonb default '{}'::jsonb,\n last_sign_in_at timestamptz default now(),\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n unique (provider, provider_id)\n);\n\n-- OAuth / PKCE flow state, bridging /authorize \u2192 provider \u2192 /callback \u2192 exchange\ncreate table if not exists auth.flow_state (\n id uuid primary key default gen_random_uuid(),\n provider text not null,\n provider_state text not null unique,\n redirect_to text,\n code_challenge text,\n code_challenge_method text,\n auth_code text unique,\n user_id uuid references auth.users(id) on delete cascade,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ncreate table if not exists auth.mfa_factors (\n id uuid primary key default gen_random_uuid(),\n user_id uuid not null references auth.users(id) on delete cascade,\n friendly_name text,\n factor_type text not null default 'totp',\n status text not null default 'unverified', -- unverified | verified\n secret text,\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists auth.mfa_challenges (\n id uuid primary key default gen_random_uuid(),\n factor_id uuid not null references auth.mfa_factors(id) on delete cascade,\n verified_at timestamptz,\n created_at timestamptz default now(),\n expires_at timestamptz not null\n);\n\ngrant usage on schema auth to anon, authenticated, service_role;\n\ncreate or replace function auth.jwt() returns jsonb\nlanguage sql stable as $$\n select coalesce(\n nullif(current_setting('request.jwt.claims', true), ''),\n '{}'\n )::jsonb\n$$;\n\ncreate or replace function auth.uid() returns uuid\nlanguage sql stable as $$\n select nullif(auth.jwt() ->> 'sub', '')::uuid\n$$;\n\ncreate or replace function auth.role() returns text\nlanguage sql stable as $$\n select coalesce(auth.jwt() ->> 'role', 'anon')\n$$;\n\ncreate or replace function auth.email() returns text\nlanguage sql stable as $$\n select auth.jwt() ->> 'email'\n$$;\n\ngrant execute on function auth.jwt(), auth.uid(), auth.role(), auth.email()\n to anon, authenticated, service_role;\n\n-- \u2500\u2500 Storage schema (storage-api-compatible subset) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists storage;\n\ncreate table if not exists storage.buckets (\n id text primary key,\n name text not null unique,\n owner uuid,\n public boolean default false,\n file_size_limit bigint,\n allowed_mime_types text[],\n created_at timestamptz default now(),\n updated_at timestamptz default now()\n);\n\ncreate table if not exists storage.objects (\n id uuid primary key default gen_random_uuid(),\n bucket_id text not null references storage.buckets(id),\n name text not null,\n owner uuid,\n version text,\n metadata jsonb default '{}'::jsonb,\n created_at timestamptz default now(),\n updated_at timestamptz default now(),\n last_accessed_at timestamptz default now(),\n unique (bucket_id, name)\n);\n\ncreate index if not exists objects_bucket_name_idx on storage.objects(bucket_id, name);\n\ngrant usage on schema storage to anon, authenticated, service_role;\ngrant select on storage.buckets to anon, authenticated, service_role;\ngrant all on storage.buckets to service_role;\ngrant all on storage.objects to anon, authenticated, service_role;\n\ncreate or replace function storage.foldername(name text) returns text[]\nlanguage sql immutable as $$\n select (string_to_array(name, '/'))[1 : array_length(string_to_array(name, '/'), 1) - 1]\n$$;\n\ncreate or replace function storage.filename(name text) returns text\nlanguage sql immutable as $$\n select (string_to_array(name, '/'))[array_length(string_to_array(name, '/'), 1)]\n$$;\n\ncreate or replace function storage.extension(name text) returns text\nlanguage sql immutable as $$\n select reverse(split_part(reverse(storage.filename(name)), '.', 1))\n$$;\n\nalter table storage.objects enable row level security;\n\n-- Dev-friendly default policies. Replace them in your migrations to lock down.\ndo $$\nbegin\n if not exists (select from pg_policies where schemaname = 'storage' and tablename = 'objects' and policyname = 'tinbase_authenticated_all') then\n create policy tinbase_authenticated_all on storage.objects\n for all to authenticated using (true) with check (true);\n end if;\n if not exists (select from pg_policies where schemaname = 'storage' and tablename = 'objects' and policyname = 'tinbase_public_read') then\n create policy tinbase_public_read on storage.objects\n for select to anon\n using (bucket_id in (select id from storage.buckets where public));\n end if;\nend $$;\n\n-- \u2500\u2500 Migration bookkeeping (same table the Supabase CLI uses) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists supabase_migrations;\n\ncreate table if not exists supabase_migrations.schema_migrations (\n version text primary key,\n name text,\n statements text[],\n applied_at timestamptz default now()\n);\n\ncreate table if not exists supabase_migrations.seed_files (\n path text primary key,\n hash text,\n applied_at timestamptz default now()\n);\n\n-- \u2500\u2500 Realtime CDC plumbing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\ncreate schema if not exists tinbase;\n\ncreate or replace function tinbase.cdc_notify() returns trigger\nlanguage plpgsql security definer as $$\ndeclare\n payload text;\nbegin\n payload := json_build_object(\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'type', TG_OP,\n 'commit_timestamp', to_char(now() at time zone 'utc', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"'),\n 'record', case when TG_OP in ('INSERT', 'UPDATE') then row_to_json(NEW) else null end,\n 'old_record', case when TG_OP in ('UPDATE', 'DELETE') then row_to_json(OLD) else null end\n )::text;\n -- pg_notify payloads are capped at ~8kB; degrade like Supabase does.\n if octet_length(payload) > 7500 then\n payload := json_build_object(\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'type', TG_OP,\n 'commit_timestamp', to_char(now() at time zone 'utc', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"'),\n 'record', null,\n 'old_record', null,\n 'errors', json_build_array('Payload too large')\n )::text;\n end if;\n perform pg_notify('tinbase_cdc', payload);\n return coalesce(NEW, OLD);\nend $$;\n\n-- \u2500\u2500 Realtime Authorization + broadcast-from-database \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n-- Mirrors Supabase Realtime: developers write RLS policies on\n-- realtime.messages using realtime.topic(); a SELECT policy grants a private\n-- channel's subscribers the right to *receive*, an INSERT policy the right to\n-- *broadcast*. realtime.send() lets the database push a broadcast to a topic.\ncreate schema if not exists realtime;\n\ncreate table if not exists realtime.messages (\n id uuid not null default gen_random_uuid(),\n topic text not null,\n extension text not null,\n event text,\n payload jsonb,\n private boolean default false,\n inserted_at timestamptz not null default now(),\n updated_at timestamptz not null default now(),\n primary key (id)\n);\nalter table realtime.messages enable row level security;\n\ngrant usage on schema realtime to anon, authenticated, service_role;\ngrant all on realtime.messages to anon, authenticated, service_role;\n\n-- the topic currently being authorized/broadcast (set per operation)\ncreate or replace function realtime.topic() returns text\n language sql stable as $$ select nullif(current_setting('realtime.topic', true), '') $$;\n\n-- push a broadcast message to all subscribers of <topic> from SQL / triggers.\n-- Delivered over the websocket by the in-process realtime engine, which listens\n-- on the 'tinbase_realtime_broadcast' channel.\ncreate or replace function realtime.send(payload jsonb, event text, topic text, private boolean default true)\n returns void language plpgsql security definer as $$\nbegin\n perform pg_notify(\n 'tinbase_realtime_broadcast',\n json_build_object('topic', topic, 'event', event, 'payload', payload, 'private', private)::text\n );\nexception when others then\n -- never let a notify failure abort the caller's transaction\n null;\nend $$;\n\ngrant execute on function realtime.topic() to anon, authenticated, service_role;\ngrant execute on function realtime.send(jsonb, text, text, boolean) to anon, authenticated, service_role;\n";
@@ -3,6 +3,139 @@
3
3
  * Supabase project: roles, auth schema, storage schema, helper functions,
4
4
  * migration bookkeeping, and the realtime CDC plumbing.
5
5
  */
6
+ /**
7
+ * Reduced bootstrap for subset engines (pg-mem) that can't run plpgsql, RLS
8
+ * policies, extensions, or LISTEN/NOTIFY. Just the schemas, core tables, and
9
+ * SQL-language auth helpers needed for the REST + auth CRUD surface. No RLS is
10
+ * enforced here — this path is for local-dev/preview only.
11
+ */
12
+ export const MINIMAL_BOOTSTRAP_SQL = `
13
+ create schema if not exists auth;
14
+ create schema if not exists storage;
15
+ create schema if not exists supabase_migrations;
16
+
17
+ create table if not exists auth.users (
18
+ id uuid primary key default gen_random_uuid(),
19
+ aud text default 'authenticated',
20
+ role text default 'authenticated',
21
+ email text unique,
22
+ encrypted_password text,
23
+ email_confirmed_at timestamptz,
24
+ last_sign_in_at timestamptz,
25
+ raw_app_meta_data jsonb default '{}'::jsonb,
26
+ raw_user_meta_data jsonb default '{}'::jsonb,
27
+ is_super_admin boolean default false,
28
+ created_at timestamptz default now(),
29
+ updated_at timestamptz default now(),
30
+ phone text unique,
31
+ phone_confirmed_at timestamptz,
32
+ banned_until timestamptz,
33
+ deleted_at timestamptz,
34
+ is_anonymous boolean default false
35
+ );
36
+
37
+ create table if not exists auth.refresh_tokens (
38
+ id bigserial primary key,
39
+ token text unique not null,
40
+ user_id uuid not null,
41
+ parent text,
42
+ session_id uuid,
43
+ revoked boolean default false,
44
+ created_at timestamptz default now(),
45
+ updated_at timestamptz default now()
46
+ );
47
+
48
+ create table if not exists auth.one_time_tokens (
49
+ id uuid primary key default gen_random_uuid(),
50
+ user_id uuid,
51
+ email text not null,
52
+ token_type text not null,
53
+ token text not null,
54
+ created_at timestamptz default now(),
55
+ expires_at timestamptz not null
56
+ );
57
+
58
+ create table if not exists auth.identities (
59
+ id uuid primary key default gen_random_uuid(),
60
+ user_id uuid not null,
61
+ provider text not null,
62
+ provider_id text not null,
63
+ identity_data jsonb default '{}'::jsonb,
64
+ last_sign_in_at timestamptz default now(),
65
+ created_at timestamptz default now(),
66
+ updated_at timestamptz default now(),
67
+ unique (provider, provider_id)
68
+ );
69
+
70
+ create table if not exists auth.flow_state (
71
+ id uuid primary key default gen_random_uuid(),
72
+ provider text not null,
73
+ provider_state text not null unique,
74
+ redirect_to text,
75
+ code_challenge text,
76
+ code_challenge_method text,
77
+ auth_code text unique,
78
+ user_id uuid,
79
+ created_at timestamptz default now(),
80
+ expires_at timestamptz not null
81
+ );
82
+
83
+ create table if not exists auth.mfa_factors (
84
+ id uuid primary key default gen_random_uuid(),
85
+ user_id uuid not null,
86
+ friendly_name text,
87
+ factor_type text not null default 'totp',
88
+ status text not null default 'unverified',
89
+ secret text,
90
+ created_at timestamptz default now(),
91
+ updated_at timestamptz default now()
92
+ );
93
+
94
+ create table if not exists auth.mfa_challenges (
95
+ id uuid primary key default gen_random_uuid(),
96
+ factor_id uuid not null,
97
+ verified_at timestamptz,
98
+ created_at timestamptz default now(),
99
+ expires_at timestamptz not null
100
+ );
101
+
102
+ create table if not exists storage.buckets (
103
+ id text primary key,
104
+ name text not null unique,
105
+ owner uuid,
106
+ public boolean default false,
107
+ file_size_limit bigint,
108
+ allowed_mime_types text[],
109
+ created_at timestamptz default now(),
110
+ updated_at timestamptz default now()
111
+ );
112
+
113
+ create table if not exists storage.objects (
114
+ id uuid primary key default gen_random_uuid(),
115
+ bucket_id text not null,
116
+ name text not null,
117
+ owner uuid,
118
+ version text,
119
+ metadata jsonb default '{}'::jsonb,
120
+ created_at timestamptz default now(),
121
+ updated_at timestamptz default now(),
122
+ last_accessed_at timestamptz default now(),
123
+ unique (bucket_id, name)
124
+ );
125
+
126
+ create table if not exists supabase_migrations.schema_migrations (
127
+ version text primary key,
128
+ name text,
129
+ statements text[],
130
+ applied_at timestamptz default now()
131
+ );
132
+
133
+ create table if not exists supabase_migrations.seed_files (
134
+ path text primary key,
135
+ hash text,
136
+ applied_at timestamptz default now()
137
+ );
138
+ `;
6
139
  export const BOOTSTRAP_SQL = `
7
140
  -- ── Extensions ─────────────────────────────────────────────────────────────
8
141
  -- Supabase enables these by default and migrations lean on them
@@ -17,11 +150,27 @@ begin
17
150
  begin
18
151
  execute format('create extension if not exists %I with schema extensions', ext);
19
152
  exception when others then
20
- -- extension not bundled in this engine; continue
153
+ -- extension not bundled in this engine build; continue
21
154
  end;
22
155
  end loop;
23
156
  end $$;
24
157
 
158
+ -- uuid-ossp isn't in every Postgres build (it needs an external UUID lib at
159
+ -- build time — e.g. the theseus Linux binaries omit it). uuid_generate_v4() is
160
+ -- the single most-used function from it, so shim it onto core gen_random_uuid()
161
+ -- (also a v4 UUID) whenever the real extension isn't present, so migrations
162
+ -- that call it work identically on every engine and platform.
163
+ do $$
164
+ begin
165
+ if not exists (
166
+ select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace
167
+ where p.proname = 'uuid_generate_v4' and n.nspname in ('public', 'extensions')
168
+ ) then
169
+ create function extensions.uuid_generate_v4() returns uuid
170
+ language sql volatile as 'select gen_random_uuid()';
171
+ end if;
172
+ end $$;
173
+
25
174
  -- Make extension functions resolvable unqualified (uuid_generate_v4(), …) on
26
175
  -- the current session (migrations run here) and for future connections.
27
176
  do $$
@@ -113,6 +262,51 @@ create table if not exists auth.one_time_tokens (
113
262
  expires_at timestamptz not null
114
263
  );
115
264
 
265
+ create table if not exists auth.identities (
266
+ id uuid primary key default gen_random_uuid(),
267
+ user_id uuid not null references auth.users(id) on delete cascade,
268
+ provider text not null,
269
+ provider_id text not null,
270
+ identity_data jsonb default '{}'::jsonb,
271
+ last_sign_in_at timestamptz default now(),
272
+ created_at timestamptz default now(),
273
+ updated_at timestamptz default now(),
274
+ unique (provider, provider_id)
275
+ );
276
+
277
+ -- OAuth / PKCE flow state, bridging /authorize → provider → /callback → exchange
278
+ create table if not exists auth.flow_state (
279
+ id uuid primary key default gen_random_uuid(),
280
+ provider text not null,
281
+ provider_state text not null unique,
282
+ redirect_to text,
283
+ code_challenge text,
284
+ code_challenge_method text,
285
+ auth_code text unique,
286
+ user_id uuid references auth.users(id) on delete cascade,
287
+ created_at timestamptz default now(),
288
+ expires_at timestamptz not null
289
+ );
290
+
291
+ create table if not exists auth.mfa_factors (
292
+ id uuid primary key default gen_random_uuid(),
293
+ user_id uuid not null references auth.users(id) on delete cascade,
294
+ friendly_name text,
295
+ factor_type text not null default 'totp',
296
+ status text not null default 'unverified', -- unverified | verified
297
+ secret text,
298
+ created_at timestamptz default now(),
299
+ updated_at timestamptz default now()
300
+ );
301
+
302
+ create table if not exists auth.mfa_challenges (
303
+ id uuid primary key default gen_random_uuid(),
304
+ factor_id uuid not null references auth.mfa_factors(id) on delete cascade,
305
+ verified_at timestamptz,
306
+ created_at timestamptz default now(),
307
+ expires_at timestamptz not null
308
+ );
309
+
116
310
  grant usage on schema auth to anon, authenticated, service_role;
117
311
 
118
312
  create or replace function auth.jwt() returns jsonb
@@ -253,5 +447,50 @@ begin
253
447
  perform pg_notify('tinbase_cdc', payload);
254
448
  return coalesce(NEW, OLD);
255
449
  end $$;
450
+
451
+ -- ── Realtime Authorization + broadcast-from-database ──────────────────────
452
+ -- Mirrors Supabase Realtime: developers write RLS policies on
453
+ -- realtime.messages using realtime.topic(); a SELECT policy grants a private
454
+ -- channel's subscribers the right to *receive*, an INSERT policy the right to
455
+ -- *broadcast*. realtime.send() lets the database push a broadcast to a topic.
456
+ create schema if not exists realtime;
457
+
458
+ create table if not exists realtime.messages (
459
+ id uuid not null default gen_random_uuid(),
460
+ topic text not null,
461
+ extension text not null,
462
+ event text,
463
+ payload jsonb,
464
+ private boolean default false,
465
+ inserted_at timestamptz not null default now(),
466
+ updated_at timestamptz not null default now(),
467
+ primary key (id)
468
+ );
469
+ alter table realtime.messages enable row level security;
470
+
471
+ grant usage on schema realtime to anon, authenticated, service_role;
472
+ grant all on realtime.messages to anon, authenticated, service_role;
473
+
474
+ -- the topic currently being authorized/broadcast (set per operation)
475
+ create or replace function realtime.topic() returns text
476
+ language sql stable as $$ select nullif(current_setting('realtime.topic', true), '') $$;
477
+
478
+ -- push a broadcast message to all subscribers of <topic> from SQL / triggers.
479
+ -- Delivered over the websocket by the in-process realtime engine, which listens
480
+ -- on the 'tinbase_realtime_broadcast' channel.
481
+ create or replace function realtime.send(payload jsonb, event text, topic text, private boolean default true)
482
+ returns void language plpgsql security definer as $$
483
+ begin
484
+ perform pg_notify(
485
+ 'tinbase_realtime_broadcast',
486
+ json_build_object('topic', topic, 'event', event, 'payload', payload, 'private', private)::text
487
+ );
488
+ exception when others then
489
+ -- never let a notify failure abort the caller's transaction
490
+ null;
491
+ end $$;
492
+
493
+ grant execute on function realtime.topic() to anon, authenticated, service_role;
494
+ grant execute on function realtime.send(jsonb, text, text, boolean) to anon, authenticated, service_role;
256
495
  `;
257
496
  //# sourceMappingURL=bootstrap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/db/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0P5B,CAAA"}
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/db/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8HpC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoW5B,CAAA"}
@@ -73,10 +73,34 @@ export declare class Database {
73
73
  name: string | null;
74
74
  }[]>;
75
75
  invalidateSchemaCache(): void;
76
+ private rlsCache;
77
+ /** Names of tables in `schema` that have row-level security enabled. */
78
+ getRlsTables(schema: string): Promise<Set<string>>;
76
79
  getSchemaInfo(schema: string): Promise<SchemaInfo>;
77
80
  getFunctions(schema: string, name: string): Promise<FunctionInfo[]>;
78
81
  ensureCdcTrigger(schema: string, table: string): Promise<void>;
79
82
  onCdcEvent(cb: (e: CdcEvent) => void): Promise<() => void>;
83
+ /**
84
+ * True when the engine can't run the trigger + `pg_notify` CDC pipeline
85
+ * (pg-mem has no triggers/LISTEN/NOTIFY). For those engines the REST layer
86
+ * synthesizes change events in JS via {@link emitCdc}, since every write goes
87
+ * through it in-process.
88
+ */
89
+ get jsCdc(): boolean;
90
+ /**
91
+ * Feed synthetic CDC events into the same listener set the trigger path uses,
92
+ * so realtime `postgres_changes` and database webhooks fire on engines without
93
+ * triggers/NOTIFY (pg-mem). Called by the REST handler after a committed
94
+ * mutation, one event per affected row.
95
+ *
96
+ * NOTE: these engines have no RLS, so events are delivered unfiltered — the
97
+ * per-subscriber row check in the realtime layer is a no-op here.
98
+ */
99
+ emitCdc(meta: {
100
+ schema: string;
101
+ table: string;
102
+ type: CdcEvent['type'];
103
+ }, rows: Record<string, unknown>[]): void;
80
104
  close(): Promise<void>;
81
105
  }
82
106
  export declare function quoteIdent(name: string): string;
@@ -1,4 +1,5 @@
1
- import { BOOTSTRAP_SQL } from './bootstrap.js';
1
+ import { BOOTSTRAP_SQL, MINIMAL_BOOTSTRAP_SQL } from './bootstrap.js';
2
+ import { PGMQ_SQL, CRON_SQL } from './emulated.js';
2
3
  import { createPgliteEngine } from './pglite-engine.js';
3
4
  export class Database {
4
5
  engine;
@@ -14,7 +15,17 @@ export class Database {
14
15
  const engine = dataDirOrEngine && typeof dataDirOrEngine === 'object'
15
16
  ? dataDirOrEngine
16
17
  : await createPgliteEngine(dataDirOrEngine);
17
- await engine.exec(BOOTSTRAP_SQL);
18
+ if (engine.minimalBootstrap) {
19
+ // subset engine (pg-mem): schemas + tables only, no plpgsql/RLS/extensions
20
+ await engine.exec(MINIMAL_BOOTSTRAP_SQL);
21
+ }
22
+ else {
23
+ await engine.exec(BOOTSTRAP_SQL);
24
+ // emulated extensions (pgmq queues, cron) — pure SQL, so pgmq.*/cron.* work
25
+ // with no C extension on either engine
26
+ await engine.exec(PGMQ_SQL);
27
+ await engine.exec(CRON_SQL);
28
+ }
18
29
  return new Database(engine);
19
30
  }
20
31
  /** Superuser query — used by auth/storage internals and introspection. */
@@ -76,6 +87,20 @@ export class Database {
76
87
  invalidateSchemaCache() {
77
88
  this.schemaCache.clear();
78
89
  this.fnCache.clear();
90
+ this.rlsCache.clear();
91
+ }
92
+ rlsCache = new Map();
93
+ /** Names of tables in `schema` that have row-level security enabled. */
94
+ async getRlsTables(schema) {
95
+ const cached = this.rlsCache.get(schema);
96
+ if (cached)
97
+ return cached;
98
+ const res = await this.engine.query(`select c.relname from pg_class c
99
+ join pg_namespace n on n.oid = c.relnamespace
100
+ where n.nspname = $1 and c.relrowsecurity = true`, [schema]);
101
+ const set = new Set(res.rows.map((r) => r.relname));
102
+ this.rlsCache.set(schema, set);
103
+ return set;
79
104
  }
80
105
  async getSchemaInfo(schema) {
81
106
  const cached = this.schemaCache.get(schema);
@@ -218,6 +243,40 @@ export class Database {
218
243
  }
219
244
  return () => this.cdcListeners.delete(cb);
220
245
  }
246
+ /**
247
+ * True when the engine can't run the trigger + `pg_notify` CDC pipeline
248
+ * (pg-mem has no triggers/LISTEN/NOTIFY). For those engines the REST layer
249
+ * synthesizes change events in JS via {@link emitCdc}, since every write goes
250
+ * through it in-process.
251
+ */
252
+ get jsCdc() {
253
+ return !!this.engine.minimalBootstrap;
254
+ }
255
+ /**
256
+ * Feed synthetic CDC events into the same listener set the trigger path uses,
257
+ * so realtime `postgres_changes` and database webhooks fire on engines without
258
+ * triggers/NOTIFY (pg-mem). Called by the REST handler after a committed
259
+ * mutation, one event per affected row.
260
+ *
261
+ * NOTE: these engines have no RLS, so events are delivered unfiltered — the
262
+ * per-subscriber row check in the realtime layer is a no-op here.
263
+ */
264
+ emitCdc(meta, rows) {
265
+ if (this.cdcListeners.size === 0 || rows.length === 0)
266
+ return;
267
+ const commit_timestamp = new Date().toISOString();
268
+ for (const row of rows) {
269
+ const record = meta.type === 'DELETE' ? null : row;
270
+ const old_record = meta.type === 'DELETE' ? row : null;
271
+ let event = { ...meta, commit_timestamp, record, old_record };
272
+ // mirror the trigger's ~8kB pg_notify payload cap
273
+ if (JSON.stringify(record ?? old_record ?? {}).length > 7500) {
274
+ event = { ...event, record: null, old_record: null, errors: ['Payload too large'] };
275
+ }
276
+ for (const listener of this.cdcListeners)
277
+ listener(event);
278
+ }
279
+ }
221
280
  async close() {
222
281
  await this.engine.close();
223
282
  }
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/db/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AA6DvD,MAAM,OAAO,QAAQ;IAMQ;IALnB,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC3C,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAA;IAC3C,YAAY,GAAG,IAAI,GAAG,EAAyB,CAAA;IAC/C,UAAU,GAAG,KAAK,CAAA;IAE1B,YAA2B,MAAgB;QAAhB,WAAM,GAAN,MAAM,CAAU;IAAG,CAAC;IAE/C,oEAAoE;IACpE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,eAAmC;Q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,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IACpF,OAAO,CAAC,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACzF,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Pure-SQL emulations of Supabase's queue and cron extensions, so migrations
3
+ * and app code that call pgmq.* / cron.* work with no C extension on either
4
+ * engine. pgmq is fully self-contained SQL. cron records jobs here; the
5
+ * in-process CronService (src/cron/service.ts) executes them.
6
+ *
7
+ * These match the real extensions' function signatures closely enough that
8
+ * `pgmq.send(...)`, `pgmq.read(...)`, `select cron.schedule(...)` etc. behave
9
+ * the same from the client's and a migration's point of view.
10
+ */
11
+ export declare const PGMQ_SQL = "\ncreate schema if not exists pgmq;\ngrant usage on schema pgmq to anon, authenticated, service_role;\n\ndo $$ begin\n if not exists (select 1 from pg_type t join pg_namespace n on n.oid = t.typnamespace\n where t.typname = 'message_record' and n.nspname = 'pgmq') then\n create type pgmq.message_record as (\n msg_id bigint, read_ct integer, enqueued_at timestamptz, vt timestamptz, message jsonb\n );\n end if;\nend $$;\n\ncreate or replace function pgmq.create(queue_name text) returns void language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n execute format('create table if not exists pgmq.%I (\n msg_id bigint generated always as identity primary key,\n read_ct integer not null default 0,\n enqueued_at timestamptz not null default now(),\n vt timestamptz not null default now(),\n message jsonb)', 'q_' || queue_name);\n execute format('create table if not exists pgmq.%I (\n msg_id bigint primary key, read_ct integer not null default 0,\n enqueued_at timestamptz not null, archived_at timestamptz not null default now(),\n vt timestamptz, message jsonb)', 'a_' || queue_name);\nend $pgmq$;\n\ncreate or replace function pgmq.send(queue_name text, msg jsonb, delay integer default 0)\nreturns bigint language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare id bigint;\nbegin\n perform pgmq.create(queue_name);\n execute format('insert into pgmq.%I (vt, message) values (now() + make_interval(secs => $1), $2) returning msg_id', 'q_' || queue_name)\n into id using delay, msg;\n return id;\nend $pgmq$;\n\ncreate or replace function pgmq.read(queue_name text, vt integer, qty integer)\nreturns setof pgmq.message_record language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n return query execute format($fmt$\n with cte as (\n select msg_id from pgmq.%I where vt <= now() order by msg_id limit $1 for update skip locked\n )\n update pgmq.%I m set vt = now() + make_interval(secs => $2), read_ct = read_ct + 1\n from cte where m.msg_id = cte.msg_id\n returning m.msg_id, m.read_ct, m.enqueued_at, m.vt, m.message\n $fmt$, 'q_' || queue_name, 'q_' || queue_name) using qty, vt;\nend $pgmq$;\n\ncreate or replace function pgmq.pop(queue_name text)\nreturns setof pgmq.message_record language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\nbegin\n return query execute format($fmt$\n with cte as (select msg_id from pgmq.%I where vt <= now() order by msg_id limit 1 for update skip locked)\n delete from pgmq.%I m using cte where m.msg_id = cte.msg_id\n returning m.msg_id, m.read_ct, m.enqueued_at, m.vt, m.message\n $fmt$, 'q_' || queue_name, 'q_' || queue_name);\nend $pgmq$;\n\ncreate or replace function pgmq.delete(queue_name text, msg_id bigint)\nreturns boolean language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare n integer;\nbegin\n execute format('delete from pgmq.%I where msg_id = $1', 'q_' || queue_name) using msg_id;\n get diagnostics n = row_count;\n return n > 0;\nend $pgmq$;\n\ncreate or replace function pgmq.archive(queue_name text, msg_id bigint)\nreturns boolean language plpgsql security definer set search_path = pgmq, pg_catalog, public as $pgmq$\ndeclare n integer;\nbegin\n execute format($fmt$\n with del as (delete from pgmq.%I where msg_id = $1 returning *)\n insert into pgmq.%I (msg_id, read_ct, enqueued_at, vt, message)\n select msg_id, read_ct, enqueued_at, vt, message from del\n $fmt$, 'q_' || queue_name, 'a_' || queue_name) using msg_id;\n get diagnostics n = row_count;\n return n > 0;\nend $pgmq$;\n\ngrant execute on all functions in schema pgmq to anon, authenticated, service_role;\n";
12
+ export declare const CRON_SQL = "\ncreate schema if not exists cron;\ngrant usage on schema cron to service_role, authenticated;\n\ncreate table if not exists cron.job (\n jobid bigint generated always as identity primary key,\n schedule text not null,\n command text not null,\n jobname text unique,\n active boolean not null default true,\n created_at timestamptz not null default now()\n);\n\ncreate table if not exists cron.job_run_details (\n runid bigint generated always as identity primary key,\n jobid bigint,\n command text,\n status text,\n return_message text,\n start_time timestamptz,\n end_time timestamptz\n);\n\ncreate or replace function cron.schedule(job_name text, schedule text, command text)\nreturns bigint language plpgsql security definer set search_path = cron, pg_catalog, public as $cron$\ndeclare id bigint;\nbegin\n insert into cron.job (jobname, schedule, command) values (job_name, schedule, command)\n on conflict (jobname) do update set schedule = excluded.schedule, command = excluded.command, active = true\n returning jobid into id;\n return id;\nend $cron$;\n\ncreate or replace function cron.schedule(schedule text, command text)\nreturns bigint language plpgsql security definer set search_path = cron, pg_catalog, public as $cron$\nbegin\n return cron.schedule('job_' || floor(extract(epoch from clock_timestamp()) * 1000)::bigint::text, schedule, command);\nend $cron$;\n\ncreate or replace function cron.unschedule(job_name text)\nreturns boolean language plpgsql security definer set search_path = cron, pg_catalog, public as $cron$\ndeclare n integer;\nbegin\n delete from cron.job where jobname = job_name;\n get diagnostics n = row_count;\n return n > 0;\nend $cron$;\n\ncreate or replace function cron.unschedule(job_id bigint)\nreturns boolean language plpgsql security definer set search_path = cron, pg_catalog, public as $cron$\ndeclare n integer;\nbegin\n delete from cron.job where jobid = job_id;\n get diagnostics n = row_count;\n return n > 0;\nend $cron$;\n\ngrant execute on function cron.schedule(text,text,text), cron.schedule(text,text), cron.unschedule(text), cron.unschedule(bigint) to service_role, authenticated;\n";