better-supabase 0.4.0 → 0.5.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 (180) hide show
  1. package/README.md +135 -16
  2. package/dist/actor-DaJjqD5R.d.ts +43 -0
  3. package/dist/channel-FQW-CnGR.d.ts +70 -0
  4. package/dist/cli/bin.js +1 -1
  5. package/dist/cli/codemod-DqV7612m.js +388 -0
  6. package/dist/cli/{config-D9R0o1LH.js → config-CPVpXP5I.js} +78 -8
  7. package/dist/cli/{config-SSKSTUl2.js → config-dtoekM0v.js} +1 -1
  8. package/dist/cli/{read-sets-CMa29t9a.js → diff-SjkO5rNr.js} +1 -220
  9. package/dist/cli/{dist-CFgGknmZ.js → dist-DBPdlPYK.js} +4 -4
  10. package/dist/cli/{dist-B1MvLv-M.js → dist-DreZ24Sz.js} +1 -1
  11. package/dist/cli/{dist-Du7VnEUG.js → dist-xn4wlboc.js} +112 -1
  12. package/dist/cli/{doctor-BOym3mbL.js → doctor-C_A-KEAz.js} +533 -50
  13. package/dist/cli/{env-BZ0uy8XK.js → env-DmKv_G4A.js} +1 -1
  14. package/dist/cli/gen-CIdSQZad.js +2 -0
  15. package/dist/cli/{gen-Ccn_p90L.js → gen-CjElD1Vw.js} +321 -88
  16. package/dist/cli/index.d.ts +1 -1
  17. package/dist/cli/index.js +4 -4
  18. package/dist/cli/{init-ClnxRYBF.js → init-DMa6M7hV.js} +2 -2
  19. package/dist/cli/{introspect-DxqfkVIv.js → introspect-BKlaIu_M.js} +2 -2
  20. package/dist/cli/{openapi-8WHjxiTJ.js → openapi-Cp5Fyta-.js} +1 -1
  21. package/dist/cli/read-sets-VQcPgxU9.js +436 -0
  22. package/dist/cli/{run-CP20LKk_.js → run-Bo_NLT5n.js} +16 -12
  23. package/dist/cli/{seed-5J6eu_Xg.js → seed-CUlqWh-8.js} +1 -1
  24. package/dist/cli/sql-CVx-1O8G.js +373 -0
  25. package/dist/cli/{version-5mW_8sY1.js → version-BCtlgDQx.js} +1 -1
  26. package/dist/client/index.d.ts +1 -1
  27. package/dist/client/index.js +3 -10
  28. package/dist/clone-BfgmLU90.js +21 -0
  29. package/dist/{compiler-DB3aSFOA.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
  30. package/dist/config/index.d.ts +4 -4
  31. package/dist/config/index.js +4 -4
  32. package/dist/{config-C1CYcm6o.d.ts → config-Bv7gvfzC.d.ts} +185 -11
  33. package/dist/{config-CbvFmGD8.js → config-DreERlKo.js} +1 -1
  34. package/dist/{define-CRS2MRV3.d.ts → define-Bp_BZa5h.d.ts} +11 -7
  35. package/dist/{define-Bh0AqTik.js → define-cNKzqwL_.js} +202 -16
  36. package/dist/edge/index.d.ts +16 -5
  37. package/dist/edge/index.js +10 -7
  38. package/dist/{entitlements-Dm-FHpNH.d.ts → entitlements-BiJZ4t49.d.ts} +1 -1
  39. package/dist/env/index.d.ts +2 -2
  40. package/dist/env/index.js +34 -1
  41. package/dist/{errors-L0xK41y_.js → errors-DtwXa6b8.js} +1 -0
  42. package/dist/events/index.d.ts +3 -2
  43. package/dist/events/index.js +65 -12
  44. package/dist/events-aIO7vsIk.d.ts +230 -0
  45. package/dist/{result-CqEsbgYs.d.ts → executor-BunPOO-k.d.ts} +200 -1
  46. package/dist/{executor-CZ7ImRiD.d.ts → executor-Cghdstwu.d.ts} +1 -2
  47. package/dist/{executor-CVt6dD0B.js → executor-XycESQPH.js} +3 -3
  48. package/dist/hono/index.d.ts +17 -6
  49. package/dist/hono/index.js +40 -5
  50. package/dist/impersonation-BgSHAYLf.js +133 -0
  51. package/dist/{resolve-BAqQcwMW.d.ts → impersonation-BmePsuxz.d.ts} +36 -6
  52. package/dist/{index-BhHEC04r.d.ts → index-C7f8cOBM.d.ts} +2 -2
  53. package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
  54. package/dist/{index-Cf-D2jk1.d.ts → index-CWMDdEr4.d.ts} +2 -2
  55. package/dist/{index-D5IfUIDh.d.ts → index-DOESKG27.d.ts} +33 -8
  56. package/dist/{index-DFmOpBGC.d.ts → index-DgILJRXj.d.ts} +35 -9
  57. package/dist/{index-RlLXd8dL.d.ts → index-DmXSxbLi.d.ts} +4 -4
  58. package/dist/{index-BBdvo-5d.d.ts → index-Dp2VDwog.d.ts} +49 -6
  59. package/dist/{index-528Ugmyp.d.ts → index-SaTsEfGP.d.ts} +76 -8
  60. package/dist/{index-BAy4tsAP.d.ts → index-fag8VJZ2.d.ts} +3 -4
  61. package/dist/index.d.ts +30 -13
  62. package/dist/index.js +10 -9
  63. package/dist/jobs/index.d.ts +147 -101
  64. package/dist/jobs/index.js +744 -237
  65. package/dist/{json-schema-DP6V7cbr.js → json-schema-m1fiwKgN.js} +22 -1
  66. package/dist/kit-events-CTFDfSwb.js +60 -0
  67. package/dist/kit-transport-B82k1djG.d.ts +33 -0
  68. package/dist/kit-transport-DJlHQUBU.js +55 -0
  69. package/dist/{config-BpxDfnbg.js → kits-CGLLrNPd.js} +37 -9
  70. package/dist/list/index.d.ts +1 -1
  71. package/dist/{live-BHakSWWo.d.ts → live-D9W2M5aO.d.ts} +6 -5
  72. package/dist/mcp/index.d.ts +25 -8
  73. package/dist/mcp/index.js +23 -14
  74. package/dist/{mfa-C7MNQ1Ob.d.ts → mfa-Cu96oJdw.d.ts} +2 -16
  75. package/dist/next/index.d.ts +31 -10
  76. package/dist/next/index.js +136 -27
  77. package/dist/notifications/index.d.ts +162 -0
  78. package/dist/notifications/index.js +264 -0
  79. package/dist/openapi/index.d.ts +1 -1
  80. package/dist/openapi/index.js +2 -2
  81. package/dist/orgs/index.d.ts +132 -0
  82. package/dist/orgs/index.js +245 -0
  83. package/dist/orpc/index.d.ts +28 -8
  84. package/dist/orpc/index.js +16 -3
  85. package/dist/otel/index.d.ts +21 -2
  86. package/dist/otel/index.js +50 -9
  87. package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
  88. package/dist/permdock-sql-DgOfeixi.js +51 -0
  89. package/dist/plugin-DwARMuQp.js +59 -0
  90. package/dist/{plugin-bNhvJwRh.d.ts → plugin-o144f322.d.ts} +17 -5
  91. package/dist/plugins/actor/index.d.ts +5 -2
  92. package/dist/plugins/actor/index.js +22 -8
  93. package/dist/plugins/rules/index.d.ts +2 -2
  94. package/dist/plugins/rules/index.js +15 -10
  95. package/dist/plugins/soft-delete/index.d.ts +3 -3
  96. package/dist/plugins/soft-delete/index.js +14 -5
  97. package/dist/plugins/tenant/index.d.ts +2 -2
  98. package/dist/plugins/tenant/index.js +38 -20
  99. package/dist/plugins/timestamps/index.d.ts +1 -1
  100. package/dist/plugins/timestamps/index.js +4 -3
  101. package/dist/plugins/validation/index.d.ts +2 -2
  102. package/dist/plugins/validation/index.js +26 -6
  103. package/dist/{pool-DFwEQwmN.d.ts → pool-C9voM4Kw.d.ts} +17 -6
  104. package/dist/postgres/index.d.ts +5 -5
  105. package/dist/postgres/index.js +20 -11
  106. package/dist/{postgrest-Bc-0Xw62.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
  107. package/dist/{problem-BihjPR0t.js → problem-BW1KhzSG.js} +2 -1
  108. package/dist/{problem-U8UEKccv.d.ts → problem-Blxe8S31.d.ts} +1 -1
  109. package/dist/query/index.d.ts +2 -2
  110. package/dist/query/index.js +3 -3
  111. package/dist/{query-BMMSWbI7.js → query-CCbo44lG.js} +2 -2
  112. package/dist/queue-BYUCjr59.d.ts +252 -0
  113. package/dist/react/index.d.ts +8 -7
  114. package/dist/react/index.js +4 -3
  115. package/dist/react/server.d.ts +14 -3
  116. package/dist/react/server.js +10 -2
  117. package/dist/react/session.d.ts +7 -1
  118. package/dist/react/session.js +9 -1
  119. package/dist/{react-CQHMaESR.js → react-C_s7kiNz.js} +103 -11
  120. package/dist/{read-set-FWK8qQ58.js → read-set-DQFt1N_Y.js} +22 -1
  121. package/dist/realtime/index.d.ts +3 -3
  122. package/dist/realtime/index.js +5 -4
  123. package/dist/{refresh-BwYkyNOQ.d.ts → refresh-CFPX0Qft.d.ts} +1 -1
  124. package/dist/{resource-BJcaIfxi.d.ts → resource-DNRFP7KR.d.ts} +5 -5
  125. package/dist/{resource-My_y-Syh.js → resource-mqfJW4YF.js} +22 -7
  126. package/dist/respond-BR1fJWOB.d.ts +377 -0
  127. package/dist/{result-Bj6yt33D.js → result-BKiliPY7.js} +1 -1
  128. package/dist/server/index.d.ts +15 -12
  129. package/dist/server/index.js +11 -17
  130. package/dist/{server-BA75B0mT.js → server-B1mZ7CgQ.js} +259 -37
  131. package/dist/{shared-DnoCdMDr.js → shared-D1dRUrAg.js} +16 -2
  132. package/dist/signers-Cc6r98SW.d.ts +162 -0
  133. package/dist/{simplify-Cqvfr9dj.js → simplify-_0oUKqCd.js} +4 -115
  134. package/dist/sql/index.d.ts +283 -11
  135. package/dist/sql/index.js +8705 -775
  136. package/dist/{sql-B34HU2DI.js → sql-Coh6n4cC.js} +9 -2
  137. package/dist/ssr/index.d.ts +4 -4
  138. package/dist/ssr/index.js +1 -2
  139. package/dist/{standard-BRyBGTtp.js → standard-D7r6dMUu.js} +6 -3
  140. package/dist/{standard-BsaCYQJc.d.ts → standard-J4YgMOLm.d.ts} +1 -1
  141. package/dist/{stats-C_YxA2r1.js → stats-Bqob3WqT.js} +4 -4
  142. package/dist/storage/index.d.ts +4 -4
  143. package/dist/storage/index.js +155 -26
  144. package/dist/support-CEPwlw2G.d.ts +89 -0
  145. package/dist/support-view-B8SlToQX.d.ts +17 -0
  146. package/dist/support-view-g4YLBeqX.js +18 -0
  147. package/dist/support-wHnK6zp-.js +293 -0
  148. package/dist/{permdock-sql-C4KFzLc9.js → template-TxrGI5jR.js} +2 -31
  149. package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
  150. package/dist/{temporal-required-CBNHT6ni.js → temporal-required-CAt4Dc9Z.js} +2 -2
  151. package/dist/testing/index.d.ts +132 -10
  152. package/dist/testing/index.js +476 -8
  153. package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
  154. package/dist/user-change-CHFEUro1.js +49 -0
  155. package/dist/{webhooks-Bh_Jf_-l.js → verify-Ce49ETPz.js} +5 -5
  156. package/dist/{version-Bmf7_FzM.js → version-DOYTYwHP.js} +1 -1
  157. package/dist/{mfa-byfjruR9.js → view-Bn6HNKUe.js} +97 -98
  158. package/dist/{view-B64o81wp.d.ts → view-CbgObAeb.d.ts} +22 -31
  159. package/dist/webhooks/index.d.ts +135 -4
  160. package/dist/webhooks/index.js +588 -2
  161. package/dist/wire-D2dT86vi.js +35 -0
  162. package/package.json +27 -19
  163. package/schemas/config-v1.json +131 -1
  164. package/schemas/doctor-report-v1.json +11 -0
  165. package/skills/better-supabase/SKILL.md +9 -6
  166. package/skills/better-supabase/references/plugins.md +6 -3
  167. package/skills/better-supabase/references/troubleshooting.md +1 -0
  168. package/skills/better-supabase-api/SKILL.md +9 -2
  169. package/skills/better-supabase-api/references/adapters.md +11 -8
  170. package/skills/better-supabase-auth/SKILL.md +18 -7
  171. package/skills/better-supabase-auth/references/permdock.md +78 -11
  172. package/dist/cli/gen-D5cLCULx.js +0 -2
  173. package/dist/cli/sql-D4VbqmXi.js +0 -199
  174. package/dist/events-B21UOhvP.d.ts +0 -84
  175. package/dist/executor-B5IoUxLE.d.ts +0 -195
  176. package/dist/invalidate-CgxmRamI.js +0 -24
  177. package/dist/permdock-sql-DImJULY-.d.ts +0 -17
  178. package/dist/plugin-BqR6wKMB.js +0 -23
  179. package/dist/respond-DgIbdrt8.d.ts +0 -194
  180. package/dist/view-BrJI2LKp.js +0 -45
@@ -1,8 +1,8 @@
1
- import { n as dbError, t as DbException } from "./errors-L0xK41y_.js";
1
+ import { n as isPlainObject } from "./clone-BfgmLU90.js";
2
+ import { n as dbError, t as DbException } from "./errors-DtwXa6b8.js";
2
3
  import { t as lookupOf } from "./lookup-BaP5bI27.js";
3
- import { i as temporalText } from "./temporal-BwshQk0W.js";
4
- import { t as temporal } from "./temporal-required-CBNHT6ni.js";
5
4
  import { i as or, r as not, t as and } from "./types-6cYK9pbJ.js";
5
+ import { r as encodeValue } from "./wire-D2dT86vi.js";
6
6
  //#region src/schema/define.ts
7
7
  /**
8
8
  * Binds generated model types to runtime metadata. Called from the generated
@@ -29,112 +29,6 @@ function relationMeta(meta, table, relation) {
29
29
  };
30
30
  }
31
31
  //#endregion
32
- //#region src/ir/codec.ts
33
- /** Wire form of an app value: Temporal values to ISO text, `bigint` to decimal text. */
34
- function encodeValue(value) {
35
- if (typeof value !== "object" || value === null) return typeof value === "bigint" ? value.toString() : value;
36
- const text = temporalText(value);
37
- if (text !== void 0) return text;
38
- if (Array.isArray(value)) return value.map(encodeValue);
39
- return value;
40
- }
41
- function decodeScalar(codec, value) {
42
- if (value === null || value === void 0) return value;
43
- switch (codec) {
44
- case "instant": return temporal().Instant.from(String(value));
45
- case "plainDateTime": return temporal().PlainDateTime.from(String(value));
46
- case "bigint": return BigInt(value);
47
- case "string": return String(value);
48
- default: return codec;
49
- }
50
- }
51
- function decode(codec, value) {
52
- return Array.isArray(value) ? value.map((item) => decodeScalar(codec, item)) : decodeScalar(codec, value);
53
- }
54
- /** Whether decoding `selection` changes anything, so plain reads skip the walk. */
55
- function needsDecoding(selection) {
56
- let needs = decodes.get(selection);
57
- if (needs === void 0) {
58
- needs = computeNeedsDecoding(selection);
59
- decodes.set(selection, needs);
60
- }
61
- return needs;
62
- }
63
- const decodes = /* @__PURE__ */ new WeakMap();
64
- function computeNeedsDecoding(selection) {
65
- return selection.aggregate !== void 0 || selection.columns.some((column) => column.codec !== void 0) || selection.includes.some((include) => include.count !== void 0 || include.aggregate !== void 0 || needsDecoding(include.selection));
66
- }
67
- /** PostgREST returns `[{ count }]` for a `(count)` embed; SQL returns the number. */
68
- function countOf(value) {
69
- if (Array.isArray(value)) {
70
- const first = value[0];
71
- return Number(first?.count ?? 0);
72
- }
73
- return Number(value ?? 0);
74
- }
75
- function measureOf(measure, value) {
76
- if (value === void 0 || value === null) return null;
77
- return measure.codec ? decodeScalar(measure.codec, value) : value;
78
- }
79
- /** Adds `value` under `row[key][name]`, next to what is already there. */
80
- function fold(row, folded, key, name, value) {
81
- let target = folded.get(key);
82
- if (!target) {
83
- target = { ...row[key] };
84
- folded.set(key, target);
85
- row[key] = target;
86
- }
87
- target[name] = value;
88
- }
89
- const droppedKeys = /* @__PURE__ */ new WeakMap();
90
- /** Wire keys that decoding folds into `_count`, `_sum` and the rest. */
91
- function droppedOf(selection) {
92
- let dropped = droppedKeys.get(selection);
93
- if (!dropped) {
94
- dropped = /* @__PURE__ */ new Set([...selection.aggregate?.measures.map((measure) => measure.key) ?? [], ...selection.includes.filter((include) => include.count !== void 0 || include.aggregate !== void 0).map((include) => include.alias)]);
95
- droppedKeys.set(selection, dropped);
96
- }
97
- return dropped;
98
- }
99
- function decodeRow(selection, row) {
100
- const dropped = droppedOf(selection);
101
- const out = {};
102
- for (const key in row) if (!dropped.has(key) && Object.hasOwn(row, key)) out[key] = row[key];
103
- const folded = /* @__PURE__ */ new Map();
104
- for (const column of selection.columns) if (column.codec && column.alias in out) out[column.alias] = decode(column.codec, out[column.alias]);
105
- if (selection.aggregate) {
106
- if (selection.aggregate.count) out["_count"] = countOf(out["_count"]);
107
- for (const measure of selection.aggregate.measures) {
108
- const value = row[measure.key];
109
- fold(out, folded, `_${measure.fn}`, measure.alias, measureOf(measure, value));
110
- }
111
- }
112
- for (const include of selection.includes) {
113
- const value = row[include.alias];
114
- if (include.count !== void 0) {
115
- if (!(include.alias in row)) continue;
116
- fold(out, folded, "_count", include.count, countOf(value));
117
- continue;
118
- }
119
- if (include.aggregate !== void 0) {
120
- if (!(include.alias in row)) continue;
121
- const inner = Array.isArray(value) ? value[0] : value;
122
- const measures = {};
123
- for (const measure of include.selection.aggregate?.measures ?? []) measures[measure.alias] = measureOf(measure, inner?.[measure.key]);
124
- fold(out, folded, `_${include.aggregate.fn}`, include.aggregate.name, measures);
125
- continue;
126
- }
127
- if (Array.isArray(value)) out[include.alias] = value.map((item) => decodeRow(include.selection, item));
128
- else if (value && typeof value === "object") out[include.alias] = decodeRow(include.selection, value);
129
- }
130
- return out;
131
- }
132
- /** Applies column codecs to returned rows, including embedded relations. */
133
- function decodeRows(selection, rows, checked = false) {
134
- if (!selection || !checked && !needsDecoding(selection)) return rows;
135
- return rows.map((row) => decodeRow(selection, row));
136
- }
137
- //#endregion
138
32
  //#region src/ir/build.ts
139
33
  const AGGREGATE_KEYS = {
140
34
  _sum: "sum",
@@ -181,11 +75,6 @@ const FIELD_OPS = /* @__PURE__ */ new Set([
181
75
  "has",
182
76
  "containedBy"
183
77
  ]);
184
- function isPlainObject(value) {
185
- if (typeof value !== "object" || value === null) return false;
186
- const proto = Object.getPrototypeOf(value);
187
- return proto === Object.prototype || proto === null;
188
- }
189
78
  function isOpsObject(value) {
190
79
  if (!isPlainObject(value)) return false;
191
80
  const keys = Object.keys(value);
@@ -699,4 +588,4 @@ function simplifyOrFalse(condition) {
699
588
  };
700
589
  }
701
590
  //#endregion
702
- export { invalidRequest as a, needsDecoding as c, escapeLike as i, defineSchema as l, simplifyOrFalse as n, decodeRows as o, builderFor as r, encodeValue as s, simplify as t, tableMeta as u };
591
+ export { invalidRequest as a, escapeLike as i, simplifyOrFalse as n, defineSchema as o, builderFor as r, tableMeta as s, simplify as t };
@@ -1,8 +1,154 @@
1
- import { s as ClaimsMeta } from "../types-DONv9SHN.js";
2
- import { B as ReadSet } from "../define-CRS2MRV3.js";
3
- import { b as ResolvedConfig } from "../config-C1CYcm6o.js";
4
- import { n as permdockKeys } from "../permdock-sql-DImJULY-.js";
1
+ import { c as ClaimsMeta } from "../types-Dnf_wRDz.js";
2
+ import { B as ReadSet } from "../define-Bp_BZa5h.js";
3
+ import { b as ResolvedConfig, ct as KitsConfig, lt as ResolvedKitModule, ot as KitMode } from "../config-Bv7gvfzC.js";
4
+ import { a as permdockKeys, i as permdockKeyStatus, n as PermdockCatalog, r as PermdockKeyStatus, t as PERMDOCK_SCHEMA } from "../permdock-sql-C2Inc6Xc.js";
5
+ //#region src/sql/context.d.ts
6
+ /** The scope id types kit modules render. */
7
+ export declare const KIT_ID_TYPES: readonly ["uuid", "text", "bigint", "integer"];
8
+ type KitIdType = (typeof KIT_ID_TYPES)[number];
9
+ export declare const isKitIdType: (value: string) => value is KitIdType;
10
+ /**
11
+ * A Postgres type name as one of `KIT_ID_TYPES`: case and spacing are
12
+ * normalised and aliases such as `int8` resolved. `undefined` for any other
13
+ * type, so callers refuse it instead of guessing.
14
+ */
15
+ export declare function kitIdType(value: string): KitIdType | undefined;
16
+ /** One logical table of a module: its default name and logical columns. */
17
+ interface KitTableSpec {
18
+ /** Default name, in the module's schema. */
19
+ readonly name: string;
20
+ /** Logical column to default column name. */
21
+ readonly columns: Readonly<Record<string, string>>;
22
+ /**
23
+ * Logical columns an adopted table may lack (mapped to `null`): the module
24
+ * leaves out the feature that needs them.
25
+ */
26
+ readonly optional?: readonly string[];
27
+ /** The app may lack the whole table (`kits.<name>.tables.<table>: null`). */
28
+ readonly optionalTable?: boolean;
29
+ }
30
+ interface KitNames {
31
+ readonly tables: Readonly<Record<string, KitTableSpec>>;
32
+ /** The `before_*` and `after_*` hooks the module calls, so `kits.<name>.hooks.functions` is checked. */
33
+ readonly hooks?: readonly string[];
34
+ /** The `kits.<name>.options` keys the module reads; any other key is rejected. */
35
+ readonly options?: readonly string[];
36
+ }
37
+ /** An event a module writes to the outbox, as SQL expressions. */
38
+ interface KitEmit {
39
+ /** The event type, e.g. `org.created`. */
40
+ readonly type: string;
41
+ /** A `jsonb` expression. */
42
+ readonly payload: string;
43
+ /** A `text` expression, e.g. `'organizations/' || new_org`. */
44
+ readonly subject?: string;
45
+ /** The tenant id expression; it is cast to text. */
46
+ readonly tenant?: string;
47
+ /** A `text` idempotency key expression. */
48
+ readonly key?: string;
49
+ }
50
+ /** A function of a module's contract: what other modules and the TypeScript side call. */
51
+ interface KitContractFunction {
52
+ readonly name: string;
53
+ /** Argument types; `{id}` stands for the module's id type. */
54
+ readonly args: readonly string[];
55
+ readonly returns: string;
56
+ }
57
+ /** What a module's `build` reads: resolved names for one layout. */
58
+ interface KitContext {
59
+ readonly module: string;
60
+ readonly mode: KitMode;
61
+ readonly config: ResolvedKitModule;
62
+ /** The quoted schema of the module's functions and managed tables. */
63
+ readonly schema: string;
64
+ readonly schemaName: string;
65
+ readonly idType: KitIdType;
66
+ readonly claims: ClaimsMeta;
67
+ readonly kits: KitsConfig;
68
+ /** `schema.name` of a module function, quoted. */
69
+ fn(name: string): string;
70
+ /** `schema.table` of a logical table, quoted. */
71
+ table(logical: string): string;
72
+ /** The unquoted schema and name of a logical table. */
73
+ tableName(logical: string): {
74
+ readonly schema: string;
75
+ readonly name: string;
76
+ };
77
+ /** A logical column, quoted. Throws when an adopted table lacks it. */
78
+ col(table: string, column: string): string;
79
+ /** Whether a logical column exists (adopted tables can map it to `null`). */
80
+ has(table: string, column: string): boolean;
81
+ /** Whether an optional logical table exists (it can be mapped to `null`). */
82
+ hasTable(table: string): boolean;
83
+ /** Whether the module owns `table` (managed mode). */
84
+ readonly manages: boolean;
85
+ /** The permission key for a kit action, as a SQL literal. */
86
+ permission(action: string, fallback: string): string;
87
+ /** The permission key for a kit action. */
88
+ permissionKey(action: string, fallback: string): string;
89
+ /** A trigger name with the module's prefix, quoted. */
90
+ trigger(name: string): string;
91
+ /** Whether `module` is installed alongside this one. */
92
+ installed(module: string): boolean;
93
+ /** The context of another module in the same layout. */
94
+ of(module: string): KitContext;
95
+ /** A string module option (`kits.<name>.options`). */
96
+ text(name: string, fallback: string): string;
97
+ number(name: string, fallback: number): number;
98
+ flag(name: string, fallback: boolean): boolean;
99
+ /** A module option that is a list of strings. */
100
+ list(name: string, fallback: readonly string[]): readonly string[];
101
+ /** A declared module option as configured, for object-shaped options. */
102
+ option(name: string): unknown;
103
+ /**
104
+ * PL/pgSQL that calls the app's hook function when it exists, with
105
+ * `[type, expression]` arguments: `if to_regprocedure(...) is not null
106
+ * then perform ...; end if;`.
107
+ */
108
+ hook(name: string, args: readonly (readonly [string, string])[]): string;
109
+ /** The app function a hook calls, quoted, for hooks that return a value. */
110
+ hookTarget(name: string): string;
111
+ /**
112
+ * PL/pgSQL that writes the event to the outbox (`emit_event`) when the
113
+ * `outbox` module is installed and `kits.<name>.events` isn't false;
114
+ * otherwise an empty string.
115
+ */
116
+ emit(event: KitEmit): string;
117
+ }
118
+ /** The contract's argument list with `{id}` resolved, as Postgres prints it. */
119
+ export declare function contractSignature(fn: KitContractFunction, idType: string): string;
120
+ //#endregion
5
121
  //#region src/sql/kit.d.ts
122
+ /** The step from one module version to the next, for `sql upgrade`. */
123
+ interface KitUpgrade {
124
+ /** The installed version this step upgrades from. */
125
+ readonly from: number;
126
+ readonly description: string;
127
+ /** SQL run before the module's current file, e.g. renames and backfills. */
128
+ readonly sql: (ctx: KitContext) => string;
129
+ }
130
+ /**
131
+ * A renamed kit symbol. It keeps a compatibility wrapper for at least one
132
+ * minor release, then is removed; doctor reports uses of both (BS309), and
133
+ * the name stays reserved.
134
+ */
135
+ interface KitDeprecation {
136
+ readonly kind: "function" | "claim" | "table" | "column";
137
+ /** The old name: `schema.function`, a claim name, `schema.table` or `table.column`. */
138
+ readonly symbol: string;
139
+ /** What to use instead. */
140
+ readonly use: string;
141
+ /** The package version that deprecated it. */
142
+ readonly since: string;
143
+ /** The package version that removed it; until then `wrapper` is written. */
144
+ readonly removed?: string;
145
+ /**
146
+ * The compatibility wrapper the module file keeps, e.g. a function with the
147
+ * old name that calls the new one and a `comment on function ... is
148
+ * 'deprecated: use X'`.
149
+ */
150
+ readonly wrapper?: (ctx: KitContext) => string;
151
+ }
6
152
  /**
7
153
  * SQL kit modules for `better-supabase sql add`. Every module is idempotent
8
154
  * (`create or replace`, `if not exists`), so re-running it upgrades in place.
@@ -15,19 +161,42 @@ interface SqlModule {
15
161
  readonly requires: readonly string[];
16
162
  /** What it needs instead when the layout has `permdock`. */
17
163
  readonly permdockRequires?: readonly string[];
164
+ /** What it needs for this layout, e.g. per `kits.access.model`; overrides both. */
165
+ readonly dependencies?: (layout: KitLayout) => readonly string[];
18
166
  /** `schema` files go with your schemas; `test` files go to `supabase/tests`. */
19
167
  readonly target: "schema" | "test";
20
168
  /** The module with the default claim names. */
21
169
  readonly sql: string;
22
170
  /** The module for configured claim names (`config.claims`), when it reads claims. */
23
171
  readonly render?: (claims: ClaimsMeta, layout: KitLayout) => string;
172
+ /** Bumped when installed databases need an upgrade step. Defaults to 1. */
173
+ readonly version?: number;
174
+ /** The modes `kits.<name>.mode` accepts. Defaults to `managed` only. */
175
+ readonly modes?: readonly KitMode[];
176
+ /** The logical tables and columns `kits.<name>.tables` and `columns` map. */
177
+ readonly names?: KitNames;
178
+ /** The functions other modules and the TypeScript side call. */
179
+ readonly contract?: (ctx: KitContext) => readonly KitContractFunction[];
180
+ /** Renders the module for a layout; takes precedence over `render`. */
181
+ readonly build?: (ctx: KitContext, layout: KitLayout) => string;
182
+ readonly upgrades?: readonly KitUpgrade[];
183
+ readonly deprecated?: readonly KitDeprecation[];
184
+ /**
185
+ * Rows, role settings and calls that a schema diff doesn't capture. They
186
+ * go to `better-supabase-data/` next to the schema folder and a migration
187
+ * (`sql data`) instead of the schema file.
188
+ */
189
+ readonly data?: (ctx: KitContext, layout: KitLayout) => string;
24
190
  }
191
+ export declare const moduleVersion: (module: SqlModule) => number;
25
192
  /** New modules go at the end: the position is part of the file name. */
26
193
  export declare const SQL_MODULES: Readonly<Record<string, SqlModule>>;
27
194
  /** The modules to install for `names`, dependencies first. Throws on an unknown name. */
28
195
  export declare function resolveModules(names: readonly string[], layout?: KitLayout): SqlModule[];
29
196
  interface KitFile {
30
197
  readonly module: string;
198
+ /** `schema` and `test` files are diffed; `data` files go in a migration too. */
199
+ readonly kind: "schema" | "data" | "test";
31
200
  readonly path: string;
32
201
  readonly contents: string;
33
202
  }
@@ -42,7 +211,9 @@ interface KitLayout {
42
211
  readonly version?: string;
43
212
  /** `config.realtime.tables`: registered at the end of the `realtime-tables` module. */
44
213
  readonly realtimeTables?: readonly string[];
45
- /** Tenant column passed to `track_realtime`; tables without it broadcast unscoped. */
214
+ /** `config.realtime.global`: tables registered with `tenant_column => null`. */
215
+ readonly realtimeGlobal?: readonly string[];
216
+ /** Tenant column passed to `track_realtime` for the other tables. */
46
217
  readonly tenantColumn?: string;
47
218
  /** Check constraints for the `jsonb-schemas` module. */
48
219
  readonly jsonSchemas?: readonly JsonSchemaCheck[];
@@ -61,6 +232,10 @@ interface KitLayout {
61
232
  readonly claims?: ClaimsMeta;
62
233
  /** PermDock's helpers and membership sources, from its manifest: `entitlements` reads them instead of `tenant`. */
63
234
  readonly permdock?: KitPermdock;
235
+ /** PermDock's permission helpers for the `access` module's `permdock` model, from its manifest. */
236
+ readonly accessPermdock?: KitAccessPermdock;
237
+ /** `config.kits`: modes, names and permission keys per module. */
238
+ readonly kits?: KitsConfig;
64
239
  }
65
240
  /** One PermDock membership source, from the manifest's `memberships`. */
66
241
  interface KitMembershipSource {
@@ -80,8 +255,19 @@ interface KitPermdock {
80
255
  readonly schema: string;
81
256
  /** The PermDock scope tenants map to, e.g. `organization`. */
82
257
  readonly scope: string;
258
+ /** The scope's id type, from the manifest's `rls.scopes[].type`. */
259
+ readonly idType: KitIdType;
83
260
  readonly memberships: readonly KitMembershipSource[];
84
261
  }
262
+ /** Where the `permdock` access model finds `permitted_<scope>_ids` and `permdock_has`. */
263
+ interface KitAccessPermdock {
264
+ /** PermDock's `rls.schema`. */
265
+ readonly schema: string;
266
+ /** The PermDock scope tenants are: the manifest's root scope unless set. */
267
+ readonly scope: string;
268
+ /** The scope's id type, from the manifest's `rls.scopes[].type`. */
269
+ readonly idType: KitIdType;
270
+ }
85
271
  /** An embedding column `db.$search` can query. */
86
272
  interface VectorSearchTable {
87
273
  /** `table` or `schema.table`. */
@@ -91,10 +277,10 @@ interface VectorSearchTable {
91
277
  }
92
278
  /** The table holding each tenant's Stripe customer id. */
93
279
  interface EntitlementsSource {
94
- /** `table` or `schema.table`. */
95
- readonly table: string;
280
+ /** `table` or `schema.table`; unset uses the `organizations` module's. */
281
+ readonly table?: string;
96
282
  /** Column with the Stripe customer id (`cus_...`). */
97
- readonly column: string;
283
+ readonly column?: string;
98
284
  /** Column with the tenant id. */
99
285
  readonly key: string;
100
286
  }
@@ -114,12 +300,98 @@ interface JsonSchemaCheck {
114
300
  }
115
301
  /** Whether an installed file matches, ignoring the version stamped in its header. */
116
302
  export declare function sameKitFile(current: string | undefined, expected: string): boolean;
117
- /** The files `sql add` writes for these modules. */
303
+ /** The installed version of a kit file, from its `@bs-kit` line. */
304
+ export declare function kitFileVersion(contents: string): {
305
+ readonly module: string;
306
+ readonly version: number;
307
+ } | undefined;
308
+ /** A module's SQL for `layout`, without header; `undefined` in custom mode. */
309
+ export declare function moduleBody(name: string, layout?: KitLayout): string | undefined;
310
+ /**
311
+ * The schema or test file `renderKit` writes for each of `names` and the
312
+ * modules they pull in, without rendering: modules in custom mode have none.
313
+ */
314
+ export declare function kitFilePaths(names: readonly string[], layout?: KitLayout): ReadonlyMap<string, string>;
315
+ /** A permission key a kit module checks, from `kitPermissionKeys`. */
316
+ interface KitPermissionKey {
317
+ readonly module: string;
318
+ /** The action in `kits.<module>.permissions` that overrides the key. */
319
+ readonly action: string;
320
+ readonly key: string;
321
+ /**
322
+ * `tenant` for keys checked in a tenant (`member_can`, `can`,
323
+ * `tenant_ids_with`), `platform` for `is_platform` and `platform_can`.
324
+ */
325
+ readonly scope: "tenant" | "platform";
326
+ }
327
+ /**
328
+ * Every permission key the modules `names` install (with what they pull
329
+ * in) check, after `kits.<module>.permissions` overrides. Modules in custom
330
+ * mode are skipped, and so is `invitations.invitePlatform` without platform
331
+ * roles. PermDock's doctor runs the same catalog check from its side.
332
+ */
333
+ export declare function kitPermissionKeys(kits: KitsConfig, names: readonly string[]): KitPermissionKey[];
334
+ /**
335
+ * The files `sql add` writes for these modules. Modules in `custom` mode
336
+ * write nothing: the app implements their contract. A schema module's rows,
337
+ * role settings and other statements a schema diff can't capture go to a
338
+ * second file in `better-supabase-data/` (`kind: 'data'`), which
339
+ * `sql data` writes into a migration.
340
+ */
118
341
  export declare function renderKit(names: readonly string[], layout?: KitLayout): KitFile[];
342
+ /** An installed module, from its file's `@bs-kit` line or `kit_modules`. */
343
+ interface InstalledKitModule {
344
+ readonly module: string;
345
+ readonly version: number;
346
+ }
347
+ /** What `sql upgrade` runs for one module behind the current version. */
348
+ interface KitUpgradePlan {
349
+ readonly module: string;
350
+ readonly from: number;
351
+ readonly to: number;
352
+ readonly steps: readonly {
353
+ readonly from: number;
354
+ readonly description: string;
355
+ readonly sql: string;
356
+ }[];
357
+ }
358
+ /**
359
+ * The upgrade steps for modules installed at an older version. A version
360
+ * without a step needs none: the module file upgrades in place. Modules in
361
+ * custom mode belong to the app and are skipped.
362
+ */
363
+ export declare function upgradePlan(installed: readonly InstalledKitModule[], layout?: KitLayout, modules?: Readonly<Record<string, SqlModule>>): KitUpgradePlan[];
364
+ /** Every deprecated or removed kit symbol, with its module. */
365
+ export declare function kitDeprecations(modules?: Readonly<Record<string, SqlModule>>): readonly (KitDeprecation & {
366
+ readonly module: string;
367
+ })[];
368
+ /** The contract functions of the modules in `custom` mode, for doctor. */
369
+ export declare function customContracts(names: readonly string[], layout?: KitLayout): {
370
+ readonly module: string;
371
+ readonly schema: string;
372
+ readonly idType: KitIdType;
373
+ readonly functions: readonly KitContractFunction[];
374
+ }[];
119
375
  //#endregion
120
376
  //#region src/sql/layout.d.ts
121
377
  /** Where and how `sql add` writes kit files for this config. */
122
- export declare function kitLayout(config: ResolvedConfig, testsDir?: string, readSets?: KitLayout["readSets"], permdock?: KitPermdock): KitLayout;
378
+ export declare function kitLayout(config: ResolvedConfig, testsDir?: string, readSets?: KitLayout["readSets"], permdock?: KitPermdock, accessPermdock?: KitAccessPermdock): KitLayout;
379
+ //#endregion
380
+ //#region src/sql/migration-options.d.ts
381
+ /** A migration-only option a config sets. */
382
+ interface MigrationOptionUse {
383
+ readonly module: string;
384
+ readonly option: string;
385
+ readonly value: unknown;
386
+ readonly adopted: boolean;
387
+ /** `kits.<module>.options.<option> ... It <effect>.` */
388
+ readonly message: string;
389
+ }
390
+ /**
391
+ * The migration-only options `kits` sets to a value other than the managed
392
+ * default. They are accepted in `adopt` mode only; doctor warns about each.
393
+ */
394
+ export declare function migrationOptionUses(kits?: KitsConfig): MigrationOptionUse[];
123
395
  //#endregion
124
396
  //#region src/sql/read-sets.d.ts
125
397
  /** A read set compiled to the SQL of its function. */
@@ -136,4 +408,4 @@ export declare function compileReadSet(set: ReadSet): Promise<CompiledReadSet>;
136
408
  /** Compiles every set, sorted by name. Throws on a duplicate name. */
137
409
  export declare function compileReadSets(sets: readonly ReadSet[]): Promise<CompiledReadSet[]>;
138
410
  //#endregion
139
- export { type CompiledReadSet, type KitFile, type KitLayout, type KitPermdock, type SqlModule, permdockKeys };
411
+ export { type CompiledReadSet, type InstalledKitModule, type KitAccessPermdock, type KitContext, type KitContractFunction, type KitDeprecation, type KitFile, type KitIdType, type KitLayout, type KitNames, type KitPermdock, type KitPermissionKey, type KitTableSpec, type KitUpgrade, type KitUpgradePlan, type MigrationOptionUse, PERMDOCK_SCHEMA, type PermdockCatalog, type PermdockKeyStatus, type SqlModule, permdockKeyStatus, permdockKeys };