@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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConnectionsState,
|
|
3
|
+
DatabaseConnection,
|
|
4
|
+
} from '../../app/build/composables/useDatabaseConnections'
|
|
5
|
+
import type { BackendRead } from './serverRender'
|
|
6
|
+
|
|
7
|
+
export const CONNECTIONS_URL = '/api/database/connections'
|
|
8
|
+
|
|
9
|
+
/** The project database as the API names it: by a label the console never shows. */
|
|
10
|
+
export const OWN: DatabaseConnection = {
|
|
11
|
+
id: 'own',
|
|
12
|
+
kind: 'own',
|
|
13
|
+
label: 'legacy-label',
|
|
14
|
+
engine: 'mongodb',
|
|
15
|
+
access: 'read-write',
|
|
16
|
+
canWrite: true,
|
|
17
|
+
unsupported: [],
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A customer's Postgres, read only, that its account may write to. */
|
|
21
|
+
export const WAREHOUSE: DatabaseConnection = {
|
|
22
|
+
id: 'warehouse',
|
|
23
|
+
kind: 'external',
|
|
24
|
+
label: 'Warehouse',
|
|
25
|
+
engine: 'postgres',
|
|
26
|
+
access: 'read',
|
|
27
|
+
canWrite: true,
|
|
28
|
+
unsupported: ['diagram', 'queryConsole', 'instances', 'rowReferences'],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The state the API answers while `selected` is browsed. */
|
|
32
|
+
export function connectionsState(
|
|
33
|
+
selected: DatabaseConnection,
|
|
34
|
+
overrides: Partial<ConnectionsState> = {},
|
|
35
|
+
): ConnectionsState {
|
|
36
|
+
return {
|
|
37
|
+
selected: selected.id,
|
|
38
|
+
accessEditable: true,
|
|
39
|
+
connections: [OWN, WAREHOUSE].map((connection) =>
|
|
40
|
+
connection.id === selected.id ? selected : connection,
|
|
41
|
+
),
|
|
42
|
+
...overrides,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A backend that answers the connections read with `state`, every write to
|
|
48
|
+
* it with what `answer` makes of the request (the state by default), and
|
|
49
|
+
* everything else with `others`.
|
|
50
|
+
*/
|
|
51
|
+
export function connectionsBackend(
|
|
52
|
+
state: ConnectionsState,
|
|
53
|
+
options: {
|
|
54
|
+
answer?: (write: BackendRead) => unknown
|
|
55
|
+
others?: (read: BackendRead) => unknown
|
|
56
|
+
} = {},
|
|
57
|
+
): (read: BackendRead) => unknown {
|
|
58
|
+
return (read) => {
|
|
59
|
+
if (read.url === CONNECTIONS_URL) return state
|
|
60
|
+
if (read.url.startsWith(`${CONNECTIONS_URL}/`) && read.method === 'PUT')
|
|
61
|
+
return options.answer ? options.answer(read) : state
|
|
62
|
+
return options.others ? options.others(read) : {}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The writes a mount made to the connections API, as method, URL and body. */
|
|
67
|
+
export function connectionWrites(
|
|
68
|
+
reads: BackendRead[],
|
|
69
|
+
): { method: string; url: string; body: unknown }[] {
|
|
70
|
+
return reads
|
|
71
|
+
.filter((read) => read.method !== 'GET')
|
|
72
|
+
.map(({ method, url, body }) => ({ method, url, body }))
|
|
73
|
+
}
|
|
@@ -18,6 +18,8 @@ export interface BackendRead {
|
|
|
18
18
|
url: string
|
|
19
19
|
method: string
|
|
20
20
|
query: Record<string, unknown>
|
|
21
|
+
body?: unknown
|
|
22
|
+
headers?: Record<string, string>
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export type Backend = (read: BackendRead) => unknown
|
|
@@ -25,9 +27,41 @@ export type Backend = (read: BackendRead) => unknown
|
|
|
25
27
|
interface FetchOptions {
|
|
26
28
|
method?: string
|
|
27
29
|
query?: Record<string, unknown>
|
|
30
|
+
body?: unknown
|
|
31
|
+
headers?: Record<string, string>
|
|
28
32
|
signal?: AbortSignal
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
const CONNECTIONS_URL = '/api/database/connections'
|
|
36
|
+
/**
|
|
37
|
+
* What the connections read answers when a test's backend says nothing of it:
|
|
38
|
+
* the project database alone, selected.
|
|
39
|
+
*/
|
|
40
|
+
const OWN_DATABASE_ONLY = {
|
|
41
|
+
selected: 'own',
|
|
42
|
+
accessEditable: false,
|
|
43
|
+
connections: [
|
|
44
|
+
{
|
|
45
|
+
id: 'own',
|
|
46
|
+
kind: 'own',
|
|
47
|
+
label: 'own',
|
|
48
|
+
engine: null,
|
|
49
|
+
access: 'read-write',
|
|
50
|
+
canWrite: true,
|
|
51
|
+
unsupported: [],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function answerIsConnections(answer: unknown): boolean {
|
|
57
|
+
return (
|
|
58
|
+
typeof answer === 'object' &&
|
|
59
|
+
answer !== null &&
|
|
60
|
+
'connections' in answer &&
|
|
61
|
+
Array.isArray(answer.connections)
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
31
65
|
let backend: Backend = () => ({})
|
|
32
66
|
const reads: BackendRead[] = []
|
|
33
67
|
/** The options each read was made with, as `useDmsFetch` passed them. */
|
|
@@ -38,10 +72,15 @@ const $authFetch = async (url: string, options: FetchOptions = {}) => {
|
|
|
38
72
|
url,
|
|
39
73
|
method: (options.method ?? 'GET').toUpperCase(),
|
|
40
74
|
query: options.query ?? {},
|
|
75
|
+
body: options.body,
|
|
76
|
+
headers: options.headers,
|
|
41
77
|
}
|
|
42
78
|
reads.push(read)
|
|
43
79
|
readOptions.set(read, options)
|
|
44
|
-
|
|
80
|
+
const answer = backend(read)
|
|
81
|
+
if (read.url === CONNECTIONS_URL && read.method === 'GET')
|
|
82
|
+
return answerIsConnections(answer) ? answer : OWN_DATABASE_ONLY
|
|
83
|
+
return answer
|
|
45
84
|
}
|
|
46
85
|
|
|
47
86
|
const noop = () => undefined
|
|
@@ -78,9 +117,51 @@ vi.stubGlobal('useRegionalFormat', () => ({
|
|
|
78
117
|
}))
|
|
79
118
|
vi.stubGlobal('regionalDayKey', regional.regionalDayKey)
|
|
80
119
|
vi.stubGlobal('regionalDayNumber', regional.regionalDayNumber)
|
|
81
|
-
vi.stubGlobal('useToast', () => ({ add:
|
|
82
|
-
|
|
83
|
-
|
|
120
|
+
vi.stubGlobal('useToast', () => ({ add: () => ({ id: 'toast' }) }))
|
|
121
|
+
/** The sidebar entries the mounted components locked, as the layer's `useMenuLocks` keeps them. */
|
|
122
|
+
export const menuLocks = vue.ref<{ fullId: string; reason: string }[]>([])
|
|
123
|
+
vi.stubGlobal('useMenuLocks', () => ({
|
|
124
|
+
locks: menuLocks,
|
|
125
|
+
lock: (entry: { fullId: string; reason: string }) => {
|
|
126
|
+
const known = menuLocks.value.find((lock) => lock.fullId === entry.fullId)
|
|
127
|
+
if (known?.reason === entry.reason) return
|
|
128
|
+
menuLocks.value = [
|
|
129
|
+
...menuLocks.value.filter((known) => known.fullId !== entry.fullId),
|
|
130
|
+
entry,
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
unlock: (fullId: string) => {
|
|
134
|
+
if (!menuLocks.value.some((lock) => lock.fullId === fullId)) return
|
|
135
|
+
menuLocks.value = menuLocks.value.filter((known) => known.fullId !== fullId)
|
|
136
|
+
},
|
|
137
|
+
}))
|
|
138
|
+
/** Every page of the site layout, its `fullId` derived from its path. */
|
|
139
|
+
vi.stubGlobal('useSiteLayout', () => ({
|
|
140
|
+
findMatchingRoute: (path: string) => ({
|
|
141
|
+
metadata: { fullId: `page${path}` },
|
|
142
|
+
}),
|
|
143
|
+
}))
|
|
144
|
+
/** The confirmation dialogs the mounted components opened, in order. */
|
|
145
|
+
export const confirmations: unknown[] = []
|
|
146
|
+
let confirmationAnswer = false
|
|
147
|
+
/** What the next confirmation dialogs resolve: the user's choice. */
|
|
148
|
+
export function answerConfirmations(confirmed: boolean): void {
|
|
149
|
+
confirmationAnswer = confirmed
|
|
150
|
+
}
|
|
151
|
+
vi.stubGlobal('useConfirm', () => ({
|
|
152
|
+
confirm: async (options: unknown) => {
|
|
153
|
+
confirmations.push(options)
|
|
154
|
+
return confirmationAnswer
|
|
155
|
+
},
|
|
156
|
+
}))
|
|
157
|
+
/** The options of each drawer the mounted components opened, in order. */
|
|
158
|
+
export const drawers: { componentOptions?: Record<string, unknown> }[] = []
|
|
159
|
+
vi.stubGlobal('useDrawer', () => ({
|
|
160
|
+
open: (options: { componentOptions?: Record<string, unknown> }) => {
|
|
161
|
+
drawers.push(options)
|
|
162
|
+
return { result: new Promise(noop), patch: noop }
|
|
163
|
+
},
|
|
164
|
+
}))
|
|
84
165
|
vi.stubGlobal('resolveDmsComponent', engine.resolveDmsComponent)
|
|
85
166
|
vi.stubGlobal('useUnsavedChanges', noop)
|
|
86
167
|
vi.stubGlobal('useDmsUserSession', () => ({
|
|
@@ -102,12 +183,12 @@ for (const [name, module] of Object.entries({
|
|
|
102
183
|
// renders its default slot, its props as attributes.
|
|
103
184
|
const UI_COMPONENTS = [
|
|
104
185
|
'DmsAutoLink',
|
|
105
|
-
'
|
|
106
|
-
'
|
|
186
|
+
'DmsCardPanel',
|
|
187
|
+
'DmsChartBlock',
|
|
107
188
|
'DmsCodeSnippet',
|
|
108
189
|
'DmsContainerFooter',
|
|
109
190
|
'DmsEmptyState',
|
|
110
|
-
'
|
|
191
|
+
'DmsEyebrowLabel',
|
|
111
192
|
'DmsFieldRow',
|
|
112
193
|
'DmsFlowCanvas',
|
|
113
194
|
'DmsFormErrorText',
|
|
@@ -116,15 +197,16 @@ const UI_COMPONENTS = [
|
|
|
116
197
|
'DmsInputText',
|
|
117
198
|
'DmsNavCardGridBlock',
|
|
118
199
|
'DmsSaveBar',
|
|
119
|
-
'
|
|
200
|
+
'DmsSegmentedControl',
|
|
120
201
|
'DmsStatusSummary',
|
|
121
|
-
'
|
|
122
|
-
'
|
|
202
|
+
'DmsInputSwitch',
|
|
203
|
+
'DmsInputTextarea',
|
|
123
204
|
'I18nT',
|
|
124
205
|
'UAlert',
|
|
125
206
|
'UAvatar',
|
|
126
207
|
'UBadge',
|
|
127
208
|
'UButton',
|
|
209
|
+
'UDropdownMenu',
|
|
128
210
|
'UFormField',
|
|
129
211
|
'UIcon',
|
|
130
212
|
'UInput',
|
|
@@ -213,6 +295,18 @@ function mountText(node: MountNode): string {
|
|
|
213
295
|
return `<${node.tag}${attributes}>${node.children.map(mountText).join('')}</${node.tag}>`
|
|
214
296
|
}
|
|
215
297
|
|
|
298
|
+
function findNode(
|
|
299
|
+
node: MountNode,
|
|
300
|
+
match: (props: Record<string, unknown>) => boolean,
|
|
301
|
+
): MountNode | undefined {
|
|
302
|
+
if (node.tag !== undefined && match(node.props)) return node
|
|
303
|
+
for (const child of node.children) {
|
|
304
|
+
const found = findNode(child, match)
|
|
305
|
+
if (found) return found
|
|
306
|
+
}
|
|
307
|
+
return undefined
|
|
308
|
+
}
|
|
309
|
+
|
|
216
310
|
/** A component mounted in a browser, as a client navigation shows it. */
|
|
217
311
|
export interface BrowserMount {
|
|
218
312
|
/**
|
|
@@ -222,11 +316,26 @@ export interface BrowserMount {
|
|
|
222
316
|
shown: Promise<void>
|
|
223
317
|
/** What the component shows now (`''` while the navigation waits). */
|
|
224
318
|
text: () => string
|
|
319
|
+
/**
|
|
320
|
+
* The props, handlers included, of the first element shown that `match`
|
|
321
|
+
* accepts: what a click or a toggle on it would call.
|
|
322
|
+
*/
|
|
323
|
+
find: (
|
|
324
|
+
match: (props: Record<string, unknown>) => boolean,
|
|
325
|
+
) => Record<string, unknown> | undefined
|
|
225
326
|
reads: BackendRead[]
|
|
226
327
|
/** What the mounted components threw outside a test's own calls. */
|
|
227
328
|
errors: unknown[]
|
|
228
329
|
}
|
|
229
330
|
|
|
331
|
+
/** What a browser mount adds to the app around the component. */
|
|
332
|
+
export interface BrowserMountOptions {
|
|
333
|
+
/** Values the app provides, as an installed module does for the whole app. */
|
|
334
|
+
provide?: [symbol, unknown][]
|
|
335
|
+
/** Components registered over the stubs, by name. */
|
|
336
|
+
components?: Record<string, Component>
|
|
337
|
+
}
|
|
338
|
+
|
|
230
339
|
/**
|
|
231
340
|
* Mounts `component` in a browser's app (no server render to hydrate) inside
|
|
232
341
|
* the `<Suspense>` a page navigation renders in, answering each backend
|
|
@@ -236,9 +345,12 @@ export function browserMount(
|
|
|
236
345
|
component: Component,
|
|
237
346
|
respond: Backend,
|
|
238
347
|
props: Record<string, unknown> = {},
|
|
348
|
+
options: BrowserMountOptions = {},
|
|
239
349
|
): BrowserMount {
|
|
240
350
|
backend = respond
|
|
241
351
|
reads.length = 0
|
|
352
|
+
confirmations.length = 0
|
|
353
|
+
drawers.length = 0
|
|
242
354
|
const runtime = engine.createDmsFrontendRuntime(undefined, {}, false)
|
|
243
355
|
let resolveShown!: () => void
|
|
244
356
|
const shown = new Promise<void>((resolve) => (resolveShown = resolve))
|
|
@@ -255,7 +367,12 @@ export function browserMount(
|
|
|
255
367
|
// themselves in the render's context: an empty one stands in for it.
|
|
256
368
|
app.provide(vue.ssrContextKey, {})
|
|
257
369
|
app.component('DmsClientOnly', engine.DmsClientOnly)
|
|
258
|
-
|
|
370
|
+
const replacements = options.components ?? {}
|
|
371
|
+
for (const name of UI_COMPONENTS)
|
|
372
|
+
if (!Object.hasOwn(replacements, name)) app.component(name, uiStub(name))
|
|
373
|
+
for (const [name, replacement] of Object.entries(replacements))
|
|
374
|
+
app.component(name, replacement)
|
|
375
|
+
for (const [key, value] of options.provide ?? []) app.provide(key, value)
|
|
259
376
|
app.config.warnHandler = noop
|
|
260
377
|
const errors: unknown[] = []
|
|
261
378
|
app.config.errorHandler = (error) => {
|
|
@@ -263,7 +380,13 @@ export function browserMount(
|
|
|
263
380
|
}
|
|
264
381
|
const root = mountNode({ tag: 'root' })
|
|
265
382
|
app.mount(root)
|
|
266
|
-
return {
|
|
383
|
+
return {
|
|
384
|
+
shown,
|
|
385
|
+
text: () => mountText(root),
|
|
386
|
+
find: (match) => findNode(root, match)?.props,
|
|
387
|
+
reads,
|
|
388
|
+
errors,
|
|
389
|
+
}
|
|
267
390
|
}
|
|
268
391
|
|
|
269
392
|
export interface ServerRender {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { browserMount } from './fixtures/serverRender'
|
|
3
|
+
import {
|
|
4
|
+
CONNECTIONS_URL,
|
|
5
|
+
OWN,
|
|
6
|
+
WAREHOUSE,
|
|
7
|
+
connectionsBackend,
|
|
8
|
+
connectionsState,
|
|
9
|
+
} from './fixtures/connections'
|
|
10
|
+
import QueryConsole from '../app/components/QueryConsole.vue'
|
|
11
|
+
import SchemaDiagram from '../app/components/SchemaDiagram.vue'
|
|
12
|
+
|
|
13
|
+
const LOCKED = 'data-feature-locked'
|
|
14
|
+
|
|
15
|
+
async function mount(
|
|
16
|
+
component: typeof QueryConsole | typeof SchemaDiagram,
|
|
17
|
+
state = connectionsState(WAREHOUSE),
|
|
18
|
+
) {
|
|
19
|
+
const page = browserMount(component, connectionsBackend(state))
|
|
20
|
+
await page.shown
|
|
21
|
+
return page
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe('diagram page on an external database', () => {
|
|
25
|
+
it('shows the locked state with the lock icon and the reason, and reads nothing but the selection', async () => {
|
|
26
|
+
const page = await mount(SchemaDiagram)
|
|
27
|
+
expect(page.text()).toContain(LOCKED)
|
|
28
|
+
expect(page.text()).toContain('icon="i-ph-lock"')
|
|
29
|
+
expect(page.text()).toContain('dms_database.connections.locked.reason')
|
|
30
|
+
expect(page.reads.map((read) => read.url)).toEqual([CONNECTIONS_URL])
|
|
31
|
+
expect(page.errors).toEqual([])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('is locked by what the connection lists, not by being external', async () => {
|
|
35
|
+
const page = await mount(
|
|
36
|
+
SchemaDiagram,
|
|
37
|
+
connectionsState({ ...WAREHOUSE, unsupported: ['queryConsole'] }),
|
|
38
|
+
)
|
|
39
|
+
expect(page.text()).not.toContain(LOCKED)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('query console page on an external database', () => {
|
|
44
|
+
it('shows the locked state with the lock icon and the reason, and reads neither the library nor the schemas', async () => {
|
|
45
|
+
const page = await mount(QueryConsole)
|
|
46
|
+
expect(page.text()).toContain(LOCKED)
|
|
47
|
+
expect(page.text()).toContain('icon="i-ph-lock"')
|
|
48
|
+
expect(page.text()).toContain('dms_database.connections.locked.reason')
|
|
49
|
+
expect(page.reads.map((read) => read.url)).toEqual([CONNECTIONS_URL])
|
|
50
|
+
expect(page.errors).toEqual([])
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('stays open when only the diagram is listed as unsupported', async () => {
|
|
54
|
+
const page = await mount(
|
|
55
|
+
QueryConsole,
|
|
56
|
+
connectionsState({ ...WAREHOUSE, unsupported: ['diagram'] }),
|
|
57
|
+
)
|
|
58
|
+
expect(page.text()).not.toContain(LOCKED)
|
|
59
|
+
expect(page.reads.map((read) => read.url)).toContain(
|
|
60
|
+
'/api/database/schemas',
|
|
61
|
+
)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('stays open on the project database', async () => {
|
|
65
|
+
const page = await mount(QueryConsole, connectionsState(OWN))
|
|
66
|
+
expect(page.text()).not.toContain(LOCKED)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -139,7 +139,7 @@ describe('server render: what only the browser reads', () => {
|
|
|
139
139
|
expect(row('status')).toContain('layout="form"')
|
|
140
140
|
expect(row('description')).toContain('layout="stack"')
|
|
141
141
|
expect(row('address')).toContain('layout="stack"')
|
|
142
|
-
expect(page.html.match(/data-stub="
|
|
142
|
+
expect(page.html.match(/data-stub="DmsInputTextarea"/g)).toHaveLength(2)
|
|
143
143
|
// Every editable field, the switch too, keeps the same end slot.
|
|
144
144
|
expect(page.html.match(/data-null-slot/g)).toHaveLength(4)
|
|
145
145
|
expect(page.html.match(/icon="i-ph-circle-dashed"/g)).toHaveLength(4)
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { expect, it, vi } from 'vitest'
|
|
2
2
|
import frontendModule from '../dms.frontend'
|
|
3
|
+
import {
|
|
4
|
+
DATABASE_SWITCHER_WIDGET,
|
|
5
|
+
registerDatabaseSwitcher,
|
|
6
|
+
} from '../app/build/composables/registerDatabaseSwitcher'
|
|
3
7
|
|
|
4
8
|
it('registers every component under the module prefix the backend names', async () => {
|
|
5
9
|
const registerComponent = vi.fn()
|
|
6
10
|
const registerPage = vi.fn()
|
|
11
|
+
const registerPlugin = vi.fn()
|
|
7
12
|
await frontendModule.setup({
|
|
8
13
|
options: { public: {} },
|
|
9
14
|
registerComponent,
|
|
@@ -11,11 +16,14 @@ it('registers every component under the module prefix the backend names', async
|
|
|
11
16
|
registerDynamicPage: vi.fn(),
|
|
12
17
|
registerLayout: vi.fn(),
|
|
13
18
|
registerErrorPage: vi.fn(),
|
|
14
|
-
registerPlugin
|
|
19
|
+
registerPlugin,
|
|
15
20
|
registerMiddleware: vi.fn(),
|
|
16
21
|
provide: vi.fn(),
|
|
17
22
|
use: vi.fn(),
|
|
18
23
|
})
|
|
24
|
+
expect(registerPlugin).toHaveBeenCalledExactlyOnceWith(
|
|
25
|
+
registerDatabaseSwitcher,
|
|
26
|
+
)
|
|
19
27
|
expect(frontendModule.componentPrefix).toBe('DmsDatabase')
|
|
20
28
|
expect(registerPage).not.toHaveBeenCalled()
|
|
21
29
|
const names = registerComponent.mock.calls.map(([name]) => name)
|
|
@@ -29,6 +37,12 @@ it('registers every component under the module prefix the backend names', async
|
|
|
29
37
|
]) {
|
|
30
38
|
expect(names).toContain(name)
|
|
31
39
|
}
|
|
40
|
+
expect(names).toContain(
|
|
41
|
+
DATABASE_SWITCHER_WIDGET.component.replace(
|
|
42
|
+
frontendModule.componentPrefix ?? '',
|
|
43
|
+
'',
|
|
44
|
+
),
|
|
45
|
+
)
|
|
32
46
|
expect(names.every((name) => !name.startsWith('Dms'))).toBe(true)
|
|
33
47
|
expect(new Set(names).size).toBe(names.length)
|
|
34
48
|
})
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
2
|
import { defineComponent, h } from 'vue'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
menuLocks,
|
|
5
|
+
serverRender,
|
|
6
|
+
type BackendRead,
|
|
7
|
+
} from './fixtures/serverRender'
|
|
4
8
|
import ConnectionStatus from '../app/components/ConnectionStatus.vue'
|
|
5
9
|
import DataBrowser from '../app/components/DataBrowser.vue'
|
|
6
10
|
import DataGrid from '../app/components/DataGrid.vue'
|
|
@@ -8,11 +12,16 @@ import QueryConsole from '../app/components/QueryConsole.vue'
|
|
|
8
12
|
import SchemaDiagram from '../app/components/SchemaDiagram.vue'
|
|
9
13
|
import SchemasFilterBar from '../app/components/SchemasFilterBar.vue'
|
|
10
14
|
import TableInspector from '../app/components/TableInspector.vue'
|
|
15
|
+
import DatabaseSwitcher from '../app/components/DatabaseSwitcher.vue'
|
|
16
|
+
import { useDatabaseConnections } from '../app/build/composables/useDatabaseConnections'
|
|
17
|
+
import { WAREHOUSE, connectionsState } from './fixtures/connections'
|
|
11
18
|
|
|
12
19
|
// What a server render of each page reads, and that the browser is handed
|
|
13
20
|
// every response it read: a read the page does not hand over is made again
|
|
14
21
|
// by the browser, after a server request for nothing.
|
|
15
22
|
|
|
23
|
+
const CONNECTIONS_URL = '/api/database/connections'
|
|
24
|
+
|
|
16
25
|
const table = (name: string) => ({
|
|
17
26
|
name,
|
|
18
27
|
fields: {
|
|
@@ -100,11 +109,12 @@ const render = (
|
|
|
100
109
|
describe('server render: every read is handed to the browser', () => {
|
|
101
110
|
it('data browser: the table counts of the first schema', async () => {
|
|
102
111
|
const page = await render(DataBrowser, {}, '/modules/database/data')
|
|
103
|
-
|
|
112
|
+
const reads = page.reads.filter((read) => read.url !== CONNECTIONS_URL)
|
|
113
|
+
expect(reads.map((read) => read.url)).toEqual([
|
|
104
114
|
'/api/database/schemas',
|
|
105
115
|
'/api/database/browse/tables',
|
|
106
116
|
])
|
|
107
|
-
expect(
|
|
117
|
+
expect(reads[1]!.query).toEqual({ filter_schema: 'is:audit' })
|
|
108
118
|
expect(page.untransferred).toEqual([])
|
|
109
119
|
expect(page.html).toContain('4242')
|
|
110
120
|
})
|
|
@@ -115,7 +125,8 @@ describe('server render: every read is handed to the browser', () => {
|
|
|
115
125
|
{},
|
|
116
126
|
'/modules/database/data?schema=shop&table=orders&instance=eu',
|
|
117
127
|
)
|
|
118
|
-
|
|
128
|
+
const reads = page.reads.filter((read) => read.url !== CONNECTIONS_URL)
|
|
129
|
+
expect(reads[1]!.query).toEqual({
|
|
119
130
|
filter_schema: 'is:shop',
|
|
120
131
|
filter_instance: 'is:eu',
|
|
121
132
|
})
|
|
@@ -165,6 +176,7 @@ describe('server render: every read is handed to the browser', () => {
|
|
|
165
176
|
it('query console: the library, saved, shared and run', async () => {
|
|
166
177
|
const page = await render(QueryConsole, {}, '/modules/database/query')
|
|
167
178
|
expect(page.reads.map((read) => read.url).sort()).toEqual([
|
|
179
|
+
CONNECTIONS_URL,
|
|
168
180
|
'/api/database/query/history',
|
|
169
181
|
'/api/database/query/saved',
|
|
170
182
|
'/api/database/query/saved',
|
|
@@ -179,6 +191,7 @@ describe('server render: every read is handed to the browser', () => {
|
|
|
179
191
|
it('diagram: no layout or notes, which only the browser draws', async () => {
|
|
180
192
|
const page = await render(SchemaDiagram, {}, '/modules/database/diagram')
|
|
181
193
|
expect(page.reads.map((read) => read.url)).toEqual([
|
|
194
|
+
CONNECTIONS_URL,
|
|
182
195
|
'/api/database/schemas',
|
|
183
196
|
])
|
|
184
197
|
expect(page.untransferred).toEqual([])
|
|
@@ -195,6 +208,7 @@ describe('server render: every read is handed to the browser', () => {
|
|
|
195
208
|
const page = await render(SchemasFirst, {}, '/modules/database/diagram')
|
|
196
209
|
expect(page.reads.map((read) => read.url)).toEqual([
|
|
197
210
|
'/api/database/schemas',
|
|
211
|
+
CONNECTIONS_URL,
|
|
198
212
|
])
|
|
199
213
|
expect(page.untransferred).toEqual([])
|
|
200
214
|
})
|
|
@@ -207,12 +221,52 @@ describe('server render: every read is handed to the browser', () => {
|
|
|
207
221
|
)
|
|
208
222
|
expect(page.reads.map((read) => read.url).sort()).toEqual([
|
|
209
223
|
'/api/database/browse/count',
|
|
224
|
+
CONNECTIONS_URL,
|
|
210
225
|
'/api/database/schemas',
|
|
211
226
|
])
|
|
212
227
|
expect(page.untransferred).toEqual([])
|
|
213
228
|
expect(page.html).toContain('9876')
|
|
214
229
|
})
|
|
215
230
|
|
|
231
|
+
it('database switcher: sets no sidebar lock in a server render, even once the connections are read, which the sidebar it renders before would hydrate against a locked client state', async () => {
|
|
232
|
+
menuLocks.value = []
|
|
233
|
+
const ConnectionsFirst = defineComponent({
|
|
234
|
+
async setup() {
|
|
235
|
+
await useDatabaseConnections().ready
|
|
236
|
+
return () => h(DatabaseSwitcher)
|
|
237
|
+
},
|
|
238
|
+
})
|
|
239
|
+
await serverRender(
|
|
240
|
+
ConnectionsFirst,
|
|
241
|
+
{},
|
|
242
|
+
{
|
|
243
|
+
url: '/modules/database/data',
|
|
244
|
+
respond: (read) =>
|
|
245
|
+
read.url === CONNECTIONS_URL
|
|
246
|
+
? connectionsState(WAREHOUSE)
|
|
247
|
+
: backend(read),
|
|
248
|
+
},
|
|
249
|
+
)
|
|
250
|
+
expect(menuLocks.value).toEqual([])
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('table inspector on an external database: offers neither the query console nor the diagram, which an inspector linking to locked pages would not', async () => {
|
|
254
|
+
const external = connectionsState(WAREHOUSE)
|
|
255
|
+
const page = await serverRender(
|
|
256
|
+
TableInspector,
|
|
257
|
+
{ rowData: { schema: 'shop', name: 'orders' } },
|
|
258
|
+
{
|
|
259
|
+
url: '/modules/database/schemas',
|
|
260
|
+
respond: (read) =>
|
|
261
|
+
read.url === CONNECTIONS_URL ? external : backend(read),
|
|
262
|
+
},
|
|
263
|
+
)
|
|
264
|
+
expect(page.untransferred).toEqual([])
|
|
265
|
+
expect(page.html).toContain('dms_database.inspector.actions.browse')
|
|
266
|
+
expect(page.html).not.toContain('dms_database.inspector.actions.query')
|
|
267
|
+
expect(page.html).not.toContain('dms_database.inspector.actions.diagram')
|
|
268
|
+
})
|
|
269
|
+
|
|
216
270
|
it('table inspector: leaves the position and steps to the DMS header', async () => {
|
|
217
271
|
const page = await render(
|
|
218
272
|
TableInspector,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolve } from 'node:path'
|
|
2
2
|
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import { normalizePath } from 'vite'
|
|
3
4
|
import { defineConfig } from 'vitest/config'
|
|
4
5
|
import { backendBoundary } from './build/backend-boundary.ts'
|
|
5
6
|
|
|
@@ -10,7 +11,10 @@ const root = resolve(__dirname, '..', 'node_modules', '@antelopejs')
|
|
|
10
11
|
|
|
11
12
|
/** Matches one test file wherever the checkout lives, dot directories included. */
|
|
12
13
|
const testFile = (name: string) =>
|
|
13
|
-
resolve(__dirname, 'tests', name).replace(
|
|
14
|
+
normalizePath(resolve(__dirname, 'tests', name)).replace(
|
|
15
|
+
/[*?[\]{}()!+@|]/g,
|
|
16
|
+
'\\$&',
|
|
17
|
+
)
|
|
14
18
|
|
|
15
19
|
export default defineConfig({
|
|
16
20
|
plugins: [vue(), backendBoundary()],
|
|
@@ -21,6 +25,7 @@ export default defineConfig({
|
|
|
21
25
|
'dms-frontend/templates/vue/frontend-module.ts',
|
|
22
26
|
),
|
|
23
27
|
'#dms-core': resolve(root, 'dms/frontend-vue/layers/dms-core'),
|
|
28
|
+
'#dms-ui': resolve(root, 'dms/frontend-vue/layers/dms-ui'),
|
|
24
29
|
// The renderer's own imports, from this package's dependencies: one
|
|
25
30
|
// Vue for the renderer and the components.
|
|
26
31
|
vue: resolve(__dirname, 'node_modules/vue'),
|
|
@@ -41,6 +46,11 @@ export default defineConfig({
|
|
|
41
46
|
testFile('clientNavigation.test.ts'),
|
|
42
47
|
testFile('apiErrorPresentation.test.ts'),
|
|
43
48
|
testFile('connectionStatus.test.ts'),
|
|
49
|
+
testFile('databaseSwitcher.test.ts'),
|
|
50
|
+
testFile('accessBar.test.ts'),
|
|
51
|
+
testFile('lockedPages.test.ts'),
|
|
52
|
+
testFile('externalBrowser.test.ts'),
|
|
53
|
+
testFile('editRequest.test.ts'),
|
|
44
54
|
],
|
|
45
55
|
},
|
|
46
56
|
},
|