tinbase 0.10.0 → 0.10.1

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 (156) hide show
  1. package/README.md +10 -9
  2. package/dist/admin/api.d.ts +62 -1
  3. package/dist/admin/api.js +209 -10
  4. package/dist/admin/api.js.map +1 -1
  5. package/dist/admin/ui.d.ts +1 -1
  6. package/dist/admin/ui.js +1548 -16
  7. package/dist/admin/ui.js.map +1 -1
  8. package/dist/auth/handler.d.ts +52 -5
  9. package/dist/auth/handler.js +147 -36
  10. package/dist/auth/handler.js.map +1 -1
  11. package/dist/auth/inbox.d.ts +4 -2
  12. package/dist/auth/inbox.js +1 -0
  13. package/dist/auth/inbox.js.map +1 -1
  14. package/dist/auth/oauth.d.ts +30 -4
  15. package/dist/auth/oauth.js +22 -6
  16. package/dist/auth/oauth.js.map +1 -1
  17. package/dist/auth/password.d.ts +5 -0
  18. package/dist/auth/password.js +7 -0
  19. package/dist/auth/password.js.map +1 -1
  20. package/dist/auth/qr.d.ts +1 -1
  21. package/dist/auth/qr.js +1 -1
  22. package/dist/auth/rate-limit.d.ts +33 -0
  23. package/dist/auth/rate-limit.js +63 -0
  24. package/dist/auth/rate-limit.js.map +1 -0
  25. package/dist/auth/redirect.d.ts +20 -0
  26. package/dist/auth/redirect.js +79 -0
  27. package/dist/auth/redirect.js.map +1 -0
  28. package/dist/auth/settings.d.ts +55 -0
  29. package/dist/auth/settings.js +116 -0
  30. package/dist/auth/settings.js.map +1 -0
  31. package/dist/auth/totp.js +1 -1
  32. package/dist/cli.js +43 -21
  33. package/dist/cli.js.map +1 -1
  34. package/dist/cron/service.d.ts +15 -2
  35. package/dist/cron/service.js +19 -2
  36. package/dist/cron/service.js.map +1 -1
  37. package/dist/db/bootstrap.d.ts +13 -6
  38. package/dist/db/bootstrap.js +26 -5
  39. package/dist/db/bootstrap.js.map +1 -1
  40. package/dist/db/database.d.ts +61 -3
  41. package/dist/db/database.js +72 -9
  42. package/dist/db/database.js.map +1 -1
  43. package/dist/db/emulated.d.ts +39 -2
  44. package/dist/db/emulated.js +39 -23
  45. package/dist/db/emulated.js.map +1 -1
  46. package/dist/db/engine.d.ts +19 -5
  47. package/dist/db/engine.js +4 -2
  48. package/dist/db/engine.js.map +1 -1
  49. package/dist/db/inspect.d.ts +6 -1
  50. package/dist/db/inspect.js +2 -1
  51. package/dist/db/inspect.js.map +1 -1
  52. package/dist/db/pglite-engine.d.ts +7 -1
  53. package/dist/db/pglite-engine.js +7 -1
  54. package/dist/db/pglite-engine.js.map +1 -1
  55. package/dist/db/pgmem-engine.d.ts +9 -3
  56. package/dist/db/pgmem-engine.js +13 -7
  57. package/dist/db/pgmem-engine.js.map +1 -1
  58. package/dist/db/schema-diff.d.ts +9 -1
  59. package/dist/db/schema-diff.js +19 -5
  60. package/dist/db/schema-diff.js.map +1 -1
  61. package/dist/db/sql-compat.d.ts +2 -2
  62. package/dist/db/sql-compat.js +2 -2
  63. package/dist/functions/deno-shim.d.ts +6 -17
  64. package/dist/functions/deno-shim.js +42 -10
  65. package/dist/functions/deno-shim.js.map +1 -1
  66. package/dist/functions/handler.d.ts +9 -4
  67. package/dist/functions/handler.js +9 -1
  68. package/dist/functions/handler.js.map +1 -1
  69. package/dist/gen-types.d.ts +6 -1
  70. package/dist/gen-types.js +53 -41
  71. package/dist/gen-types.js.map +1 -1
  72. package/dist/index.d.ts +33 -3
  73. package/dist/index.js +158 -28
  74. package/dist/index.js.map +1 -1
  75. package/dist/jwt.d.ts +4 -1
  76. package/dist/jwt.js +4 -2
  77. package/dist/jwt.js.map +1 -1
  78. package/dist/log-buffer.d.ts +7 -1
  79. package/dist/log-buffer.js +3 -0
  80. package/dist/log-buffer.js.map +1 -1
  81. package/dist/net/service.d.ts +35 -6
  82. package/dist/net/service.js +72 -17
  83. package/dist/net/service.js.map +1 -1
  84. package/dist/node/bun-server.d.ts +2 -1
  85. package/dist/node/bun-server.js +11 -1
  86. package/dist/node/bun-server.js.map +1 -1
  87. package/dist/node/bundle-function.d.ts +1 -1
  88. package/dist/node/bundle-function.js +1 -1
  89. package/dist/node/config-toml.d.ts +31 -0
  90. package/dist/node/config-toml.js +186 -0
  91. package/dist/node/config-toml.js.map +1 -0
  92. package/dist/node/db-diff.d.ts +13 -1
  93. package/dist/node/db-diff.js +3 -1
  94. package/dist/node/db-diff.js.map +1 -1
  95. package/dist/node/fs-driver.d.ts +16 -1
  96. package/dist/node/fs-driver.js +20 -1
  97. package/dist/node/fs-driver.js.map +1 -1
  98. package/dist/node/index.d.ts +2 -2
  99. package/dist/node/index.js +1 -1
  100. package/dist/node/index.js.map +1 -1
  101. package/dist/node/load-config.d.ts +80 -0
  102. package/dist/node/load-config.js +230 -0
  103. package/dist/node/load-config.js.map +1 -0
  104. package/dist/node/load-functions.d.ts +17 -2
  105. package/dist/node/load-functions.js +17 -4
  106. package/dist/node/load-functions.js.map +1 -1
  107. package/dist/node/native/engine.d.ts +7 -0
  108. package/dist/node/native/engine.js +58 -7
  109. package/dist/node/native/engine.js.map +1 -1
  110. package/dist/node/native/wire.d.ts +15 -1
  111. package/dist/node/native/wire.js +32 -10
  112. package/dist/node/native/wire.js.map +1 -1
  113. package/dist/node/project.d.ts +15 -1
  114. package/dist/node/project.js +19 -7
  115. package/dist/node/project.js.map +1 -1
  116. package/dist/node/server-shared.d.ts +4 -1
  117. package/dist/node/server.d.ts +11 -0
  118. package/dist/node/server.js +11 -0
  119. package/dist/node/server.js.map +1 -1
  120. package/dist/node/ws.d.ts +26 -1
  121. package/dist/node/ws.js +26 -3
  122. package/dist/node/ws.js.map +1 -1
  123. package/dist/realtime/engine.d.ts +6 -0
  124. package/dist/realtime/engine.js +45 -34
  125. package/dist/realtime/engine.js.map +1 -1
  126. package/dist/rest/build.d.ts +37 -1
  127. package/dist/rest/build.js +48 -8
  128. package/dist/rest/build.js.map +1 -1
  129. package/dist/rest/errors.d.ts +8 -0
  130. package/dist/rest/errors.js +12 -1
  131. package/dist/rest/errors.js.map +1 -1
  132. package/dist/rest/handler.d.ts +17 -1
  133. package/dist/rest/handler.js +48 -5
  134. package/dist/rest/handler.js.map +1 -1
  135. package/dist/rest/parse.d.ts +24 -1
  136. package/dist/rest/parse.js +7 -1
  137. package/dist/rest/parse.js.map +1 -1
  138. package/dist/retention/service.d.ts +3 -0
  139. package/dist/retention/service.js +3 -1
  140. package/dist/retention/service.js.map +1 -1
  141. package/dist/security.d.ts +22 -0
  142. package/dist/security.js +47 -0
  143. package/dist/security.js.map +1 -0
  144. package/dist/storage/driver.d.ts +8 -1
  145. package/dist/storage/driver.js +4 -1
  146. package/dist/storage/driver.js.map +1 -1
  147. package/dist/storage/handler.d.ts +10 -1
  148. package/dist/storage/handler.js +93 -12
  149. package/dist/storage/handler.js.map +1 -1
  150. package/dist/types.d.ts +77 -1
  151. package/dist/types.js +10 -0
  152. package/dist/types.js.map +1 -1
  153. package/dist/webhooks/service.d.ts +25 -2
  154. package/dist/webhooks/service.js +21 -3
  155. package/dist/webhooks/service.js.map +1 -1
  156. package/package.json +5 -3
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/cron/service.ts"],"names":[],"mappings":"AAkBA,MAAM,OAAO,WAAW;IAMZ;IAEA;IACA;IARF,KAAK,GAA0C,IAAI,CAAA;IACnD,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAC,+BAA+B;IACnE,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAC,iCAAiC;IAEhF,YACU,EAAY;IACpB,kFAAkF;IAC1E,SAAS,IAAI,EACb,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;QAHlC,OAAE,GAAF,EAAE,CAAU;QAEZ,WAAM,GAAN,MAAM,CAAO;QACb,QAAG,GAAH,GAAG,CAA+B;IACzC,CAAC;IAEJ,KAAK;QACH,IAAI,IAAI,CAAC,KAAK;YAAE,OAAM;QACtB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,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Q,CAAC,CAAA;YAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAA;YACjC,IAAI,KAAK,KAAK,CAAC,CAAC;gBAAE,OAAO,CAAC,KAAK,KAAK,CAAA;YACpC,EAAE,GAAG,CAAC,CAAA;YACN,EAAE,GAAG,GAAG,CAAA;QACV,CAAC;IACH,CAAC;IACD,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,KAAK,CAAA;IAC1C,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,CAAA;AAClC,CAAC"}
@@ -1,13 +1,20 @@
1
1
  /**
2
- * Idempotent bootstrap SQL that shapes a fresh PGlite database like a
3
- * Supabase project: roles, auth schema, storage schema, helper functions,
4
- * migration bookkeeping, and the realtime CDC plumbing.
2
+ * Idempotent bootstrap SQL that shapes a fresh database like a Supabase
3
+ * project. Two variants: the full {@link BOOTSTRAP_SQL} for the real engines,
4
+ * and the reduced {@link MINIMAL_BOOTSTRAP_SQL} below for the pg-mem subset.
5
+ * Both are safe to re-run (create ... if not exists / create or replace).
5
6
  */
