@rebasepro/studio 0.23.0 → 0.24.1-canary.g56af4a4
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-pYMZflL3.js → ApiExplorer-Bzt7Ye49.js} +18 -29
- package/dist/ApiExplorer-Bzt7Ye49.js.map +1 -0
- package/dist/ApiKeysView-Bqf6XYR1.js +1739 -0
- package/dist/ApiKeysView-Bqf6XYR1.js.map +1 -0
- package/dist/BackupsView-BhOHB6iP.js +354 -0
- package/dist/BackupsView-BhOHB6iP.js.map +1 -0
- package/dist/{BranchesView-D6Sz1a5f.js → BranchesView-BHfwGTYc.js} +16 -10
- package/dist/BranchesView-BHfwGTYc.js.map +1 -0
- package/dist/{CronJobsView-7hjgSYId.js → CronJobsView-CMNK7eWO.js} +175 -116
- package/dist/CronJobsView-CMNK7eWO.js.map +1 -0
- package/dist/{JSEditor-qiuwmcvk.js → JSEditor-DIO2Mw8q.js} +230 -165
- package/dist/JSEditor-DIO2Mw8q.js.map +1 -0
- package/dist/{LogsExplorer-Xq8K4oo6.js → LogsExplorer-C-bwDFIl.js} +66 -44
- package/dist/LogsExplorer-C-bwDFIl.js.map +1 -0
- package/dist/{RLSEditor-Djh43lBE.js → RLSEditor-jFD_d06f.js} +246 -84
- package/dist/RLSEditor-jFD_d06f.js.map +1 -0
- package/dist/{SQLEditor-TBw_K6CW.js → SQLEditor-D5Ci4pyW.js} +502 -600
- package/dist/SQLEditor-D5Ci4pyW.js.map +1 -0
- package/dist/{SchemaVisualizer-DtDzIUNy.js → SchemaVisualizer-D-rAqwul.js} +496 -227
- package/dist/SchemaVisualizer-D-rAqwul.js.map +1 -0
- package/dist/{StorageView-CMG1DOVX.js → StorageView-CPkDKbsX.js} +838 -451
- package/dist/StorageView-CPkDKbsX.js.map +1 -0
- package/dist/assets/dagre-layout.worker-BFnhAzuR.js.map +1 -0
- package/dist/components/ApiExplorer/TryItPanel.d.ts +6 -1
- package/dist/components/ApiKeys/CreateApiKeyDialog.d.ts +21 -2
- package/dist/components/ApiKeys/scope-words.d.ts +37 -0
- package/dist/components/ApiKeys/scopes.d.ts +113 -0
- package/dist/components/AuthSimulationSelector.d.ts +5 -1
- package/dist/components/LogsExplorer/useLogTail.d.ts +9 -0
- package/dist/components/RLSEditor/policyListing.d.ts +44 -0
- package/dist/components/SQLEditor/SQLEditor.d.ts +11 -0
- package/dist/components/SchemaVisualizer/dagre-layout.d.ts +32 -0
- package/dist/components/SchemaVisualizer/dagre-layout.worker.d.ts +13 -0
- package/dist/components/SchemaVisualizer/layout-runner.d.ts +23 -0
- package/dist/components/SchemaVisualizer/schema-visualizer.utils.d.ts +21 -11
- package/dist/components/SchemaVisualizer/useSchemaGraph.d.ts +44 -1
- package/dist/components/StorageView/useVisibleFileMetadata.d.ts +46 -0
- package/dist/components/load-failure.d.ts +1 -1
- package/dist/components/useRunAsUsers.d.ts +25 -0
- package/dist/dagre-layout.worker-j9NbH9Gb.js +27 -0
- package/dist/dagre-layout.worker-j9NbH9Gb.js.map +1 -0
- package/dist/index.es.js +16 -14
- package/dist/index.es.js.map +1 -1
- package/dist/{load-failure-C6OMJSGC.js → load-failure-Bd8lFIO7.js} +2 -2
- package/dist/load-failure-Bd8lFIO7.js.map +1 -0
- package/dist/sql_utils-BZD31xE3.js +478 -0
- package/dist/sql_utils-BZD31xE3.js.map +1 -0
- package/dist/useRunAsUsers-CLaAtXt6.js +122 -0
- package/dist/useRunAsUsers-CLaAtXt6.js.map +1 -0
- package/dist/utils/sql_utils.d.ts +150 -49
- package/package.json +9 -9
- package/dist/ApiExplorer-pYMZflL3.js.map +0 -1
- package/dist/ApiKeysView-qLSs47tw.js +0 -1239
- package/dist/ApiKeysView-qLSs47tw.js.map +0 -1
- package/dist/AuthSimulationSelector-BewmhMBw.js +0 -56
- package/dist/AuthSimulationSelector-BewmhMBw.js.map +0 -1
- package/dist/BackupsView-DYTAD6aW.js +0 -253
- package/dist/BackupsView-DYTAD6aW.js.map +0 -1
- package/dist/BranchesView-D6Sz1a5f.js.map +0 -1
- package/dist/CronJobsView-7hjgSYId.js.map +0 -1
- package/dist/JSEditor-qiuwmcvk.js.map +0 -1
- package/dist/LogsExplorer-Xq8K4oo6.js.map +0 -1
- package/dist/RLSEditor-Djh43lBE.js.map +0 -1
- package/dist/SQLEditor-TBw_K6CW.js.map +0 -1
- package/dist/SchemaVisualizer-DtDzIUNy.js.map +0 -1
- package/dist/StorageView-CMG1DOVX.js.map +0 -1
- package/dist/components/ApiKeys/permissions.d.ts +0 -66
- package/dist/load-failure-C6OMJSGC.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ParsedEndpoint } from "./types.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type User } from "@rebasepro/types";
|
|
4
4
|
interface TryItPanelProps {
|
|
5
5
|
endpoint: ParsedEndpoint;
|
|
6
6
|
apiUrl: string;
|
|
@@ -11,6 +11,11 @@ interface TryItPanelProps {
|
|
|
11
11
|
/**
|
|
12
12
|
* Interactive "Try It" panel that lets the user execute API requests
|
|
13
13
|
* using their current JWT token directly from the Studio.
|
|
14
|
+
*
|
|
15
|
+
* An administrator can run a request as another user: it is sent with their
|
|
16
|
+
* own token and the {@link IMPERSONATE_HEADER} header, and the server runs it
|
|
17
|
+
* as that user — their uid and roles, under row-level security — or refuses
|
|
18
|
+
* it. It never runs as the administrator instead.
|
|
14
19
|
*/
|
|
15
20
|
export declare function TryItPanel({ endpoint, apiUrl, getAuthToken, user, basePath }: TryItPanelProps): React.JSX.Element;
|
|
16
21
|
export {};
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type
|
|
3
|
-
|
|
2
|
+
import { type ApiKeyKind, type ApiKeyWithSecret } from "@rebasepro/types";
|
|
3
|
+
import { type ScopeListing, type ScopePlane } from "./scopes.js";
|
|
4
|
+
/** The scope catalogue as the panel holds it: still loading, read, or not readable. */
|
|
5
|
+
export type ScopeListingState = {
|
|
6
|
+
status: "loading";
|
|
7
|
+
} | {
|
|
8
|
+
status: "ready";
|
|
9
|
+
listing: ScopeListing;
|
|
10
|
+
} | {
|
|
11
|
+
status: "failed";
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function PlaneIcon({ plane, className }: {
|
|
15
|
+
plane: ScopePlane;
|
|
16
|
+
className?: string;
|
|
17
|
+
}): React.JSX.Element;
|
|
18
|
+
export declare function CreateApiKeyDialog({ kind, scopeListing, onRetryScopes, onClose, onCreated }: {
|
|
19
|
+
/** A service key for the project, or a personal key for the signed-in account. */
|
|
20
|
+
kind: ApiKeyKind;
|
|
21
|
+
scopeListing: ScopeListingState;
|
|
22
|
+
onRetryScopes: () => void;
|
|
4
23
|
onClose: () => void;
|
|
5
24
|
onCreated: (key: ApiKeyWithSecret) => void;
|
|
6
25
|
}): React.JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the key panel words scopes: plane headings, "every collection", the
|
|
3
|
+
* title over a minting refusal. One place, so the detail panel, the create
|
|
4
|
+
* dialog and the secret confirmation cannot drift apart.
|
|
5
|
+
*
|
|
6
|
+
* Every string is a translation key. A built-in scope's label and description
|
|
7
|
+
* are keys too, derived from the scope (`data:read` →
|
|
8
|
+
* `studio_scope_data_read_label`); an app's own scopes are worded as the app
|
|
9
|
+
* declared them, in the server's catalogue (`GET /auth/scopes`).
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { type ScopeSummary } from "@rebasepro/types";
|
|
14
|
+
import type { HeldScope, KeyErrorCode, ScopePlane } from "./scopes.js";
|
|
15
|
+
/** The panel's `t`, from `useTranslation()`. */
|
|
16
|
+
export type Translate = (key: string, vars?: Record<string, string | number>) => string;
|
|
17
|
+
/** `data:read` → `studio_scope_data_read_label`. */
|
|
18
|
+
export declare function scopeLabelKey(scope: string): string;
|
|
19
|
+
/** `data:read` → `studio_scope_data_read_description`. */
|
|
20
|
+
export declare function scopeDescriptionKey(scope: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* The catalogue in the panel's language. Built-in scopes are translated; an
|
|
23
|
+
* app scope keeps the label its app declared, and a built-in scope this panel
|
|
24
|
+
* has no key for (one the server added since) keeps the server's wording
|
|
25
|
+
* rather than rendering blank or as a key.
|
|
26
|
+
*/
|
|
27
|
+
export declare function localizeScopes(t: Translate, catalogue: readonly ScopeSummary[]): ScopeSummary[];
|
|
28
|
+
export declare function planeLabel(t: Translate, plane: ScopePlane): string;
|
|
29
|
+
export declare function planeHint(t: Translate, plane: ScopePlane): string;
|
|
30
|
+
/** "Every collection", "Every storage source", "Every function", "Any project". */
|
|
31
|
+
export declare function everyTargetLabel(t: Translate, targetKind: string): string;
|
|
32
|
+
/** One target as a person reads it: the default storage source is "Default bucket", not `(default)`. */
|
|
33
|
+
export declare function targetLabel(t: Translate, targetKind: string | undefined, target: string): string;
|
|
34
|
+
/** A held scope as one line: "Read data — posts, authors", "Read data — every collection", "Read server logs". */
|
|
35
|
+
export declare function heldScopeLine(t: Translate, held: HeldScope): string;
|
|
36
|
+
/** The title over a refused create; the server's own message goes underneath. */
|
|
37
|
+
export declare function keyErrorTitle(t: Translate, code: KeyErrorCode | null): string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of the API-key panel: reading a key's scopes back as groups a
|
|
3
|
+
* person can scan, and turning the create dialog's picker into the scope list
|
|
4
|
+
* the server mints.
|
|
5
|
+
*
|
|
6
|
+
* The vocabulary itself — what a scope is, which ones take a target, which
|
|
7
|
+
* plane each belongs to — is `@rebasepro/types`' `scopes.ts`, the same module
|
|
8
|
+
* the server enforces with. Nothing here re-derives it; this file only shapes
|
|
9
|
+
* it for the screen, so it can be tested without rendering one.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { type ScopeSummary } from "@rebasepro/types";
|
|
14
|
+
/** Which plane a scope belongs to, as `GET /auth/scopes` names it. */
|
|
15
|
+
export type ScopePlane = ScopeSummary["plane"];
|
|
16
|
+
/** The planes in the order the panel shows them. */
|
|
17
|
+
export declare const SCOPE_PLANES: readonly ScopePlane[];
|
|
18
|
+
/** One scope a key holds, with every target it holds it on. */
|
|
19
|
+
export interface HeldScope {
|
|
20
|
+
/** `resource:action`, without a target. */
|
|
21
|
+
scope: string;
|
|
22
|
+
label: string;
|
|
23
|
+
description: string;
|
|
24
|
+
plane: ScopePlane;
|
|
25
|
+
/** What a target names — `collection`, `bucket`, `function`, or an app's own word. */
|
|
26
|
+
targetKind?: string;
|
|
27
|
+
/** `"all"` for the unqualified grant, otherwise the targets it is narrowed to. */
|
|
28
|
+
targets: "all" | string[];
|
|
29
|
+
}
|
|
30
|
+
export interface ScopeGroup {
|
|
31
|
+
plane: ScopePlane;
|
|
32
|
+
scopes: HeldScope[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A key's scopes, grouped by plane and folded per scope: `data:read:posts` and
|
|
36
|
+
* `data:read:authors` read as one "Read data" row narrowed to two collections,
|
|
37
|
+
* and `data:read` beside them as the same row on every collection.
|
|
38
|
+
*
|
|
39
|
+
* Ordered the way the catalogue lists scopes; a scope the catalogue does not
|
|
40
|
+
* know (an app scope removed since the key was minted) keeps its raw name and
|
|
41
|
+
* lands at the end of the plane it would belong to.
|
|
42
|
+
*/
|
|
43
|
+
export declare function groupKeyScopes(scopes: readonly string[], catalogue?: readonly ScopeSummary[]): ScopeGroup[];
|
|
44
|
+
/** Never offered: a key that manages keys could mint its own successor. */
|
|
45
|
+
export declare function isKeyManagementScope(scope: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The catalogue entries a caller may put on a key: the ones they hold, on at
|
|
48
|
+
* least one target, minus key management. The server refuses anything else
|
|
49
|
+
* (`SCOPE_EXCEEDS_CREATOR`, `KEY_MANAGEMENT_SCOPE`), so offering it would only
|
|
50
|
+
* be a way to fail.
|
|
51
|
+
*/
|
|
52
|
+
export declare function grantableScopes(catalogue: readonly ScopeSummary[], held: readonly string[]): ScopeSummary[];
|
|
53
|
+
/** For one chosen scope: every target, or only the listed ones. */
|
|
54
|
+
export type TargetChoice = {
|
|
55
|
+
mode: "all";
|
|
56
|
+
} | {
|
|
57
|
+
mode: "some";
|
|
58
|
+
targets: string[];
|
|
59
|
+
};
|
|
60
|
+
/** The chosen scopes, keyed by `resource:action`. A scope absent here is not chosen. */
|
|
61
|
+
export type ScopeSelection = Readonly<Record<string, TargetChoice>>;
|
|
62
|
+
/** `data:read` on everything — the narrowest useful key, and what the dialog opens with. */
|
|
63
|
+
export declare function defaultSelection(grantable: readonly ScopeSummary[]): ScopeSelection;
|
|
64
|
+
/**
|
|
65
|
+
* The scope strings a selection mints, in catalogue order when one is given.
|
|
66
|
+
*
|
|
67
|
+
* A scope on every target is sent unqualified; one narrowed to targets is sent
|
|
68
|
+
* once per target. A scope narrowed to no target at all grants nothing and is
|
|
69
|
+
* left out — {@link incompleteScopes} is how the dialog says so.
|
|
70
|
+
*/
|
|
71
|
+
export declare function buildScopeList(selection: ScopeSelection, order?: readonly string[]): string[];
|
|
72
|
+
/** Scopes switched to "only some" with nothing chosen yet. */
|
|
73
|
+
export declare function incompleteScopes(selection: ScopeSelection): string[];
|
|
74
|
+
/** Free text in a target field: commas or whitespace separate entries. */
|
|
75
|
+
export declare function splitList(text: string): string[];
|
|
76
|
+
/**
|
|
77
|
+
* The roles a service key runs as beside `service`: the picked ones, then any
|
|
78
|
+
* typed ones, deduplicated. `service` itself is every service key's identity
|
|
79
|
+
* already, so listing it adds nothing and is dropped, as the server does.
|
|
80
|
+
*/
|
|
81
|
+
export declare function combineRoles(picked: readonly string[], typed: string): string[];
|
|
82
|
+
export declare const EXPIRY_CHOICES: readonly ["never", "7d", "30d", "90d", "1y"];
|
|
83
|
+
export type ExpiryChoice = (typeof EXPIRY_CHOICES)[number];
|
|
84
|
+
export declare function isExpiryChoice(value: string): value is ExpiryChoice;
|
|
85
|
+
/** The `expires_at` an expiry choice sends: an ISO instant, or null for never. */
|
|
86
|
+
export declare function expiresAtFor(choice: ExpiryChoice, now?: number): string | null;
|
|
87
|
+
/** The `rate_limit` a rate-limit field sends: a positive integer, or null for the server default. */
|
|
88
|
+
export declare function rateLimitFrom(text: string): number | null;
|
|
89
|
+
/** The minting refusals the dialog names, beside the server's own message. */
|
|
90
|
+
export declare const KEY_ERROR_CODES: readonly ["INVALID_SCOPES", "SCOPE_EXCEEDS_CREATOR", "ROLE_EXCEEDS_CREATOR", "UNKNOWN_SCOPE_TARGET", "KEY_MANAGEMENT_SCOPE"];
|
|
91
|
+
export type KeyErrorCode = (typeof KEY_ERROR_CODES)[number];
|
|
92
|
+
export interface KeyError {
|
|
93
|
+
/** One of {@link KEY_ERROR_CODES}, or null for anything else. */
|
|
94
|
+
code: KeyErrorCode | null;
|
|
95
|
+
/** The server's message, never re-worded. */
|
|
96
|
+
message: string;
|
|
97
|
+
}
|
|
98
|
+
export declare function readKeyError(error: unknown): KeyError;
|
|
99
|
+
/** The backend answered `403 PERSONAL_KEYS_DISABLED`: the app has not switched them on. */
|
|
100
|
+
export declare function isPersonalKeysDisabled(error: unknown): boolean;
|
|
101
|
+
/** What `GET /auth/scopes` answers. */
|
|
102
|
+
export interface ScopeListing {
|
|
103
|
+
scopes: ScopeSummary[];
|
|
104
|
+
held: string[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Read `GET /auth/scopes`. Null for anything that is not that shape — a backend
|
|
108
|
+
* older than scopes answers this route with something else, and offering a
|
|
109
|
+
* picker built from it would offer scopes the server does not know.
|
|
110
|
+
*/
|
|
111
|
+
export declare function readScopeListing(body: unknown): ScopeListing | null;
|
|
112
|
+
/** Function names out of `GET /functions` — `{ functions: [{ name }] }`. */
|
|
113
|
+
export declare function functionNamesFrom(body: unknown): string[];
|
|
@@ -7,6 +7,10 @@ export interface AuthSimulationSelectorProps {
|
|
|
7
7
|
setSelectedUser: (user: SelectableUser | null) => void;
|
|
8
8
|
users: SelectableUser[];
|
|
9
9
|
loading?: boolean;
|
|
10
|
+
/** For a caller that searches `users` on the server — see `UserSelectPopover`. */
|
|
11
|
+
onUserSearchTextChange?: (searchText: string) => void;
|
|
12
|
+
/** How many users that search matched, when `users` is only its first page — see `UserSelectPopover`. */
|
|
13
|
+
userTotalCount?: number;
|
|
10
14
|
currentUser: SelectableUser | null;
|
|
11
15
|
}
|
|
12
|
-
export declare function AuthSimulationSelector({ authMode, setAuthMode, selectedUser, setSelectedUser, users, loading, currentUser }: AuthSimulationSelectorProps): React.JSX.Element;
|
|
16
|
+
export declare function AuthSimulationSelector({ authMode, setAuthMode, selectedUser, setSelectedUser, users, loading, onUserSearchTextChange, userTotalCount, currentUser }: AuthSimulationSelectorProps): React.JSX.Element;
|
|
@@ -52,6 +52,15 @@ export interface LogTail {
|
|
|
52
52
|
* a tail with a hole in it that says so beats one that silently lies.
|
|
53
53
|
*/
|
|
54
54
|
dropped: number;
|
|
55
|
+
/**
|
|
56
|
+
* The server process whose log this is, as its stream names it — `null`
|
|
57
|
+
* until the stream says, and against a server that does not.
|
|
58
|
+
*
|
|
59
|
+
* Each process keeps its own log in memory, so with several replicas (or
|
|
60
|
+
* split runtime roles) this view shows one of them, and a reconnect can
|
|
61
|
+
* land on another.
|
|
62
|
+
*/
|
|
63
|
+
instance: string | null;
|
|
55
64
|
}
|
|
56
65
|
/**
|
|
57
66
|
* Tail the server's log buffer.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CollectionConfig, PostgresPolicy } from "@rebasepro/types";
|
|
2
|
+
/** A part of a policy the database can hold differently from its declaration. */
|
|
3
|
+
export type PolicyDriftField = "roles" | "command" | "mode" | "USING" | "WITH CHECK";
|
|
4
|
+
/** A row of the RLS editor's policy list. */
|
|
5
|
+
export interface ListedPolicy extends PostgresPolicy {
|
|
6
|
+
/**
|
|
7
|
+
* What the project's code compiles this policy to, when it declares one by
|
|
8
|
+
* this name. For a policy the database also has, the row's own fields are
|
|
9
|
+
* the database's and this is what they are compared against.
|
|
10
|
+
*/
|
|
11
|
+
declared?: PostgresPolicy;
|
|
12
|
+
/** Where the database's policy differs from {@link declared}. Empty when it does not. */
|
|
13
|
+
drift?: PolicyDriftField[];
|
|
14
|
+
/**
|
|
15
|
+
* Rebase adds this policy itself — the admin baseline, a tenancy or
|
|
16
|
+
* auth-write gate, a junction's derived policies — so no rule of the
|
|
17
|
+
* author's holds it, and the next server start re-creates it.
|
|
18
|
+
*/
|
|
19
|
+
generated?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Where a live policy differs from the one the code compiles to.
|
|
23
|
+
*
|
|
24
|
+
* The same comparison `rebase doctor` makes: the `TO` list, the command, the
|
|
25
|
+
* mode, and whether each clause is there at all. Never the clause text —
|
|
26
|
+
* Postgres rewrites an expression when it stores it, so the text of a policy
|
|
27
|
+
* that matches its declaration exactly still differs from the declaration's.
|
|
28
|
+
* A clause that is missing is not a rewrite, though: a `USING` that is gone
|
|
29
|
+
* changes who the policy admits.
|
|
30
|
+
*/
|
|
31
|
+
export declare function policyDrift(declared: PostgresPolicy, live: PostgresPolicy): PolicyDriftField[];
|
|
32
|
+
/**
|
|
33
|
+
* The policies of one table: every policy the database has, as the database
|
|
34
|
+
* has it, and every policy the code declares for the table that it does not.
|
|
35
|
+
*
|
|
36
|
+
* A policy in both keeps the database's fields — this list is what Postgres
|
|
37
|
+
* enforces — and carries the declaration beside them, with where the two
|
|
38
|
+
* differ.
|
|
39
|
+
*
|
|
40
|
+
* @param live The table's `pg_policies` rows.
|
|
41
|
+
* @param collection The collection the table belongs to, if any.
|
|
42
|
+
* @param collections Every collection, to resolve the ones a rule refers to.
|
|
43
|
+
*/
|
|
44
|
+
export declare function listPolicies(live: readonly PostgresPolicy[], collection: CollectionConfig | null, tableName: string, collections: readonly CollectionConfig[]): ListedPolicy[];
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { SQLEditorColumnInfo, TableInfo } from "./sql_editor_types.js";
|
|
3
3
|
export type { SQLEditorColumnInfo, TableInfo };
|
|
4
|
+
/**
|
|
5
|
+
* The box a result cell is edited in. It closes once: Enter saves, Escape
|
|
6
|
+
* cancels, a click away saves — and the blur a closing box can still receive
|
|
7
|
+
* is not a second answer, which made Enter save twice and Escape save at all.
|
|
8
|
+
*/
|
|
9
|
+
export declare const FixedEditorOverlay: ({ displayValue, onSave, onCancel }: {
|
|
10
|
+
displayValue: string;
|
|
11
|
+
/** What the box holds when it closes — the text as typed. */
|
|
12
|
+
onSave: (val: string) => void;
|
|
13
|
+
onCancel: () => void;
|
|
14
|
+
}) => React.JSX.Element;
|
|
4
15
|
export declare const SQLEditor: () => React.JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the layout reads, as plain data: each table's id and box, each
|
|
3
|
+
* relation's ends. Plain so it can cross into the layout worker unchanged.
|
|
4
|
+
*/
|
|
5
|
+
export interface LayoutInput {
|
|
6
|
+
nodes: {
|
|
7
|
+
id: string;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}[];
|
|
11
|
+
edges: {
|
|
12
|
+
source: string;
|
|
13
|
+
target: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
/** Each table's top-left corner, by node id. */
|
|
17
|
+
export type LayoutPositions = Record<string, {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Place the graph with dagre, top to bottom.
|
|
23
|
+
*
|
|
24
|
+
* An ERD read as a column of tables fits the tall, narrow canvas the
|
|
25
|
+
* visualizer is given, and it is the only layout the visualizer offers.
|
|
26
|
+
* Deterministic: the same input always gives the same positions.
|
|
27
|
+
*
|
|
28
|
+
* The cost is in dagre's ordering phase and grows fast with cross-linked
|
|
29
|
+
* graphs — 5 s at 200 tables with two relations each, 90 s at 500 — which is
|
|
30
|
+
* why the visualizer runs this in a worker (`dagre-layout.worker.ts`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function runDagre(input: LayoutInput): LayoutPositions;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schema visualizer's layout, off the main thread.
|
|
3
|
+
*
|
|
4
|
+
* Receives one {@link LayoutInput}, answers with its positions (or the error's
|
|
5
|
+
* message). Bundled with dagre by the `?worker&inline` import in
|
|
6
|
+
* `layout-runner.ts`, so it needs nothing from the page that starts it.
|
|
7
|
+
*/
|
|
8
|
+
import { type LayoutPositions } from "./dagre-layout.js";
|
|
9
|
+
export type LayoutWorkerReply = {
|
|
10
|
+
positions: LayoutPositions;
|
|
11
|
+
} | {
|
|
12
|
+
error: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type LayoutInput, type LayoutPositions } from "./dagre-layout.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether this environment can start the layout worker.
|
|
4
|
+
*
|
|
5
|
+
* No in tests (jsdom has no `Worker`) and on a server render; there the
|
|
6
|
+
* layout runs where it is asked for, as it always did.
|
|
7
|
+
*/
|
|
8
|
+
export declare const canLayOutOffThread: () => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Lay a graph out in a worker of its own, which ends with the layout.
|
|
11
|
+
*
|
|
12
|
+
* The worker is inlined into the bundle (`?worker&inline`) rather than emitted
|
|
13
|
+
* as a file beside it: `@rebasepro/studio` is a library, and a worker file
|
|
14
|
+
* would be found only by an app bundler that rewrites
|
|
15
|
+
* `new URL(…, import.meta.url)` inside dependencies, which Vite's dependency
|
|
16
|
+
* pre-bundling does not. Imported on first use, so a page that never lays a
|
|
17
|
+
* graph out never decodes it.
|
|
18
|
+
*
|
|
19
|
+
* A worker that cannot be started or loaded — a Content-Security-Policy
|
|
20
|
+
* without `blob:` in `worker-src`, say — is not a broken diagram: the layout
|
|
21
|
+
* runs on the main thread instead, as it did before there was a worker.
|
|
22
|
+
*/
|
|
23
|
+
export declare function layOutOffThread(input: LayoutInput): Promise<LayoutPositions>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Node, Edge } from "@xyflow/react";
|
|
2
|
+
import { type LayoutInput, type LayoutPositions } from "./dagre-layout.js";
|
|
2
3
|
export declare const NODE_WIDTH = 280;
|
|
3
4
|
/**
|
|
4
5
|
* Compute the correct header height for a table node.
|
|
@@ -13,19 +14,28 @@ export declare const getHeaderHeight: (opts: {
|
|
|
13
14
|
* relative to the top of the node.
|
|
14
15
|
*/
|
|
15
16
|
export declare const getColumnRowY: (rowIndex: number, headerHeight?: number) => number;
|
|
17
|
+
/** A graph's layout input, and the key its positions are kept under. */
|
|
18
|
+
export interface LayoutPlan {
|
|
19
|
+
input: LayoutInput;
|
|
20
|
+
signature: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* What dagre will be given for these nodes and edges: each node's id and
|
|
24
|
+
* box, each edge's ends, in order. The signature is all of it, so a changed
|
|
25
|
+
* schema — a table, a column count, a relation — is a different key.
|
|
26
|
+
*/
|
|
27
|
+
export declare const planLayout: (nodes: Node[], edges: Edge[]) => LayoutPlan;
|
|
28
|
+
/** The positions for this plan, if it has been laid out before. */
|
|
29
|
+
export declare const cachedLayout: (plan: LayoutPlan) => LayoutPositions | undefined;
|
|
30
|
+
/** Lay the plan out here, on the calling thread. */
|
|
31
|
+
export declare const layOutNow: (plan: LayoutPlan) => LayoutPositions;
|
|
16
32
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* The graph always ranks top to bottom: an ERD read as a column of tables
|
|
21
|
-
* fits the tall, narrow canvas the visualizer is given, and it is the only
|
|
22
|
-
* layout the visualizer offers.
|
|
33
|
+
* Lay the plan out in a worker; the main thread stays free while it runs.
|
|
34
|
+
* See {@link layOutOffThread}.
|
|
23
35
|
*/
|
|
24
|
-
export declare const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
export declare const getTypeLabel: (type: string) => string;
|
|
36
|
+
export declare const layOutInBackground: (plan: LayoutPlan) => Promise<LayoutPositions>;
|
|
37
|
+
/** The nodes at their laid-out positions, as new objects. */
|
|
38
|
+
export declare const placeNodes: (nodes: Node[], positions: LayoutPositions) => Node[];
|
|
29
39
|
export interface RelationEdgeData {
|
|
30
40
|
cardinality: "one" | "many";
|
|
31
41
|
direction: "owning" | "inverse";
|
|
@@ -3,6 +3,12 @@ import type { AdminCollection } from "@rebasepro/cms-types";
|
|
|
3
3
|
export interface ColumnInfo {
|
|
4
4
|
name: string;
|
|
5
5
|
type: string;
|
|
6
|
+
/**
|
|
7
|
+
* The type the collection declares — `string`, `number`, `date`… — or
|
|
8
|
+
* `FK` for a relation's key. Not the database's column type: the diagram
|
|
9
|
+
* is drawn from the collections, and a property's column type depends on
|
|
10
|
+
* more than its `type` (`columnType`, `isId`, integer validation).
|
|
11
|
+
*/
|
|
6
12
|
typeLabel: string;
|
|
7
13
|
isPrimaryKey: boolean;
|
|
8
14
|
isForeignKey: boolean;
|
|
@@ -23,16 +29,53 @@ export interface TableNodeData {
|
|
|
23
29
|
icon?: string;
|
|
24
30
|
[key: string]: unknown;
|
|
25
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Above this many tables the diagram draws one table's neighbourhood, not
|
|
34
|
+
* the whole schema. Laying out 300 cross-linked tables takes dagre several
|
|
35
|
+
* seconds even in a worker, and a canvas of that many tables is no longer
|
|
36
|
+
* something anyone reads.
|
|
37
|
+
*/
|
|
38
|
+
export declare const LARGE_SCHEMA_TABLES = 300;
|
|
39
|
+
/** How far from the focused table the drawn neighbourhood reaches. */
|
|
40
|
+
export type NeighbourhoodDepth = 1 | 2;
|
|
26
41
|
export interface UseSchemaGraphResult {
|
|
42
|
+
/**
|
|
43
|
+
* The tables and relations on the canvas, placed. Empty while
|
|
44
|
+
* {@link layingOut} — the layout of a graph not seen before runs in a
|
|
45
|
+
* worker, never in render.
|
|
46
|
+
*/
|
|
27
47
|
nodes: Node[];
|
|
28
48
|
edges: Edge[];
|
|
49
|
+
/** Every table and junction table in the schema, drawn or not. */
|
|
50
|
+
allNodes: Node[];
|
|
29
51
|
relayout: () => void;
|
|
52
|
+
/** Tables and relations in the whole schema. */
|
|
30
53
|
tableCount: number;
|
|
31
54
|
relationCount: number;
|
|
55
|
+
/** The layout is running off the main thread. */
|
|
56
|
+
layingOut: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Set when the schema has more than {@link LARGE_SCHEMA_TABLES} tables:
|
|
59
|
+
* which table's neighbourhood is drawn, how far it reaches, how many
|
|
60
|
+
* tables that is, and how many there are in all.
|
|
61
|
+
*/
|
|
62
|
+
neighbourhood: {
|
|
63
|
+
focus: string;
|
|
64
|
+
depth: NeighbourhoodDepth;
|
|
65
|
+
shown: number;
|
|
66
|
+
total: number;
|
|
67
|
+
} | null;
|
|
32
68
|
}
|
|
33
69
|
export declare const useSchemaGraph: (collections: AdminCollection[] | undefined,
|
|
34
70
|
/**
|
|
35
71
|
* `schema.table` for every table the database reports RLS on, or `null`
|
|
36
72
|
* when there is no SQL capability to ask. See {@link useLiveRlsTables}.
|
|
37
73
|
*/
|
|
38
|
-
liveRls?: Set<string> | null
|
|
74
|
+
liveRls?: Set<string> | null,
|
|
75
|
+
/**
|
|
76
|
+
* The table whose neighbourhood a large schema draws, by node id. When it
|
|
77
|
+
* is absent, or not a table of this schema, the most connected one. Not
|
|
78
|
+
* read for a schema of {@link LARGE_SCHEMA_TABLES} tables or fewer, which
|
|
79
|
+
* is drawn whole.
|
|
80
|
+
*/
|
|
81
|
+
focus?: string | null, depth?: NeighbourhoodDepth) => UseSchemaGraphResult;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { DownloadConfig, StorageSource } from "@rebasepro/types";
|
|
2
|
+
/**
|
|
3
|
+
* What the storage browser shows of a file beyond its name. The listing carries
|
|
4
|
+
* the size and version — and, except on S3, the type — of every file; the rest
|
|
5
|
+
* is read per file, from the server, when it is needed.
|
|
6
|
+
*/
|
|
7
|
+
export interface FileMetadata {
|
|
8
|
+
size?: number;
|
|
9
|
+
contentType?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A link minted when the metadata was read, for the thumbnail only: a
|
|
12
|
+
* private file's token expires, and a link to share or download is minted
|
|
13
|
+
* when it is used (see `FileLink` in `StorageView.tsx`).
|
|
14
|
+
*/
|
|
15
|
+
downloadUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function fileMetadataOf(config: DownloadConfig): FileMetadata;
|
|
18
|
+
/**
|
|
19
|
+
* How many metadata requests run at once: what one origin gets over HTTP/1.1.
|
|
20
|
+
* Each is a round trip to the server, an auth hook and a HEAD on the bucket.
|
|
21
|
+
*/
|
|
22
|
+
export declare const METADATA_CONCURRENCY = 6;
|
|
23
|
+
/**
|
|
24
|
+
* Metadata for the files of a listing, asked for as each comes on screen —
|
|
25
|
+
* and only for those `wants` says need it: the listing already describes most
|
|
26
|
+
* files (see `StorageReference.size`), so what is left is a file a source
|
|
27
|
+
* listed bare, and the link an image's thumbnail is drawn from.
|
|
28
|
+
*
|
|
29
|
+
* The browser used to ask for every file's metadata before it showed any of
|
|
30
|
+
* them: a folder of 1,000 files was 1,001 requests and seconds of a spinner.
|
|
31
|
+
* The listing is shown as it comes back; a file's metadata is asked for when
|
|
32
|
+
* its element — given {@link observe} as its `ref`, and its path as
|
|
33
|
+
* `data-storage-path` — scrolls into view, a few requests at a time.
|
|
34
|
+
*
|
|
35
|
+
* Kept per listing: keyed by path, and dropped when `files` or `source`
|
|
36
|
+
* changes — another folder, another source, or the same folder read again
|
|
37
|
+
* after an upload or a delete, whose files may have changed. Without an
|
|
38
|
+
* `IntersectionObserver` every file of the listing is asked for, still a few
|
|
39
|
+
* at a time and still after the listing is shown.
|
|
40
|
+
*/
|
|
41
|
+
export declare function useVisibleFileMetadata<F extends {
|
|
42
|
+
fullPath: string;
|
|
43
|
+
}>(source: StorageSource | null, files: readonly F[], wants?: (file: F) => boolean): {
|
|
44
|
+
metadata: ReadonlyMap<string, FileMetadata>;
|
|
45
|
+
observe: (element: HTMLElement | null) => (() => void) | undefined;
|
|
46
|
+
};
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
export type LoadFailureKind =
|
|
36
36
|
/** The project's own rules, or the caller's own role, said no. Not an error. */
|
|
37
37
|
"denied"
|
|
38
|
-
/** We could not reach or read the source. */
|
|
38
|
+
/** We could not reach or read the source — including a session the server no longer accepts. */
|
|
39
39
|
| "unavailable";
|
|
40
40
|
export interface LoadFailure {
|
|
41
41
|
kind: LoadFailureKind;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type SelectableUser } from "@rebasepro/app";
|
|
2
|
+
export interface RunAsUsers {
|
|
3
|
+
/** The signed-in user first, then the users the latest search found. */
|
|
4
|
+
users: SelectableUser[];
|
|
5
|
+
/** The signed-in user, the picker's "self" row. */
|
|
6
|
+
currentUser: SelectableUser | null;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
/** Search the project's users on the server. */
|
|
9
|
+
onSearchTextChange: (searchText: string) => void;
|
|
10
|
+
/**
|
|
11
|
+
* How many users the latest search matched on the server, set only when
|
|
12
|
+
* that is more than the one page listed — so the picker can say so rather
|
|
13
|
+
* than present the page as everyone.
|
|
14
|
+
*/
|
|
15
|
+
totalCount?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The users a "Run as" picker offers.
|
|
19
|
+
*
|
|
20
|
+
* The signed-in user, and — for an administrator, the only caller the server
|
|
21
|
+
* lets run a request as someone else — the project's users, searched on the
|
|
22
|
+
* server. Disabled accounts are left out: nothing can run as them, and the
|
|
23
|
+
* server refuses them.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useRunAsUsers(): RunAsUsers;
|