@rebasepro/studio 0.35.0 → 0.36.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 +1 -1
- package/dist/{ApiExplorer-C61w8gCc.js → ApiExplorer-BVQHAjHB.js} +3 -2
- package/dist/{ApiExplorer-C61w8gCc.js.map → ApiExplorer-BVQHAjHB.js.map} +1 -1
- package/dist/{useRunAsUsers-CF7tkGzj.js → AuthSimulationSelector-XogpkeXC.js} +4 -68
- package/dist/AuthSimulationSelector-XogpkeXC.js.map +1 -0
- package/dist/{CronJobsView-DUuyzkJK.js → CronJobsView-DyX9MINh.js} +2 -2
- package/dist/{CronJobsView-DUuyzkJK.js.map → CronJobsView-DyX9MINh.js.map} +1 -1
- package/dist/DatabaseView-Bi0NZS90.js +1897 -0
- package/dist/DatabaseView-Bi0NZS90.js.map +1 -0
- package/dist/{JSEditor-Bi2Aol-Y.js → JSEditor-B4Lazm-z.js} +4 -3
- package/dist/{JSEditor-Bi2Aol-Y.js.map → JSEditor-B4Lazm-z.js.map} +1 -1
- package/dist/RLSEditor-CcHkWFNg.js +973 -0
- package/dist/RLSEditor-CcHkWFNg.js.map +1 -0
- package/dist/{SQLEditor-DRo5kW1h.js → SQLEditorRoute-f5j_ZKdj.js} +1472 -320
- package/dist/SQLEditorRoute-f5j_ZKdj.js.map +1 -0
- package/dist/SchemaDiagramView-CckQobIZ.js +98 -0
- package/dist/SchemaDiagramView-CckQobIZ.js.map +1 -0
- package/dist/{StorageView-D0D8z4lI.js → StorageView-B7QHjEGY.js} +2 -2
- package/dist/{StorageView-D0D8z4lI.js.map → StorageView-B7QHjEGY.js.map} +1 -1
- package/dist/TableEditorView-BRZNvD6U.js +3615 -0
- package/dist/TableEditorView-BRZNvD6U.js.map +1 -0
- package/dist/TablePolicies-C1-tbC8x.js +1740 -0
- package/dist/TablePolicies-C1-tbC8x.js.map +1 -0
- package/dist/{SchemaVisualizer-Dy4kWKT5.js → TablesDiagram-RTJfwVEN.js} +651 -489
- package/dist/TablesDiagram-RTJfwVEN.js.map +1 -0
- package/dist/{UsersAndRolesView-CKw4SJPj.js → UsersAndRolesView-Cx6xtMVH.js} +2 -2
- package/dist/{UsersAndRolesView-CKw4SJPj.js.map → UsersAndRolesView-Cx6xtMVH.js.map} +1 -1
- package/dist/{WebhooksView-CFPY-N9h.js → WebhooksView-Bn9KB7xG.js} +2 -2
- package/dist/{WebhooksView-CFPY-N9h.js.map → WebhooksView-Bn9KB7xG.js.map} +1 -1
- package/dist/{adminFetch-BfOnfRgU.js → adminFetch-C7Ra8rpP.js} +26 -1
- package/dist/{adminFetch-BfOnfRgU.js.map → adminFetch-C7Ra8rpP.js.map} +1 -1
- package/dist/components/Database/ActivitySection.d.ts +9 -0
- package/dist/components/Database/AdvisorsSection.d.ts +17 -0
- package/dist/components/Database/DatabaseView.d.ts +13 -0
- package/dist/components/Database/ExtensionsSection.d.ts +2 -0
- package/dist/components/Database/FunctionsSection.d.ts +2 -0
- package/dist/components/Database/QueriesSection.d.ts +3 -0
- package/dist/components/Database/TriggersSection.d.ts +2 -0
- package/dist/components/Database/TypesSection.d.ts +2 -0
- package/dist/components/Database/format.d.ts +6 -0
- package/dist/components/Database/links.d.ts +11 -0
- package/dist/components/Database/shared.d.ts +35 -0
- package/dist/components/Database/source.d.ts +12 -0
- package/dist/components/Database/useCatalogList.d.ts +13 -0
- package/dist/components/RLSEditor/RLSEditor.d.ts +2 -0
- package/dist/components/RLSEditor/TablePolicies.d.ts +54 -0
- package/dist/components/SQLEditor/ExplainVisualizer.d.ts +8 -20
- package/dist/components/SQLEditor/ResultChart.d.ts +18 -0
- package/dist/components/SQLEditor/SQLEditor.d.ts +13 -1
- package/dist/components/SQLEditor/SQLEditorRoute.d.ts +13 -0
- package/dist/components/SQLEditor/SQLEditorSidebar.d.ts +7 -1
- package/dist/components/SQLEditor/SqlParamsPanel.d.ts +16 -0
- package/dist/components/SQLEditor/useSqlSnippets.d.ts +47 -0
- package/dist/components/SchemaVisualizer/SchemaDiagramView.d.ts +12 -0
- package/dist/components/SchemaVisualizer/TablesDiagram.d.ts +23 -0
- package/dist/components/SchemaVisualizer/useSchemaGraph.d.ts +32 -1
- package/dist/components/TableEditor/CreateTableDialog.d.ts +8 -0
- package/dist/components/TableEditor/DdlConfirm.d.ts +23 -0
- package/dist/components/TableEditor/SqlBlock.d.ts +7 -0
- package/dist/components/TableEditor/TableDdlSheet.d.ts +9 -0
- package/dist/components/TableEditor/TableEditorView.d.ts +7 -0
- package/dist/components/TableEditor/tableModel.d.ts +210 -0
- package/dist/components/TableEditor/tabs/DataTab.d.ts +12 -0
- package/dist/components/TableEditor/tabs/PoliciesTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/RelationsTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/SettingsTab.d.ts +11 -0
- package/dist/components/TableEditor/tabs/StatsTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/StructureTab.d.ts +12 -0
- package/dist/index.es.js +29 -15
- package/dist/index.es.js.map +1 -1
- package/dist/{sql_utils-CYcgpgam.js → sql_utils-DkMYltfq.js} +27 -3
- package/dist/sql_utils-DkMYltfq.js.map +1 -0
- package/dist/useRunAsUsers-GPFCxcBC.js +69 -0
- package/dist/useRunAsUsers-GPFCxcBC.js.map +1 -0
- package/dist/utils/adminFetch.d.ts +1 -0
- package/dist/utils/csv_parse.d.ts +11 -0
- package/dist/utils/explain_plan.d.ts +70 -0
- package/dist/utils/sql_params.d.ts +51 -0
- package/dist/utils/sql_utils.d.ts +16 -0
- package/package.json +11 -9
- package/dist/RLSEditor-CTG3jLE7.js +0 -2572
- package/dist/RLSEditor-CTG3jLE7.js.map +0 -1
- package/dist/SQLEditor-DRo5kW1h.js.map +0 -1
- package/dist/SchemaVisualizer-Dy4kWKT5.js.map +0 -1
- package/dist/TableEditorView-BKhSBG-K.js +0 -1694
- package/dist/TableEditorView-BKhSBG-K.js.map +0 -1
- package/dist/components/SchemaVisualizer/SchemaVisualizer.d.ts +0 -3
- package/dist/policy-presets-CJKzAvQp.js +0 -167
- package/dist/policy-presets-CJKzAvQp.js.map +0 -1
- package/dist/sql_utils-CYcgpgam.js.map +0 -1
- package/dist/useRunAsUsers-CF7tkGzj.js.map +0 -1
|
@@ -0,0 +1,973 @@
|
|
|
1
|
+
import { a as asStringArray, i as asString, n as asNullableString, o as isRecord, s as useAdminFetch, t as asBoolean } from "./adminFetch-C7Ra8rpP.js";
|
|
2
|
+
import { i as servedJunctionsOf, n as classifyTableClient, o as readPolicyRoles, r as mapsTable, t as TablePolicies } from "./TablePolicies-C1-tbC8x.js";
|
|
3
|
+
import { ErrorView, useRebaseContext, useSnackbarController, useTableDescriptors, useTranslation } from "@rebasepro/app";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { Alert, AlertTriangleIcon, BooleanSwitchWithLabel, Button, Card, Chip, CircularProgress, DatabaseIcon, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, LockIcon, PlusIcon, RefreshCwIcon, ResizablePanels, Select, SelectItem, ShieldIcon, Tab, Table, TableBody, TableCell, TableHeader, TableRow, Tabs, TextField, Tooltip, Trash2Icon, Typography, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useSearchParams } from "react-router";
|
|
8
|
+
import { JUNCTION_TABLES_SQL, REBASE_INTERNAL_SCHEMAS } from "@rebasepro/common";
|
|
9
|
+
//#region src/components/RLSEditor/DirectRlsPoliciesPanel.tsx
|
|
10
|
+
var COMMANDS = [
|
|
11
|
+
"ALL",
|
|
12
|
+
"SELECT",
|
|
13
|
+
"INSERT",
|
|
14
|
+
"UPDATE",
|
|
15
|
+
"DELETE"
|
|
16
|
+
];
|
|
17
|
+
var POLICY_TEMPLATES = [
|
|
18
|
+
{
|
|
19
|
+
labelKey: "studio_rls_direct_tpl_public_read",
|
|
20
|
+
name: "public_read",
|
|
21
|
+
command: "SELECT",
|
|
22
|
+
using: "true",
|
|
23
|
+
withCheck: ""
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
labelKey: "studio_rls_direct_tpl_authenticated",
|
|
27
|
+
name: "authenticated_all",
|
|
28
|
+
command: "ALL",
|
|
29
|
+
using: "rebase.uid() IS NOT NULL",
|
|
30
|
+
withCheck: "rebase.uid() IS NOT NULL"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
labelKey: "studio_rls_direct_tpl_owner",
|
|
34
|
+
name: "owner_all",
|
|
35
|
+
command: "ALL",
|
|
36
|
+
using: "user_id = rebase.uid()",
|
|
37
|
+
withCheck: "user_id = rebase.uid()"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
labelKey: "studio_rls_direct_tpl_admin",
|
|
41
|
+
name: "admin_all",
|
|
42
|
+
command: "ALL",
|
|
43
|
+
using: "'admin' = ANY(string_to_array(rebase.roles(), ','))",
|
|
44
|
+
withCheck: "'admin' = ANY(string_to_array(rebase.roles(), ','))"
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
function parsePolicy(raw) {
|
|
48
|
+
if (!isRecord(raw) || typeof raw.name !== "string") return null;
|
|
49
|
+
return {
|
|
50
|
+
name: raw.name,
|
|
51
|
+
command: asString(raw.operation ?? raw.command, "ALL"),
|
|
52
|
+
roles: asStringArray(raw.roles),
|
|
53
|
+
using: asNullableString(raw.using),
|
|
54
|
+
withCheck: asNullableString(raw.withCheck)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function parseTable(raw) {
|
|
58
|
+
if (!isRecord(raw) || typeof raw.name !== "string") return null;
|
|
59
|
+
const policies = Array.isArray(raw.policies) ? raw.policies.map(parsePolicy).filter((p) => p !== null) : [];
|
|
60
|
+
return {
|
|
61
|
+
schema: asString(raw.schema, "public"),
|
|
62
|
+
name: raw.name,
|
|
63
|
+
rlsEnabled: asBoolean(raw.rlsEnabled, false),
|
|
64
|
+
policies
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Direct PostgreSQL RLS policy manager over `/api/admin/db/tables`.
|
|
69
|
+
* Works with zero `backend/schema` source files — every change applies live
|
|
70
|
+
* to Postgres and reloads the data API immediately.
|
|
71
|
+
*/
|
|
72
|
+
function DirectRlsPoliciesPanel() {
|
|
73
|
+
const { requestJson } = useAdminFetch();
|
|
74
|
+
const snackbar = useSnackbarController();
|
|
75
|
+
const { t } = useTranslation();
|
|
76
|
+
const [tables, setTables] = useState([]);
|
|
77
|
+
const [loading, setLoading] = useState(true);
|
|
78
|
+
const [error, setError] = useState(null);
|
|
79
|
+
const [selectedName, setSelectedName] = useState(null);
|
|
80
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
81
|
+
const [policyName, setPolicyName] = useState("");
|
|
82
|
+
const [command, setCommand] = useState("ALL");
|
|
83
|
+
const [usingExpr, setUsingExpr] = useState("rebase.uid() IS NOT NULL");
|
|
84
|
+
const [withCheckExpr, setWithCheckExpr] = useState("");
|
|
85
|
+
const [saving, setSaving] = useState(false);
|
|
86
|
+
const load = useCallback(async () => {
|
|
87
|
+
setLoading(true);
|
|
88
|
+
setError(null);
|
|
89
|
+
try {
|
|
90
|
+
const raw = await requestJson("/admin/db/tables");
|
|
91
|
+
const list = isRecord(raw) && Array.isArray(raw.tables) ? raw.tables.map(parseTable).filter((t) => t !== null) : [];
|
|
92
|
+
setTables(list);
|
|
93
|
+
setSelectedName((prev) => prev && list.some((t) => t.name === prev) ? prev : list[0]?.name ?? null);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
setError(err instanceof Error ? err.message : t("studio_rls_direct_load_failed"));
|
|
96
|
+
} finally {
|
|
97
|
+
setLoading(false);
|
|
98
|
+
}
|
|
99
|
+
}, [requestJson, t]);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
load();
|
|
102
|
+
}, [load]);
|
|
103
|
+
const selected = useMemo(() => tables.find((t) => t.name === selectedName) ?? null, [tables, selectedName]);
|
|
104
|
+
const handleToggleRls = async (enabled) => {
|
|
105
|
+
if (!selected) return;
|
|
106
|
+
try {
|
|
107
|
+
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}`, {
|
|
108
|
+
method: "PATCH",
|
|
109
|
+
body: { rlsEnabled: enabled }
|
|
110
|
+
});
|
|
111
|
+
snackbar.open({
|
|
112
|
+
type: "success",
|
|
113
|
+
message: t(enabled ? "studio_tables_rls_enabled_on" : "studio_tables_rls_disabled_on", { name: selected.name })
|
|
114
|
+
});
|
|
115
|
+
await load();
|
|
116
|
+
} catch (err) {
|
|
117
|
+
snackbar.open({
|
|
118
|
+
type: "error",
|
|
119
|
+
message: err instanceof Error ? err.message : t("studio_rls_direct_update_failed")
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const handleCreatePolicy = async () => {
|
|
124
|
+
if (!selected || !policyName.trim()) return;
|
|
125
|
+
setSaving(true);
|
|
126
|
+
try {
|
|
127
|
+
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}/policies`, {
|
|
128
|
+
method: "POST",
|
|
129
|
+
body: {
|
|
130
|
+
name: policyName.trim(),
|
|
131
|
+
operation: command,
|
|
132
|
+
...usingExpr.trim() ? { using: usingExpr.trim() } : {},
|
|
133
|
+
...withCheckExpr.trim() ? { withCheck: withCheckExpr.trim() } : {}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
snackbar.open({
|
|
137
|
+
type: "success",
|
|
138
|
+
message: t("studio_rls_direct_policy_created", { name: policyName.trim() })
|
|
139
|
+
});
|
|
140
|
+
setDialogOpen(false);
|
|
141
|
+
setPolicyName("");
|
|
142
|
+
await load();
|
|
143
|
+
} catch (err) {
|
|
144
|
+
snackbar.open({
|
|
145
|
+
type: "error",
|
|
146
|
+
message: err instanceof Error ? err.message : t("studio_rls_direct_policy_create_failed")
|
|
147
|
+
});
|
|
148
|
+
} finally {
|
|
149
|
+
setSaving(false);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const handleDropPolicy = async (name) => {
|
|
153
|
+
if (!selected) return;
|
|
154
|
+
try {
|
|
155
|
+
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}/policies/${encodeURIComponent(name)}`, { method: "DELETE" });
|
|
156
|
+
snackbar.open({
|
|
157
|
+
type: "success",
|
|
158
|
+
message: t("studio_rls_direct_policy_dropped", { name })
|
|
159
|
+
});
|
|
160
|
+
await load();
|
|
161
|
+
} catch (err) {
|
|
162
|
+
snackbar.open({
|
|
163
|
+
type: "error",
|
|
164
|
+
message: err instanceof Error ? err.message : t("studio_rls_direct_policy_drop_failed")
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
169
|
+
className: "flex h-full w-full overflow-hidden bg-surface-card",
|
|
170
|
+
children: [
|
|
171
|
+
/* @__PURE__ */ jsxs("aside", {
|
|
172
|
+
className: cls("w-64 shrink-0 border-r bg-surface-card flex flex-col", defaultBorderMixin),
|
|
173
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
174
|
+
className: cls("h-[42px] px-3 border-b bg-surface-sheet flex items-center justify-between shrink-0", defaultBorderMixin),
|
|
175
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
176
|
+
variant: "caption",
|
|
177
|
+
className: "font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark",
|
|
178
|
+
children: t("studio_rls_direct_tables_heading")
|
|
179
|
+
}), /* @__PURE__ */ jsx(Tooltip, {
|
|
180
|
+
title: t("refresh"),
|
|
181
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
182
|
+
size: "small",
|
|
183
|
+
"aria-label": t("studio_rls_direct_refresh_aria"),
|
|
184
|
+
onClick: () => void load(),
|
|
185
|
+
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
186
|
+
})
|
|
187
|
+
})]
|
|
188
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
189
|
+
className: "flex-1 overflow-y-auto p-2 flex flex-col gap-1",
|
|
190
|
+
children: loading ? /* @__PURE__ */ jsx("div", {
|
|
191
|
+
className: "flex justify-center py-8",
|
|
192
|
+
children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
|
|
193
|
+
}) : tables.map((table) => /* @__PURE__ */ jsxs("button", {
|
|
194
|
+
type: "button",
|
|
195
|
+
onClick: () => setSelectedName(table.name),
|
|
196
|
+
className: cls("w-full text-left px-2.5 h-8 rounded-lg flex items-center justify-between gap-2 text-[13px] transition-colors cursor-pointer", table.name === selectedName ? "bg-surface-active text-text-primary dark:text-text-primary-dark font-medium" : "text-text-secondary dark:text-text-secondary-dark hover:bg-surface-hover hover:text-text-primary dark:hover:text-text-primary-dark"),
|
|
197
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
198
|
+
className: "font-mono truncate",
|
|
199
|
+
children: table.name
|
|
200
|
+
}), /* @__PURE__ */ jsx(Chip, {
|
|
201
|
+
size: "small",
|
|
202
|
+
colorScheme: table.rlsEnabled ? "greenLight" : "grayLight",
|
|
203
|
+
children: table.policies.length
|
|
204
|
+
})]
|
|
205
|
+
}, table.name))
|
|
206
|
+
})]
|
|
207
|
+
}),
|
|
208
|
+
/* @__PURE__ */ jsxs("main", {
|
|
209
|
+
className: "flex-1 flex flex-col min-w-0 h-full overflow-hidden bg-surface-sheet",
|
|
210
|
+
children: [error && /* @__PURE__ */ jsx("div", {
|
|
211
|
+
className: "p-5 pb-0",
|
|
212
|
+
children: /* @__PURE__ */ jsx(Alert, {
|
|
213
|
+
color: "error",
|
|
214
|
+
children: error
|
|
215
|
+
})
|
|
216
|
+
}), !selected ? /* @__PURE__ */ jsx("div", {
|
|
217
|
+
className: "p-5",
|
|
218
|
+
children: /* @__PURE__ */ jsx(Card, {
|
|
219
|
+
className: "p-8 text-center",
|
|
220
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
221
|
+
variant: "body2",
|
|
222
|
+
color: "secondary",
|
|
223
|
+
children: t("studio_rls_direct_select_table")
|
|
224
|
+
})
|
|
225
|
+
})
|
|
226
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
227
|
+
className: cls("h-[42px] px-4 border-b bg-surface-sheet flex items-center justify-between gap-4 shrink-0", defaultBorderMixin),
|
|
228
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
229
|
+
className: "flex items-center gap-2.5 min-w-0",
|
|
230
|
+
children: [
|
|
231
|
+
/* @__PURE__ */ jsx(ShieldIcon, {
|
|
232
|
+
size: iconSize.small,
|
|
233
|
+
className: "text-text-secondary shrink-0"
|
|
234
|
+
}),
|
|
235
|
+
/* @__PURE__ */ jsxs(Typography, {
|
|
236
|
+
variant: "subtitle2",
|
|
237
|
+
className: "font-mono truncate",
|
|
238
|
+
children: [
|
|
239
|
+
selected.schema,
|
|
240
|
+
".",
|
|
241
|
+
selected.name
|
|
242
|
+
]
|
|
243
|
+
}),
|
|
244
|
+
/* @__PURE__ */ jsx(Chip, {
|
|
245
|
+
size: "smallest",
|
|
246
|
+
colorScheme: selected.rlsEnabled ? "greenLight" : "orangeLight",
|
|
247
|
+
children: selected.rlsEnabled ? t("studio_rls_enabled") : t("studio_rls_disabled")
|
|
248
|
+
})
|
|
249
|
+
]
|
|
250
|
+
}), /* @__PURE__ */ jsxs(Button, {
|
|
251
|
+
size: "small",
|
|
252
|
+
color: "primary",
|
|
253
|
+
variant: "filled",
|
|
254
|
+
onClick: () => setDialogOpen(true),
|
|
255
|
+
children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_new_policy")]
|
|
256
|
+
})]
|
|
257
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
258
|
+
className: "flex-1 overflow-auto p-5 flex flex-col gap-4",
|
|
259
|
+
children: [/* @__PURE__ */ jsx(Card, {
|
|
260
|
+
className: "p-4",
|
|
261
|
+
children: /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
|
|
262
|
+
label: t("studio_rls_direct_enabled_label"),
|
|
263
|
+
value: selected.rlsEnabled,
|
|
264
|
+
onValueChange: (v) => void handleToggleRls(v)
|
|
265
|
+
})
|
|
266
|
+
}), selected.policies.length === 0 ? /* @__PURE__ */ jsxs(Card, {
|
|
267
|
+
className: "p-8 text-center flex flex-col items-center gap-3",
|
|
268
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
269
|
+
variant: "body2",
|
|
270
|
+
color: "secondary",
|
|
271
|
+
children: t("studio_rls_direct_no_policies", { name: selected.name })
|
|
272
|
+
}), /* @__PURE__ */ jsxs(Button, {
|
|
273
|
+
size: "small",
|
|
274
|
+
color: "primary",
|
|
275
|
+
variant: "filled",
|
|
276
|
+
onClick: () => setDialogOpen(true),
|
|
277
|
+
children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_rls_direct_add_first_policy")]
|
|
278
|
+
})]
|
|
279
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
280
|
+
className: cls("overflow-x-auto rounded-lg border", defaultBorderMixin),
|
|
281
|
+
children: /* @__PURE__ */ jsxs(Table, {
|
|
282
|
+
className: "w-full",
|
|
283
|
+
children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
|
|
284
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
285
|
+
header: true,
|
|
286
|
+
children: t("studio_policy_name")
|
|
287
|
+
}),
|
|
288
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
289
|
+
header: true,
|
|
290
|
+
children: t("studio_rls_direct_command")
|
|
291
|
+
}),
|
|
292
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
293
|
+
header: true,
|
|
294
|
+
children: "USING"
|
|
295
|
+
}),
|
|
296
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
297
|
+
header: true,
|
|
298
|
+
children: "WITH CHECK"
|
|
299
|
+
}),
|
|
300
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
301
|
+
header: true,
|
|
302
|
+
className: "text-right",
|
|
303
|
+
children: t("actions")
|
|
304
|
+
})
|
|
305
|
+
] }), /* @__PURE__ */ jsx(TableBody, { children: selected.policies.map((p) => /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
306
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
307
|
+
className: "font-mono text-sm font-medium",
|
|
308
|
+
children: p.name
|
|
309
|
+
}),
|
|
310
|
+
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Chip, {
|
|
311
|
+
size: "small",
|
|
312
|
+
colorScheme: "blueLight",
|
|
313
|
+
children: p.command
|
|
314
|
+
}) }),
|
|
315
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
316
|
+
className: "font-mono text-xs text-text-secondary",
|
|
317
|
+
children: p.using ?? "—"
|
|
318
|
+
}),
|
|
319
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
320
|
+
className: "font-mono text-xs text-text-secondary",
|
|
321
|
+
children: p.withCheck ?? "—"
|
|
322
|
+
}),
|
|
323
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
324
|
+
className: "text-right",
|
|
325
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
326
|
+
size: "small",
|
|
327
|
+
"aria-label": t("studio_rls_direct_drop_policy_aria", { name: p.name }),
|
|
328
|
+
onClick: () => void handleDropPolicy(p.name),
|
|
329
|
+
children: /* @__PURE__ */ jsx(Trash2Icon, {
|
|
330
|
+
size: iconSize.small,
|
|
331
|
+
className: "text-red-500"
|
|
332
|
+
})
|
|
333
|
+
})
|
|
334
|
+
})
|
|
335
|
+
] }, p.name)) })]
|
|
336
|
+
})
|
|
337
|
+
})]
|
|
338
|
+
})] })]
|
|
339
|
+
}),
|
|
340
|
+
/* @__PURE__ */ jsxs(Dialog, {
|
|
341
|
+
open: dialogOpen,
|
|
342
|
+
onOpenChange: setDialogOpen,
|
|
343
|
+
maxWidth: "md",
|
|
344
|
+
fullWidth: true,
|
|
345
|
+
children: [
|
|
346
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: t("studio_rls_direct_new_policy_title", { name: selected?.name ?? "" }) }),
|
|
347
|
+
/* @__PURE__ */ jsxs(DialogContent, {
|
|
348
|
+
className: "flex flex-col gap-3",
|
|
349
|
+
children: [
|
|
350
|
+
/* @__PURE__ */ jsx("div", {
|
|
351
|
+
className: "flex items-center gap-1.5 flex-wrap",
|
|
352
|
+
children: POLICY_TEMPLATES.map((tpl) => /* @__PURE__ */ jsx(Chip, {
|
|
353
|
+
size: "small",
|
|
354
|
+
colorScheme: "grayLight",
|
|
355
|
+
onClick: () => {
|
|
356
|
+
setPolicyName(tpl.name);
|
|
357
|
+
setCommand(tpl.command);
|
|
358
|
+
setUsingExpr(tpl.using);
|
|
359
|
+
setWithCheckExpr(tpl.withCheck);
|
|
360
|
+
},
|
|
361
|
+
children: t(tpl.labelKey)
|
|
362
|
+
}, tpl.name))
|
|
363
|
+
}),
|
|
364
|
+
/* @__PURE__ */ jsx(TextField, {
|
|
365
|
+
label: t("studio_policy_name"),
|
|
366
|
+
value: policyName,
|
|
367
|
+
onChange: (e) => setPolicyName(e.target.value),
|
|
368
|
+
placeholder: "owner_all"
|
|
369
|
+
}),
|
|
370
|
+
/* @__PURE__ */ jsx(Select, {
|
|
371
|
+
label: t("studio_rls_direct_command"),
|
|
372
|
+
value: command,
|
|
373
|
+
onValueChange: (v) => setCommand(String(v)),
|
|
374
|
+
children: COMMANDS.map((cmd) => /* @__PURE__ */ jsx(SelectItem, {
|
|
375
|
+
value: cmd,
|
|
376
|
+
children: cmd
|
|
377
|
+
}, cmd))
|
|
378
|
+
}),
|
|
379
|
+
/* @__PURE__ */ jsx(TextField, {
|
|
380
|
+
label: t("studio_policy_using_expr"),
|
|
381
|
+
value: usingExpr,
|
|
382
|
+
onChange: (e) => setUsingExpr(e.target.value),
|
|
383
|
+
placeholder: "user_id = rebase.uid()"
|
|
384
|
+
}),
|
|
385
|
+
/* @__PURE__ */ jsx(TextField, {
|
|
386
|
+
label: t("studio_rls_direct_with_check_label"),
|
|
387
|
+
value: withCheckExpr,
|
|
388
|
+
onChange: (e) => setWithCheckExpr(e.target.value),
|
|
389
|
+
placeholder: "user_id = rebase.uid()"
|
|
390
|
+
})
|
|
391
|
+
]
|
|
392
|
+
}),
|
|
393
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
|
|
394
|
+
variant: "text",
|
|
395
|
+
onClick: () => setDialogOpen(false),
|
|
396
|
+
children: t("cancel")
|
|
397
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
398
|
+
variant: "filled",
|
|
399
|
+
disabled: saving || !policyName.trim(),
|
|
400
|
+
onClick: () => void handleCreatePolicy(),
|
|
401
|
+
children: saving ? t("saving") : t("studio_rls_create_policy")
|
|
402
|
+
})] })
|
|
403
|
+
]
|
|
404
|
+
})
|
|
405
|
+
]
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/components/RLSEditor/RLSEditor.tsx
|
|
410
|
+
/** The query parameter that names the selected table, `schema.table`, so another view can link straight to it. */
|
|
411
|
+
var RLS_TABLE_PARAM = "table";
|
|
412
|
+
function SidebarSection({ title, icon, expanded, onToggle, count, children }) {
|
|
413
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
414
|
+
className: "mb-2",
|
|
415
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
416
|
+
className: "flex items-center p-1.5 cursor-pointer hover:bg-surface-hover rounded transition-colors",
|
|
417
|
+
onClick: onToggle,
|
|
418
|
+
children: [
|
|
419
|
+
/* @__PURE__ */ jsx("svg", {
|
|
420
|
+
className: cls("w-3 h-3 mr-1.5 transition-transform text-text-disabled dark:text-text-disabled-dark", expanded ? "rotate-90" : ""),
|
|
421
|
+
fill: "currentColor",
|
|
422
|
+
viewBox: "0 0 20 20",
|
|
423
|
+
children: /* @__PURE__ */ jsx("path", { d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" })
|
|
424
|
+
}),
|
|
425
|
+
icon,
|
|
426
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
427
|
+
variant: "body2",
|
|
428
|
+
className: "text-text-primary dark:text-text-primary-dark font-medium text-xs truncate flex-grow ml-1.5",
|
|
429
|
+
children: title
|
|
430
|
+
}),
|
|
431
|
+
count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
432
|
+
className: "text-[10px] text-text-disabled dark:text-text-disabled-dark font-medium tabular-nums mr-1",
|
|
433
|
+
children: count
|
|
434
|
+
})
|
|
435
|
+
]
|
|
436
|
+
}), expanded && /* @__PURE__ */ jsx("div", {
|
|
437
|
+
className: "ml-3 mt-0.5 space-y-0.5",
|
|
438
|
+
children
|
|
439
|
+
})]
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
function SidebarTableRow({ table, isSelected, onSelect, badge, dimmed, t }) {
|
|
443
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
444
|
+
onClick: onSelect,
|
|
445
|
+
className: cls("flex items-center p-1 cursor-pointer rounded transition-colors group relative", isSelected ? "bg-primary/10 text-primary dark:bg-primary/20 dark:text-primary-light" : "hover:bg-surface-hover text-text-secondary dark:text-text-secondary-dark", dimmed && !isSelected && "opacity-60"),
|
|
446
|
+
children: [
|
|
447
|
+
/* @__PURE__ */ jsx("svg", {
|
|
448
|
+
className: "w-3.5 h-3.5 mr-1 shrink-0 text-text-disabled dark:text-text-disabled-dark",
|
|
449
|
+
fill: "none",
|
|
450
|
+
stroke: "currentColor",
|
|
451
|
+
viewBox: "0 0 24 24",
|
|
452
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
453
|
+
strokeLinecap: "round",
|
|
454
|
+
strokeLinejoin: "round",
|
|
455
|
+
strokeWidth: 2,
|
|
456
|
+
d: "M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"
|
|
457
|
+
})
|
|
458
|
+
}),
|
|
459
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
460
|
+
variant: "body2",
|
|
461
|
+
className: "text-xs truncate flex-1 min-w-0",
|
|
462
|
+
children: table.tableName
|
|
463
|
+
}),
|
|
464
|
+
/* @__PURE__ */ jsxs("div", {
|
|
465
|
+
className: "flex items-center gap-1.5 shrink-0 ml-2",
|
|
466
|
+
children: [
|
|
467
|
+
badge && /* @__PURE__ */ jsx("span", {
|
|
468
|
+
className: "text-[9px] uppercase tracking-wider font-semibold text-text-disabled dark:text-text-disabled-dark bg-surface-raised rounded px-1 py-px",
|
|
469
|
+
children: badge
|
|
470
|
+
}),
|
|
471
|
+
table.rlsEnabled ? /* @__PURE__ */ jsx(Tooltip, {
|
|
472
|
+
title: t("studio_rls_enabled"),
|
|
473
|
+
children: /* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-green-500" })
|
|
474
|
+
}) : /* @__PURE__ */ jsx(Tooltip, {
|
|
475
|
+
title: t("studio_rls_disabled"),
|
|
476
|
+
children: /* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-orange-400 opacity-50" })
|
|
477
|
+
}),
|
|
478
|
+
/* @__PURE__ */ jsx("span", {
|
|
479
|
+
className: "text-[10px] opacity-40 group-hover:opacity-100 min-w-[1.2rem] text-right font-medium",
|
|
480
|
+
children: table.policies.length
|
|
481
|
+
})
|
|
482
|
+
]
|
|
483
|
+
})
|
|
484
|
+
]
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
var RLSEditor = ({ apiUrl = "" }) => {
|
|
488
|
+
const [mode, setMode] = useState("inspector");
|
|
489
|
+
const { t } = useTranslation();
|
|
490
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
491
|
+
className: "flex flex-col h-full w-full overflow-hidden",
|
|
492
|
+
children: [/* @__PURE__ */ jsxs(Tabs, {
|
|
493
|
+
value: mode,
|
|
494
|
+
onValueChange: (v) => {
|
|
495
|
+
if (v === "inspector" || v === "direct") setMode(v);
|
|
496
|
+
},
|
|
497
|
+
variant: "boxy",
|
|
498
|
+
className: "border-b border-hairline px-4 bg-surface-sheet shrink-0",
|
|
499
|
+
children: [/* @__PURE__ */ jsx(Tab, {
|
|
500
|
+
value: "inspector",
|
|
501
|
+
children: t("studio_rls_tab_inspector")
|
|
502
|
+
}), /* @__PURE__ */ jsx(Tab, {
|
|
503
|
+
value: "direct",
|
|
504
|
+
children: t("studio_rls_tab_direct")
|
|
505
|
+
})]
|
|
506
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
507
|
+
className: "flex-1 min-h-0 overflow-hidden",
|
|
508
|
+
children: mode === "direct" ? /* @__PURE__ */ jsx(DirectRlsPoliciesPanel, {}) : /* @__PURE__ */ jsx(RLSEditorInspector, { apiUrl })
|
|
509
|
+
})]
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
var RLSEditorInspector = ({ apiUrl: _apiUrl = "" }) => {
|
|
513
|
+
const { databaseAdmin } = useRebaseContext();
|
|
514
|
+
const declaredTables = useTableDescriptors().tables;
|
|
515
|
+
const { t } = useTranslation();
|
|
516
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
517
|
+
const linkedTable = searchParams.get(RLS_TABLE_PARAM);
|
|
518
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
519
|
+
const [error, setError] = useState(null);
|
|
520
|
+
const [tables, setTables] = useState([]);
|
|
521
|
+
const selectedTable = linkedTable;
|
|
522
|
+
const setSelectedTable = useCallback((next) => {
|
|
523
|
+
setSearchParams((prev) => {
|
|
524
|
+
const current = prev.get(RLS_TABLE_PARAM);
|
|
525
|
+
const value = typeof next === "function" ? next(current) : next;
|
|
526
|
+
if (value === current) return prev;
|
|
527
|
+
const params = new URLSearchParams(prev);
|
|
528
|
+
if (value) params.set(RLS_TABLE_PARAM, value);
|
|
529
|
+
else params.delete(RLS_TABLE_PARAM);
|
|
530
|
+
return params;
|
|
531
|
+
}, { replace: true });
|
|
532
|
+
}, [setSearchParams]);
|
|
533
|
+
const [junctionTableNames, setJunctionTableNames] = useState(/* @__PURE__ */ new Set());
|
|
534
|
+
const setSelectedTableRef = useRef(setSelectedTable);
|
|
535
|
+
setSelectedTableRef.current = setSelectedTable;
|
|
536
|
+
const [sidebarSize, setSidebarSize] = useState(() => {
|
|
537
|
+
try {
|
|
538
|
+
const saved = localStorage.getItem("rebase_rls_editor_sidebar_size");
|
|
539
|
+
return saved !== null ? parseFloat(saved) : 20;
|
|
540
|
+
} catch (e) {
|
|
541
|
+
return 20;
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
const [expandedSections, setExpandedSections] = useState({
|
|
545
|
+
collection: true,
|
|
546
|
+
other: true,
|
|
547
|
+
internal: false
|
|
548
|
+
});
|
|
549
|
+
const [sidebarTab, setSidebarTab] = useState("tables");
|
|
550
|
+
useEffect(() => {
|
|
551
|
+
try {
|
|
552
|
+
localStorage.setItem("rebase_rls_editor_sidebar_size", sidebarSize.toString());
|
|
553
|
+
} catch (e) {}
|
|
554
|
+
}, [sidebarSize]);
|
|
555
|
+
const fetchRLSData = useCallback(async () => {
|
|
556
|
+
if (!databaseAdmin?.executeSql) {
|
|
557
|
+
setError(t("studio_sql_sql_not_supported"));
|
|
558
|
+
setIsLoading(false);
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
setIsLoading(true);
|
|
562
|
+
setError(null);
|
|
563
|
+
try {
|
|
564
|
+
const tablesResult = await databaseAdmin.executeSql(`
|
|
565
|
+
SELECT
|
|
566
|
+
schemaname,
|
|
567
|
+
tablename,
|
|
568
|
+
rowsecurity
|
|
569
|
+
FROM pg_tables
|
|
570
|
+
WHERE schemaname NOT IN ('information_schema', 'pg_catalog')
|
|
571
|
+
ORDER BY schemaname, tablename;
|
|
572
|
+
`);
|
|
573
|
+
const policiesResult = await databaseAdmin.executeSql(`
|
|
574
|
+
SELECT
|
|
575
|
+
schemaname,
|
|
576
|
+
tablename,
|
|
577
|
+
policyname,
|
|
578
|
+
permissive,
|
|
579
|
+
roles,
|
|
580
|
+
cmd,
|
|
581
|
+
qual,
|
|
582
|
+
with_check
|
|
583
|
+
FROM pg_policies
|
|
584
|
+
WHERE schemaname NOT IN ('information_schema', 'pg_catalog');
|
|
585
|
+
`);
|
|
586
|
+
const extractRows = (result) => {
|
|
587
|
+
if (result && typeof result === "object" && "rows" in result && Array.isArray(result.rows)) return result.rows;
|
|
588
|
+
if (Array.isArray(result)) return result;
|
|
589
|
+
return [];
|
|
590
|
+
};
|
|
591
|
+
const tRows = extractRows(tablesResult);
|
|
592
|
+
const pRows = extractRows(policiesResult);
|
|
593
|
+
const tableMap = {};
|
|
594
|
+
tRows.forEach((tRow) => {
|
|
595
|
+
const t = tRow;
|
|
596
|
+
const schema = t.schemaname || t.SCHEMANAME || "public";
|
|
597
|
+
const table = t.tablename || t.TABLENAME || "";
|
|
598
|
+
const rlsEnabled = t.rowsecurity || t.ROWSECURITY || false;
|
|
599
|
+
const key = `${schema}.${table}`;
|
|
600
|
+
tableMap[key] = {
|
|
601
|
+
schemaName: schema,
|
|
602
|
+
tableName: table,
|
|
603
|
+
rlsEnabled,
|
|
604
|
+
policies: []
|
|
605
|
+
};
|
|
606
|
+
});
|
|
607
|
+
pRows.forEach((pRow) => {
|
|
608
|
+
const p = pRow;
|
|
609
|
+
const schema = p.schemaname || p.SCHEMANAME || "public";
|
|
610
|
+
const table = p.tablename || p.TABLENAME || "";
|
|
611
|
+
const key = `${schema}.${table}`;
|
|
612
|
+
if (tableMap[key]) {
|
|
613
|
+
const parsedRoles = readPolicyRoles(p.roles || p.ROLES);
|
|
614
|
+
tableMap[key].policies.push({
|
|
615
|
+
policyname: p.policyname || p.POLICYNAME || "",
|
|
616
|
+
tablename: table,
|
|
617
|
+
permissive: p.permissive || p.PERMISSIVE || "PERMISSIVE",
|
|
618
|
+
roles: parsedRoles,
|
|
619
|
+
cmd: p.cmd || p.CMD || "ALL",
|
|
620
|
+
qual: p.qual || p.QUAL || null,
|
|
621
|
+
with_check: p.with_check || p.WITH_CHECK || null
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
const sortedTables = Object.values(tableMap).sort((a, b) => a.tableName.localeCompare(b.tableName));
|
|
626
|
+
setTables(sortedTables);
|
|
627
|
+
try {
|
|
628
|
+
const jRows = extractRows(await databaseAdmin.executeSql(JUNCTION_TABLES_SQL));
|
|
629
|
+
setJunctionTableNames(new Set(jRows.map((r) => r.table_name).filter(Boolean)));
|
|
630
|
+
} catch {}
|
|
631
|
+
if (sortedTables.length > 0) {
|
|
632
|
+
const firstUserTable = sortedTables.find((t) => !REBASE_INTERNAL_SCHEMAS.includes(t.schemaName)) ?? sortedTables[0];
|
|
633
|
+
setSelectedTableRef.current((previous) => previous ?? `${firstUserTable.schemaName}.${firstUserTable.tableName}`);
|
|
634
|
+
}
|
|
635
|
+
} catch (e) {
|
|
636
|
+
console.error("RLS fetch error:", e);
|
|
637
|
+
setError("Failed to fetch RLS policies: " + (e instanceof Error ? e.message : String(e)));
|
|
638
|
+
} finally {
|
|
639
|
+
setIsLoading(false);
|
|
640
|
+
}
|
|
641
|
+
}, [databaseAdmin, t]);
|
|
642
|
+
useEffect(() => {
|
|
643
|
+
fetchRLSData();
|
|
644
|
+
}, [fetchRLSData]);
|
|
645
|
+
const activeTableData = useMemo(() => {
|
|
646
|
+
if (!selectedTable) return null;
|
|
647
|
+
return tables.find((t) => `${t.schemaName}.${t.tableName}` === selectedTable) || null;
|
|
648
|
+
}, [selectedTable, tables]);
|
|
649
|
+
const servedJunctions = useMemo(() => servedJunctionsOf(declaredTables), [declaredTables]);
|
|
650
|
+
/** Categorize tables into 4 buckets for the sidebar. */
|
|
651
|
+
const categorizedTables = useMemo(() => {
|
|
652
|
+
const groups = {
|
|
653
|
+
collection: [],
|
|
654
|
+
junction: [],
|
|
655
|
+
internal: [],
|
|
656
|
+
other: []
|
|
657
|
+
};
|
|
658
|
+
tables.forEach((table) => {
|
|
659
|
+
const isMapped = declaredTables.some((descriptor) => mapsTable(descriptor, table));
|
|
660
|
+
const isJunction = junctionTableNames.has(table.tableName) || servedJunctions.has(`${table.schemaName}.${table.tableName}`);
|
|
661
|
+
groups[classifyTableClient(table.tableName, table.schemaName, isJunction, isMapped)].push(table);
|
|
662
|
+
});
|
|
663
|
+
return groups;
|
|
664
|
+
}, [
|
|
665
|
+
tables,
|
|
666
|
+
junctionTableNames,
|
|
667
|
+
servedJunctions,
|
|
668
|
+
declaredTables
|
|
669
|
+
]);
|
|
670
|
+
const rlsStats = useMemo(() => {
|
|
671
|
+
return {
|
|
672
|
+
total: tables.length,
|
|
673
|
+
enabled: tables.filter((t) => t.rlsEnabled).length,
|
|
674
|
+
withPolicies: tables.filter((t) => t.policies.length > 0).length,
|
|
675
|
+
totalPolicies: tables.reduce((sum, t) => sum + t.policies.length, 0)
|
|
676
|
+
};
|
|
677
|
+
}, [tables]);
|
|
678
|
+
return /* @__PURE__ */ jsx("div", {
|
|
679
|
+
className: "flex h-full w-full bg-surface-card overflow-hidden text-text-primary dark:text-text-primary-dark",
|
|
680
|
+
children: /* @__PURE__ */ jsx(ResizablePanels, {
|
|
681
|
+
dividerAriaLabel: t("resize_sidebar"),
|
|
682
|
+
orientation: "horizontal",
|
|
683
|
+
panelSizePercent: sidebarSize,
|
|
684
|
+
onPanelSizeChange: setSidebarSize,
|
|
685
|
+
minPanelSizePx: 220,
|
|
686
|
+
firstPanel: /* @__PURE__ */ jsxs("div", {
|
|
687
|
+
className: cls("flex flex-col h-full w-full bg-surface-card border-r", defaultBorderMixin),
|
|
688
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
689
|
+
className: cls("flex items-center justify-between pl-2 pr-2 border-b bg-surface-sheet shrink-0", defaultBorderMixin),
|
|
690
|
+
children: [/* @__PURE__ */ jsxs(Tabs, {
|
|
691
|
+
value: sidebarTab,
|
|
692
|
+
onValueChange: (v) => setSidebarTab(v),
|
|
693
|
+
variant: "boxy",
|
|
694
|
+
className: "w-[unset] flex-shrink-0",
|
|
695
|
+
children: [/* @__PURE__ */ jsx(Tab, {
|
|
696
|
+
value: "tables",
|
|
697
|
+
children: "Tables"
|
|
698
|
+
}), /* @__PURE__ */ jsx(Tab, {
|
|
699
|
+
value: "info",
|
|
700
|
+
children: "Info"
|
|
701
|
+
})]
|
|
702
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
703
|
+
"aria-label": t("refresh"),
|
|
704
|
+
size: "small",
|
|
705
|
+
onClick: fetchRLSData,
|
|
706
|
+
title: t("refresh"),
|
|
707
|
+
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
708
|
+
})]
|
|
709
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
710
|
+
className: "flex-grow overflow-hidden relative",
|
|
711
|
+
children: [sidebarTab === "tables" && /* @__PURE__ */ jsx("div", {
|
|
712
|
+
className: "flex flex-col h-full",
|
|
713
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
714
|
+
className: "flex-grow overflow-y-auto no-scrollbar p-1",
|
|
715
|
+
children: isLoading && tables.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
716
|
+
className: "flex justify-center p-4",
|
|
717
|
+
children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
|
|
718
|
+
}) : tables.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
719
|
+
className: "p-4 text-center",
|
|
720
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
721
|
+
variant: "caption",
|
|
722
|
+
className: "text-text-disabled dark:text-text-disabled-dark italic",
|
|
723
|
+
children: t("studio_rls_no_tables")
|
|
724
|
+
})
|
|
725
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
726
|
+
(categorizedTables.collection.length > 0 || categorizedTables.junction.length > 0) && /* @__PURE__ */ jsxs(SidebarSection, {
|
|
727
|
+
title: t("studio_rls_served_tables"),
|
|
728
|
+
icon: /* @__PURE__ */ jsx(DatabaseIcon, {
|
|
729
|
+
size: 12,
|
|
730
|
+
className: "text-primary dark:text-primary-light"
|
|
731
|
+
}),
|
|
732
|
+
expanded: expandedSections.collection ?? true,
|
|
733
|
+
onToggle: () => setExpandedSections((prev) => ({
|
|
734
|
+
...prev,
|
|
735
|
+
collection: !(prev.collection ?? true)
|
|
736
|
+
})),
|
|
737
|
+
children: [categorizedTables.collection.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
738
|
+
table,
|
|
739
|
+
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
740
|
+
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
741
|
+
t
|
|
742
|
+
}, `${table.schemaName}.${table.tableName}`)), categorizedTables.junction.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
743
|
+
table,
|
|
744
|
+
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
745
|
+
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
746
|
+
badge: "Junction",
|
|
747
|
+
dimmed: true,
|
|
748
|
+
t
|
|
749
|
+
}, `${table.schemaName}.${table.tableName}`))]
|
|
750
|
+
}),
|
|
751
|
+
categorizedTables.other.length > 0 && /* @__PURE__ */ jsx(SidebarSection, {
|
|
752
|
+
title: "Not served",
|
|
753
|
+
icon: /* @__PURE__ */ jsx(AlertTriangleIcon, {
|
|
754
|
+
size: 12,
|
|
755
|
+
className: "text-yellow-500 dark:text-yellow-400"
|
|
756
|
+
}),
|
|
757
|
+
expanded: expandedSections.other ?? true,
|
|
758
|
+
onToggle: () => setExpandedSections((prev) => ({
|
|
759
|
+
...prev,
|
|
760
|
+
other: !(prev.other ?? true)
|
|
761
|
+
})),
|
|
762
|
+
children: categorizedTables.other.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
763
|
+
table,
|
|
764
|
+
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
765
|
+
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
766
|
+
t
|
|
767
|
+
}, `${table.schemaName}.${table.tableName}`))
|
|
768
|
+
}),
|
|
769
|
+
categorizedTables.internal.length > 0 && /* @__PURE__ */ jsx(SidebarSection, {
|
|
770
|
+
title: "Rebase Internal",
|
|
771
|
+
icon: /* @__PURE__ */ jsx(LockIcon, {
|
|
772
|
+
size: 12,
|
|
773
|
+
className: "text-text-disabled dark:text-text-disabled-dark"
|
|
774
|
+
}),
|
|
775
|
+
expanded: expandedSections.internal ?? false,
|
|
776
|
+
onToggle: () => setExpandedSections((prev) => ({
|
|
777
|
+
...prev,
|
|
778
|
+
internal: !(prev.internal ?? false)
|
|
779
|
+
})),
|
|
780
|
+
count: categorizedTables.internal.length,
|
|
781
|
+
children: categorizedTables.internal.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
782
|
+
table,
|
|
783
|
+
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
784
|
+
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
785
|
+
dimmed: true,
|
|
786
|
+
t
|
|
787
|
+
}, `${table.schemaName}.${table.tableName}`))
|
|
788
|
+
})
|
|
789
|
+
] })
|
|
790
|
+
})
|
|
791
|
+
}), sidebarTab === "info" && /* @__PURE__ */ jsx("div", {
|
|
792
|
+
className: "flex flex-col h-full",
|
|
793
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
794
|
+
className: "flex-grow overflow-y-auto p-3 space-y-3 no-scrollbar",
|
|
795
|
+
children: [
|
|
796
|
+
/* @__PURE__ */ jsxs("div", {
|
|
797
|
+
className: cls("p-3 rounded-lg border bg-surface-card", defaultBorderMixin),
|
|
798
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
799
|
+
className: "flex items-center gap-2 mb-2",
|
|
800
|
+
children: [/* @__PURE__ */ jsx(ShieldIcon, {
|
|
801
|
+
size: iconSize.smallest,
|
|
802
|
+
className: "text-primary"
|
|
803
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
804
|
+
variant: "body2",
|
|
805
|
+
className: "font-semibold text-[13px]",
|
|
806
|
+
children: "RLS Studio"
|
|
807
|
+
})]
|
|
808
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
809
|
+
variant: "caption",
|
|
810
|
+
className: "text-text-secondary dark:text-text-secondary-dark text-xs leading-relaxed block",
|
|
811
|
+
children: "Manage Row Level Security policies for your PostgreSQL tables. Enable RLS and create fine-grained access policies."
|
|
812
|
+
})]
|
|
813
|
+
}),
|
|
814
|
+
/* @__PURE__ */ jsxs("div", {
|
|
815
|
+
className: "space-y-2",
|
|
816
|
+
children: [
|
|
817
|
+
/* @__PURE__ */ jsxs("div", {
|
|
818
|
+
className: cls("p-2.5 rounded border bg-surface-card flex items-center justify-between", defaultBorderMixin),
|
|
819
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
820
|
+
variant: "caption",
|
|
821
|
+
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
822
|
+
children: "Total tables"
|
|
823
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
824
|
+
variant: "body2",
|
|
825
|
+
className: "font-mono text-[13px] font-medium",
|
|
826
|
+
children: rlsStats.total
|
|
827
|
+
})]
|
|
828
|
+
}),
|
|
829
|
+
/* @__PURE__ */ jsxs("div", {
|
|
830
|
+
className: cls("p-2.5 rounded border bg-surface-card flex items-center justify-between", defaultBorderMixin),
|
|
831
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
832
|
+
variant: "caption",
|
|
833
|
+
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
834
|
+
children: t("studio_rls_enabled")
|
|
835
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
836
|
+
className: "flex items-center gap-1.5",
|
|
837
|
+
children: [/* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-green-500" }), /* @__PURE__ */ jsx(Typography, {
|
|
838
|
+
variant: "body2",
|
|
839
|
+
className: "font-mono text-[13px] font-medium",
|
|
840
|
+
children: rlsStats.enabled
|
|
841
|
+
})]
|
|
842
|
+
})]
|
|
843
|
+
}),
|
|
844
|
+
/* @__PURE__ */ jsxs("div", {
|
|
845
|
+
className: cls("p-2.5 rounded border bg-surface-card flex items-center justify-between", defaultBorderMixin),
|
|
846
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
847
|
+
variant: "caption",
|
|
848
|
+
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
849
|
+
children: "Tables with policies"
|
|
850
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
851
|
+
variant: "body2",
|
|
852
|
+
className: "font-mono text-[13px] font-medium",
|
|
853
|
+
children: rlsStats.withPolicies
|
|
854
|
+
})]
|
|
855
|
+
}),
|
|
856
|
+
/* @__PURE__ */ jsxs("div", {
|
|
857
|
+
className: cls("p-2.5 rounded border bg-surface-card flex items-center justify-between", defaultBorderMixin),
|
|
858
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
859
|
+
variant: "caption",
|
|
860
|
+
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
861
|
+
children: "Total policies"
|
|
862
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
863
|
+
variant: "body2",
|
|
864
|
+
className: "font-mono text-[13px] font-medium",
|
|
865
|
+
children: rlsStats.totalPolicies
|
|
866
|
+
})]
|
|
867
|
+
})
|
|
868
|
+
]
|
|
869
|
+
}),
|
|
870
|
+
rlsStats.total - rlsStats.enabled > 0 && /* @__PURE__ */ jsxs("div", {
|
|
871
|
+
className: cls("p-2.5 rounded border border-yellow-200 dark:border-yellow-900/50 bg-yellow-50 dark:bg-yellow-900/20 flex items-start gap-2", defaultBorderMixin),
|
|
872
|
+
children: [/* @__PURE__ */ jsx(AlertTriangleIcon, {
|
|
873
|
+
size: 14,
|
|
874
|
+
className: "text-yellow-600 dark:text-yellow-500 mt-0.5 shrink-0"
|
|
875
|
+
}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs(Typography, {
|
|
876
|
+
variant: "caption",
|
|
877
|
+
className: "text-yellow-800 dark:text-yellow-400 text-xs font-semibold block",
|
|
878
|
+
children: [
|
|
879
|
+
rlsStats.total - rlsStats.enabled,
|
|
880
|
+
" table",
|
|
881
|
+
rlsStats.total - rlsStats.enabled > 1 ? "s" : "",
|
|
882
|
+
" without RLS"
|
|
883
|
+
]
|
|
884
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
885
|
+
variant: "caption",
|
|
886
|
+
className: "text-yellow-700 dark:text-yellow-600 text-xs block mt-0.5",
|
|
887
|
+
children: "These tables have no row-level access control. If auth enforcement is disabled, data may be publicly accessible."
|
|
888
|
+
})] })]
|
|
889
|
+
}),
|
|
890
|
+
rlsStats.enabled > 0 && rlsStats.enabled - rlsStats.withPolicies > 0 && /* @__PURE__ */ jsxs("div", {
|
|
891
|
+
className: cls("p-2.5 rounded border border-blue-200 dark:border-blue-900/50 bg-blue-50 dark:bg-blue-900/20 flex items-start gap-2", defaultBorderMixin),
|
|
892
|
+
children: [/* @__PURE__ */ jsx(ShieldIcon, {
|
|
893
|
+
size: 14,
|
|
894
|
+
className: "text-blue-600 dark:text-blue-400 mt-0.5 shrink-0"
|
|
895
|
+
}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs(Typography, {
|
|
896
|
+
variant: "caption",
|
|
897
|
+
className: "text-blue-800 dark:text-blue-300 text-xs font-semibold block",
|
|
898
|
+
children: [
|
|
899
|
+
rlsStats.enabled - rlsStats.withPolicies,
|
|
900
|
+
" table",
|
|
901
|
+
rlsStats.enabled - rlsStats.withPolicies > 1 ? "s" : "",
|
|
902
|
+
" with RLS but no policies"
|
|
903
|
+
]
|
|
904
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
905
|
+
variant: "caption",
|
|
906
|
+
className: "text-blue-700 dark:text-blue-500 text-xs block mt-0.5",
|
|
907
|
+
children: "RLS is enabled but no permissive policies exist. All access is denied by default (Postgres deny-all)."
|
|
908
|
+
})] })]
|
|
909
|
+
})
|
|
910
|
+
]
|
|
911
|
+
})
|
|
912
|
+
})]
|
|
913
|
+
})]
|
|
914
|
+
}),
|
|
915
|
+
secondPanel: /* @__PURE__ */ jsxs("div", {
|
|
916
|
+
className: "flex-grow flex flex-col min-w-0 h-full w-full bg-surface-card",
|
|
917
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
918
|
+
className: cls("flex items-center justify-between pr-2 border-b bg-surface-sheet h-[42px] shrink-0", defaultBorderMixin),
|
|
919
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
920
|
+
className: "flex items-center flex-grow overflow-hidden px-4 gap-3",
|
|
921
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
922
|
+
variant: "subtitle2",
|
|
923
|
+
className: "font-mono text-text-secondary dark:text-text-secondary-dark truncate",
|
|
924
|
+
children: activeTableData ? `${activeTableData.schemaName}.${activeTableData.tableName}` : t("studio_rls_select_table")
|
|
925
|
+
}), activeTableData && /* @__PURE__ */ jsx(Chip, {
|
|
926
|
+
size: "smallest",
|
|
927
|
+
colorScheme: activeTableData.rlsEnabled ? "greenLight" : "orangeLight",
|
|
928
|
+
children: activeTableData.rlsEnabled ? t("studio_rls_enabled") : t("studio_rls_disabled")
|
|
929
|
+
})]
|
|
930
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
931
|
+
"aria-label": t("refresh"),
|
|
932
|
+
size: "small",
|
|
933
|
+
onClick: fetchRLSData,
|
|
934
|
+
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
935
|
+
})]
|
|
936
|
+
}), isLoading && !activeTableData ? /* @__PURE__ */ jsx("div", {
|
|
937
|
+
className: "flex-grow flex items-center justify-center h-full",
|
|
938
|
+
children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
|
|
939
|
+
}) : error ? /* @__PURE__ */ jsx("div", {
|
|
940
|
+
className: "p-6 h-full flex items-center justify-center",
|
|
941
|
+
children: /* @__PURE__ */ jsx(ErrorView, {
|
|
942
|
+
title: t("studio_rls_error"),
|
|
943
|
+
error,
|
|
944
|
+
onRetry: fetchRLSData
|
|
945
|
+
})
|
|
946
|
+
}) : !activeTableData ? /* @__PURE__ */ jsx("div", {
|
|
947
|
+
className: "flex-grow flex items-center justify-center text-text-disabled h-full",
|
|
948
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
949
|
+
variant: "body2",
|
|
950
|
+
children: t("studio_rls_select_table")
|
|
951
|
+
})
|
|
952
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
953
|
+
className: "p-6 pt-4 flex-grow overflow-auto bg-surface-sheet",
|
|
954
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
955
|
+
className: "max-w-4xl mx-auto",
|
|
956
|
+
children: /* @__PURE__ */ jsx(TablePolicies, {
|
|
957
|
+
schemaName: activeTableData.schemaName,
|
|
958
|
+
tableName: activeTableData.tableName,
|
|
959
|
+
rlsEnabled: activeTableData.rlsEnabled,
|
|
960
|
+
policies: activeTableData.policies,
|
|
961
|
+
isJunction: junctionTableNames.has(activeTableData.tableName),
|
|
962
|
+
onChanged: fetchRLSData
|
|
963
|
+
}, `${activeTableData.schemaName}.${activeTableData.tableName}`)
|
|
964
|
+
})
|
|
965
|
+
})]
|
|
966
|
+
})
|
|
967
|
+
})
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
//#endregion
|
|
971
|
+
export { RLSEditor };
|
|
972
|
+
|
|
973
|
+
//# sourceMappingURL=RLSEditor-CcHkWFNg.js.map
|