6
7
  /**
7
8
  * Reduced bootstrap for subset engines (pg-mem) that can't run plpgsql, RLS
8
9
  * policies, extensions, or LISTEN/NOTIFY. Just the schemas, core tables, and
9
10
  * 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
+ * enforced here - this path is for local-dev/preview only.
11
12
  */
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 attempts int not null default 0,\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 auth.audit_log_entries (\n id uuid primary key default gen_random_uuid(),\n payload jsonb,\n created_at timestamptz default now(),\n ip_address varchar(64) not null default ''\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 instance_id uuid default '00000000-0000-0000-0000-000000000000',\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 default '',\n confirmation_sent_at timestamptz,\n recovery_token text default '',\n recovery_sent_at timestamptz,\n email_change_token_new text default '',\n email_change text default '',\n email_change_sent_at timestamptz,\n email_change_token_current text default '',\n email_change_confirm_status smallint default 0,\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 phone_change text default '',\n phone_change_token text default '',\n phone_change_sent_at timestamptz,\n reauthentication_token text default '',\n reauthentication_sent_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 attempts int not null default 0,\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\n-- append-only security audit trail (GoTrue-compatible shape)\ncreate table if not exists auth.audit_log_entries (\n instance_id uuid default '00000000-0000-0000-0000-000000000000',\n id uuid primary key default gen_random_uuid(),\n payload jsonb,\n created_at timestamptz default now(),\n ip_address varchar(64) not null default ''\n);\ncreate index if not exists audit_logs_instance_id_idx on auth.audit_log_entries(created_at);\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";
13
+ 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 attempts int not null default 0,\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 auth.audit_log_entries (\n id uuid primary key default gen_random_uuid(),\n payload jsonb,\n created_at timestamptz default now(),\n ip_address varchar(64) not null default ''\n);\n\n-- runtime-mutable instance settings (Studio auth toggles)\ncreate table if not exists auth.config (\n key text primary key,\n value jsonb not null,\n updated_at timestamptz default now()\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";
14
+ /**
15
+ * Full bootstrap for the real engines (PGlite / native embedded Postgres):
16
+ * extensions, the anon/authenticated/service_role roles, GoTrue-compatible auth
17
+ * schema, storage schema with default RLS policies, migration bookkeeping, and
18
+ * the realtime CDC + broadcast plumbing.
19
+ */
20
+ 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 - 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 instance_id uuid default '00000000-0000-0000-0000-000000000000',\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 default '',\n confirmation_sent_at timestamptz,\n recovery_token text default '',\n recovery_sent_at timestamptz,\n email_change_token_new text default '',\n email_change text default '',\n email_change_sent_at timestamptz,\n email_change_token_current text default '',\n email_change_confirm_status smallint default 0,\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 phone_change text default '',\n phone_change_token text default '',\n phone_change_sent_at timestamptz,\n reauthentication_token text default '',\n reauthentication_sent_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 attempts int not null default 0,\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\n-- append-only security audit trail (GoTrue-compatible shape)\ncreate table if not exists auth.audit_log_entries (\n instance_id uuid default '00000000-0000-0000-0000-000000000000',\n id uuid primary key default gen_random_uuid(),\n payload jsonb,\n created_at timestamptz default now(),\n ip_address varchar(64) not null default ''\n);\ncreate index if not exists audit_logs_instance_id_idx on auth.audit_log_entries(created_at);\n\n-- runtime-mutable instance settings (Studio auth toggles)\ncreate table if not exists auth.config (\n key text primary key,\n value jsonb not null,\n updated_at timestamptz default now()\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";
@@ -1,13 +1,14 @@
1
1
  /**
2
- * Idempotent bootstrap SQL that shapes a fresh PGlite database like a
3
- * Supabase project: roles, auth schema, storage schema, helper functions,
4
- * migration bookkeeping, and the realtime CDC plumbing.
2
+ * Idempotent bootstrap SQL that shapes a fresh database like a Supabase
3
+ * project. Two variants: the full {@link BOOTSTRAP_SQL} for the real engines,
4
+ * and the reduced {@link MINIMAL_BOOTSTRAP_SQL} below for the pg-mem subset.
5
+ * Both are safe to re-run (create ... if not exists / create or replace).
5
6
  */
6
7
  /**
7
8
  * Reduced bootstrap for subset engines (pg-mem) that can't run plpgsql, RLS
8
9
  * policies, extensions, or LISTEN/NOTIFY. Just the schemas, core tables, and
9
10
  * 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
+ * enforced here - this path is for local-dev/preview only.
11
12
  */
12
13
  export const MINIMAL_BOOTSTRAP_SQL = `
13
14
  create schema if not exists auth;
@@ -107,6 +108,13 @@ create table if not exists auth.audit_log_entries (
107
108
  ip_address varchar(64) not null default ''
108
109
  );
109
110
 
111
+ -- runtime-mutable instance settings (Studio auth toggles)
112
+ create table if not exists auth.config (
113
+ key text primary key,
114
+ value jsonb not null,
115
+ updated_at timestamptz default now()
116
+ );
117
+
110
118
  create table if not exists storage.buckets (
111
119
  id text primary key,
112
120
  name text not null unique,
@@ -144,6 +152,12 @@ create table if not exists supabase_migrations.seed_files (
144
152
  applied_at timestamptz default now()
145
153
  );
146
154
  `;
155
+ /**
156
+ * Full bootstrap for the real engines (PGlite / native embedded Postgres):
157
+ * extensions, the anon/authenticated/service_role roles, GoTrue-compatible auth
158
+ * schema, storage schema with default RLS policies, migration bookkeeping, and
159
+ * the realtime CDC + broadcast plumbing.
160
+ */
147
161
  export const BOOTSTRAP_SQL = `
148
162
  -- ── Extensions ─────────────────────────────────────────────────────────────
149
163
  -- Supabase enables these by default and migrations lean on them
@@ -164,7 +178,7 @@ begin
164
178
  end $$;
165
179
 
166
180
  -- uuid-ossp isn't in every Postgres build (it needs an external UUID lib at
167
- -- build time — e.g. the theseus Linux binaries omit it). uuid_generate_v4() is
181
+ -- build time - e.g. the theseus Linux binaries omit it). uuid_generate_v4() is
168
182
  -- the single most-used function from it, so shim it onto core gen_random_uuid()
169
183
  -- (also a v4 UUID) whenever the real extension isn't present, so migrations
170
184
  -- that call it work identically on every engine and platform.
@@ -339,6 +353,13 @@ create table if not exists auth.audit_log_entries (
339
353
  );
340
354
  create index if not exists audit_logs_instance_id_idx on auth.audit_log_entries(created_at);
341
355
 
356
+ -- runtime-mutable instance settings (Studio auth toggles)
357
+ create table if not exists auth.config (
358
+ key text primary key,
359
+ value jsonb not null,
360
+ updated_at timestamptz default now()
361
+ );
362
+
342
363
  grant usage on schema auth to anon, authenticated, service_role;
343
364
 
344
365
  create or replace function auth.jwt() returns jsonb
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/db/bootstrap.ts"],"names":[],"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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmY5B,CAAA"}
@@ -1,12 +1,15 @@
1
1
  import type { DbEngine, EngineResults } from './engine.js';
2
2
  import type { MigrationFile, RequestContext } from '../types.js';
3
+ /** One column of an introspected table. */
3
4
  export interface ColumnInfo {
4
5
  name: string;
6
+ /** underlying pg type name (pg_type.typname / information_schema.udt_name). */
5
7
  udtName: string;
6
8
  isNullable: boolean;
7
9
  hasDefault: boolean;
8
10
  isPrimaryKey: boolean;
9
11
  }
12
+ /** A foreign-key constraint, with source and target columns paired by position. */
10
13
  export interface ForeignKey {
11
14
  constraintName: string;
12
15
  srcSchema: string;
@@ -16,16 +19,26 @@ export interface ForeignKey {
16
19
  tgtTable: string;
17
20
  tgtColumns: string[];
18
21
  }
22
+ /** An introspected table: its columns and primary-key column names. */
19
23
  export interface TableInfo {
20
24
  schema: string;
21
25
  name: string;
22
26
  columns: ColumnInfo[];
23
27
  primaryKey: string[];
28
+ /**
29
+ * Column-sets with a uniqueness guarantee (each PRIMARY KEY / UNIQUE
30
+ * constraint, columns in definition order). Used to decide embed cardinality:
31
+ * a foreign key whose columns are a unique key on the referencing side is a
32
+ * one-to-one relationship (PostgREST serializes it as an object, not array).
33
+ */
34
+ uniqueKeys: string[][];
24
35
  }
36
+ /** One argument of a database function. */
25
37
  export interface FunctionArg {
26
38
  name: string;
27
39
  type: string;
28
40
  }
41
+ /** An introspected database function (used to route RPC calls). */
29
42
  export interface FunctionInfo {
30
43
  schema: string;
31
44
  name: string;
@@ -33,22 +46,38 @@ export interface FunctionInfo {
33
46
  returnType: string;
34
47
  /** pg_type.typtype: b=base, c=composite, p=pseudo, d=domain, e=enum */
35
48
  returnTypType: string;
49
+ /** pg_proc.provolatile: v=volatile, s=stable, i=immutable. Volatile calls may run DDL. */
50
+ volatility: string;
36
51
  args: FunctionArg[];
37
52
  }
53
+ /** Introspected shape of one schema: tables keyed by name, plus its foreign keys. */
38
54
  export interface SchemaInfo {
39
55
  tables: Map<string, TableInfo>;
40
56
  foreignKeys: ForeignKey[];
41
57
  }
58
+ /** A function that runs a parameterized query, e.g. one bound to a transaction. */
42
59
  export type Querier = (sql: string, params?: unknown[]) => Promise<EngineResults>;
60
+ /**
61
+ * A change-data-capture event for one row, shaped like Supabase Realtime's
62
+ * `postgres_changes` payload. Emitted by the SQL trigger on the real engines
63
+ * and synthesized in JS on pg-mem (see {@link Database.emitCdc}).
64
+ */
43
65
  export interface CdcEvent {
44
66
  schema: string;
45
67
  table: string;
46
68
  type: 'INSERT' | 'UPDATE' | 'DELETE';
47
69
  commit_timestamp: string;
70
+ /** post-image; null on DELETE (and on a payload that was too large). */
48
71
  record: Record<string, unknown> | null;
72
+ /** pre-image; null on INSERT (and on a payload that was too large). */
49
73
  old_record: Record<string, unknown> | null;
74
+ /** set when the row was dropped from the payload, e.g. 'Payload too large'. */
50
75
  errors?: string[];
51
76
  }
77
+ /**
78
+ * The database facade: wraps a {@link DbEngine} with bootstrap, migration
79
+ * application, schema introspection (cached), and the realtime CDC pipeline.
80
+ */
52
81
  export declare class Database {
53
82
  engine: DbEngine;
54
83
  private schemaCache;
@@ -60,27 +89,48 @@ export declare class Database {
60
89
  static create(dataDirOrEngine?: string | DbEngine, opts?: {
61
90
  vaultKey?: string;
62
91
  }): Promise<Database>;
63
- /** Superuser query — used by auth/storage internals and introspection. */
92
+ /** Superuser query - used by auth/storage internals and introspection. */
64
93
  query<T = any>(sql: string, params?: unknown[]): Promise<EngineResults<T>>;
94
+ /** Run one or more SQL statements with no params (superuser). */
65
95
  exec(sql: string): Promise<unknown>;
66
96
  /**
67
97
  * Run `fn` inside a transaction with the request's Postgres role and JWT
68
- * claims applied via SET LOCAL — this is what makes RLS behave exactly
98
+ * claims applied via SET LOCAL - this is what makes RLS behave exactly
69
99
  * like hosted Supabase.
70
100
  */
71
101
  withContext<T>(ctx: RequestContext, fn: (q: Querier) => Promise<T>): Promise<T>;
102
+ /**
103
+ * Apply any not-yet-recorded migrations (in lexicographic version order) and
104
+ * an optional seed, each in its own transaction, then invalidate the schema
105
+ * cache. Returns the names of what was applied this run.
106
+ *
107
+ * @throws whatever a migration throws, except on the pg-mem engine where an
108
+ * unsupported migration is skipped with a warning instead of aborting.
109
+ */
72
110
  runMigrations(migrations: MigrationFile[], seedSql?: string): Promise<string[]>;
111
+ /** Every migration recorded as applied, oldest version first. */
73
112
  listAppliedMigrations(): Promise<{
74
113
  version: string;
75
114
  name: string | null;
76
115
  }[]>;
116
+ /** Drop all cached introspection; call after any DDL changes the schema. */
77
117
  invalidateSchemaCache(): void;
78
118
  private rlsCache;
79
119
  /** Names of tables in `schema` that have row-level security enabled. */
80
120
  getRlsTables(schema: string): Promise<Set<string>>;
121
+ /** Introspect a schema's tables, columns, PKs, and FKs. Cached per schema. */
81
122
  getSchemaInfo(schema: string): Promise<SchemaInfo>;
123
+ /**
124
+ * All overloads of a function by schema + name (cached). Multiple rows mean
125
+ * the name is overloaded on argument types.
126
+ */
82
127
  getFunctions(schema: string, name: string): Promise<FunctionInfo[]>;
128
+ /** Idempotently attach the CDC notify trigger to a table (real engines only). */
83
129
  ensureCdcTrigger(schema: string, table: string): Promise<void>;
130
+ /**
131
+ * Register a CDC listener; the first call starts the single LISTEN on the
132
+ * shared `tinbase_cdc` channel. Returns an unsubscribe fn.
133
+ */
84
134
  onCdcEvent(cb: (e: CdcEvent) => void): Promise<() => void>;
85
135
  /**
86
136
  * True when the engine can't run the trigger + `pg_notify` CDC pipeline
@@ -95,7 +145,7 @@ export declare class Database {
95
145
  * triggers/NOTIFY (pg-mem). Called by the REST handler after a committed
96
146
  * mutation, one event per affected row.
97
147
  *
98
- * NOTE: these engines have no RLS, so events are delivered unfiltered — the
148
+ * NOTE: these engines have no RLS, so events are delivered unfiltered - the
99
149
  * per-subscriber row check in the realtime layer is a no-op here.
100
150
  */
101
151
  emitCdc(meta: {
@@ -103,7 +153,15 @@ export declare class Database {
103
153
  table: string;
104
154
  type: CdcEvent['type'];
105
155
  }, rows: Record<string, unknown>[]): void;
156
+ /** Close the underlying engine and its connection. */
106
157
  close(): Promise<void>;
107
158
  }
159
+ /** Parse pg_get_function_identity_arguments output: "a integer, b text[]". */
160
+ export declare function parseIdentityArgs(identity: string): FunctionArg[];
161
+ /**
162
+ * Double-quote an identifier for safe interpolation into SQL.
163
+ * @throws if the name contains a NUL, which Postgres identifiers can't hold.
164
+ */
108
165
  export declare function quoteIdent(name: string): string;
166
+ /** Single-quote a string literal for safe interpolation into SQL. */
109
167
  export declare function quoteLiteral(value: string): string;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * The Database facade over a DbEngine: bootstraps a fresh database into a
3
+ * Supabase-shaped project, applies migrations/seeds the way the Supabase CLI
4
+ * does, introspects schema/functions (with caching), and drives the realtime
5
+ * CDC pipeline. Everything above the engine (REST, auth, storage, realtime)
6
+ * goes through this class.
7
+ */
1
8
  import { BOOTSTRAP_SQL, MINIMAL_BOOTSTRAP_SQL } from './bootstrap.js';
2
9
  import { PGMQ_SQL, CRON_SQL, NET_SQL, EXT_COMPAT_SQL, VAULT_SQL } from './emulated.js';
3
10
  import { rewriteMigrationSql } from './sql-compat.js';
@@ -6,6 +13,10 @@ import { rewriteMigrationSql } from './sql-compat.js';
6
13
  // migration's own `SET search_path` can't leak across our single connection.
7
14
  const DEFAULT_SEARCH_PATH_SQL = `set search_path to "$user", public, extensions`;
8
15
  import { createPgliteEngine } from './pglite-engine.js';
16
+ /**
17
+ * The database facade: wraps a {@link DbEngine} with bootstrap, migration
18
+ * application, schema introspection (cached), and the realtime CDC pipeline.
19
+ */
9
20
  export class Database {
10
21
  engine;
11
22
  schemaCache = new Map();
@@ -26,7 +37,7 @@ export class Database {
26
37
  }
27
38
  else {
28
39
  await engine.exec(BOOTSTRAP_SQL);
29
- // emulated extensions (pgmq queues, cron, pg_net) — pure SQL, so
40
+ // emulated extensions (pgmq queues, cron, pg_net) - pure SQL, so
30
41
  // pgmq.*/cron.*/net.* work with no C extension on either engine
31
42
  await engine.exec(PGMQ_SQL);
32
43
  await engine.exec(CRON_SQL);
@@ -41,16 +52,17 @@ export class Database {
41
52
  }
42
53
  return new Database(engine);
43
54
  }
44
- /** Superuser query — used by auth/storage internals and introspection. */
55
+ /** Superuser query - used by auth/storage internals and introspection. */
45
56
  query(sql, params) {
46
57
  return this.engine.query(sql, params);
47
58
  }
59
+ /** Run one or more SQL statements with no params (superuser). */
48
60
  exec(sql) {
49
61
  return this.engine.exec(sql);
50
62
  }
51
63
  /**
52
64
  * Run `fn` inside a transaction with the request's Postgres role and JWT
53
- * claims applied via SET LOCAL — this is what makes RLS behave exactly
65
+ * claims applied via SET LOCAL - this is what makes RLS behave exactly
54
66
  * like hosted Supabase.
55
67
  */
56
68
  async withContext(ctx, fn) {
@@ -61,9 +73,20 @@ export class Database {
61
73
  });
62
74
  }
63
75
  // ── Migrations (Supabase CLI conventions) ────────────────────────────
76
+ /**
77
+ * Apply any not-yet-recorded migrations (in lexicographic version order) and
78
+ * an optional seed, each in its own transaction, then invalidate the schema
79
+ * cache. Returns the names of what was applied this run.
80
+ *
81
+ * @throws whatever a migration throws, except on the pg-mem engine where an
82
+ * unsupported migration is skipped with a warning instead of aborting.
83
+ */
64
84
  async runMigrations(migrations, seedSql) {
65
85
  const applied = [];
66
- const sorted = [...migrations].sort((a, b) => a.name.localeCompare(b.name));
86
+ // Plain code-unit comparison (not localeCompare, which is locale-dependent
87
+ // and can reorder `_`/digits) so migrations apply in the same order on every
88
+ // machine, matching the Supabase CLI's lexicographic version ordering.
89
+ const sorted = [...migrations].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
67
90
  for (const m of sorted) {
68
91
  const version = m.name.match(/^(\d+)/)?.[1] ?? m.name;
69
92
  const seen = await this.engine.query(`select 1 from supabase_migrations.schema_migrations where version = $1`, [version]);
@@ -73,7 +96,7 @@ export class Database {
73
96
  // The Supabase CLI applies each migration on a fresh connection, so a
74
97
  // top-level `SET search_path TO ''` in one file never leaks to the next.
75
98
  // tinbase runs every migration on one connection, so reset to the
76
- // default first — otherwise a hardened migration's search_path change
99
+ // default first - otherwise a hardened migration's search_path change
77
100
  // breaks unqualified calls (e.g. gen_random_bytes) in later files.
78
101
  await tx.exec(DEFAULT_SEARCH_PATH_SQL);
79
102
  await tx.exec(rewriteMigrationSql(m.sql));
@@ -109,18 +132,20 @@ export class Database {
109
132
  }
110
133
  }
111
134
  if (applied.length > 0) {
112
- // a migration/seed may have left the session search_path at '' — restore
135
+ // a migration/seed may have left the session search_path at '' - restore
113
136
  // the default so runtime queries resolve extension functions unqualified
114
137
  await this.engine.exec(DEFAULT_SEARCH_PATH_SQL);
115
138
  this.invalidateSchemaCache();
116
139
  }
117
140
  return applied;
118
141
  }
142
+ /** Every migration recorded as applied, oldest version first. */
119
143
  async listAppliedMigrations() {
120
144
  const res = await this.engine.query(`select version, name from supabase_migrations.schema_migrations order by version`);
121
145
  return res.rows;
122
146
  }
123
147
  // ── Introspection ────────────────────────────────────────────────────
148
+ /** Drop all cached introspection; call after any DDL changes the schema. */
124
149
  invalidateSchemaCache() {
125
150
  this.schemaCache.clear();
126
151
  this.fnCache.clear();
@@ -139,6 +164,7 @@ export class Database {
139
164
  this.rlsCache.set(schema, set);
140
165
  return set;
141
166
  }
167
+ /** Introspect a schema's tables, columns, PKs, and FKs. Cached per schema. */
142
168
  async getSchemaInfo(schema) {
143
169
  const cached = this.schemaCache.get(schema);
144
170
  if (cached)
@@ -154,6 +180,25 @@ export class Database {
154
180
  on kcu.constraint_name = tc.constraint_name
155
181
  and kcu.constraint_schema = tc.constraint_schema
156
182
  where tc.constraint_type = 'PRIMARY KEY' and tc.table_schema = $1`, [schema]);
183
+ // PRIMARY KEY + UNIQUE constraints, grouped per constraint (in column order)
184
+ // so embed cardinality can tell one-to-one from one-to-many.
185
+ const uniq = await this.engine.query(`select kcu.table_name, kcu.constraint_name, kcu.column_name, kcu.ordinal_position as ordinal
186
+ from information_schema.table_constraints tc
187
+ join information_schema.key_column_usage kcu
188
+ on kcu.constraint_name = tc.constraint_name
189
+ and kcu.constraint_schema = tc.constraint_schema
190
+ where tc.constraint_type in ('PRIMARY KEY', 'UNIQUE') and tc.table_schema = $1
191
+ order by kcu.constraint_name, kcu.ordinal_position`, [schema]);
192
+ // table -> constraint -> ordered column list
193
+ const uniqByTable = new Map();
194
+ for (const u of uniq.rows) {
195
+ if (!uniqByTable.has(u.table_name))
196
+ uniqByTable.set(u.table_name, new Map());
197
+ const byConstraint = uniqByTable.get(u.table_name);
198
+ if (!byConstraint.has(u.constraint_name))
199
+ byConstraint.set(u.constraint_name, []);
200
+ byConstraint.get(u.constraint_name).push(u.column_name);
201
+ }
157
202
  const fks = await this.engine.query(`select
158
203
  tc.constraint_name,
159
204
  tc.table_schema as src_schema, tc.table_name as src_table,
@@ -185,6 +230,7 @@ export class Database {
185
230
  name: c.table_name,
186
231
  columns: [],
187
232
  primaryKey: [...(pkSet.get(c.table_name) ?? [])],
233
+ uniqueKeys: [...(uniqByTable.get(c.table_name)?.values() ?? [])],
188
234
  });
189
235
  }
190
236
  tables.get(c.table_name).columns.push({
@@ -219,6 +265,10 @@ export class Database {
219
265
  this.schemaCache.set(schema, info);
220
266
  return info;
221
267
  }
268
+ /**
269
+ * All overloads of a function by schema + name (cached). Multiple rows mean
270
+ * the name is overloaded on argument types.
271
+ */
222
272
  async getFunctions(schema, name) {
223
273
  const key = `${schema}.${name}`;
224
274
  const cached = this.fnCache.get(key);
@@ -226,6 +276,7 @@ export class Database {
226
276
  return cached;
227
277
  const res = await this.engine.query(`select p.proname as name, p.proretset as returns_set,
228
278
  t.typname as return_type, t.typtype as return_typtype,
279
+ p.provolatile as volatility,
229
280
  pg_get_function_identity_arguments(p.oid) as identity_args
230
281
  from pg_proc p
231
282
  join pg_namespace n on n.oid = p.pronamespace
@@ -237,12 +288,14 @@ export class Database {
237
288
  returnsSet: r.returns_set,
238
289
  returnType: r.return_type,
239
290
  returnTypType: r.return_typtype,
291
+ volatility: r.volatility,
240
292
  args: parseIdentityArgs(r.identity_args),
241
293
  }));
242
294
  this.fnCache.set(key, fns);
243
295
  return fns;
244
296
  }
