better-supabase 0.4.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.
- package/README.md +2 -0
- package/dist/channel-FQW-CnGR.d.ts +70 -0
- package/dist/cli/bin.js +1 -1
- package/dist/cli/codemod-DqV7612m.js +388 -0
- package/dist/cli/{config-D9R0o1LH.js → config-CPVpXP5I.js} +78 -8
- package/dist/cli/{config-SSKSTUl2.js → config-dtoekM0v.js} +1 -1
- package/dist/cli/{read-sets-CMa29t9a.js → diff-SjkO5rNr.js} +1 -220
- package/dist/cli/{dist-CFgGknmZ.js → dist-DBPdlPYK.js} +4 -4
- package/dist/cli/{dist-B1MvLv-M.js → dist-DreZ24Sz.js} +1 -1
- package/dist/cli/{dist-Du7VnEUG.js → dist-xn4wlboc.js} +112 -1
- package/dist/cli/{doctor-BOym3mbL.js → doctor-L7Z8mYTx.js} +531 -50
- package/dist/cli/{env-BZ0uy8XK.js → env-DmKv_G4A.js} +1 -1
- package/dist/cli/gen-BJc9vdyu.js +2 -0
- package/dist/cli/{gen-Ccn_p90L.js → gen-C2osRcr5.js} +283 -87
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +4 -4
- package/dist/cli/{init-ClnxRYBF.js → init-Saf5-R9T.js} +2 -2
- package/dist/cli/{introspect-DxqfkVIv.js → introspect--H7oGmcd.js} +2 -2
- package/dist/cli/{openapi-8WHjxiTJ.js → openapi-Cp5Fyta-.js} +1 -1
- package/dist/cli/read-sets-BfMQcKy8.js +289 -0
- package/dist/cli/{run-CP20LKk_.js → run-BKR2W_79.js} +16 -12
- package/dist/cli/{seed-5J6eu_Xg.js → seed-CUlqWh-8.js} +1 -1
- package/dist/cli/sql-DzPbfngx.js +348 -0
- package/dist/cli/{version-5mW_8sY1.js → version-BDJuO0UR.js} +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +3 -10
- package/dist/clone-BfgmLU90.js +21 -0
- package/dist/{compiler-DB3aSFOA.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
- package/dist/config/index.d.ts +4 -4
- package/dist/config/index.js +4 -4
- package/dist/{config-CbvFmGD8.js → config-DreERlKo.js} +1 -1
- package/dist/{config-C1CYcm6o.d.ts → config-T_ejwyd3.d.ts} +176 -11
- package/dist/{define-CRS2MRV3.d.ts → define-Bp_BZa5h.d.ts} +11 -7
- package/dist/{define-Bh0AqTik.js → define-cNKzqwL_.js} +202 -16
- package/dist/edge/index.d.ts +16 -5
- package/dist/edge/index.js +10 -7
- package/dist/{entitlements-Dm-FHpNH.d.ts → entitlements-DUxU4oHe.d.ts} +1 -1
- package/dist/env/index.d.ts +2 -2
- package/dist/env/index.js +34 -1
- package/dist/{errors-L0xK41y_.js → errors-DtwXa6b8.js} +1 -0
- package/dist/events/index.d.ts +3 -2
- package/dist/events/index.js +65 -12
- package/dist/events-aIO7vsIk.d.ts +230 -0
- package/dist/{result-CqEsbgYs.d.ts → executor-BunPOO-k.d.ts} +200 -1
- package/dist/{executor-CZ7ImRiD.d.ts → executor-Cghdstwu.d.ts} +1 -2
- package/dist/{executor-CVt6dD0B.js → executor-XycESQPH.js} +3 -3
- package/dist/hono/index.d.ts +17 -6
- package/dist/hono/index.js +40 -5
- package/dist/impersonation-VfaGc4Q_.js +41 -0
- package/dist/{index-BBdvo-5d.d.ts → index-BGdgBPdf.d.ts} +49 -6
- package/dist/{index-BhHEC04r.d.ts → index-C7f8cOBM.d.ts} +2 -2
- package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
- package/dist/{index-D5IfUIDh.d.ts → index-DOESKG27.d.ts} +33 -8
- package/dist/{index-DFmOpBGC.d.ts → index-DgILJRXj.d.ts} +35 -9
- package/dist/{index-RlLXd8dL.d.ts → index-DmXSxbLi.d.ts} +4 -4
- package/dist/{index-Cf-D2jk1.d.ts → index-Dxn2a5cw.d.ts} +2 -2
- package/dist/{index-528Ugmyp.d.ts → index-SaTsEfGP.d.ts} +76 -8
- package/dist/{index-BAy4tsAP.d.ts → index-fag8VJZ2.d.ts} +3 -4
- package/dist/index.d.ts +30 -13
- package/dist/index.js +10 -9
- package/dist/jobs/index.d.ts +147 -101
- package/dist/jobs/index.js +744 -237
- package/dist/{json-schema-DP6V7cbr.js → json-schema-m1fiwKgN.js} +22 -1
- package/dist/kit-events-CTFDfSwb.js +60 -0
- package/dist/kit-transport-B82k1djG.d.ts +33 -0
- package/dist/kit-transport-DJlHQUBU.js +55 -0
- package/dist/{config-BpxDfnbg.js → kits-CGLLrNPd.js} +37 -9
- package/dist/list/index.d.ts +1 -1
- package/dist/{live-BHakSWWo.d.ts → live-D9W2M5aO.d.ts} +6 -5
- package/dist/mcp/index.d.ts +25 -8
- package/dist/mcp/index.js +23 -14
- package/dist/{mfa-C7MNQ1Ob.d.ts → mfa-CusDgPaD.d.ts} +5 -1
- package/dist/next/index.d.ts +31 -10
- package/dist/next/index.js +136 -27
- package/dist/notifications/index.d.ts +162 -0
- package/dist/notifications/index.js +264 -0
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +2 -2
- package/dist/orgs/index.d.ts +132 -0
- package/dist/orgs/index.js +245 -0
- package/dist/orpc/index.d.ts +28 -8
- package/dist/orpc/index.js +16 -3
- package/dist/otel/index.d.ts +21 -2
- package/dist/otel/index.js +50 -9
- package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
- package/dist/permdock-sql-DgOfeixi.js +51 -0
- package/dist/plugin-DwARMuQp.js +59 -0
- package/dist/{plugin-bNhvJwRh.d.ts → plugin-o144f322.d.ts} +17 -5
- package/dist/plugins/actor/index.d.ts +5 -2
- package/dist/plugins/actor/index.js +22 -8
- package/dist/plugins/rules/index.d.ts +2 -2
- package/dist/plugins/rules/index.js +15 -10
- package/dist/plugins/soft-delete/index.d.ts +3 -3
- package/dist/plugins/soft-delete/index.js +14 -5
- package/dist/plugins/tenant/index.d.ts +2 -2
- package/dist/plugins/tenant/index.js +38 -20
- package/dist/plugins/timestamps/index.d.ts +1 -1
- package/dist/plugins/timestamps/index.js +4 -3
- package/dist/plugins/validation/index.d.ts +2 -2
- package/dist/plugins/validation/index.js +26 -6
- package/dist/{pool-DFwEQwmN.d.ts → pool-C9voM4Kw.d.ts} +17 -6
- package/dist/postgres/index.d.ts +5 -5
- package/dist/postgres/index.js +20 -11
- package/dist/{postgrest-Bc-0Xw62.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
- package/dist/{problem-BihjPR0t.js → problem-BW1KhzSG.js} +2 -1
- package/dist/{problem-U8UEKccv.d.ts → problem-Blxe8S31.d.ts} +1 -1
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.js +3 -3
- package/dist/{query-BMMSWbI7.js → query-CCbo44lG.js} +2 -2
- package/dist/queue-BYUCjr59.d.ts +252 -0
- package/dist/react/index.d.ts +8 -7
- package/dist/react/index.js +4 -3
- package/dist/react/server.d.ts +14 -3
- package/dist/react/server.js +10 -2
- package/dist/react/session.d.ts +7 -1
- package/dist/react/session.js +9 -1
- package/dist/{react-CQHMaESR.js → react-C_s7kiNz.js} +103 -11
- package/dist/{read-set-FWK8qQ58.js → read-set-DQFt1N_Y.js} +22 -1
- package/dist/realtime/index.d.ts +3 -3
- package/dist/realtime/index.js +5 -4
- package/dist/{refresh-BwYkyNOQ.d.ts → refresh-BTrQ_ZTp.d.ts} +1 -1
- package/dist/{resolve-BAqQcwMW.d.ts → resolve-C15TJq77.d.ts} +11 -5
- package/dist/{resource-My_y-Syh.js → resource-CRxxwkQq.js} +22 -7
- package/dist/{resource-BJcaIfxi.d.ts → resource-D8iqWMr-.d.ts} +5 -5
- package/dist/respond-D2OQl62-.d.ts +371 -0
- package/dist/{result-Bj6yt33D.js → result-BKiliPY7.js} +1 -1
- package/dist/server/index.d.ts +14 -12
- package/dist/server/index.js +11 -17
- package/dist/{server-BA75B0mT.js → server-Csx2sRjg.js} +251 -34
- package/dist/{shared-DnoCdMDr.js → shared-D1dRUrAg.js} +16 -2
- package/dist/signers-Cc6r98SW.d.ts +162 -0
- package/dist/{simplify-Cqvfr9dj.js → simplify-_0oUKqCd.js} +4 -115
- package/dist/sql/index.d.ts +247 -10
- package/dist/sql/index.js +8590 -779
- package/dist/{sql-B34HU2DI.js → sql-Coh6n4cC.js} +9 -2
- package/dist/ssr/index.d.ts +4 -4
- package/dist/ssr/index.js +1 -2
- package/dist/{standard-BRyBGTtp.js → standard-D7r6dMUu.js} +6 -3
- package/dist/{standard-BsaCYQJc.d.ts → standard-J4YgMOLm.d.ts} +1 -1
- package/dist/{stats-C_YxA2r1.js → stats-Bqob3WqT.js} +4 -4
- package/dist/storage/index.d.ts +4 -4
- package/dist/storage/index.js +155 -26
- package/dist/support-DT-OhSxD.d.ts +88 -0
- package/dist/support-Dk6vdmEw.js +291 -0
- package/dist/support-view-Da5peKFg.d.ts +17 -0
- package/dist/support-view-g4YLBeqX.js +18 -0
- package/dist/{permdock-sql-C4KFzLc9.js → template-TxrGI5jR.js} +2 -31
- package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
- package/dist/{temporal-required-CBNHT6ni.js → temporal-required-CAt4Dc9Z.js} +2 -2
- package/dist/testing/index.d.ts +100 -10
- package/dist/testing/index.js +336 -8
- package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
- package/dist/user-change-CHFEUro1.js +49 -0
- package/dist/{webhooks-Bh_Jf_-l.js → verify-Ce49ETPz.js} +5 -5
- package/dist/{version-Bmf7_FzM.js → version-DM_Roffb.js} +1 -1
- package/dist/{view-B64o81wp.d.ts → view-BEf0diC5.d.ts} +8 -3
- package/dist/{mfa-byfjruR9.js → view-Bq64ki8-.js} +95 -38
- package/dist/webhooks/index.d.ts +135 -4
- package/dist/webhooks/index.js +588 -2
- package/dist/wire-D2dT86vi.js +35 -0
- package/package.json +16 -8
- package/schemas/config-v1.json +131 -1
- package/schemas/doctor-report-v1.json +10 -0
- package/skills/better-supabase/SKILL.md +9 -6
- package/skills/better-supabase/references/plugins.md +6 -3
- package/skills/better-supabase/references/troubleshooting.md +1 -0
- package/skills/better-supabase-api/SKILL.md +9 -2
- package/skills/better-supabase-api/references/adapters.md +11 -8
- package/skills/better-supabase-auth/SKILL.md +3 -0
- package/skills/better-supabase-auth/references/permdock.md +56 -11
- package/dist/cli/gen-D5cLCULx.js +0 -2
- package/dist/cli/sql-D4VbqmXi.js +0 -199
- package/dist/events-B21UOhvP.d.ts +0 -84
- package/dist/executor-B5IoUxLE.d.ts +0 -195
- package/dist/invalidate-CgxmRamI.js +0 -24
- package/dist/permdock-sql-DImJULY-.d.ts +0 -17
- package/dist/plugin-BqR6wKMB.js +0 -23
- package/dist/respond-DgIbdrt8.d.ts +0 -194
- package/dist/view-BrJI2LKp.js +0 -45
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as
|
|
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,
|
|
591
|
+
export { invalidRequest as a, escapeLike as i, simplifyOrFalse as n, defineSchema as o, builderFor as r, tableMeta as s, simplify as t };
|
package/dist/sql/index.d.ts
CHANGED
|
@@ -1,8 +1,154 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { B as ReadSet } from "../define-
|
|
3
|
-
import { b as ResolvedConfig } from "../config-
|
|
4
|
-
import {
|
|
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-T_ejwyd3.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
|
-
/**
|
|
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,8 @@ 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
|
+
/** `config.kits`: modes, names and permission keys per module. */
|
|
236
|
+
readonly kits?: KitsConfig;
|
|
64
237
|
}
|
|
65
238
|
/** One PermDock membership source, from the manifest's `memberships`. */
|
|
66
239
|
interface KitMembershipSource {
|
|
@@ -80,6 +253,8 @@ interface KitPermdock {
|
|
|
80
253
|
readonly schema: string;
|
|
81
254
|
/** The PermDock scope tenants map to, e.g. `organization`. */
|
|
82
255
|
readonly scope: string;
|
|
256
|
+
/** The scope's id type, from the manifest's `rls.scopes[].type`. */
|
|
257
|
+
readonly idType: KitIdType;
|
|
83
258
|
readonly memberships: readonly KitMembershipSource[];
|
|
84
259
|
}
|
|
85
260
|
/** An embedding column `db.$search` can query. */
|
|
@@ -91,10 +266,10 @@ interface VectorSearchTable {
|
|
|
91
266
|
}
|
|
92
267
|
/** The table holding each tenant's Stripe customer id. */
|
|
93
268
|
interface EntitlementsSource {
|
|
94
|
-
/** `table` or `schema.table
|
|
95
|
-
readonly table
|
|
269
|
+
/** `table` or `schema.table`; unset uses the `organizations` module's. */
|
|
270
|
+
readonly table?: string;
|
|
96
271
|
/** Column with the Stripe customer id (`cus_...`). */
|
|
97
|
-
readonly column
|
|
272
|
+
readonly column?: string;
|
|
98
273
|
/** Column with the tenant id. */
|
|
99
274
|
readonly key: string;
|
|
100
275
|
}
|
|
@@ -114,13 +289,75 @@ interface JsonSchemaCheck {
|
|
|
114
289
|
}
|
|
115
290
|
/** Whether an installed file matches, ignoring the version stamped in its header. */
|
|
116
291
|
export declare function sameKitFile(current: string | undefined, expected: string): boolean;
|
|
117
|
-
/** The
|
|
292
|
+
/** The installed version of a kit file, from its `@bs-kit` line. */
|
|
293
|
+
export declare function kitFileVersion(contents: string): {
|
|
294
|
+
readonly module: string;
|
|
295
|
+
readonly version: number;
|
|
296
|
+
} | undefined;
|
|
297
|
+
/** A module's SQL for `layout`, without header; `undefined` in custom mode. */
|
|
298
|
+
export declare function moduleBody(name: string, layout?: KitLayout): string | undefined;
|
|
299
|
+
/**
|
|
300
|
+
* The files `sql add` writes for these modules. Modules in `custom` mode
|
|
301
|
+
* write nothing: the app implements their contract. A schema module's rows,
|
|
302
|
+
* role settings and other statements a schema diff can't capture go to a
|
|
303
|
+
* second file in `better-supabase-data/` (`kind: 'data'`), which
|
|
304
|
+
* `sql data` writes into a migration.
|
|
305
|
+
*/
|
|
118
306
|
export declare function renderKit(names: readonly string[], layout?: KitLayout): KitFile[];
|
|
307
|
+
/** An installed module, from its file's `@bs-kit` line or `kit_modules`. */
|
|
308
|
+
interface InstalledKitModule {
|
|
309
|
+
readonly module: string;
|
|
310
|
+
readonly version: number;
|
|
311
|
+
}
|
|
312
|
+
/** What `sql upgrade` runs for one module behind the current version. */
|
|
313
|
+
interface KitUpgradePlan {
|
|
314
|
+
readonly module: string;
|
|
315
|
+
readonly from: number;
|
|
316
|
+
readonly to: number;
|
|
317
|
+
readonly steps: readonly {
|
|
318
|
+
readonly from: number;
|
|
319
|
+
readonly description: string;
|
|
320
|
+
readonly sql: string;
|
|
321
|
+
}[];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* The upgrade steps for modules installed at an older version. A version
|
|
325
|
+
* without a step needs none: the module file upgrades in place. Modules in
|
|
326
|
+
* custom mode belong to the app and are skipped.
|
|
327
|
+
*/
|
|
328
|
+
export declare function upgradePlan(installed: readonly InstalledKitModule[], layout?: KitLayout, modules?: Readonly<Record<string, SqlModule>>): KitUpgradePlan[];
|
|
329
|
+
/** Every deprecated or removed kit symbol, with its module. */
|
|
330
|
+
export declare function kitDeprecations(modules?: Readonly<Record<string, SqlModule>>): readonly (KitDeprecation & {
|
|
331
|
+
readonly module: string;
|
|
332
|
+
})[];
|
|
333
|
+
/** The contract functions of the modules in `custom` mode, for doctor. */
|
|
334
|
+
export declare function customContracts(names: readonly string[], layout?: KitLayout): {
|
|
335
|
+
readonly module: string;
|
|
336
|
+
readonly schema: string;
|
|
337
|
+
readonly idType: KitIdType;
|
|
338
|
+
readonly functions: readonly KitContractFunction[];
|
|
339
|
+
}[];
|
|
119
340
|
//#endregion
|
|
120
341
|
//#region src/sql/layout.d.ts
|
|
121
342
|
/** Where and how `sql add` writes kit files for this config. */
|
|
122
343
|
export declare function kitLayout(config: ResolvedConfig, testsDir?: string, readSets?: KitLayout["readSets"], permdock?: KitPermdock): KitLayout;
|
|
123
344
|
//#endregion
|
|
345
|
+
//#region src/sql/migration-options.d.ts
|
|
346
|
+
/** A migration-only option a config sets. */
|
|
347
|
+
interface MigrationOptionUse {
|
|
348
|
+
readonly module: string;
|
|
349
|
+
readonly option: string;
|
|
350
|
+
readonly value: unknown;
|
|
351
|
+
readonly adopted: boolean;
|
|
352
|
+
/** `kits.<module>.options.<option> ... It <effect>.` */
|
|
353
|
+
readonly message: string;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* The migration-only options `kits` sets to a value other than the managed
|
|
357
|
+
* default. They are accepted in `adopt` mode only; doctor warns about each.
|
|
358
|
+
*/
|
|
359
|
+
export declare function migrationOptionUses(kits?: KitsConfig): MigrationOptionUse[];
|
|
360
|
+
//#endregion
|
|
124
361
|
//#region src/sql/read-sets.d.ts
|
|
125
362
|
/** A read set compiled to the SQL of its function. */
|
|
126
363
|
interface CompiledReadSet {
|
|
@@ -136,4 +373,4 @@ export declare function compileReadSet(set: ReadSet): Promise<CompiledReadSet>;
|
|
|
136
373
|
/** Compiles every set, sorted by name. Throws on a duplicate name. */
|
|
137
374
|
export declare function compileReadSets(sets: readonly ReadSet[]): Promise<CompiledReadSet[]>;
|
|
138
375
|
//#endregion
|
|
139
|
-
export { type CompiledReadSet, type KitFile, type KitLayout, type KitPermdock, type SqlModule, permdockKeys };
|
|
376
|
+
export { type CompiledReadSet, type InstalledKitModule, type KitContext, type KitContractFunction, type KitDeprecation, type KitFile, type KitIdType, type KitLayout, type KitNames, type KitPermdock, type KitTableSpec, type KitUpgrade, type KitUpgradePlan, type MigrationOptionUse, PERMDOCK_SCHEMA, type PermdockCatalog, type PermdockKeyStatus, type SqlModule, permdockKeyStatus, permdockKeys };
|