better-supabase 0.3.0 → 0.5.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 (211) hide show
  1. package/README.md +9 -6
  2. package/bin/better-supabase.js +4 -0
  3. package/dist/{base64-CQeB1eSf.js → base64-D2gsioCY.js} +2 -2
  4. package/dist/channel-FQW-CnGR.d.ts +70 -0
  5. package/dist/claims-BAf6c7is.js +48 -0
  6. package/dist/cli/_format-Cax5EsM9.js +101 -0
  7. package/dist/cli/bin.d.ts +1 -0
  8. package/dist/cli/bin.js +48 -0
  9. package/dist/cli/codemod-DqV7612m.js +388 -0
  10. package/dist/cli/command-CK14fP91.js +502 -0
  11. package/dist/cli/compare-BmIWVEui.js +9 -0
  12. package/dist/cli/config-CPVpXP5I.js +1965 -0
  13. package/dist/cli/config-dtoekM0v.js +2 -0
  14. package/dist/cli/db-DOBPt660.js +52 -0
  15. package/dist/cli/diff-SjkO5rNr.js +752 -0
  16. package/dist/cli/dist-DBPdlPYK.js +1112 -0
  17. package/dist/cli/dist-DreZ24Sz.js +129 -0
  18. package/dist/cli/dist-xn4wlboc.js +732 -0
  19. package/dist/cli/doctor-L7Z8mYTx.js +2863 -0
  20. package/dist/cli/env-DmKv_G4A.js +108 -0
  21. package/dist/cli/env-jIFUADLY.js +511 -0
  22. package/dist/cli/errors-4v4DTtda.js +56 -0
  23. package/dist/cli/fastest-levenshtein-CFN-lNDv.js +120 -0
  24. package/dist/cli/gen-BJc9vdyu.js +2 -0
  25. package/dist/cli/gen-C2osRcr5.js +2204 -0
  26. package/dist/cli/index.d.ts +493 -0
  27. package/dist/cli/index.js +184 -0
  28. package/dist/cli/init-Saf5-R9T.js +550 -0
  29. package/dist/cli/introspect--H7oGmcd.js +81 -0
  30. package/dist/cli/io-k41_z-jT.js +24 -0
  31. package/dist/cli/json5-ChRycquj.js +787 -0
  32. package/dist/cli/jsonc-BUniUpOk.js +2 -0
  33. package/dist/cli/jsonc-D5Fu67jw.js +45 -0
  34. package/dist/cli/keys-ByKHnvP9.js +83 -0
  35. package/dist/cli/ohash-D7bG_EOb.js +277 -0
  36. package/dist/cli/openapi-Cp5Fyta-.js +66 -0
  37. package/dist/cli/project-B_GeXyHh.js +70 -0
  38. package/dist/cli/prompts-BNcNfAve.js +1142 -0
  39. package/dist/cli/prompts-BTYQGunc.js +2 -0
  40. package/dist/cli/read-sets-BfMQcKy8.js +289 -0
  41. package/dist/cli/rolldown-runtime-BPOCksWG.js +24 -0
  42. package/dist/cli/run-BKR2W_79.js +351 -0
  43. package/dist/cli/seed-CUlqWh-8.js +98 -0
  44. package/dist/cli/skills-LJJIhLFR.js +137 -0
  45. package/dist/cli/sql-DzPbfngx.js +348 -0
  46. package/dist/cli/style-C0NFdJRL.js +29 -0
  47. package/dist/cli/toml-DB-MNnFs.js +424 -0
  48. package/dist/cli/version-BDJuO0UR.js +4 -0
  49. package/dist/cli/yaml-CYCbJ6et.js +2252 -0
  50. package/dist/client/index.d.ts +2 -2
  51. package/dist/client/index.js +15 -22
  52. package/dist/clone-BfgmLU90.js +21 -0
  53. package/dist/{compiler-2zqGzxVZ.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
  54. package/dist/config/index.d.ts +4 -4
  55. package/dist/config/index.js +5 -5
  56. package/dist/{config-DOsGYSiT.js → config-DreERlKo.js} +1 -1
  57. package/dist/{config-C1CYcm6o.d.ts → config-T_ejwyd3.d.ts} +176 -11
  58. package/dist/{define-DUbydmJa.d.ts → define-Bp_BZa5h.d.ts} +37 -29
  59. package/dist/{define-DF341GDj.js → define-cNKzqwL_.js} +356 -89
  60. package/dist/edge/index.d.ts +20 -13
  61. package/dist/edge/index.js +55 -26
  62. package/dist/{entitlements-DvJXoI02.d.ts → entitlements-DUxU4oHe.d.ts} +2 -2
  63. package/dist/env/index.d.ts +2 -2
  64. package/dist/env/index.js +34 -1
  65. package/dist/{errors-Bl3rkOzo.js → errors-DtwXa6b8.js} +2 -1
  66. package/dist/events/index.d.ts +3 -2
  67. package/dist/events/index.js +69 -16
  68. package/dist/events-aIO7vsIk.d.ts +230 -0
  69. package/dist/executor-BunPOO-k.d.ts +402 -0
  70. package/dist/{executor-B26lgbHD.d.ts → executor-Cghdstwu.d.ts} +1 -2
  71. package/dist/{executor-C57jx2pn.js → executor-XycESQPH.js} +3 -3
  72. package/dist/hono/index.d.ts +27 -23
  73. package/dist/hono/index.js +46 -11
  74. package/dist/impersonation-VfaGc4Q_.js +41 -0
  75. package/dist/{index-BNsABq7P.d.ts → index-BGdgBPdf.d.ts} +66 -25
  76. package/dist/{index-qriRM9cZ.d.ts → index-C7f8cOBM.d.ts} +4 -4
  77. package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
  78. package/dist/{index-GV77NpRP.d.ts → index-DOESKG27.d.ts} +34 -9
  79. package/dist/{index-CriFFJ_p.d.ts → index-DgILJRXj.d.ts} +43 -17
  80. package/dist/{index-UJ-LUxtI.d.ts → index-DmXSxbLi.d.ts} +14 -14
  81. package/dist/{index-Cf-D2jk1.d.ts → index-Dxn2a5cw.d.ts} +2 -2
  82. package/dist/{index-CTTMS6_1.d.ts → index-SaTsEfGP.d.ts} +86 -9
  83. package/dist/{index-CADlNHK-.d.ts → index-fag8VJZ2.d.ts} +5 -6
  84. package/dist/index.d.ts +34 -17
  85. package/dist/index.js +15 -14
  86. package/dist/jobs/index.d.ts +147 -95
  87. package/dist/jobs/index.js +773 -250
  88. package/dist/{json-schema--aOXAGfU.js → json-schema-m1fiwKgN.js} +23 -2
  89. package/dist/kit-events-CTFDfSwb.js +60 -0
  90. package/dist/kit-transport-B82k1djG.d.ts +33 -0
  91. package/dist/kit-transport-DJlHQUBU.js +55 -0
  92. package/dist/{config-Be4GwsqI.js → kits-CGLLrNPd.js} +38 -10
  93. package/dist/list/index.d.ts +1 -1
  94. package/dist/list/index.js +3 -3
  95. package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
  96. package/dist/{live-QE3UPbGm.d.ts → live-D9W2M5aO.d.ts} +16 -15
  97. package/dist/lookup-BaP5bI27.js +18 -0
  98. package/dist/mcp/index.d.ts +39 -22
  99. package/dist/mcp/index.js +39 -25
  100. package/dist/{mfa-x3V3vGh-.d.ts → mfa-CusDgPaD.d.ts} +5 -1
  101. package/dist/next/image/index.js +6 -3
  102. package/dist/next/index.d.ts +60 -36
  103. package/dist/next/index.js +167 -50
  104. package/dist/notifications/index.d.ts +162 -0
  105. package/dist/notifications/index.js +264 -0
  106. package/dist/openapi/index.d.ts +1 -1
  107. package/dist/openapi/index.js +6 -6
  108. package/dist/orgs/index.d.ts +132 -0
  109. package/dist/orgs/index.js +245 -0
  110. package/dist/orpc/index.d.ts +37 -20
  111. package/dist/orpc/index.js +24 -11
  112. package/dist/otel/index.d.ts +24 -5
  113. package/dist/otel/index.js +124 -64
  114. package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
  115. package/dist/permdock-sql-DgOfeixi.js +51 -0
  116. package/dist/plugin-DwARMuQp.js +59 -0
  117. package/dist/{plugin-DVRB8qNE.d.ts → plugin-o144f322.d.ts} +17 -5
  118. package/dist/plugins/actor/index.d.ts +5 -2
  119. package/dist/plugins/actor/index.js +22 -8
  120. package/dist/plugins/rules/index.d.ts +2 -2
  121. package/dist/plugins/rules/index.js +52 -17
  122. package/dist/plugins/soft-delete/index.d.ts +3 -3
  123. package/dist/plugins/soft-delete/index.js +14 -5
  124. package/dist/plugins/tenant/index.d.ts +3 -3
  125. package/dist/plugins/tenant/index.js +45 -21
  126. package/dist/plugins/timestamps/index.d.ts +1 -1
  127. package/dist/plugins/timestamps/index.js +4 -3
  128. package/dist/plugins/validation/index.d.ts +2 -2
  129. package/dist/plugins/validation/index.js +26 -6
  130. package/dist/{pool-B9qsLyFR.d.ts → pool-C9voM4Kw.d.ts} +24 -6
  131. package/dist/postgres/index.d.ts +5 -5
  132. package/dist/postgres/index.js +20 -10
  133. package/dist/{postgrest-DmBlevh-.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
  134. package/dist/{problem-CGt1ADix.js → problem-BW1KhzSG.js} +2 -1
  135. package/dist/{problem-Z2RTQjZD.d.ts → problem-Blxe8S31.d.ts} +1 -1
  136. package/dist/query/index.d.ts +2 -2
  137. package/dist/query/index.js +3 -3
  138. package/dist/{query-BdKLTPlj.js → query-CCbo44lG.js} +18 -18
  139. package/dist/queue-BYUCjr59.d.ts +252 -0
  140. package/dist/react/index.d.ts +8 -7
  141. package/dist/react/index.js +4 -3
  142. package/dist/react/server.d.ts +16 -5
  143. package/dist/react/server.js +12 -4
  144. package/dist/react/session.d.ts +10 -4
  145. package/dist/react/session.js +11 -3
  146. package/dist/{react-DNBYNazu.js → react-C_s7kiNz.js} +138 -46
  147. package/dist/{read-set-D0qBcboM.js → read-set-DQFt1N_Y.js} +71 -15
  148. package/dist/realtime/index.d.ts +3 -3
  149. package/dist/realtime/index.js +14 -12
  150. package/dist/{index-kpgopLNv.d.ts → refresh-BTrQ_ZTp.d.ts} +6 -3
  151. package/dist/{resolve-BRciX2jK.d.ts → resolve-C15TJq77.d.ts} +22 -11
  152. package/dist/{resource-D30rp0GN.js → resource-CRxxwkQq.js} +24 -9
  153. package/dist/{resource-CwVgiI5q.d.ts → resource-D8iqWMr-.d.ts} +6 -6
  154. package/dist/respond-D2OQl62-.d.ts +371 -0
  155. package/dist/{result-DWXatkd6.js → result-BKiliPY7.js} +2 -2
  156. package/dist/server/index.d.ts +17 -15
  157. package/dist/server/index.js +16 -22
  158. package/dist/server-Csx2sRjg.js +655 -0
  159. package/dist/{shared-_6-uPL7E.js → shared-D1dRUrAg.js} +19 -4
  160. package/dist/signers-Cc6r98SW.d.ts +162 -0
  161. package/dist/{simplify-LakqK1vH.js → simplify-_0oUKqCd.js} +27 -95
  162. package/dist/sql/index.d.ts +247 -10
  163. package/dist/sql/index.js +8591 -780
  164. package/dist/{sql-BIgk12ew.js → sql-Coh6n4cC.js} +11 -3
  165. package/dist/ssr/index.d.ts +4 -4
  166. package/dist/ssr/index.js +1 -2
  167. package/dist/{standard-FUi3Z3-7.js → standard-D7r6dMUu.js} +6 -3
  168. package/dist/{standard-eudBiRk1.d.ts → standard-J4YgMOLm.d.ts} +1 -1
  169. package/dist/{stats-D78UQ8Yu.js → stats-Bqob3WqT.js} +34 -9
  170. package/dist/storage/index.d.ts +4 -4
  171. package/dist/storage/index.js +174 -27
  172. package/dist/support-DT-OhSxD.d.ts +88 -0
  173. package/dist/support-Dk6vdmEw.js +291 -0
  174. package/dist/support-view-Da5peKFg.d.ts +17 -0
  175. package/dist/support-view-g4YLBeqX.js +18 -0
  176. package/dist/{tables-Dhha3BXM.js → tables-Cb-3_VWc.js} +14 -0
  177. package/dist/{permdock-sql-Bta_G0v-.js → template-TxrGI5jR.js} +2 -31
  178. package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
  179. package/dist/{temporal-required-CMxeSVPo.js → temporal-required-CAt4Dc9Z.js} +2 -2
  180. package/dist/testing/index.d.ts +113 -24
  181. package/dist/testing/index.js +375 -47
  182. package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
  183. package/dist/user-change-CHFEUro1.js +49 -0
  184. package/dist/{webhooks-CAIFQSTM.js → verify-Ce49ETPz.js} +38 -19
  185. package/dist/{version-BfpG2gks.js → version-DM_Roffb.js} +1 -1
  186. package/dist/{view-3Po_PVlr.d.ts → view-BEf0diC5.d.ts} +10 -5
  187. package/dist/{mfa-BxoR1RkN.js → view-Bq64ki8-.js} +210 -64
  188. package/dist/webhooks/index.d.ts +136 -5
  189. package/dist/webhooks/index.js +588 -2
  190. package/dist/wire-D2dT86vi.js +35 -0
  191. package/package.json +50 -10
  192. package/schemas/config-v1.json +131 -1
  193. package/schemas/doctor-report-v1.json +10 -0
  194. package/skills/better-supabase/SKILL.md +60 -10
  195. package/skills/better-supabase/references/plugins.md +13 -14
  196. package/skills/better-supabase/references/troubleshooting.md +25 -4
  197. package/skills/better-supabase-api/SKILL.md +74 -19
  198. package/skills/better-supabase-api/references/adapters.md +48 -27
  199. package/skills/better-supabase-auth/SKILL.md +149 -0
  200. package/skills/better-supabase-auth/references/permdock.md +100 -0
  201. package/skills/better-supabase-testing/SKILL.md +58 -4
  202. package/dist/claims-CoTobNC-.js +0 -25
  203. package/dist/events-Do8jXh4D.d.ts +0 -84
  204. package/dist/executor-DynmIWhq.d.ts +0 -195
  205. package/dist/invalidate-DbxuL2jL.js +0 -18
  206. package/dist/permdock-sql-DImJULY-.d.ts +0 -17
  207. package/dist/plugin-BqR6wKMB.js +0 -23
  208. package/dist/respond-C44EZAJo.js +0 -399
  209. package/dist/respond-DAkPIdTH.d.ts +0 -175
  210. package/dist/result-c2OYgCV2.d.ts +0 -203
  211. package/dist/view-wZ-9qIUz.js +0 -45
@@ -1,2 +1,2 @@
1
- import { a as BrowserOptions, i as BrowserAuth, n as AuthUser, o as createBrowser, r as BetterBrowser, t as AuthSnapshot } from "../index-UJ-LUxtI.js";
2
- export { AuthSnapshot, AuthUser, BetterBrowser, BrowserAuth, BrowserOptions, createBrowser };
1
+ import { a as ClientOptions, i as ClientAuth, n as AuthUser, o as createClient, r as BetterClient, t as AuthSnapshot } from "../index-DmXSxbLi.js";
2
+ export { AuthSnapshot, AuthUser, BetterClient, ClientAuth, ClientOptions, createClient };
@@ -1,8 +1,9 @@
1
- import { n as decodeJwtPayload } from "../base64-CQeB1eSf.js";
1
+ import { n as decodeJwtPayload } from "../base64-D2gsioCY.js";
2
+ import { r as userContext } from "../impersonation-VfaGc4Q_.js";
2
3
  import { EnvValidationError, parseEnv } from "../env/index.js";
3
- import { t as createQueries } from "../query-BdKLTPlj.js";
4
+ import { t as createQueries } from "../query-CCbo44lG.js";
4
5
  import { createBrowserClient } from "@supabase/ssr";
5
- import { createClient } from "@supabase/supabase-js";
6
+ import { createClient as createClient$1 } from "@supabase/supabase-js";
6
7
  //#region src/client/index.ts
7
8
  const LOADING = {
8
9
  status: "loading",
@@ -37,25 +38,17 @@ function contextOf(snapshot) {
37
38
  },
38
39
  claims: { role: "anon" }
39
40
  };
40
- return {
41
- actor: {
42
- id: snapshot.user.id,
43
- kind: "user",
44
- ...snapshot.user.role ? { role: snapshot.user.role } : {},
45
- ...snapshot.user.email ? { email: snapshot.user.email } : {}
46
- },
47
- claims: snapshot.claims
48
- };
41
+ return userContext(snapshot.user, snapshot.claims);
49
42
  }
50
43
  function clientFor(options) {
51
44
  if (options.client) return options.client;
52
- if (!options.env) throw new TypeError("createBrowser needs `env` ({ url, publishableKey }) or `client`");
45
+ if (!options.env) throw new TypeError("createClient needs `env` ({ url, publishableKey }) or `client`");
53
46
  const checked = parseEnv({
54
47
  SUPABASE_URL: options.env.url,
55
48
  SUPABASE_PUBLISHABLE_KEY: options.env.publishableKey
56
49
  });
57
50
  if (!checked.ok) throw new EnvValidationError(checked.issues);
58
- if (options.storage === "local") return createClient(checked.env.url, checked.env.publishableKey);
51
+ if (options.storage === "local") return createClient$1(checked.env.url, checked.env.publishableKey);
59
52
  return createBrowserClient(checked.env.url, checked.env.publishableKey);
60
53
  }
61
54
  /**
@@ -63,10 +56,10 @@ function clientFor(options) {
63
56
  * session, TanStack Query options and an auth store for UI state.
64
57
  *
65
58
  * ```ts
66
- * export const browser = createBrowser(sb, { env: { url, publishableKey } });
59
+ * export const bs = createClient(betterSupabase, { env: { url, publishableKey } });
67
60
  * ```
68
61
  */
69
- function createBrowser(sb, options = {}) {
62
+ function createClient(betterSupabase, options = {}) {
70
63
  const supabase = clientFor(options);
71
64
  let snapshot = LOADING;
72
65
  let db;
@@ -78,14 +71,14 @@ function createBrowser(sb, options = {}) {
78
71
  db = void 0;
79
72
  for (const listener of listeners) listener();
80
73
  });
81
- const browser = {
82
- sb,
74
+ const client = {
75
+ betterSupabase,
83
76
  supabase,
84
77
  get db() {
85
- db ??= sb.connect(supabase, contextOf(snapshot));
78
+ db ??= betterSupabase.connect(supabase, contextOf(snapshot));
86
79
  return db;
87
80
  },
88
- queries: createQueries(sb, () => browser.db),
81
+ queries: createQueries(betterSupabase, () => client.db),
89
82
  auth: {
90
83
  current: () => snapshot,
91
84
  subscribe: (listener) => {
@@ -96,7 +89,7 @@ function createBrowser(sb, options = {}) {
96
89
  }
97
90
  }
98
91
  };
99
- return browser;
92
+ return client;
100
93
  }
101
94
  //#endregion
102
- export { createBrowser };
95
+ export { createClient };
@@ -0,0 +1,21 @@
1
+ //#region src/core/clone.ts
2
+ function isPlainObject(value) {
3
+ if (typeof value !== "object" || value === null) return false;
4
+ const proto = Object.getPrototypeOf(value);
5
+ return proto === Object.prototype || proto === null;
6
+ }
7
+ /**
8
+ * Copies plain objects and arrays so hooks and listeners cannot change the
9
+ * caller's result (invariant 5). Temporal values are immutable and stay shared.
10
+ */
11
+ function cloneValue(value) {
12
+ if (Array.isArray(value)) return value.map(cloneValue);
13
+ if (isPlainObject(value)) {
14
+ const copy = {};
15
+ for (const [key, item] of Object.entries(value)) copy[key] = cloneValue(item);
16
+ return copy;
17
+ }
18
+ return value;
19
+ }
20
+ //#endregion
21
+ export { isPlainObject as n, cloneValue as t };
@@ -1,5 +1,5 @@
1
- import { g as Operation } from "./executor-DynmIWhq.js";
2
- import { i as PostgrestPlan } from "./postgrest-DmBlevh-.js";
1
+ import { U as Operation } from "./executor-BunPOO-k.js";
2
+ import { i as PostgrestPlan } from "./postgrest-CruYKAvV.js";
3
3
  //#region src/core/compiler.d.ts
4
4
  /**
5
5
  * Turns an IR operation into something a backend runs. An `Executor` for a
@@ -1,4 +1,4 @@
1
- import { a as Casing } from "../types-DONv9SHN.js";
2
- import { $ as GeneratorMetadata, A as VectorSearchConfig, B as CatalogFunction, C as SoftDeleteConfig, D as TenantConfig, E as TableConfig, F as CatalogCheck, G as CatalogTable, H as CatalogGrant, I as CatalogColumn, J as ExtrasFunction, K as CatalogTrigger, L as CatalogColumnGrant, M as resolveConfig, N as resolveJsonSchema, O as TimestampsConfig, P as Catalog, Q as ForeignKeyAction, R as CatalogEnum, S as SeedConfig, T as SqlConfig, U as CatalogIndex, V as CatalogFunctionArg, W as CatalogPolicy, X as ExtrasHookFunction, Y as ExtrasHook, Z as ExtrasTable, _ as PluginFlagsConfig, a as ClaimsConfig, b as ResolvedConfig, c as EntitlementsConfig, d as Generator, et as Snapshot, f as GeneratorInput, g as PermdockPathsConfig, h as OpenApiConfig, i as CONFIG_SCHEMA_URL, j as defineConfig, k as VectorDistance, l as ExposeConfig, m as JsonTypeConfig, n as BetterSupabaseConfig, nt as SnapshotExtras, o as CodecsConfig, p as JsonSchemaSource, q as CatalogUnique, r as BucketConfig, s as DoctorConfig, t as ActorConfig, tt as SnapshotBucket, u as GeneratedFile, v as Privilege, w as SourceConfig, x as ResolvedExpose, y as RealtimeConfig, z as CatalogForeignKey } from "../config-C1CYcm6o.js";
3
- import { a as JsonSchemaGeneratorOptions, c as DEFAULT_CLAIMS, i as valibot, l as tenantClaimPaths, n as zod, o as buildJsonSchema, r as ValibotGeneratorOptions, s as jsonSchema, t as ZodGeneratorOptions } from "../index-Cf-D2jk1.js";
4
- export { type ActorConfig, type BetterSupabaseConfig, type BucketConfig, CONFIG_SCHEMA_URL, type Casing, type Catalog, type CatalogCheck, type CatalogColumn, type CatalogColumnGrant, type CatalogEnum, type CatalogForeignKey, type CatalogFunction, type CatalogFunctionArg, type CatalogGrant, type CatalogIndex, type CatalogPolicy, type CatalogTable, type CatalogTrigger, type CatalogUnique, type ClaimsConfig, type CodecsConfig, DEFAULT_CLAIMS, type DoctorConfig, type EntitlementsConfig, type ExposeConfig, type ExtrasFunction, type ExtrasHook, type ExtrasHookFunction, type ExtrasTable, type ForeignKeyAction, type GeneratedFile, type Generator, type GeneratorInput, type GeneratorMetadata, type JsonSchemaGeneratorOptions, type JsonSchemaSource, type JsonTypeConfig, type OpenApiConfig, type PermdockPathsConfig, type PluginFlagsConfig, type Privilege, type RealtimeConfig, type ResolvedConfig, type ResolvedExpose, type SeedConfig, type Snapshot, type SnapshotBucket, type SnapshotExtras, type SoftDeleteConfig, type SourceConfig, type SqlConfig, type TableConfig, type TenantConfig, type TimestampsConfig, type ValibotGeneratorOptions, type VectorDistance, type VectorSearchConfig, type ZodGeneratorOptions, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, tenantClaimPaths, valibot, zod };
1
+ import { o as Casing } from "../types-Dnf_wRDz.js";
2
+ import { $ as GeneratorMetadata, A as VectorSearchConfig, B as CatalogFunction, C as SoftDeleteConfig, D as TenantConfig, E as TableConfig, F as CatalogCheck, G as CatalogTable, H as CatalogGrant, I as CatalogColumn, J as ExtrasFunction, K as CatalogTrigger, L as CatalogColumnGrant, M as resolveConfig, N as resolveJsonSchema, O as TimestampsConfig, P as Catalog, Q as ForeignKeyAction, R as CatalogEnum, S as SeedConfig, T as SqlConfig, U as CatalogIndex, V as CatalogFunctionArg, W as CatalogPolicy, X as ExtrasHookFunction, Y as ExtrasHook, Z as ExtrasTable, _ as PluginFlagsConfig, a as ClaimsConfig, at as DEFAULT_ACTIVE_TENANT, b as ResolvedConfig, c as EntitlementsConfig, ct as KitsConfig, d as Generator, et as Snapshot, f as GeneratorInput, g as PermdockPathsConfig, h as OpenApiConfig, i as CONFIG_SCHEMA_URL, it as ActiveTenantSource, j as defineConfig, k as VectorDistance, l as ExposeConfig, m as JsonTypeConfig, n as BetterSupabaseConfig, nt as SnapshotExtras, o as CodecsConfig, ot as KitMode, p as JsonSchemaSource, q as CatalogUnique, r as BucketConfig, rt as AccessKitConfig, s as DoctorConfig, st as KitModuleConfig, t as ActorConfig, tt as SnapshotBucket, u as GeneratedFile, v as Privilege, w as SourceConfig, x as ResolvedExpose, y as RealtimeConfig, z as CatalogForeignKey } from "../config-T_ejwyd3.js";
3
+ import { a as JsonSchemaGeneratorOptions, c as DEFAULT_CLAIMS, i as valibot, l as tenantClaimPaths, n as zod, o as buildJsonSchema, r as ValibotGeneratorOptions, s as jsonSchema, t as ZodGeneratorOptions } from "../index-Dxn2a5cw.js";
4
+ export { type AccessKitConfig, type ActiveTenantSource, type ActorConfig, type BetterSupabaseConfig, type BucketConfig, CONFIG_SCHEMA_URL, type Casing, type Catalog, type CatalogCheck, type CatalogColumn, type CatalogColumnGrant, type CatalogEnum, type CatalogForeignKey, type CatalogFunction, type CatalogFunctionArg, type CatalogGrant, type CatalogIndex, type CatalogPolicy, type CatalogTable, type CatalogTrigger, type CatalogUnique, type ClaimsConfig, type CodecsConfig, DEFAULT_ACTIVE_TENANT, DEFAULT_CLAIMS, type DoctorConfig, type EntitlementsConfig, type ExposeConfig, type ExtrasFunction, type ExtrasHook, type ExtrasHookFunction, type ExtrasTable, type ForeignKeyAction, type GeneratedFile, type Generator, type GeneratorInput, type GeneratorMetadata, type JsonSchemaGeneratorOptions, type JsonSchemaSource, type JsonTypeConfig, type KitMode, type KitModuleConfig, type KitsConfig, type OpenApiConfig, type PermdockPathsConfig, type PluginFlagsConfig, type Privilege, type RealtimeConfig, type ResolvedConfig, type ResolvedExpose, type SeedConfig, type Snapshot, type SnapshotBucket, type SnapshotExtras, type SoftDeleteConfig, type SourceConfig, type SqlConfig, type TableConfig, type TenantConfig, type TimestampsConfig, type ValibotGeneratorOptions, type VectorDistance, type VectorSearchConfig, type ZodGeneratorOptions, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, tenantClaimPaths, valibot, zod };
@@ -1,5 +1,5 @@
1
- import { i as tenantClaimPaths, t as DEFAULT_CLAIMS } from "../claims-CoTobNC-.js";
2
- import { i as resolveJsonSchema, n as defineConfig, r as resolveConfig, t as CONFIG_SCHEMA_URL } from "../config-Be4GwsqI.js";
3
- import { n as jsonSchema, t as buildJsonSchema } from "../json-schema--aOXAGfU.js";
4
- import { n as valibot, t as zod } from "../config-DOsGYSiT.js";
5
- export { CONFIG_SCHEMA_URL, DEFAULT_CLAIMS, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, tenantClaimPaths, valibot, zod };
1
+ import { i as tenantClaimPaths, t as DEFAULT_CLAIMS } from "../claims-BAf6c7is.js";
2
+ import { a as resolveConfig, i as defineConfig, o as resolveJsonSchema, r as CONFIG_SCHEMA_URL, t as DEFAULT_ACTIVE_TENANT } from "../kits-CGLLrNPd.js";
3
+ import { n as jsonSchema, t as buildJsonSchema } from "../json-schema-m1fiwKgN.js";
4
+ import { n as valibot, t as zod } from "../config-DreERlKo.js";
5
+ export { CONFIG_SCHEMA_URL, DEFAULT_ACTIVE_TENANT, DEFAULT_CLAIMS, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, tenantClaimPaths, valibot, zod };
@@ -1,4 +1,4 @@
1
- import { a as parseImport, c as schemaName, d as variantsFor, i as fieldsFor, l as siblingPath, o as propertyKey, r as HEADER, s as rowType, u as tableEntries } from "./json-schema--aOXAGfU.js";
1
+ import { a as parseImport, c as schemaName, d as variantsFor, i as fieldsFor, l as siblingPath, o as propertyKey, r as HEADER, s as rowType, u as tableEntries } from "./json-schema-m1fiwKgN.js";
2
2
  //#region src/generators/valibot.ts
3
3
  function scalar$1(kind) {
4
4
  switch (kind.kind) {
@@ -1,6 +1,150 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { A as SchemaMeta, a as Casing, b as PermdockBucketPolicy, i as BucketPolicyName } from "./types-DONv9SHN.js";
2
+ import { a as BucketPolicyName, j as SchemaMeta, o as Casing, t as AccessBucketPolicy, x as PermdockBucketPolicy } from "./types-Dnf_wRDz.js";
3
3
  import { GeneratorMetadata } from "@supabase/postgrest-typegen";
4
+ //#region src/config/kits.d.ts
5
+ /**
6
+ * `kits` in `better-supabase.config.ts`: how each SQL kit module maps onto
7
+ * the app's database. A module's contract (the functions other modules and
8
+ * the TypeScript side call) stays the same in every mode; only the tables
9
+ * behind it change.
10
+ */
11
+ /**
12
+ * `managed`: the kit owns its tables. `adopt`: the kit writes its functions
13
+ * and views over tables the app already has (`tables` and `columns`), never
14
+ * `create table`. `custom`: the app implements the contract functions itself;
15
+ * the kit writes nothing and doctor checks the signatures (BS307).
16
+ */
17
+ type KitMode = "managed" | "adopt" | "custom";
18
+ /** Options every module takes. */
19
+ interface KitModuleConfig {
20
+ readonly mode?: KitMode;
21
+ /** Schema of the module's functions and managed tables. Defaults to `better_supabase`. */
22
+ readonly schema?: string;
23
+ /**
24
+ * Logical table to `table` or `schema.table`, e.g.
25
+ * `{ memberships: 'public.organization_users' }`. An unqualified name is in
26
+ * `schema`. `null` marks an optional table the app doesn't have.
27
+ */
28
+ readonly tables?: Readonly<Record<string, string | null>>;
29
+ /**
30
+ * Logical table to logical column to column name, e.g.
31
+ * `{ memberships: { tenant: 'organization_id', role: 'role_id' } }`.
32
+ * `null` marks an optional column the adopted table doesn't have.
33
+ */
34
+ readonly columns?: Readonly<Record<string, Readonly<Record<string, string | null>>>>;
35
+ /** Type of tenant ids: `uuid` (default), `text`, `bigint` or `integer`. */
36
+ readonly idType?: string;
37
+ /**
38
+ * Kit action to permission key, checked through the access contract, e.g.
39
+ * `{ invite: 'organization.members.invite' }`.
40
+ */
41
+ readonly permissions?: Readonly<Record<string, string>>;
42
+ /** Module-specific options; each module's docs page lists them. */
43
+ readonly options?: Readonly<Record<string, unknown>>;
44
+ /**
45
+ * The app's optional `before_*` and `after_*` functions the module calls
46
+ * when they exist, e.g. `after_organization_create(org, user)`. They are
47
+ * looked up in `schema` (default `public`); `functions` maps a hook name
48
+ * to another function, e.g. `{ after_organization_create: 'app.seed_org' }`.
49
+ */
50
+ readonly hooks?: {
51
+ readonly schema?: string;
52
+ readonly functions?: Readonly<Record<string, string>>;
53
+ };
54
+ /**
55
+ * Whether the module writes its events to the outbox (`emit_event`) when
56
+ * the `outbox` module is installed. Defaults to true.
57
+ */
58
+ readonly events?: boolean;
59
+ }
60
+ /**
61
+ * Where the active tenant of a request comes from. Every source counts only
62
+ * while the caller is a member, so a stale claim or setting grants nothing.
63
+ */
64
+ type ActiveTenantSource = "claim" | "resolver" | {
65
+ readonly profileColumn: string;
66
+ readonly key?: string;
67
+ };
68
+ /** URL tenancy: the tenant comes from the request (a slug), not a stored setting. */
69
+ declare const DEFAULT_ACTIVE_TENANT: ActiveTenantSource;
70
+ /**
71
+ * The access contract every kit checks permissions through:
72
+ * `can(scope, id, permission)`, `tenant_ids_with(permission)`,
73
+ * `is_platform(permission)` and `can_user(user, scope, id, permission)`.
74
+ */
75
+ interface AccessKitConfig extends KitModuleConfig {
76
+ /**
77
+ * `roles`: a fixed role list from `roles` (the default). `catalog`: role,
78
+ * permission and override tables (`tables.roles`, `permissions`,
79
+ * `rolePermissions`, `overrides`, `platformAssignments`). `permdock`:
80
+ * PermDock's `permitted_<scope>_ids` and `permdock_has`. `custom`:
81
+ * expression templates in `functions`.
82
+ */
83
+ readonly model?: "roles" | "catalog" | "permdock" | "custom";
84
+ /**
85
+ * `roles` model: role name to permission keys. `*` grants everything and
86
+ * `prefix.*` a prefix. Defaults to owner, admin, member and viewer.
87
+ */
88
+ readonly roles?: Readonly<Record<string, readonly string[]>>;
89
+ /**
90
+ * `custom` model: SQL expressions with `{scope}`, `{id}`, `{permission}`
91
+ * and `{user}` placeholders, e.g.
92
+ * `{ can: 'public.authorize_scope({scope}::public.scope_type, {id}, {permission})' }`.
93
+ */
94
+ readonly functions?: {
95
+ readonly can?: string;
96
+ readonly tenantIdsWith?: string;
97
+ readonly isPlatform?: string;
98
+ readonly canUser?: string;
99
+ /** `{tenant}` and `{role}`: whether the caller may assign the role. Defaults to true. */
100
+ readonly canAssign?: string;
101
+ /** `{user}`: the permission claim for the access token hook. */
102
+ readonly permissionClaims?: string;
103
+ };
104
+ /**
105
+ * `roles` model: the JWT claim holding the caller's platform permission
106
+ * keys (an array). Defaults to `platform_permissions`.
107
+ */
108
+ readonly platformClaim?: string;
109
+ /**
110
+ * Columns that disable a tenant or a user when set, as
111
+ * `schema.table.column`, keyed by the table's `id` (tenant) or the column
112
+ * named in `userKey` (user). Disabled tenants and users get no permissions.
113
+ */
114
+ readonly disabled?: {
115
+ readonly tenant?: string;
116
+ readonly user?: string;
117
+ readonly userKey?: string;
118
+ };
119
+ readonly activeTenant?: ActiveTenantSource;
120
+ /** `permdock` model: PermDock's `rls.schema` and the scope tenants are. */
121
+ readonly permdock?: {
122
+ readonly schema?: string;
123
+ readonly scope?: string;
124
+ };
125
+ }
126
+ /** `kits` in the config, keyed by module name. */
127
+ interface KitsConfig {
128
+ readonly access?: AccessKitConfig;
129
+ /** `AccessKitConfig` is listed so an `access` literal passes the excess-property check. */
130
+ readonly [module: string]: KitModuleConfig | AccessKitConfig | undefined;
131
+ }
132
+ /** A module's config with defaults applied. */
133
+ interface ResolvedKitModule {
134
+ readonly mode: KitMode;
135
+ readonly schema: string;
136
+ readonly tables: Readonly<Record<string, string | null>>;
137
+ readonly columns: Readonly<Record<string, Readonly<Record<string, string | null>>>>;
138
+ readonly idType?: string;
139
+ readonly permissions: Readonly<Record<string, string>>;
140
+ readonly options: Readonly<Record<string, unknown>>;
141
+ readonly hooks: {
142
+ readonly schema: string;
143
+ readonly functions: Readonly<Record<string, string>>;
144
+ };
145
+ readonly events: boolean;
146
+ }
147
+ //#endregion
4
148
  //#region src/config/snapshot.d.ts
5
149
  /**
6
150
  * What `better-supabase introspect` reads from Postgres. `generator` is the
@@ -330,6 +474,8 @@ interface ClaimsConfig {
330
474
  interface ActorConfig {
331
475
  readonly createdBy?: string;
332
476
  readonly updatedBy?: string;
477
+ /** Defaults to `impersonated_by`, the column the SQL kit's `track_actor` fills. */
478
+ readonly impersonatedBy?: string;
333
479
  }
334
480
  interface PluginFlagsConfig {
335
481
  readonly timestamps?: boolean | TimestampsConfig;
@@ -342,8 +488,11 @@ interface BucketConfig {
342
488
  readonly public?: boolean;
343
489
  /** Path template with `{placeholders}`, e.g. `{orgId}/{customerId}/logo.webp`. */
344
490
  readonly path: string;
345
- /** Generated storage policy, or a PermDock policy (`{ permdock, scope }`). */
346
- readonly policy?: BucketPolicyName | PermdockBucketPolicy;
491
+ /**
492
+ * Generated storage policy, a PermDock policy (`{ permdock, scope }`) or
493
+ * an access contract policy (`{ access }`).
494
+ */
495
+ readonly policy?: BucketPolicyName | PermdockBucketPolicy | AccessBucketPolicy;
347
496
  readonly fileSizeLimit?: string;
348
497
  readonly allowedMimeTypes?: readonly string[];
349
498
  }
@@ -443,12 +592,19 @@ interface RealtimeConfig {
443
592
  * triggers with `better-supabase sql add realtime-tables`.
444
593
  */
445
594
  readonly tables?: readonly string[];
595
+ /**
596
+ * Tables in `tables` without a tenant column. They broadcast on one topic
597
+ * every signed-in user receives. With the `tenant` plugin, a table that
598
+ * lacks the tenant column and is not listed here fails to install.
599
+ */
600
+ readonly global?: readonly string[];
446
601
  }
447
602
  interface EntitlementsConfig {
448
603
  /**
449
604
  * `table.column` (or `schema.table.column`) holding each tenant's Stripe
450
- * customer id, read by the `entitlements` SQL kit module. Defaults to
451
- * `organizations.stripe_customer_id`.
605
+ * customer id, read by the `entitlements` SQL kit module. Required
606
+ * without the `organizations` module; with it, defaults to the
607
+ * `stripe_customer_id` column that module adds.
452
608
  */
453
609
  readonly customer?: string;
454
610
  /** The tenant id column of that table. Defaults to `id`. */
@@ -457,8 +613,9 @@ interface EntitlementsConfig {
457
613
  * With a PermDock manifest, `has_entitlement` and `feature_claims` read
458
614
  * PermDock's memberships (`member_<scope>_ids()` and
459
615
  * `member_<scope>_ids_for(user)`) instead of `better_supabase.memberships`.
460
- * `scope` is the PermDock scope tenants are (default `organization`);
461
- * `false` keeps the kit's memberships table.
616
+ * `scope` is the PermDock scope tenants are. It defaults to the manifest's
617
+ * root scope (the `rls.scopes` entry without `within`); `false` keeps the
618
+ * kit's memberships table.
462
619
  */
463
620
  readonly permdock?: false | {
464
621
  readonly scope?: string;
@@ -558,6 +715,12 @@ interface BetterSupabaseConfig {
558
715
  */
559
716
  readonly vectorSearch?: Readonly<Record<string, VectorSearchConfig>>;
560
717
  readonly sql?: SqlConfig;
718
+ /**
719
+ * How each SQL kit module maps onto the database: `managed` tables, or
720
+ * `adopt` and `custom` over the app's own, with table, column and
721
+ * permission names, keyed by module name.
722
+ */
723
+ readonly kits?: KitsConfig;
561
724
  readonly seed?: SeedConfig;
562
725
  readonly openapi?: OpenApiConfig;
563
726
  readonly doctor?: DoctorConfig;
@@ -589,11 +752,12 @@ interface ResolvedConfig {
589
752
  readonly claims: Required<ClaimsConfig>;
590
753
  readonly buckets: Readonly<Record<string, BucketConfig>>;
591
754
  readonly entitlements: {
592
- readonly table: string;
593
- readonly column: string;
755
+ /** Unset without `entitlements.customer`. */
756
+ readonly table?: string;
757
+ readonly column?: string;
594
758
  readonly key: string;
595
759
  readonly permdock: false | {
596
- readonly scope: string;
760
+ readonly scope?: string;
597
761
  };
598
762
  };
599
763
  readonly permdock: Required<PermdockPathsConfig>;
@@ -605,6 +769,7 @@ interface ResolvedConfig {
605
769
  readonly topics: Readonly<Record<string, string>>;
606
770
  readonly realtime: Required<RealtimeConfig>;
607
771
  readonly sql: Required<SqlConfig>;
772
+ readonly kits: KitsConfig;
608
773
  readonly seed: Required<SeedConfig>;
609
774
  readonly openapi: Required<OpenApiConfig>;
610
775
  readonly doctor: Required<Omit<DoctorConfig, "claimsLimit">> & Pick<DoctorConfig, "claimsLimit">;
@@ -615,4 +780,4 @@ declare function defineConfig(config: BetterSupabaseConfig): BetterSupabaseConfi
615
780
  /** Applies defaults. Paths stay relative to `root`. */
616
781
  declare function resolveConfig(config: BetterSupabaseConfig, root: string): ResolvedConfig;
617
782
  //#endregion
618
- export { GeneratorMetadata as $, VectorSearchConfig as A, CatalogFunction as B, SoftDeleteConfig as C, TenantConfig as D, TableConfig as E, CatalogCheck as F, CatalogTable as G, CatalogGrant as H, CatalogColumn as I, ExtrasFunction as J, CatalogTrigger as K, CatalogColumnGrant as L, resolveConfig as M, resolveJsonSchema as N, TimestampsConfig as O, Catalog as P, ForeignKeyAction as Q, CatalogEnum as R, SeedConfig as S, SqlConfig as T, CatalogIndex as U, CatalogFunctionArg as V, CatalogPolicy as W, ExtrasHookFunction as X, ExtrasHook as Y, ExtrasTable as Z, PluginFlagsConfig as _, ClaimsConfig as a, ResolvedConfig as b, EntitlementsConfig as c, Generator as d, Snapshot as et, GeneratorInput as f, PermdockPathsConfig as g, OpenApiConfig as h, CONFIG_SCHEMA_URL as i, defineConfig as j, VectorDistance as k, ExposeConfig as l, JsonTypeConfig as m, BetterSupabaseConfig as n, SnapshotExtras as nt, CodecsConfig as o, JsonSchemaSource as p, CatalogUnique as q, BucketConfig as r, DoctorConfig as s, ActorConfig as t, SnapshotBucket as tt, GeneratedFile as u, Privilege as v, SourceConfig as w, ResolvedExpose as x, RealtimeConfig as y, CatalogForeignKey as z };
783
+ export { GeneratorMetadata as $, VectorSearchConfig as A, CatalogFunction as B, SoftDeleteConfig as C, TenantConfig as D, TableConfig as E, CatalogCheck as F, CatalogTable as G, CatalogGrant as H, CatalogColumn as I, ExtrasFunction as J, CatalogTrigger as K, CatalogColumnGrant as L, resolveConfig as M, resolveJsonSchema as N, TimestampsConfig as O, Catalog as P, ForeignKeyAction as Q, CatalogEnum as R, SeedConfig as S, SqlConfig as T, CatalogIndex as U, CatalogFunctionArg as V, CatalogPolicy as W, ExtrasHookFunction as X, ExtrasHook as Y, ExtrasTable as Z, PluginFlagsConfig as _, ClaimsConfig as a, DEFAULT_ACTIVE_TENANT as at, ResolvedConfig as b, EntitlementsConfig as c, KitsConfig as ct, Generator as d, Snapshot as et, GeneratorInput as f, PermdockPathsConfig as g, OpenApiConfig as h, CONFIG_SCHEMA_URL as i, ActiveTenantSource as it, defineConfig as j, VectorDistance as k, ExposeConfig as l, ResolvedKitModule as lt, JsonTypeConfig as m, BetterSupabaseConfig as n, SnapshotExtras as nt, CodecsConfig as o, KitMode as ot, JsonSchemaSource as p, CatalogUnique as q, BucketConfig as r, AccessKitConfig as rt, DoctorConfig as s, KitModuleConfig as st, ActorConfig as t, SnapshotBucket as tt, GeneratedFile as u, Privilege as v, SourceConfig as w, ResolvedExpose as x, RealtimeConfig as y, CatalogForeignKey as z };
@@ -1,11 +1,10 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { A as SchemaMeta, C as PrimaryKeyValue, D as Relations, E as RelationTypes, I as UniqueKeyName, L as UniqueWhere, N as TableKey, O as Row, P as TableMeta, R as Update, g as Insert, j as Simplify, k as Schema, n as AnyModels, t as AnyFunctions } from "./types-DONv9SHN.js";
3
- import { g as Operation, l as CountMode, r as Executor } from "./executor-DynmIWhq.js";
4
- import { p as DbError, s as ThrowMapper, t as AsyncResult, v as ErrorMapper } from "./result-c2OYgCV2.js";
5
- import { a as EventHub, f as Logger, i as EventHandler, o as EventName, s as MutationNotice, u as RpcNotice } from "./events-Do8jXh4D.js";
6
- import { a as ExtensionOf, g as WithExtension, h as RequestContext, n as AnyPlugin, r as ApplyExtension } from "./plugin-DVRB8qNE.js";
7
- import { t as StandardSchemaV1 } from "./standard-eudBiRk1.js";
8
- import { i as PostgrestPlan } from "./postgrest-DmBlevh-.js";
2
+ import { A as Schema, D as RelationTypes, F as TableMeta, L as UniqueKeyName, M as Simplify, O as Relations, P as TableKey, R as UniqueWhere, _ as Insert, j as SchemaMeta, k as Row, n as AnyFunctions, r as AnyModels, w as PrimaryKeyValue, z as Update } from "./types-Dnf_wRDz.js";
3
+ import { I as CountMode, S as ErrorMapper, U as Operation, _ as DbError, a as AsyncResult, d as ThrowMapper, r as Executor } from "./executor-BunPOO-k.js";
4
+ import { E as Logger, a as EventHub, i as EventHandler, o as EventName, s as MutationNotice, u as RpcNotice } from "./events-aIO7vsIk.js";
5
+ import { _ as WithExtension, a as ExtensionOf, g as RequestContext, n as AnyPlugin, r as ApplyExtension } from "./plugin-o144f322.js";
6
+ import { t as StandardSchemaV1 } from "./standard-J4YgMOLm.js";
7
+ import { i as PostgrestPlan } from "./postgrest-CruYKAvV.js";
9
8
  //#region src/ir/args.d.ts
10
9
  interface BaseOps<V> {
11
10
  readonly eq?: V;
@@ -178,13 +177,17 @@ type AggregateResult<M extends AnyModels, T extends keyof M, A> = A extends {
178
177
  readonly groupBy: readonly unknown[];
179
178
  } ? AggregateRow<M, T, A>[] : AggregateRow<M, T, A>;
180
179
  /** The row type returned for read arguments `A` on table `T`. */
181
- type Payload<M extends AnyModels, T extends keyof M, A> = Simplify<SelectPart<M, T, A> & IncludePart<M, T, A>>;
180
+ type Payload<M extends AnyModels, T extends keyof M, A> = A extends {
181
+ readonly include: unknown;
182
+ } ? Simplify<SelectPart<M, T, A> & IncludePart<M, T, A>> : A extends {
183
+ readonly select: readonly unknown[];
184
+ } ? Simplify<SelectPart<M, T, A>> : Row<M, T>;
182
185
  //#endregion
183
186
  //#region src/core/spec.d.ts
184
187
  type ReadMethod = "findMany" | "findFirst" | "findUnique" | "findById" | "count" | "aggregate" | "exists" | "paginate";
185
188
  declare const resultType: unique symbol;
186
189
  /**
187
- * A read, described as plain JSON: build it with `sb.spec`, run it with
190
+ * A read, described as plain JSON: build it with `betterSupabase.spec`, run it with
188
191
  * `db.$run(spec)`, send it from a Server Component to the client, or hand it
189
192
  * to `/query` and `/next`. Args never carry a `signal`.
190
193
  */
@@ -269,7 +272,7 @@ interface ReadSetOptions<P extends ReadSetParamTypes> {
269
272
  *
270
273
  * ```ts
271
274
  * export const appChrome = defineReadSet(
272
- * sb,
275
+ * betterSupabase,
273
276
  * 'app_chrome',
274
277
  * { params: { userId: 'uuid' } },
275
278
  * (s, p) => ({
@@ -282,7 +285,7 @@ interface ReadSetOptions<P extends ReadSetParamTypes> {
282
285
  * `p` holds placeholders, not values: pass them straight into `where` (or
283
286
  * `in`), where the function reads them from its `p jsonb` argument.
284
287
  */
285
- declare function defineReadSet<M extends AnyModels, D, F extends AnyFunctions, E, const N extends string, const P extends ReadSetParamTypes, const S extends Readonly<Record<string, QuerySpec>>>(sb: BetterSupabase<M, D, F, E>, name: N, options: ReadSetOptions<P>, build: (specs: Specs<M, E>, params: ReadSetParams<P>) => S): ReadSet<N, P, S>;
288
+ declare function defineReadSet<M extends AnyModels, D, F extends AnyFunctions, E, const N extends string, const P extends ReadSetParamTypes, const S extends Readonly<Record<string, QuerySpec>>>(betterSupabase: BetterSupabase<M, D, F, E>, name: N, options: ReadSetOptions<P>, build: (specs: Specs<M, E>, params: ReadSetParams<P>) => S): ReadSet<N, P, S>;
286
289
  declare function isReadSet(value: unknown): value is ReadSet;
287
290
  /** App keys of every table the set reads. */
288
291
  declare function readSetTables(set: ReadSet, meta?: SchemaMeta): string[];
@@ -333,6 +336,11 @@ type DeleteExt<E, M extends AnyModels, T extends keyof M> = ApplyExtension<E, M,
333
336
  interface WriteArgs<M extends AnyModels, T extends keyof M> extends ReadArgs<M, T> {
334
337
  /** `false` skips `RETURNING` (needed when RLS hides the written row). */
335
338
  readonly returning?: boolean;
339
+ /**
340
+ * Keep caller-supplied values for columns that `timestamps()`, `actor()`
341
+ * and `softDelete()` fill (imports, backfills). Without it they are refused.
342
+ */
343
+ readonly override?: boolean;
336
344
  }
337
345
  interface UpdateArgs<M extends AnyModels, T extends keyof M> extends WriteArgs<M, T> {
338
346
  /**
@@ -385,7 +393,7 @@ type PageOf<M extends AnyModels, T extends keyof M, A> = A extends {
385
393
  readonly after: unknown;
386
394
  } ? CursorPage<Payload<M, T, A>> : OffsetPage<Payload<M, T, A>>;
387
395
  interface Repository<M extends AnyModels, T extends TableKey<M>, E = unknown> {
388
- readonly $table: T;
396
+ readonly $tableName: T;
389
397
  readonly $meta: TableMeta;
390
398
  findMany<const A extends FindManyArgs<M, T> & FindExt<E, M, T>>(args?: A): AsyncResult<Payload<M, T, A>[]>;
391
399
  findFirst<const A extends FindFirstArgs<M, T> & FindExt<E, M, T>>(args?: A): AsyncResult<Payload<M, T, A> | null>;
@@ -471,7 +479,7 @@ interface DbHelpers<M extends AnyModels, F extends AnyFunctions, E, C> {
471
479
  $table<T extends TableKey<M>>(name: T): RepositoryOf<M, T, E>;
472
480
  /** Calls, waves, tables and time for everything run through this `db`. */
473
481
  $stats(): DbStats;
474
- /** Runs a `QuerySpec` built with `sb.spec`. */
482
+ /** Runs a `QuerySpec` built with `betterSupabase.spec`. */
475
483
  $run<S extends QuerySpec<TableKey<M>>>(spec: S, options?: {
476
484
  readonly signal?: AbortSignal;
477
485
  }): AsyncResult<InferResult<S>>;
@@ -516,7 +524,7 @@ interface CacheTarget {
516
524
  /**
517
525
  * Invalidates cached reads after a mutation. First-party adapters:
518
526
  * `nextCache()` (Next.js cache tags) and `queryCache(client)` (TanStack
519
- * Query). Attach one with `sb.cache(adapter)`; prove custom ones with
527
+ * Query). Attach one with `betterSupabase.cache(adapter)`; prove custom ones with
520
528
  * `testCacheAdapter`.
521
529
  */
522
530
  interface CacheAdapter {
@@ -550,20 +558,20 @@ declare function postgrestExecutor(client: PostgrestClientLike): Executor;
550
558
  declare function explainPostgrest(op: Operation): PostgrestPlan;
551
559
  //#endregion
552
560
  //#region src/core/define.d.ts
553
- interface DefineSupabaseOptions {
561
+ interface SupabaseOptions {
554
562
  /** Clock used by plugins (timestamps, soft delete). */
555
563
  readonly now?: () => Temporal.Instant;
556
564
  /** Extra error mappers, run before plugin mappers. */
557
565
  readonly errors?: readonly ErrorMapper[];
558
566
  /** Receives errors from event handlers, hooks and cache adapters. Defaults to `console`. */
559
567
  readonly logger?: Logger;
560
- /** RPCs that change tables, keyed by function name. Prefer `sb.defineRpc()`. */
568
+ /** RPCs that change tables, keyed by function name. Prefer `betterSupabase.defineRpc()`. */
561
569
  readonly rpc?: Readonly<Record<string, RpcDefinition>>;
562
- /** Builds the error `.orThrow()` throws. Prefer `sb.mapError()`. */
570
+ /** Builds the error `.orThrow()` throws. Prefer `betterSupabase.mapError()`. */
563
571
  readonly throwAs?: ThrowMapper;
564
- /** Validates verified JWT claims on the server. Prefer `sb.claims()`, which also types them. */
572
+ /** Validates verified JWT claims on the server. Prefer `betterSupabase.claims()`, which also types them. */
565
573
  readonly claims?: StandardSchemaV1;
566
- /** Parses `user_metadata` into `session.profile`. Prefer `sb.userMetadata()`, which also types it. */
574
+ /** Parses `user_metadata` into `session.profile`. Prefer `betterSupabase.userMetadata()`, which also types it. */
567
575
  readonly userMetadata?: StandardSchemaV1;
568
576
  /**
569
577
  * PostgREST's `db-max-rows`: the most rows one read returns. An unbounded
@@ -594,8 +602,8 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
594
602
  readonly schema: Schema<M, D, F>;
595
603
  readonly plugins: readonly AnyPlugin[];
596
604
  readonly events: EventHub;
597
- readonly options: DefineSupabaseOptions;
598
- constructor(schema: Schema<M, D, F>, plugins?: readonly AnyPlugin[], options?: DefineSupabaseOptions, events?: EventHub);
605
+ readonly options: SupabaseOptions;
606
+ constructor(schema: Schema<M, D, F>, plugins?: readonly AnyPlugin[], options?: SupabaseOptions, events?: EventHub);
599
607
  get meta(): SchemaMeta;
600
608
  /** The schema set by `claims()`; its output types `session.claims`. */
601
609
  get claimsSchema(): StandardSchemaV1<unknown, C> | undefined;
@@ -607,7 +615,7 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
607
615
  * A token that fails it resolves to `{ kind: 'invalid', reason: 'claims' }`.
608
616
  *
609
617
  * ```ts
610
- * const sb = defineSupabase(schema).claims(z.object({ tenant_id: z.uuid() }));
618
+ * const betterSupabase = defineSupabase(schema).claims(z.object({ tenant_id: z.uuid() }));
611
619
  * ```
612
620
  */
613
621
  claims<S extends StandardSchemaV1>(schema: S): BetterSupabase<M, D, F, E, StandardSchemaV1.InferOutput<S>, P>;
@@ -620,7 +628,7 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
620
628
  * the verified claims, never from `profile`.
621
629
  *
622
630
  * ```ts
623
- * const sb = defineSupabase(schema).userMetadata(z.object({ display_name: z.string() }));
631
+ * const betterSupabase = defineSupabase(schema).userMetadata(z.object({ display_name: z.string() }));
624
632
  * ```
625
633
  */
626
634
  userMetadata<S extends StandardSchemaV1>(schema: S): BetterSupabase<M, D, F, E, C, StandardSchemaV1.InferOutput<S>>;
@@ -630,13 +638,13 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
630
638
  * Results themselves keep their `DbError`.
631
639
  *
632
640
  * ```ts
633
- * const sb = defineSupabase(schema).mapError((error) => new AppError(error));
641
+ * const betterSupabase = defineSupabase(schema).mapError((error) => new AppError(error));
634
642
  * ```
635
643
  */
636
644
  mapError(mapper: (error: DbError) => unknown): BetterSupabase<M, D, F, E, C, P>;
637
645
  /**
638
646
  * Builds serializable `QuerySpec`s with the same arguments and result types
639
- * as the repository: `sb.spec.customers.findMany({ select: ['id'] })`.
647
+ * as the repository: `betterSupabase.spec.customers.findMany({ select: ['id'] })`.
640
648
  */
641
649
  get spec(): Specs<M, E>;
642
650
  /** App keys of every table a spec reads; mutations of any of them make it stale. */
@@ -648,7 +656,7 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
648
656
  * invalidate them after it succeeds.
649
657
  *
650
658
  * ```ts
651
- * sb.defineRpc('archive_customer', { invalidates: ['customers', 'notes'] });
659
+ * betterSupabase.defineRpc('archive_customer', { invalidates: ['customers', 'notes'] });
652
660
  * ```
653
661
  */
654
662
  defineRpc(name: Extract<keyof F, string>, options: {
@@ -672,9 +680,9 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
672
680
  * Creates the data-layer definition from the generated `schema`.
673
681
  *
674
682
  * ```ts
675
- * export const sb = defineSupabase(schema).use(timestamps()).use(softDelete());
683
+ * export const betterSupabase = defineSupabase(schema).use(timestamps()).use(softDelete());
676
684
  * ```
677
685
  */
678
- declare function defineSupabase<M extends AnyModels, D, F extends AnyFunctions>(schema: Schema<M, D, F>, options?: DefineSupabaseOptions): BetterSupabase<M, D, F>;
686
+ declare function defineSupabase<M extends AnyModels, D, F extends AnyFunctions>(schema: Schema<M, D, F>, options?: SupabaseOptions): BetterSupabase<M, D, F>;
679
687
  //#endregion
680
- export { Specs as $, RpcOptions as A, ReadSet as B, FindExt as C, WhereInput as Ct, Repository as D, PageOf as E, EMPTY_STATS as F, ReadSetParams as G, ReadSetParamType as H, StatsRecorder as I, isReadSet as J, ReadSetResult as K, recordStats as L, UpsertArgs as M, WriteArgs as N, RepositoryOf as O, DbStats as P, ReadMethod as Q, SearchArgs as R, DeleteExt as S, SortDirection as St, OffsetPageArgs as T, ReadSetParamTypes as U, ReadSetOptions as V, ReadSetParamValue as W, InferResult as X, readSetTables as Y, QuerySpec as Z, CursorPage as _, OrderByInput as _t, defineSupabase as a, AggregateRow as at, DbHelpers as b, RelationMeasureArg as bt, postgrestExecutor as c, FieldFilter as ct, MemoryCache as d, IncludeArg as dt, TableSpecs as et, cacheTargetOf as f, IncludeArgs as ft, ConflictTarget as g, OrderByArg as gt, rpcCacheTargets as h, NumericMeasureArg as ht, RpcDefinition as i, AggregateResult as it, UpdateArgs as j, Returned as k, CacheAdapter as l, FindFirstArgs as lt, rowKey as m, MeasureKey as mt, ConnectOptions as n, specTables as nt, PostgrestClientLike as o, CountArg as ot, memoryCache as p, MeasureArg as pt, defineReadSet as q, DefineSupabaseOptions as r, AggregateArgs as rt, explainPostgrest as s, CountArgs as st, BetterSupabase as t, isQuerySpec as tt, CacheTarget as u, FindManyArgs as ut, CursorPageArgs as v, Payload as vt, OffsetPage as w, DeleteArgs as x, SelectArg as xt, Db as y, ReadArgs as yt, InferReadSetParams as z };
688
+ export { Specs as $, RpcOptions as A, ReadSet as B, FindExt as C, WhereInput as Ct, Repository as D, PageOf as E, EMPTY_STATS as F, ReadSetParams as G, ReadSetParamType as H, StatsRecorder as I, isReadSet as J, ReadSetResult as K, recordStats as L, UpsertArgs as M, WriteArgs as N, RepositoryOf as O, DbStats as P, ReadMethod as Q, SearchArgs as R, DeleteExt as S, SortDirection as St, OffsetPageArgs as T, ReadSetParamTypes as U, ReadSetOptions as V, ReadSetParamValue as W, InferResult as X, readSetTables as Y, QuerySpec as Z, CursorPage as _, OrderByInput as _t, defineSupabase as a, AggregateRow as at, DbHelpers as b, RelationMeasureArg as bt, postgrestExecutor as c, FieldFilter as ct, MemoryCache as d, IncludeArg as dt, TableSpecs as et, cacheTargetOf as f, IncludeArgs as ft, ConflictTarget as g, OrderByArg as gt, rpcCacheTargets as h, NumericMeasureArg as ht, SupabaseOptions as i, AggregateResult as it, UpdateArgs as j, Returned as k, CacheAdapter as l, FindFirstArgs as lt, rowKey as m, MeasureKey as mt, ConnectOptions as n, specTables as nt, PostgrestClientLike as o, CountArg as ot, memoryCache as p, MeasureArg as pt, defineReadSet as q, RpcDefinition as r, AggregateArgs as rt, explainPostgrest as s, CountArgs as st, BetterSupabase as t, isQuerySpec as tt, CacheTarget as u, FindManyArgs as ut, CursorPageArgs as v, Payload as vt, OffsetPage as w, DeleteArgs as x, SelectArg as xt, Db as y, ReadArgs as yt, InferReadSetParams as z };