245
297
  // ── Realtime CDC ─────────────────────────────────────────────────────
298
+ /** Idempotently attach the CDC notify trigger to a table (real engines only). */
246
299
  async ensureCdcTrigger(schema, table) {
247
300
  const s = quoteIdent(schema);
248
301
  const t = quoteIdent(table);
@@ -263,6 +316,10 @@ export class Database {
263
316
  end $$;
264
317
  `);
265
318
  }
319
+ /**
320
+ * Register a CDC listener; the first call starts the single LISTEN on the
321
+ * shared `tinbase_cdc` channel. Returns an unsubscribe fn.
322
+ */
266
323
  async onCdcEvent(cb) {
267
324
  this.cdcListeners.add(cb);
268
325
  if (!this.cdcStarted) {
@@ -274,7 +331,7 @@ export class Database {
274
331
  listener(event);
275
332
  }
276
333
  catch {
277
- // malformed payload — drop
334
+ // malformed payload - drop
278
335
  }
279
336
  });
280
337
  }
@@ -295,7 +352,7 @@ export class Database {
295
352
  * triggers/NOTIFY (pg-mem). Called by the REST handler after a committed
296
353
  * mutation, one event per affected row.
297
354
  *
298
- * NOTE: these engines have no RLS, so events are delivered unfiltered — the
355
+ * NOTE: these engines have no RLS, so events are delivered unfiltered - the
299
356
  * per-subscriber row check in the realtime layer is a no-op here.
300
357
  */
301
358
  emitCdc(meta, rows) {
@@ -314,12 +371,13 @@ export class Database {
314
371
  listener(event);
315
372
  }
316
373
  }
374
+ /** Close the underlying engine and its connection. */
317
375
  async close() {
318
376
  await this.engine.close();
319
377
  }
320
378
  }
321
379
  /** Parse pg_get_function_identity_arguments output: "a integer, b text[]". */
322
- function parseIdentityArgs(identity) {
380
+ export function parseIdentityArgs(identity) {
323
381
  if (!identity.trim())
324
382
  return [];
325
383
  const parts = [];
@@ -351,11 +409,16 @@ function parseIdentityArgs(identity) {
351
409
  return { name, type: tokens.slice(1).join(' ') };
352
410
  });
353
411
  }
412
+ /**
413
+ * Double-quote an identifier for safe interpolation into SQL.
414
+ * @throws if the name contains a NUL, which Postgres identifiers can't hold.
415
+ */
354
416
  export function quoteIdent(name) {
355
417
  if (name.includes('\0'))
356
418
  throw new Error('invalid identifier');
357
419
  return `"${name.replaceAll('"', '""')}"`;
358
420
  }
421
+ /** Single-quote a string literal for safe interpolation into SQL. */
359
422
  export function quoteLiteral(value) {
360
423
  return `'${value.replaceAll("'", "''")}'`;
361
424
  }