@antelopejs/dms-database 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -10
- package/dist/automation/tableWatch.d.ts +2 -2
- package/dist/automation/tableWatch.js +3 -3
- package/dist/automation/tableWatch.js.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -1
- package/dist/connectionAccess.d.ts +3 -0
- package/dist/connectionAccess.js +20 -0
- package/dist/connectionAccess.js.map +1 -0
- package/dist/db/models/connection_selections.model.d.ts +27 -0
- package/dist/db/models/connection_selections.model.js +17 -0
- package/dist/db/models/connection_selections.model.js.map +1 -0
- package/dist/db/models/diagram_layouts.model.d.ts +4 -4
- package/dist/db/models/diagram_layouts.model.js +14 -12
- package/dist/db/models/diagram_layouts.model.js.map +1 -1
- package/dist/db/models/diagram_notes.model.d.ts +3 -3
- package/dist/db/models/index.d.ts +1 -0
- package/dist/db/models/index.js +1 -0
- package/dist/db/models/index.js.map +1 -1
- package/dist/db/models/query_history.model.d.ts +3 -3
- package/dist/db/models/saved_queries.model.d.ts +3 -3
- package/dist/db/tables/connection_selections.table.d.ts +6 -0
- package/dist/db/tables/connection_selections.table.js +30 -0
- package/dist/db/tables/connection_selections.table.js.map +1 -0
- package/dist/db/tables/index.d.ts +1 -0
- package/dist/db/tables/index.js +1 -0
- package/dist/db/tables/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/pages/externalLock.d.ts +8 -0
- package/dist/pages/externalLock.js +32 -0
- package/dist/pages/externalLock.js.map +1 -0
- package/dist/pages/overview.js +6 -3
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/schemas.js +6 -2
- package/dist/pages/schemas.js.map +1 -1
- package/dist/routes/connections.d.ts +14 -0
- package/dist/routes/connections.js +116 -0
- package/dist/routes/connections.js.map +1 -0
- package/dist/routes/data.d.ts +10 -9
- package/dist/routes/data.js +43 -62
- package/dist/routes/data.js.map +1 -1
- package/dist/routes/diagram.d.ts +6 -6
- package/dist/routes/diagram.js +16 -6
- package/dist/routes/diagram.js.map +1 -1
- package/dist/routes/health.d.ts +1 -1
- package/dist/routes/health.js +3 -2
- package/dist/routes/health.js.map +1 -1
- package/dist/routes/index.d.ts +1 -0
- package/dist/routes/index.js +1 -0
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/overview.d.ts +2 -2
- package/dist/routes/overview.js +11 -4
- package/dist/routes/overview.js.map +1 -1
- package/dist/routes/query.d.ts +1 -1
- package/dist/routes/query.js +26 -10
- package/dist/routes/query.js.map +1 -1
- package/dist/routes/schemas.d.ts +1 -1
- package/dist/routes/schemas.js +4 -2
- package/dist/routes/schemas.js.map +1 -1
- package/dist/routes/tables.d.ts +2 -1
- package/dist/routes/tables.js +29 -21
- package/dist/routes/tables.js.map +1 -1
- package/dist/service/browse.d.ts +14 -6
- package/dist/service/browse.js +120 -18
- package/dist/service/browse.js.map +1 -1
- package/dist/service/catalog.js +2 -1
- package/dist/service/catalog.js.map +1 -1
- package/dist/service/connectionState.d.ts +29 -0
- package/dist/service/connectionState.js +157 -0
- package/dist/service/connectionState.js.map +1 -0
- package/dist/service/connections.d.ts +12 -0
- package/dist/service/connections.js +72 -0
- package/dist/service/connections.js.map +1 -0
- package/dist/service/database.d.ts +12 -0
- package/dist/service/database.js +30 -0
- package/dist/service/database.js.map +1 -0
- package/dist/service/declaredFields.d.ts +3 -2
- package/dist/service/declaredFields.js +6 -7
- package/dist/service/declaredFields.js.map +1 -1
- package/dist/service/health.d.ts +2 -1
- package/dist/service/health.js +48 -21
- package/dist/service/health.js.map +1 -1
- package/dist/service/introspect.d.ts +7 -5
- package/dist/service/introspect.js +50 -47
- package/dist/service/introspect.js.map +1 -1
- package/dist/service/overview.d.ts +3 -2
- package/dist/service/overview.js +4 -4
- package/dist/service/overview.js.map +1 -1
- package/dist/service/queryInspection.js +6 -3
- package/dist/service/queryInspection.js.map +1 -1
- package/dist/service/references.d.ts +3 -2
- package/dist/service/references.js +9 -8
- package/dist/service/references.js.map +1 -1
- package/dist/service/rowEdit.d.ts +3 -0
- package/dist/service/rowEdit.js +36 -3
- package/dist/service/rowEdit.js.map +1 -1
- package/dist/service/stagedSerialization.js +5 -2
- package/dist/service/stagedSerialization.js.map +1 -1
- package/dist/service/types.d.ts +1 -1
- package/dist/utils/deadline.d.ts +2 -0
- package/dist/utils/deadline.js +18 -0
- package/dist/utils/deadline.js.map +1 -0
- package/dist/utils/guards.d.ts +2 -0
- package/dist/utils/guards.js +8 -0
- package/dist/utils/guards.js.map +1 -1
- package/dist/utils/query.js +5 -4
- package/dist/utils/query.js.map +1 -1
- package/frontend-vue/app/build/components/DataBrowserAccessBar.vue +88 -0
- package/frontend-vue/app/build/components/DataGridToolbar.vue +10 -5
- package/frontend-vue/app/build/components/FeatureLocked.vue +16 -0
- package/frontend-vue/app/build/components/QueryConsoleBoard.vue +601 -0
- package/frontend-vue/app/build/components/SchemaDiagramBoard.vue +691 -0
- package/frontend-vue/app/build/composables/registerDatabaseSwitcher.ts +16 -0
- package/frontend-vue/app/build/composables/reloadForSelection.ts +13 -0
- package/frontend-vue/app/build/composables/useDataBrowserTabs.ts +9 -0
- package/frontend-vue/app/build/composables/useDatabaseConnections.ts +164 -0
- package/frontend-vue/app/build/composables/useGridAccess.ts +25 -0
- package/frontend-vue/app/build/composables/useLockedPages.ts +53 -0
- package/frontend-vue/app/build/composables/useQueryRuntime.ts +4 -4
- package/frontend-vue/app/build/composables/useSelectionRecheck.ts +23 -0
- package/frontend-vue/app/build/data/assistantOnboarding.ts +12 -0
- package/frontend-vue/app/build/data/readOnlyReason.ts +30 -0
- package/frontend-vue/app/build/data/recentTables.ts +6 -0
- package/frontend-vue/app/build/data/staleDatabase.ts +58 -0
- package/frontend-vue/app/build/data/useStagedSave.ts +10 -1
- package/frontend-vue/app/components/DataBrowser.vue +9 -1
- package/frontend-vue/app/components/DataBrowserSidebar.vue +23 -13
- package/frontend-vue/app/components/DataGrid.vue +17 -6
- package/frontend-vue/app/components/DataGridCell.vue +5 -2
- package/frontend-vue/app/components/DatabaseSwitcher.vue +103 -0
- package/frontend-vue/app/components/QueryBuilderPanel.vue +4 -4
- package/frontend-vue/app/components/QueryConsole.vue +11 -592
- package/frontend-vue/app/components/QueryLibrary.vue +3 -3
- package/frontend-vue/app/components/QueryResultPanel.vue +14 -12
- package/frontend-vue/app/components/RowDrawer.vue +21 -14
- package/frontend-vue/app/components/SchemaDiagram.vue +10 -683
- package/frontend-vue/app/components/SchemasFilterBar.vue +3 -0
- package/frontend-vue/app/components/TableInspector.vue +8 -4
- package/frontend-vue/build/backend-boundary.ts +8 -3
- package/frontend-vue/dms.frontend.ts +2 -0
- package/frontend-vue/eslint.config.mjs +0 -1
- package/frontend-vue/i18n/locales/database-en-GB.json +31 -1
- package/frontend-vue/i18n/locales/database-fr-FR.json +31 -1
- package/frontend-vue/package.json +3 -3
- package/frontend-vue/pnpm-lock.yaml +14 -11
- package/frontend-vue/tests/accessBar.test.ts +196 -0
- package/frontend-vue/tests/backend-boundary.test.ts +15 -7
- package/frontend-vue/tests/databaseSwitcher.test.ts +339 -0
- package/frontend-vue/tests/editRequest.test.ts +146 -0
- package/frontend-vue/tests/externalBrowser.test.ts +193 -0
- package/frontend-vue/tests/fixtures/connections.ts +73 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +135 -12
- package/frontend-vue/tests/lockedPages.test.ts +68 -0
- package/frontend-vue/tests/onDemandReads.test.ts +1 -1
- package/frontend-vue/tests/registration.test.ts +15 -1
- package/frontend-vue/tests/serverRender.test.ts +58 -4
- package/frontend-vue/tsconfig.json +1 -2
- package/frontend-vue/vitest.config.ts +11 -1
- package/package.json +20 -16
- package/dist/service/schemaRegistry.d.ts +0 -2
- package/dist/service/schemaRegistry.js +0 -8
- package/dist/service/schemaRegistry.js.map +0 -1
|
@@ -64,6 +64,15 @@ function browserTabId(schema: string, instance: string, table: string): string {
|
|
|
64
64
|
return `${schema}::${instance}::${table}`
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Drops the tabs this browser tab kept: they name tables of the database
|
|
69
|
+
* that was browsed, which the next one may not hold.
|
|
70
|
+
*/
|
|
71
|
+
export function forgetBrowserTabs(): void {
|
|
72
|
+
if (typeof window === 'undefined') return
|
|
73
|
+
window.sessionStorage.removeItem(STORAGE_KEY)
|
|
74
|
+
}
|
|
75
|
+
|
|
67
76
|
interface PersistedTabs {
|
|
68
77
|
tabs: BrowserTab[]
|
|
69
78
|
activeId: string | null
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { reloadForSelection } from './reloadForSelection'
|
|
2
|
+
|
|
3
|
+
/** A part of the console an external database cannot serve. */
|
|
4
|
+
export type ConnectionFeature =
|
|
5
|
+
| 'diagram'
|
|
6
|
+
| 'queryConsole'
|
|
7
|
+
| 'instances'
|
|
8
|
+
| 'rowReferences'
|
|
9
|
+
| 'schemaEdits'
|
|
10
|
+
| 'migrations'
|
|
11
|
+
| 'indexes'
|
|
12
|
+
|
|
13
|
+
export type ConnectionAccess = 'read' | 'read-write'
|
|
14
|
+
|
|
15
|
+
export interface DatabaseConnection {
|
|
16
|
+
id: string
|
|
17
|
+
kind: 'own' | 'external'
|
|
18
|
+
label: string
|
|
19
|
+
engine: string | null
|
|
20
|
+
access: ConnectionAccess
|
|
21
|
+
/** Null when the catalog could not tell whether the account may write. */
|
|
22
|
+
canWrite: boolean | null
|
|
23
|
+
unsupported: ConnectionFeature[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ConnectionsState {
|
|
27
|
+
/** The connection this user browses: every page of the module follows it. */
|
|
28
|
+
selected: string
|
|
29
|
+
accessEditable: boolean
|
|
30
|
+
connections: DatabaseConnection[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const OWN_CONNECTION = 'own'
|
|
34
|
+
|
|
35
|
+
const CONNECTIONS_ENDPOINT = '/api/database/connections'
|
|
36
|
+
const EMPTY_STATE: ConnectionsState = {
|
|
37
|
+
selected: OWN_CONNECTION,
|
|
38
|
+
accessEditable: false,
|
|
39
|
+
connections: [],
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Whether the connection is one the console reaches through the catalog. */
|
|
43
|
+
export function isExternal(
|
|
44
|
+
connection: DatabaseConnection | undefined,
|
|
45
|
+
): connection is DatabaseConnection {
|
|
46
|
+
return connection?.kind === 'external'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Whether the connection lists the feature as one it cannot serve. */
|
|
50
|
+
export function lacksFeature(
|
|
51
|
+
connection: DatabaseConnection | undefined,
|
|
52
|
+
feature: ConnectionFeature,
|
|
53
|
+
): boolean {
|
|
54
|
+
return connection?.unsupported.includes(feature) ?? false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether the connection refuses edits: an external one left on read. */
|
|
58
|
+
export function refusesEdits(
|
|
59
|
+
connection: DatabaseConnection | undefined,
|
|
60
|
+
): boolean {
|
|
61
|
+
return isExternal(connection) && connection.access === 'read'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function useDatabaseConnections() {
|
|
65
|
+
const read = useApiData<ConnectionsState>(CONNECTIONS_ENDPOINT, {
|
|
66
|
+
default: () => EMPTY_STATE,
|
|
67
|
+
})
|
|
68
|
+
const { $authFetch } = useAuthFetch()
|
|
69
|
+
const { presentError } = useApiErrorPresenter()
|
|
70
|
+
|
|
71
|
+
const state = computed(() => read.data.value ?? EMPTY_STATE)
|
|
72
|
+
const connections = computed(() => state.value.connections)
|
|
73
|
+
const selected = computed(() =>
|
|
74
|
+
connections.value.find(
|
|
75
|
+
(connection) => connection.id === state.value.selected,
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
const failed = computed(() => read.status.value === 'error')
|
|
80
|
+
|
|
81
|
+
async function write(
|
|
82
|
+
path: string,
|
|
83
|
+
body: object,
|
|
84
|
+
fallbackKey: string,
|
|
85
|
+
keepsSelection: boolean,
|
|
86
|
+
): Promise<boolean> {
|
|
87
|
+
try {
|
|
88
|
+
const next = await $authFetch<ConnectionsState>(
|
|
89
|
+
`${CONNECTIONS_ENDPOINT}/${path}`,
|
|
90
|
+
{ method: 'PUT', body },
|
|
91
|
+
)
|
|
92
|
+
if (keepsSelection && next.selected !== state.value.selected) {
|
|
93
|
+
reloadForSelection()
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
read.data.value = next
|
|
97
|
+
return true
|
|
98
|
+
} catch (error) {
|
|
99
|
+
presentError(error, { fallbackKey })
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let rechecking: Promise<void> | null = null
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
connections,
|
|
108
|
+
selected,
|
|
109
|
+
accessEditable: computed(() => state.value.accessEditable),
|
|
110
|
+
external: computed(() => isExternal(selected.value)),
|
|
111
|
+
refusesEdits: computed(() => failed.value || refusesEdits(selected.value)),
|
|
112
|
+
lacks: (feature: ConnectionFeature) =>
|
|
113
|
+
lacksFeature(selected.value, feature),
|
|
114
|
+
/** Whether the connections could not be read: no database is known, so no edit is safe. */
|
|
115
|
+
failed,
|
|
116
|
+
/**
|
|
117
|
+
* Stores the connection this user browses; true once the server took
|
|
118
|
+
* it, and every API of the module answers for it from then on.
|
|
119
|
+
*/
|
|
120
|
+
select: (id: string) =>
|
|
121
|
+
write(
|
|
122
|
+
'selected',
|
|
123
|
+
{ connection: id },
|
|
124
|
+
'dms_database.connections.switcher.failed',
|
|
125
|
+
false,
|
|
126
|
+
),
|
|
127
|
+
/**
|
|
128
|
+
* Allows or refuses the edits of an external connection. Reloads the
|
|
129
|
+
* page instead when the server's selection is no longer the one this
|
|
130
|
+
* page loaded with.
|
|
131
|
+
*/
|
|
132
|
+
setAccess: (id: string, access: ConnectionAccess) =>
|
|
133
|
+
write(
|
|
134
|
+
`${encodeURIComponent(id)}/access`,
|
|
135
|
+
{ access },
|
|
136
|
+
'dms_database.connections.access.failed',
|
|
137
|
+
true,
|
|
138
|
+
),
|
|
139
|
+
/**
|
|
140
|
+
* Reads the connections again, apart from the page's state, and
|
|
141
|
+
* reloads the page when the server's selection is no longer the one
|
|
142
|
+
* it loaded with (another tab switched), or when the first read failed
|
|
143
|
+
* and this one answered. A failed read changes nothing.
|
|
144
|
+
*/
|
|
145
|
+
recheck: (): Promise<void> => {
|
|
146
|
+
rechecking ??= $authFetch<ConnectionsState>(CONNECTIONS_ENDPOINT)
|
|
147
|
+
.then((next) => {
|
|
148
|
+
if (failed.value || next.selected !== state.value.selected)
|
|
149
|
+
reloadForSelection()
|
|
150
|
+
})
|
|
151
|
+
.catch(() => undefined)
|
|
152
|
+
.finally(() => {
|
|
153
|
+
rechecking = null
|
|
154
|
+
})
|
|
155
|
+
return rechecking
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Settles once the first read is in, at once when the connections were
|
|
159
|
+
* read before: a page awaiting it does not fetch for a selection it
|
|
160
|
+
* does not know yet.
|
|
161
|
+
*/
|
|
162
|
+
ready: read.then(() => undefined),
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useDatabaseConnections } from './useDatabaseConnections'
|
|
2
|
+
import { CROSS_INSTANCE_VALUE, type BrowserTab } from './useDataBrowserTabs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a grid may do, by its tab's instance and the database browsed: the
|
|
6
|
+
* cross-instance union and an external database left on read take no edit,
|
|
7
|
+
* and an external database offers no instance, row reference or query console.
|
|
8
|
+
*/
|
|
9
|
+
export function useGridAccess(tab: () => BrowserTab) {
|
|
10
|
+
const { refusesEdits, lacks } = useDatabaseConnections()
|
|
11
|
+
const crossInstance = computed(() => tab().instance === CROSS_INSTANCE_VALUE)
|
|
12
|
+
const readOnly = computed(() => crossInstance.value || refusesEdits.value)
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
crossInstance,
|
|
16
|
+
readOnly,
|
|
17
|
+
showReferences: computed(
|
|
18
|
+
() => !crossInstance.value && !lacks('rowReferences'),
|
|
19
|
+
),
|
|
20
|
+
canOpenQuery: computed(() => !lacks('queryConsole')),
|
|
21
|
+
canSearchAllInstances: computed(
|
|
22
|
+
() => !readOnly.value && !lacks('instances'),
|
|
23
|
+
),
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
lacksFeature,
|
|
4
|
+
type ConnectionFeature,
|
|
5
|
+
type DatabaseConnection,
|
|
6
|
+
} from './useDatabaseConnections'
|
|
7
|
+
|
|
8
|
+
/** The module's pages an external database cannot serve, by the feature each needs. */
|
|
9
|
+
const LOCKABLE_PAGES: ReadonlyArray<{
|
|
10
|
+
path: string
|
|
11
|
+
feature: ConnectionFeature
|
|
12
|
+
}> = [
|
|
13
|
+
{ path: '/modules/database/diagram', feature: 'diagram' },
|
|
14
|
+
{ path: '/modules/database/query', feature: 'queryConsole' },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
const LOCK_REASON = '$dms_database.connections.locked.reason'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Keeps the sidebar entries of the pages the selected database cannot serve
|
|
21
|
+
* locked, with the reason as their tooltip, and unlocks them once it can.
|
|
22
|
+
* Applied once mounted: the server renders the sidebar before it knows the
|
|
23
|
+
* selection, so a lock set there would reach the client's state and not the
|
|
24
|
+
* server's markup, and the menu would not hydrate.
|
|
25
|
+
* The lock closes the entry only: each page shows its own locked state for a
|
|
26
|
+
* direct URL.
|
|
27
|
+
*
|
|
28
|
+
* @param selected The connection this user browses
|
|
29
|
+
*/
|
|
30
|
+
export function useLockedPages(selected: Ref<DatabaseConnection | undefined>) {
|
|
31
|
+
const siteLayout = useSiteLayout()
|
|
32
|
+
const { lock, unlock } = useMenuLocks()
|
|
33
|
+
const pages = computed(() =>
|
|
34
|
+
LOCKABLE_PAGES.flatMap((page) => {
|
|
35
|
+
const fullId = siteLayout.findMatchingRoute(page.path)?.metadata.fullId
|
|
36
|
+
return fullId
|
|
37
|
+
? [{ fullId, locked: lacksFeature(selected.value, page.feature) }]
|
|
38
|
+
: []
|
|
39
|
+
}),
|
|
40
|
+
)
|
|
41
|
+
onMounted(() => {
|
|
42
|
+
watch(
|
|
43
|
+
pages,
|
|
44
|
+
(entries) => {
|
|
45
|
+
for (const { fullId, locked } of entries) {
|
|
46
|
+
if (locked) lock({ fullId, reason: LOCK_REASON })
|
|
47
|
+
else unlock(fullId)
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{ immediate: true },
|
|
51
|
+
)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
@@ -62,11 +62,11 @@ function toSchemaDefinition(summary: SchemaSummary): SchemaDefLike {
|
|
|
62
62
|
|
|
63
63
|
function buildSchemasMap(
|
|
64
64
|
summaries: SchemaSummary[],
|
|
65
|
-
): Record<string, Schema<unknown,
|
|
66
|
-
const bindings: Record<string, Schema<unknown,
|
|
65
|
+
): Record<string, Schema<unknown, unknown>> {
|
|
66
|
+
const bindings: Record<string, Schema<unknown, unknown>> = {}
|
|
67
67
|
for (const summary of summaries) {
|
|
68
68
|
bindings[summary.id] =
|
|
69
|
-
Schema.get
|
|
69
|
+
Schema.get(summary.id) ??
|
|
70
70
|
new Schema(summary.id, toSchemaDefinition(summary))
|
|
71
71
|
}
|
|
72
72
|
return bindings
|
|
@@ -155,7 +155,7 @@ function compile(code: string, text: string): QueryFunction {
|
|
|
155
155
|
function evaluateUserCode(
|
|
156
156
|
code: string,
|
|
157
157
|
text: string,
|
|
158
|
-
schemas: Record<string, Schema<unknown,
|
|
158
|
+
schemas: Record<string, Schema<unknown, unknown>>,
|
|
159
159
|
): unknown {
|
|
160
160
|
return compile(code, text)(
|
|
161
161
|
guardSchemas(schemas),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs `recheck` each time the window regains focus or the page becomes
|
|
5
|
+
* visible again, while the component is mounted: what another tab did to the
|
|
6
|
+
* server's selection in the meantime shows then.
|
|
7
|
+
*/
|
|
8
|
+
export function useSelectionRecheck(recheck: () => Promise<void>): void {
|
|
9
|
+
function onVisibility() {
|
|
10
|
+
if (document.visibilityState === 'visible') void recheck()
|
|
11
|
+
}
|
|
12
|
+
function onFocus() {
|
|
13
|
+
void recheck()
|
|
14
|
+
}
|
|
15
|
+
onMounted(() => {
|
|
16
|
+
window.addEventListener('focus', onFocus)
|
|
17
|
+
document.addEventListener('visibilitychange', onVisibility)
|
|
18
|
+
})
|
|
19
|
+
onBeforeUnmount(() => {
|
|
20
|
+
window.removeEventListener('focus', onFocus)
|
|
21
|
+
document.removeEventListener('visibilitychange', onVisibility)
|
|
22
|
+
})
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What dms-assistant offers the rest of the app, mirrored here so the module
|
|
3
|
+
* depends on its shape only: `isAvailable` is false while the assistant
|
|
4
|
+
* cannot take the user through a step.
|
|
5
|
+
*/
|
|
6
|
+
export interface PublicOnboarding {
|
|
7
|
+
readonly isAvailable: boolean
|
|
8
|
+
open(step?: 'connect-database'): void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The key dms-assistant provides its onboarding under, app-wide. */
|
|
12
|
+
export const ONBOARDING_KEY = Symbol.for('dms-assistant:onboarding')
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { InjectionKey, Ref } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
refusesEdits,
|
|
4
|
+
useDatabaseConnections,
|
|
5
|
+
} from '../composables/useDatabaseConnections'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Why the grid's cells take no edit, which each cell shows where the user
|
|
9
|
+
* tries one: set while the selected external database is read only, absent
|
|
10
|
+
* otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export const READ_ONLY_REASON: InjectionKey<Ref<string | null>> = Symbol(
|
|
13
|
+
'dms-database:read-only-reason',
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
/** Gives the cells below the reason the selected database refuses edits. */
|
|
17
|
+
export function provideReadOnlyReason(): void {
|
|
18
|
+
const { t } = useI18n()
|
|
19
|
+
const { selected } = useDatabaseConnections()
|
|
20
|
+
provide(
|
|
21
|
+
READ_ONLY_REASON,
|
|
22
|
+
computed(() =>
|
|
23
|
+
selected.value && refusesEdits(selected.value)
|
|
24
|
+
? t('dms_database.data.save.read_only_access', {
|
|
25
|
+
connection: selected.value.label,
|
|
26
|
+
})
|
|
27
|
+
: null,
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -46,3 +46,9 @@ export function rememberTable(entry: Omit<RecentTable, 'openedAt'>) {
|
|
|
46
46
|
// A full or private storage only loses the suggestions.
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
/** Drops the suggestions: they name the tables of the database browsed before a switch. */
|
|
51
|
+
export function forgetRecentTables(): void {
|
|
52
|
+
if (typeof window === 'undefined') return
|
|
53
|
+
window.localStorage?.removeItem(STORAGE_KEY)
|
|
54
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const STALE_MESSAGE =
|
|
2
|
+
'The selected database changed in another tab: reload the page'
|
|
3
|
+
const STALE_KEY = 'dms_database.data.save.database_changed'
|
|
4
|
+
const CONFLICT = 409
|
|
5
|
+
const READ_ONLY_MESSAGE = /^Access to (.+) is read only$/
|
|
6
|
+
const READ_ONLY_KEY = 'dms_database.data.save.read_only_access'
|
|
7
|
+
const FORBIDDEN = 403
|
|
8
|
+
|
|
9
|
+
function read(value: unknown, key: string): unknown {
|
|
10
|
+
return typeof value === 'object' && value !== null
|
|
11
|
+
? Reflect.get(value, key)
|
|
12
|
+
: undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A refusal of the edit route, as the error API presents it: a translated key with its parameters. */
|
|
16
|
+
export class PresentableWriteError extends Error {
|
|
17
|
+
readonly data: {
|
|
18
|
+
message: string
|
|
19
|
+
params: Record<string, string>
|
|
20
|
+
severity: 'warning'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
readonly statusCode: number,
|
|
25
|
+
readonly response: unknown,
|
|
26
|
+
key: string,
|
|
27
|
+
params: Record<string, string> = {},
|
|
28
|
+
) {
|
|
29
|
+
super(key)
|
|
30
|
+
this.data = { message: key, params, severity: 'warning' }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Turns the edit route's refusals whose body the API sends as text (a write
|
|
36
|
+
* from a stale tab, a write to a connection whose access is read only) into
|
|
37
|
+
* ones the error API translates; any other error comes back as it is.
|
|
38
|
+
*/
|
|
39
|
+
export function presentableWriteError(error: unknown): unknown {
|
|
40
|
+
const response = read(error, 'response')
|
|
41
|
+
const status =
|
|
42
|
+
read(error, 'statusCode') ??
|
|
43
|
+
read(error, 'status') ??
|
|
44
|
+
read(response, 'status')
|
|
45
|
+
const body = read(error, 'data') ?? read(response, '_data')
|
|
46
|
+
const message = typeof body === 'string' ? body : read(body, 'message')
|
|
47
|
+
if (status === CONFLICT && message === STALE_MESSAGE)
|
|
48
|
+
return new PresentableWriteError(CONFLICT, response, STALE_KEY)
|
|
49
|
+
const readOnly =
|
|
50
|
+
status === FORBIDDEN && typeof message === 'string'
|
|
51
|
+
? READ_ONLY_MESSAGE.exec(message)
|
|
52
|
+
: null
|
|
53
|
+
return readOnly?.[1] === undefined
|
|
54
|
+
? error
|
|
55
|
+
: new PresentableWriteError(FORBIDDEN, response, READ_ONLY_KEY, {
|
|
56
|
+
connection: readOnly[1],
|
|
57
|
+
})
|
|
58
|
+
}
|
|
@@ -5,7 +5,9 @@ import {
|
|
|
5
5
|
import { browseSelectionQuery } from '../composables/useDataBrowserGrid'
|
|
6
6
|
import { h, onScopeDispose } from 'vue'
|
|
7
7
|
import type { BrowserTab } from '../composables/useDataBrowserTabs'
|
|
8
|
+
import { useDatabaseConnections } from '../composables/useDatabaseConnections'
|
|
8
9
|
import { cellLabel } from './cellValues'
|
|
10
|
+
import { presentableWriteError } from './staleDatabase'
|
|
9
11
|
import { type StagedChange, undoBodies, useStagedEdits } from './stagedEdits'
|
|
10
12
|
import { changesOf, type RowWriteOutcome, writeRows } from './stagedWrites'
|
|
11
13
|
|
|
@@ -53,6 +55,7 @@ export function useStagedSave(options: StagedSaveOptions) {
|
|
|
53
55
|
const { confirm } = useConfirm()
|
|
54
56
|
const toast = useToast()
|
|
55
57
|
const { presentError, resolveError } = useApiErrorPresenter()
|
|
58
|
+
const { selected } = useDatabaseConnections()
|
|
56
59
|
const staged = useStagedEdits()
|
|
57
60
|
const saving = ref(false)
|
|
58
61
|
const notice = ref<SaveNotice | null>(null)
|
|
@@ -100,8 +103,14 @@ export function useStagedSave(options: StagedSaveOptions) {
|
|
|
100
103
|
): Promise<Record<string, unknown>> {
|
|
101
104
|
return $authFetch<Record<string, unknown>>(EDIT_ENDPOINT, {
|
|
102
105
|
method: 'PUT',
|
|
103
|
-
query: {
|
|
106
|
+
query: {
|
|
107
|
+
...browseSelectionQuery(tab),
|
|
108
|
+
id: rowId,
|
|
109
|
+
...(selected.value ? { connection: selected.value.id } : {}),
|
|
110
|
+
},
|
|
104
111
|
body,
|
|
112
|
+
}).catch((error: unknown) => {
|
|
113
|
+
throw presentableWriteError(error)
|
|
105
114
|
})
|
|
106
115
|
}
|
|
107
116
|
|
|
@@ -3,10 +3,13 @@ import {
|
|
|
3
3
|
instanceBadge,
|
|
4
4
|
useDataBrowserTabs,
|
|
5
5
|
} from '../build/composables/useDataBrowserTabs'
|
|
6
|
+
import { useDatabaseConnections } from '../build/composables/useDatabaseConnections'
|
|
7
|
+
import { provideReadOnlyReason } from '../build/data/readOnlyReason'
|
|
6
8
|
import { useDatabaseSchemas } from '../build/composables/useDatabaseSchemas'
|
|
7
9
|
import { formatDatabaseRelativeTime } from '../build/utils/relativeTime'
|
|
8
10
|
import { type RecentTable, readRecentTables } from '../build/data/recentTables'
|
|
9
11
|
import { useStagedEdits } from '../build/data/stagedEdits'
|
|
12
|
+
import DataBrowserAccessBar from '../build/components/DataBrowserAccessBar.vue'
|
|
10
13
|
import DataBrowserSidebar from './DataBrowserSidebar.vue'
|
|
11
14
|
import DataBrowserTabBar from './DataBrowserTabBar.vue'
|
|
12
15
|
import DataGrid from './DataGrid.vue'
|
|
@@ -23,6 +26,8 @@ const {
|
|
|
23
26
|
error: schemasError,
|
|
24
27
|
refresh: refreshSchemas,
|
|
25
28
|
} = useDatabaseSchemas()
|
|
29
|
+
const { ready: connectionsRead } = useDatabaseConnections()
|
|
30
|
+
provideReadOnlyReason()
|
|
26
31
|
const { tabs, activeTab, restore, openTab, openFromRoute } =
|
|
27
32
|
useDataBrowserTabs()
|
|
28
33
|
const staged = useStagedEdits()
|
|
@@ -61,6 +66,8 @@ watch(activeTab, () => {
|
|
|
61
66
|
function instanceLabel(instance: string): string {
|
|
62
67
|
return instanceBadge(instance, t('dms_database.data.scope.all')) ?? ''
|
|
63
68
|
}
|
|
69
|
+
|
|
70
|
+
await connectionsRead
|
|
64
71
|
</script>
|
|
65
72
|
|
|
66
73
|
<template>
|
|
@@ -74,6 +81,7 @@ function instanceLabel(instance: string): string {
|
|
|
74
81
|
@retry="refreshSchemas()"
|
|
75
82
|
/>
|
|
76
83
|
<section class="flex min-w-0 flex-1 flex-col md:min-h-0">
|
|
84
|
+
<DataBrowserAccessBar />
|
|
77
85
|
<DataBrowserTabBar />
|
|
78
86
|
<DataGrid
|
|
79
87
|
v-if="activeTab"
|
|
@@ -93,7 +101,7 @@ function instanceLabel(instance: string): string {
|
|
|
93
101
|
>
|
|
94
102
|
<template v-if="recent.length" #actions>
|
|
95
103
|
<div class="grid w-full max-w-sm gap-1.5">
|
|
96
|
-
<
|
|
104
|
+
<DmsEyebrowLabel :label="t('dms_database.data.empty.recent')" />
|
|
97
105
|
<button
|
|
98
106
|
v-for="entry in recent"
|
|
99
107
|
:key="`${entry.schema}.${entry.instance}.${entry.table}`"
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
tabInstanceOf,
|
|
7
7
|
useDataBrowserTabs,
|
|
8
8
|
} from '../build/composables/useDataBrowserTabs'
|
|
9
|
+
import { useDatabaseConnections } from '../build/composables/useDatabaseConnections'
|
|
9
10
|
import { useTableCounts } from '../build/composables/useTableCounts'
|
|
10
11
|
import type { InstanceChoice } from '../build/data/instanceOptions'
|
|
11
12
|
import { onKeyStroke } from '@vueuse/core'
|
|
@@ -34,6 +35,7 @@ const emit = defineEmits<{ retry: [] }>()
|
|
|
34
35
|
const { t, n } = useI18n()
|
|
35
36
|
const { tabs, activeId, activeTab, activations, openTab } = useDataBrowserTabs()
|
|
36
37
|
const route = useDmsRoute()
|
|
38
|
+
const { lacks } = useDatabaseConnections()
|
|
37
39
|
|
|
38
40
|
const schemaId = ref<string | null>(null)
|
|
39
41
|
const instance = ref<string>(DEFAULT_INSTANCE_VALUE)
|
|
@@ -158,10 +160,10 @@ onKeyStroke('t', (event) => {
|
|
|
158
160
|
|
|
159
161
|
<template>
|
|
160
162
|
<aside
|
|
161
|
-
class="border-default bg-default flex max-h-[40vh] w-full shrink-0 flex-col border-b md:h-full md:max-h-none md:w-[264px] md:border-
|
|
163
|
+
class="border-default bg-default flex max-h-[40vh] w-full shrink-0 flex-col border-b md:h-full md:max-h-none md:w-[264px] md:border-b-0 md:border-r"
|
|
162
164
|
>
|
|
163
165
|
<div class="border-default grid gap-2 border-b p-3">
|
|
164
|
-
<
|
|
166
|
+
<DmsEyebrowLabel :label="t('dms_database.data.scope.schema')" />
|
|
165
167
|
<SchemaPicker
|
|
166
168
|
:model-value="schemaId"
|
|
167
169
|
:schema-ids="schemaIds"
|
|
@@ -175,16 +177,24 @@ onKeyStroke('t', (event) => {
|
|
|
175
177
|
class="w-full"
|
|
176
178
|
@update:model-value="pickSchema"
|
|
177
179
|
/>
|
|
178
|
-
<
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
180
|
+
<template v-if="!lacks('instances')">
|
|
181
|
+
<DmsEyebrowLabel
|
|
182
|
+
class="mt-1"
|
|
183
|
+
:label="t('dms_database.data.scope.instance')"
|
|
184
|
+
/>
|
|
185
|
+
<InstancePicker
|
|
186
|
+
:model-value="instanceChoice"
|
|
187
|
+
:schema="schemaId"
|
|
188
|
+
all-mode="readonly"
|
|
189
|
+
:disabled="!schemaId"
|
|
190
|
+
class="w-full"
|
|
191
|
+
@update:model-value="pickInstance"
|
|
192
|
+
/>
|
|
193
|
+
</template>
|
|
194
|
+
<DmsEyebrowLabel
|
|
195
|
+
class="mt-1"
|
|
196
|
+
:label="t('dms_database.data.scope.search')"
|
|
186
197
|
/>
|
|
187
|
-
<DmsEyebrow class="mt-1" :label="t('dms_database.data.scope.search')" />
|
|
188
198
|
<UInput
|
|
189
199
|
ref="filterInput"
|
|
190
200
|
v-model="filter"
|
|
@@ -213,10 +223,10 @@ onKeyStroke('t', (event) => {
|
|
|
213
223
|
|
|
214
224
|
<div class="flex min-h-0 flex-1 flex-col p-2">
|
|
215
225
|
<div class="flex items-center justify-between px-2 py-1">
|
|
216
|
-
<
|
|
226
|
+
<DmsEyebrowLabel
|
|
217
227
|
:label="t('dms_database.data.scope.tables', { count: tables.length })"
|
|
218
228
|
/>
|
|
219
|
-
<
|
|
229
|
+
<DmsEyebrowLabel :label="t('dms_database.data.scope.rows')" />
|
|
220
230
|
</div>
|
|
221
231
|
<nav class="min-h-0 flex-1 overflow-y-auto">
|
|
222
232
|
<div
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
DEFAULT_INSTANCE_VALUE,
|
|
5
5
|
useDataBrowserTabs,
|
|
6
6
|
} from '../build/composables/useDataBrowserTabs'
|
|
7
|
+
import { useGridAccess } from '../build/composables/useGridAccess'
|
|
7
8
|
import { useDatabaseSchemas } from '../build/composables/useDatabaseSchemas'
|
|
8
9
|
import {
|
|
9
10
|
browseListQuery,
|
|
@@ -68,8 +69,15 @@ const { tabs: browserTabs, pinTab, openTab, replaceTab } = useDataBrowserTabs()
|
|
|
68
69
|
const { open: openDrawer } = useDrawer()
|
|
69
70
|
const { schemas } = useDatabaseSchemas()
|
|
70
71
|
|
|
72
|
+
const {
|
|
73
|
+
crossInstance,
|
|
74
|
+
readOnly,
|
|
75
|
+
showReferences,
|
|
76
|
+
canOpenQuery,
|
|
77
|
+
canSearchAllInstances,
|
|
78
|
+
} = useGridAccess(() => props.tab)
|
|
79
|
+
|
|
71
80
|
const state = grid.getState(props.tab.id)
|
|
72
|
-
const readOnly = computed(() => props.tab.instance === CROSS_INSTANCE_VALUE)
|
|
73
81
|
|
|
74
82
|
// --- data loading ---
|
|
75
83
|
const selection = computed(() => browseSelectionQuery(props.tab))
|
|
@@ -127,7 +135,8 @@ const rows = computed(() => data.value?.rows ?? [])
|
|
|
127
135
|
const total = computed(() => data.value?.total ?? 0)
|
|
128
136
|
const rowIdKey = computed(() => data.value?.primaryKey ?? DEFAULT_PRIMARY_KEY)
|
|
129
137
|
const visibleColumns = computed(() =>
|
|
130
|
-
|
|
138
|
+
crossInstance.value ||
|
|
139
|
+
!columns.value.some((column) => column.name === '_instance')
|
|
131
140
|
? columns.value
|
|
132
141
|
: columns.value.filter((column) => column.name !== '_instance'),
|
|
133
142
|
)
|
|
@@ -227,7 +236,7 @@ function resizeColumn(name: string, width: number) {
|
|
|
227
236
|
// --- links out ---
|
|
228
237
|
function openInQueryConsole() {
|
|
229
238
|
const instance =
|
|
230
|
-
props.tab.instance === DEFAULT_INSTANCE_VALUE ||
|
|
239
|
+
props.tab.instance === DEFAULT_INSTANCE_VALUE || crossInstance.value
|
|
231
240
|
? undefined
|
|
232
241
|
: props.tab.instance
|
|
233
242
|
const source = `${tableAccess({ schema: props.tab.schema, table: props.tab.table, instance })}.slice(0, 100)`
|
|
@@ -475,6 +484,7 @@ function rowDrawerOptions(index: number) {
|
|
|
475
484
|
columns: visibleColumns.value,
|
|
476
485
|
table: props.table,
|
|
477
486
|
readOnly: readOnly.value,
|
|
487
|
+
showReferences: showReferences.value,
|
|
478
488
|
onStage: stage,
|
|
479
489
|
onReview: review,
|
|
480
490
|
},
|
|
@@ -502,7 +512,7 @@ function openRow(index: number) {
|
|
|
502
512
|
function rowKey(row: Record<string, unknown>, index: number): string | number {
|
|
503
513
|
const id = rowIdOf(row)
|
|
504
514
|
if (id === null) return index
|
|
505
|
-
return
|
|
515
|
+
return crossInstance.value ? `${String(row._instance ?? '')}::${id}` : id
|
|
506
516
|
}
|
|
507
517
|
|
|
508
518
|
const hasRefinements = computed(
|
|
@@ -534,6 +544,7 @@ useEventListener('keydown', (event: KeyboardEvent) => {
|
|
|
534
544
|
:table="tab.table"
|
|
535
545
|
:total="total"
|
|
536
546
|
:loading="loading"
|
|
547
|
+
:can-open-query="canOpenQuery"
|
|
537
548
|
@reload="reload"
|
|
538
549
|
@open-query="openInQueryConsole"
|
|
539
550
|
/>
|
|
@@ -546,7 +557,7 @@ useEventListener('keydown', (event: KeyboardEvent) => {
|
|
|
546
557
|
/>
|
|
547
558
|
|
|
548
559
|
<DataGridReadOnlyBanner
|
|
549
|
-
v-if="
|
|
560
|
+
v-if="crossInstance"
|
|
550
561
|
:table="tab.table"
|
|
551
562
|
:instances="namedInstances"
|
|
552
563
|
@switch-instance="switchInstance"
|
|
@@ -642,7 +653,7 @@ useEventListener('keydown', (event: KeyboardEvent) => {
|
|
|
642
653
|
:loading="loading"
|
|
643
654
|
:empty="rows.length === 0"
|
|
644
655
|
:has-refinements="hasRefinements"
|
|
645
|
-
:read-only="
|
|
656
|
+
:read-only="!canSearchAllInstances"
|
|
646
657
|
@reload="reload"
|
|
647
658
|
@clear-refinements="clearRefinements"
|
|
648
659
|
@search-all="switchInstance(CROSS_INSTANCE_VALUE)"
|