@rebasepro/studio 0.13.0 → 0.13.1-canary.g1822133
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/dist/{ApiExplorer-BIN9hE7r.js → ApiExplorer-CDOlUQzk.js} +9 -3
- package/dist/ApiExplorer-CDOlUQzk.js.map +1 -0
- package/dist/{ApiKeysView-dA-OvlcH.js → ApiKeysView-C_UoUPuR.js} +2 -1
- package/dist/{ApiKeysView-dA-OvlcH.js.map → ApiKeysView-C_UoUPuR.js.map} +1 -1
- package/dist/{BranchesView-Bgmp_1bm.js → BranchesView-CM3B-ER3.js} +3 -7
- package/dist/BranchesView-CM3B-ER3.js.map +1 -0
- package/dist/{CronJobsView-CL9q-DX7.js → CronJobsView-BHtJZeJZ.js} +19 -5
- package/dist/CronJobsView-BHtJZeJZ.js.map +1 -0
- package/dist/{JSEditor-BSTU-NXF.js → JSEditor-BaSrzWhF.js} +2 -2
- package/dist/{JSEditor-BSTU-NXF.js.map → JSEditor-BaSrzWhF.js.map} +1 -1
- package/dist/{LogsExplorer-BsHaHIMK.js → LogsExplorer-Ctk2f3MM.js} +2 -1
- package/dist/LogsExplorer-Ctk2f3MM.js.map +1 -0
- package/dist/{RLSEditor-DuzofJ8t.js → RLSEditor-CV8R1G3W.js} +52 -18
- package/dist/RLSEditor-CV8R1G3W.js.map +1 -0
- package/dist/{SQLEditor-CL6DcGRM.js → SQLEditor-BmI0iIWK.js} +62 -66
- package/dist/SQLEditor-BmI0iIWK.js.map +1 -0
- package/dist/components/RLSEditor/saveSecurityRules.d.ts +19 -0
- package/dist/index.es.js +8 -8
- package/package.json +9 -9
- package/src/components/ApiExplorer/TryItPanel.tsx +7 -2
- package/src/components/ApiKeys/ApiKeysView.tsx +1 -0
- package/src/components/Branches/BranchesView.tsx +2 -7
- package/src/components/CronJobs/CronJobsView.tsx +28 -3
- package/src/components/LogsExplorer/LogsExplorer.tsx +1 -0
- package/src/components/RLSEditor/PolicyEditor.tsx +1 -0
- package/src/components/RLSEditor/RLSEditor.tsx +20 -19
- package/src/components/RLSEditor/saveSecurityRules.ts +48 -0
- package/src/components/SQLEditor/SQLEditor.tsx +100 -78
- package/src/utils/parseSpec.test.ts +10 -2
- package/dist/ApiExplorer-BIN9hE7r.js.map +0 -1
- package/dist/BranchesView-Bgmp_1bm.js.map +0 -1
- package/dist/CronJobsView-CL9q-DX7.js.map +0 -1
- package/dist/LogsExplorer-BsHaHIMK.js.map +0 -1
- package/dist/RLSEditor-DuzofJ8t.js.map +0 -1
- package/dist/SQLEditor-CL6DcGRM.js.map +0 -1
|
@@ -235,6 +235,7 @@ export const PolicyEditor = ({
|
|
|
235
235
|
<Typography variant="caption" className="uppercase tracking-wider text-text-secondary">{t("studio_policy_name")}</Typography>
|
|
236
236
|
<TextField
|
|
237
237
|
value={name}
|
|
238
|
+
aria-label={t("studio_policy_name")}
|
|
238
239
|
onChange={(e) => setName(e.target.value)}
|
|
239
240
|
placeholder={t("studio_policy_name_placeholder")}
|
|
240
241
|
className="w-full"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { useStudioCollectionRegistry, useStudioCapabilities } from "@rebasepro/app";
|
|
3
|
-
import { useApiBase } from "@rebasepro/app";
|
|
3
|
+
import { useApiBase, useApiConfig } from "@rebasepro/app";
|
|
4
4
|
import React, { useState, useEffect, useCallback, useMemo } from "react";
|
|
5
5
|
import {
|
|
6
6
|
Alert,
|
|
@@ -32,6 +32,7 @@ import { REBASE_INTERNAL_SCHEMAS, REBASE_INTERNAL_PREFIXES, JUNCTION_TABLES_SQL
|
|
|
32
32
|
import { getPolicyNamesForRule, getPolicyNamesForRules, getPolicyOperations } from "@rebasepro/utils";
|
|
33
33
|
import { resolveJunctionSpecs, getJunctionSecurityRules, getEffectiveSecurityRules } from "@rebasepro/common";
|
|
34
34
|
import { PolicyEditor } from "./PolicyEditor";
|
|
35
|
+
import { saveSecurityRulesToCodebase } from "./saveSecurityRules";
|
|
35
36
|
|
|
36
37
|
type TableCategory = "collection" | "junction" | "internal" | "other";
|
|
37
38
|
|
|
@@ -156,9 +157,19 @@ export const RLSEditor = ({ apiUrl = "" }: { apiUrl?: string }) => {
|
|
|
156
157
|
const snackbarController = useSnackbarController();
|
|
157
158
|
const collectionRegistry = useStudioCollectionRegistry();
|
|
158
159
|
const { codebase: hasCodebase } = useStudioCapabilities();
|
|
160
|
+
const apiConfig = useApiConfig();
|
|
159
161
|
/* `apiUrl` is a bare origin; the routes live under the backend's
|
|
160
162
|
`basePath`, which is `/api` only by default. */
|
|
161
163
|
const apiBase = useApiBase() ?? `${apiUrl.replace(/\/+$/, "")}/api`;
|
|
164
|
+
|
|
165
|
+
const saveSecurityRules = useCallback(
|
|
166
|
+
(collectionId: string, securityRules: unknown[]) => saveSecurityRulesToCodebase({
|
|
167
|
+
apiBase,
|
|
168
|
+
collectionId,
|
|
169
|
+
securityRules,
|
|
170
|
+
getAuthToken: apiConfig?.getAuthToken
|
|
171
|
+
}),
|
|
172
|
+
[apiBase, apiConfig]);
|
|
162
173
|
const { t } = useTranslation();
|
|
163
174
|
|
|
164
175
|
const [isLoading, setIsLoading] = useState(true);
|
|
@@ -788,15 +799,10 @@ message: e instanceof Error ? e.message : String(e) });
|
|
|
788
799
|
}
|
|
789
800
|
|
|
790
801
|
try {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
collectionId: (activeCollection as { id?: string, path?: string, alias?: string }).id || (activeCollection as { id?: string, path?: string, alias?: string }).path || (activeCollection as { id?: string, path?: string, alias?: string }).alias || activeTableData.tableName,
|
|
796
|
-
collectionData: { securityRules: newRules }
|
|
797
|
-
})
|
|
798
|
-
});
|
|
799
|
-
if (!response.ok) throw new Error("Failed to save policy");
|
|
802
|
+
await saveSecurityRules(
|
|
803
|
+
(activeCollection as { id?: string, path?: string, alias?: string }).id || (activeCollection as { id?: string, path?: string, alias?: string }).path || (activeCollection as { id?: string, path?: string, alias?: string }).alias || activeTableData.tableName,
|
|
804
|
+
newRules
|
|
805
|
+
);
|
|
800
806
|
|
|
801
807
|
snackbarController.open({ type: "success",
|
|
802
808
|
message: "Policy saved successfully" });
|
|
@@ -987,15 +993,10 @@ message: e instanceof Error ? e.message : String(e) });
|
|
|
987
993
|
const newRules = [...existingRules, rule];
|
|
988
994
|
|
|
989
995
|
try {
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
collectionId: (activeCollection as { id?: string, path?: string, alias?: string }).id || (activeCollection as { id?: string, path?: string, alias?: string }).path || (activeCollection as { id?: string, path?: string, alias?: string }).alias || activeTableData!.tableName,
|
|
995
|
-
collectionData: { securityRules: newRules }
|
|
996
|
-
})
|
|
997
|
-
});
|
|
998
|
-
if (!response.ok) throw new Error("Failed to save policy");
|
|
996
|
+
await saveSecurityRules(
|
|
997
|
+
(activeCollection as { id?: string, path?: string, alias?: string }).id || (activeCollection as { id?: string, path?: string, alias?: string }).path || (activeCollection as { id?: string, path?: string, alias?: string }).alias || activeTableData!.tableName,
|
|
998
|
+
newRules
|
|
999
|
+
);
|
|
999
1000
|
|
|
1000
1001
|
snackbarController.open({ type: "success",
|
|
1001
1002
|
message: "Policy imported successfully" });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write a collection's security rules to its source file.
|
|
3
|
+
*
|
|
4
|
+
* The schema-editor routes sit behind an admin gate that accepts a bearer token
|
|
5
|
+
* and nothing else — there is no cookie fallback — so a request without an
|
|
6
|
+
* `Authorization` header is a 401 every time. The RLS editor's two write paths
|
|
7
|
+
* ("Create policy" on a mapped table, and "Import to codebase") both sent none,
|
|
8
|
+
* and both reported the failure as a constant "Failed to save policy", which is
|
|
9
|
+
* also what a 501 and a parse error looked like.
|
|
10
|
+
*
|
|
11
|
+
* It lives in its own module rather than inline in the component so that the
|
|
12
|
+
* header can be asserted without rendering the whole RLS editor.
|
|
13
|
+
*/
|
|
14
|
+
export async function saveSecurityRulesToCodebase(options: {
|
|
15
|
+
apiBase: string;
|
|
16
|
+
collectionId: string;
|
|
17
|
+
securityRules: unknown[];
|
|
18
|
+
getAuthToken?: () => Promise<string | null | undefined>;
|
|
19
|
+
}): Promise<void> {
|
|
20
|
+
const { apiBase, collectionId, securityRules, getAuthToken } = options;
|
|
21
|
+
|
|
22
|
+
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
|
23
|
+
const token = getAuthToken ? await getAuthToken() : null;
|
|
24
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
25
|
+
|
|
26
|
+
const response = await fetch(`${apiBase}/schema-editor/collection/save`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers,
|
|
29
|
+
// Only the rules change here. `partial` says so: read as a
|
|
30
|
+
// whole-collection save, a payload of one key deletes everything it does
|
|
31
|
+
// not mention.
|
|
32
|
+
body: JSON.stringify({ collectionId,
|
|
33
|
+
collectionData: { securityRules },
|
|
34
|
+
partial: true })
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (response.ok) return;
|
|
38
|
+
|
|
39
|
+
const body = await response.text().catch(() => "");
|
|
40
|
+
let message: string | undefined;
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(body) as { error?: { message?: string }, message?: string };
|
|
43
|
+
message = parsed.error?.message ?? parsed.message;
|
|
44
|
+
} catch {
|
|
45
|
+
message = body.trim() || undefined;
|
|
46
|
+
}
|
|
47
|
+
throw new Error(message ?? `Failed to save policy (HTTP ${response.status}).`);
|
|
48
|
+
}
|
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
} from "@rebasepro/ui";
|
|
44
44
|
|
|
45
45
|
import { useRebaseContext, useSnackbarController, ConfirmationDialog, ErrorView, useTranslation } from "@rebasepro/app";
|
|
46
|
+
import { isArrayValue, isRecordValue, readStoredJson, readStoredString, writeStoredJson, writeStoredString } from "@rebasepro/utils";
|
|
46
47
|
import { MonacoEditor } from "./MonacoEditor";
|
|
47
48
|
import { SQLEditorSidebar, Snippet } from "./SQLEditorSidebar";
|
|
48
49
|
import { parseFirst } from "pgsql-ast-parser";
|
|
@@ -203,6 +204,28 @@ const getStoragePrefix = (baseUrl?: string) => {
|
|
|
203
204
|
return baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
204
205
|
};
|
|
205
206
|
|
|
207
|
+
/** The part of a tab that is persisted; the rest is per-session. */
|
|
208
|
+
type StoredTab = {
|
|
209
|
+
id: string;
|
|
210
|
+
name: string;
|
|
211
|
+
sql: string;
|
|
212
|
+
database?: string;
|
|
213
|
+
role?: string;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Whether a stored entry is a tab this release can restore. Storage holds
|
|
218
|
+
* whatever the last version to run wrote, so the fields are checked rather
|
|
219
|
+
* than assumed.
|
|
220
|
+
*/
|
|
221
|
+
function isStoredTab(value: unknown): value is StoredTab {
|
|
222
|
+
if (typeof value !== "object" || value === null) return false;
|
|
223
|
+
const tab = value as Record<string, unknown>;
|
|
224
|
+
return typeof tab.id === "string"
|
|
225
|
+
&& typeof tab.name === "string"
|
|
226
|
+
&& typeof tab.sql === "string";
|
|
227
|
+
}
|
|
228
|
+
|
|
206
229
|
export const SQLEditor = () => {
|
|
207
230
|
const { databaseAdmin, client } = useRebaseContext();
|
|
208
231
|
const sidePanelController = useStudioSidePanelController();
|
|
@@ -222,11 +245,11 @@ export const SQLEditor = () => {
|
|
|
222
245
|
// Connection state
|
|
223
246
|
const [selectedDatabase, setSelectedDatabase] = useState<string | undefined>(() => {
|
|
224
247
|
const projectPrefixSync = client?.baseUrl ? client.baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_") : "default";
|
|
225
|
-
return
|
|
248
|
+
return readStoredString(`rebase_sql_selected_db_${projectPrefixSync}`) || undefined;
|
|
226
249
|
});
|
|
227
250
|
const [selectedRole, setSelectedRole] = useState<string | undefined>(() => {
|
|
228
251
|
const projectPrefixSync = client?.baseUrl ? client.baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_") : "default";
|
|
229
|
-
return
|
|
252
|
+
return readStoredString(`rebase_sql_selected_role_${projectPrefixSync}`) || undefined;
|
|
230
253
|
});
|
|
231
254
|
|
|
232
255
|
const [availableDatabases, setAvailableDatabases] = useState<string[]>([]);
|
|
@@ -247,25 +270,32 @@ export const SQLEditor = () => {
|
|
|
247
270
|
execTime: number | null,
|
|
248
271
|
lastExecutedSql: string | null
|
|
249
272
|
}>>(() => {
|
|
250
|
-
const projectPrefixSync = client?.baseUrl
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
273
|
+
const projectPrefixSync = getStoragePrefix(client?.baseUrl);
|
|
274
|
+
// This runs during the first render, so anything it throws takes the
|
|
275
|
+
// whole editor down — and the value that threw is still in storage on
|
|
276
|
+
// reload. `readStoredJson` turns unreadable and wrong-shaped state into
|
|
277
|
+
// the default set of tabs instead, and `isStoredTab` drops the
|
|
278
|
+
// individual entries an older release wrote differently: a tab with no
|
|
279
|
+
// `id` never matches the active tab and cannot be closed.
|
|
280
|
+
const saved = readStoredJson<unknown[]>(
|
|
281
|
+
`rebase_sql_tabs_${projectPrefixSync}`,
|
|
282
|
+
{ fallback: [], accept: isArrayValue }
|
|
283
|
+
);
|
|
284
|
+
const restored = saved.filter(isStoredTab).map(t => ({
|
|
285
|
+
...t,
|
|
286
|
+
results: null,
|
|
287
|
+
loading: false,
|
|
288
|
+
error: null,
|
|
289
|
+
execTime: null,
|
|
290
|
+
lastExecutedSql: null
|
|
291
|
+
}));
|
|
292
|
+
if (restored.length > 0) return restored;
|
|
263
293
|
return [{
|
|
264
294
|
id: "1",
|
|
265
295
|
name: "Query 1",
|
|
266
296
|
sql: "SELECT * FROM ",
|
|
267
|
-
database:
|
|
268
|
-
role:
|
|
297
|
+
database: readStoredString(`rebase_sql_selected_db_${projectPrefixSync}`) || undefined,
|
|
298
|
+
role: readStoredString(`rebase_sql_selected_role_${projectPrefixSync}`) || undefined,
|
|
269
299
|
results: null,
|
|
270
300
|
loading: false,
|
|
271
301
|
error: null,
|
|
@@ -275,7 +305,7 @@ export const SQLEditor = () => {
|
|
|
275
305
|
});
|
|
276
306
|
const [activeTabId, setActiveTabId] = useState<string>(() => {
|
|
277
307
|
const projectPrefixSync = client?.baseUrl ? client.baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_") : "default";
|
|
278
|
-
return
|
|
308
|
+
return readStoredString(`rebase_sql_active_tab_${projectPrefixSync}`) || "1";
|
|
279
309
|
});
|
|
280
310
|
|
|
281
311
|
const activeTab = tabs.find(t => t.id === activeTabId) || tabs[0];
|
|
@@ -318,15 +348,18 @@ export const SQLEditor = () => {
|
|
|
318
348
|
setAvailableDatabases(dbs);
|
|
319
349
|
setAvailableRoles(roles);
|
|
320
350
|
|
|
321
|
-
const loadedDb =
|
|
322
|
-
const loadedRole =
|
|
323
|
-
|
|
324
|
-
const initialActiveTabId =
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
351
|
+
const loadedDb = readStoredString(`rebase_sql_selected_db_${projectPrefix}`) || undefined;
|
|
352
|
+
const loadedRole = readStoredString(`rebase_sql_selected_role_${projectPrefix}`) || undefined;
|
|
353
|
+
|
|
354
|
+
const initialActiveTabId = readStoredString(`rebase_sql_active_tab_${projectPrefix}`) || "1";
|
|
355
|
+
// The old guard caught a parse failure but not a parse
|
|
356
|
+
// *success* of the wrong shape, and the `.find` below sat
|
|
357
|
+
// outside it — so an object where an array was expected
|
|
358
|
+
// still threw.
|
|
359
|
+
const initialTabs = readStoredJson<Array<{ id?: string; database?: string; role?: string }>>(
|
|
360
|
+
`rebase_sql_tabs_${projectPrefix}`,
|
|
361
|
+
{ fallback: [], accept: isArrayValue }
|
|
362
|
+
);
|
|
330
363
|
const currentActiveTab = initialTabs.find(t => t.id === initialActiveTabId);
|
|
331
364
|
|
|
332
365
|
let actualDb = currentActiveTab?.database || loadedDb;
|
|
@@ -337,7 +370,7 @@ export const SQLEditor = () => {
|
|
|
337
370
|
|
|
338
371
|
if (actualDb) {
|
|
339
372
|
setSelectedDatabase(actualDb);
|
|
340
|
-
|
|
373
|
+
writeStoredString(`rebase_sql_selected_db_${projectPrefix}`, actualDb);
|
|
341
374
|
setTabs(prev => prev.map(t => t.id === initialActiveTabId && (!t.database || !dbs.includes(t.database)) ? { ...t,
|
|
342
375
|
database: actualDb } : t));
|
|
343
376
|
}
|
|
@@ -356,7 +389,7 @@ database: actualDb } : t));
|
|
|
356
389
|
|
|
357
390
|
if (actualRole) {
|
|
358
391
|
setSelectedRole(actualRole);
|
|
359
|
-
|
|
392
|
+
writeStoredString(`rebase_sql_selected_role_${projectPrefix}`, actualRole);
|
|
360
393
|
setTabs(prev => prev.map(t => t.id === initialActiveTabId && (!t.role || !roles.includes(t.role)) ? { ...t,
|
|
361
394
|
role: actualRole } : t));
|
|
362
395
|
}
|
|
@@ -381,7 +414,7 @@ role: actualRole } : t));
|
|
|
381
414
|
|
|
382
415
|
const handleDatabaseChange = (db: string, tabId?: string) => {
|
|
383
416
|
setSelectedDatabase(db);
|
|
384
|
-
|
|
417
|
+
writeStoredString(`rebase_sql_selected_db_${projectPrefix}`, db);
|
|
385
418
|
setTabs(prev => prev.map(t => t.id === (tabId || activeTabId) ? { ...t,
|
|
386
419
|
database: db } : t));
|
|
387
420
|
// Reset so the schema will be re-fetched for the new database
|
|
@@ -390,7 +423,7 @@ database: db } : t));
|
|
|
390
423
|
|
|
391
424
|
const handleRoleChange = (role: string, tabId?: string) => {
|
|
392
425
|
setSelectedRole(role);
|
|
393
|
-
|
|
426
|
+
writeStoredString(`rebase_sql_selected_role_${projectPrefix}`, role);
|
|
394
427
|
setTabs(prev => prev.map(t => t.id === (tabId || activeTabId) ? { ...t,
|
|
395
428
|
role } : t));
|
|
396
429
|
};
|
|
@@ -401,7 +434,7 @@ role } : t));
|
|
|
401
434
|
if (newTab) {
|
|
402
435
|
if (newTab.database && newTab.database !== selectedDatabase) {
|
|
403
436
|
setSelectedDatabase(newTab.database);
|
|
404
|
-
|
|
437
|
+
writeStoredString(`rebase_sql_selected_db_${projectPrefix}`, newTab.database);
|
|
405
438
|
schemaFetchedRef.current = false;
|
|
406
439
|
} else if (!newTab.database && selectedDatabase) {
|
|
407
440
|
setTabs(prev => prev.map(t => t.id === newTabId ? { ...t,
|
|
@@ -410,7 +443,7 @@ database: selectedDatabase } : t));
|
|
|
410
443
|
|
|
411
444
|
if (newTab.role && newTab.role !== selectedRole) {
|
|
412
445
|
setSelectedRole(newTab.role);
|
|
413
|
-
|
|
446
|
+
writeStoredString(`rebase_sql_selected_role_${projectPrefix}`, newTab.role);
|
|
414
447
|
} else if (!newTab.role && selectedRole) {
|
|
415
448
|
setTabs(prev => prev.map(t => t.id === newTabId ? { ...t,
|
|
416
449
|
role: selectedRole } : t));
|
|
@@ -631,8 +664,10 @@ role: selectedRole });
|
|
|
631
664
|
|
|
632
665
|
const [columnWidths, setColumnWidths] = useState<Record<string, Record<string, number>>>(() => {
|
|
633
666
|
const projectPrefixSync = client?.baseUrl ? client.baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_") : "default";
|
|
634
|
-
|
|
635
|
-
|
|
667
|
+
return readStoredJson<Record<string, Record<string, number>>>(
|
|
668
|
+
`rebase_sql_column_widths_${projectPrefixSync}`,
|
|
669
|
+
{ fallback: {}, accept: isRecordValue }
|
|
670
|
+
);
|
|
636
671
|
});
|
|
637
672
|
const [snippets, setSnippets] = useState<Snippet[]>([]);
|
|
638
673
|
const [history, setHistory] = useState<string[]>([]);
|
|
@@ -641,22 +676,20 @@ role: selectedRole });
|
|
|
641
676
|
|
|
642
677
|
// Load from local storage
|
|
643
678
|
useEffect(() => {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (savedHistory) {
|
|
653
|
-
setHistory(JSON.parse(savedHistory));
|
|
654
|
-
} else {
|
|
655
|
-
setHistory([]);
|
|
656
|
-
}
|
|
679
|
+
setSnippets(readStoredJson<Snippet[]>(
|
|
680
|
+
`rebase_sql_snippets_${projectPrefix}`,
|
|
681
|
+
{ fallback: [], accept: isArrayValue }
|
|
682
|
+
));
|
|
683
|
+
setHistory(readStoredJson<string[]>(
|
|
684
|
+
`rebase_sql_history_${projectPrefix}`,
|
|
685
|
+
{ fallback: [], accept: isArrayValue }
|
|
686
|
+
));
|
|
657
687
|
}, [projectPrefix]);
|
|
658
688
|
|
|
659
|
-
// Save tabs and active tab to local storage
|
|
689
|
+
// Save tabs and active tab to local storage. Tab text is persisted on every
|
|
690
|
+
// edit, so this is the write that reaches the origin's quota first — and a
|
|
691
|
+
// `QuotaExceededError` thrown out of an effect is not something the view
|
|
692
|
+
// can do anything with.
|
|
660
693
|
useEffect(() => {
|
|
661
694
|
const sanitizedTabs = tabs.map(t => ({
|
|
662
695
|
id: t.id,
|
|
@@ -665,21 +698,21 @@ role: selectedRole });
|
|
|
665
698
|
database: t.database,
|
|
666
699
|
role: t.role
|
|
667
700
|
}));
|
|
668
|
-
|
|
701
|
+
writeStoredJson(`rebase_sql_tabs_${projectPrefix}`, sanitizedTabs);
|
|
669
702
|
}, [tabs, projectPrefix]);
|
|
670
703
|
|
|
671
704
|
useEffect(() => {
|
|
672
|
-
|
|
705
|
+
writeStoredString(`rebase_sql_active_tab_${projectPrefix}`, activeTabId);
|
|
673
706
|
}, [activeTabId, projectPrefix]);
|
|
674
707
|
|
|
675
708
|
const saveSnippets = (newSnippets: Snippet[]) => {
|
|
676
709
|
setSnippets(newSnippets);
|
|
677
|
-
|
|
710
|
+
writeStoredJson(`rebase_sql_snippets_${projectPrefix}`, newSnippets);
|
|
678
711
|
};
|
|
679
712
|
|
|
680
713
|
const saveHistory = (newHistory: string[]) => {
|
|
681
714
|
setHistory(newHistory);
|
|
682
|
-
|
|
715
|
+
writeStoredJson(`rebase_sql_history_${projectPrefix}`, newHistory.slice(-50));
|
|
683
716
|
};
|
|
684
717
|
|
|
685
718
|
const handleDeleteSnippet = (id: string) => {
|
|
@@ -740,7 +773,7 @@ role: selectedRole });
|
|
|
740
773
|
[key]: width
|
|
741
774
|
}
|
|
742
775
|
};
|
|
743
|
-
|
|
776
|
+
writeStoredJson(`rebase_sql_column_widths_${projectPrefix}`, newWidths);
|
|
744
777
|
return newWidths;
|
|
745
778
|
});
|
|
746
779
|
}, [activeTab.sql, projectPrefix]);
|
|
@@ -1213,35 +1246,24 @@ id: String(ra.entityId) })}
|
|
|
1213
1246
|
);
|
|
1214
1247
|
};
|
|
1215
1248
|
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
const [
|
|
1226
|
-
|
|
1227
|
-
const projectPrefixSync = client?.baseUrl ? client.baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_") : "default";
|
|
1228
|
-
const saved = localStorage.getItem(`rebase_sql_editor_height_${projectPrefixSync}`);
|
|
1229
|
-
return saved !== null ? parseFloat(saved) : 50;
|
|
1230
|
-
} catch (e) {
|
|
1231
|
-
return 50;
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1249
|
+
// `parseFloat` answers NaN for anything it cannot read, and a NaN pane size
|
|
1250
|
+
// lays the editor out to nothing — so the stored value has to be checked,
|
|
1251
|
+
// not just parsed.
|
|
1252
|
+
const readStoredSize = (key: string, fallback: number) => {
|
|
1253
|
+
const saved = readStoredString(`${key}_${getStoragePrefix(client?.baseUrl)}`);
|
|
1254
|
+
const parsed = saved === null ? NaN : parseFloat(saved);
|
|
1255
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
const [sidebarSize, setSidebarSize] = useState(() => readStoredSize("rebase_sql_editor_sidebar_size", 20));
|
|
1259
|
+
const [editorHeight, setEditorHeight] = useState(() => readStoredSize("rebase_sql_editor_height", 50));
|
|
1234
1260
|
|
|
1235
1261
|
useEffect(() => {
|
|
1236
|
-
|
|
1237
|
-
localStorage.setItem(`rebase_sql_editor_sidebar_size_${projectPrefix}`, sidebarSize.toString());
|
|
1238
|
-
} catch (e) { /* ignore */ }
|
|
1262
|
+
writeStoredString(`rebase_sql_editor_sidebar_size_${projectPrefix}`, sidebarSize.toString());
|
|
1239
1263
|
}, [sidebarSize, projectPrefix]);
|
|
1240
1264
|
|
|
1241
1265
|
useEffect(() => {
|
|
1242
|
-
|
|
1243
|
-
localStorage.setItem(`rebase_sql_editor_height_${projectPrefix}`, editorHeight.toString());
|
|
1244
|
-
} catch (e) { /* ignore */ }
|
|
1266
|
+
writeStoredString(`rebase_sql_editor_height_${projectPrefix}`, editorHeight.toString());
|
|
1245
1267
|
}, [editorHeight, projectPrefix]);
|
|
1246
1268
|
|
|
1247
1269
|
const activeSnippet = snippets.find(s => s.sql === activeTab.sql);
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { parseOpenApiSpec, resolveRefName, resolveRef } from "../components/ApiExplorer/parseSpec";
|
|
2
|
-
import type { OpenApiSpec } from "../components/ApiExplorer/types";
|
|
2
|
+
import type { OpenApiParameter, OpenApiSpec } from "../components/ApiExplorer/types";
|
|
3
3
|
|
|
4
4
|
function makeSpec(overrides: Partial<OpenApiSpec> = {}): OpenApiSpec {
|
|
5
5
|
return {
|
|
6
|
+
// `openapi` and `info` are required on `OpenApiSpec` and this builder
|
|
7
|
+
// supplied neither, so every fixture below was one cast away from being
|
|
8
|
+
// a document no parser would accept.
|
|
9
|
+
openapi: "3.0.0",
|
|
10
|
+
info: { title: "Test API",
|
|
11
|
+
version: "1.0.0" },
|
|
6
12
|
paths: {},
|
|
7
13
|
tags: [],
|
|
8
14
|
...overrides
|
|
@@ -164,7 +170,9 @@ summary: "List" }
|
|
|
164
170
|
});
|
|
165
171
|
|
|
166
172
|
it("extracts parameters and requestBody", () => {
|
|
167
|
-
|
|
173
|
+
// Annotated: inferred, `in` widens to `string` and the array is not an
|
|
174
|
+
// `OpenApiParameter[]` — the very shape this test says it extracts.
|
|
175
|
+
const params: OpenApiParameter[] = [{ name: "id",
|
|
168
176
|
in: "path",
|
|
169
177
|
required: true }];
|
|
170
178
|
const requestBody = { content: { "application/json": { schema: {} } } };
|