@antelopejs/dms-database 0.4.4 → 0.5.1
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 +121 -0
- package/dist/routes/connections.js.map +1 -0
- package/dist/routes/data.d.ts +10 -9
- package/dist/routes/data.js +45 -61
- 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/builderRefusal.d.ts +2 -0
- package/dist/service/builderRefusal.js +28 -0
- package/dist/service/builderRefusal.js.map +1 -0
- package/dist/service/catalog.js +2 -1
- package/dist/service/catalog.js.map +1 -1
- package/dist/service/connectionRefusals.d.ts +17 -0
- package/dist/service/connectionRefusals.js +26 -0
- package/dist/service/connectionRefusals.js.map +1 -0
- package/dist/service/connectionState.d.ts +27 -0
- package/dist/service/connectionState.js +167 -0
- package/dist/service/connectionState.js.map +1 -0
- package/dist/service/connections.d.ts +12 -0
- package/dist/service/connections.js +73 -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 +49 -41
- 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/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/DataGridFooter.vue +16 -1
- 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 +11 -0
- package/frontend-vue/app/build/composables/useDataBrowserGrid.ts +1 -0
- package/frontend-vue/app/build/composables/useDataBrowserTabs.ts +100 -15
- 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/gridData.ts +22 -1
- package/frontend-vue/app/build/data/readOnlyReason.ts +30 -0
- package/frontend-vue/app/build/data/recentTables.ts +15 -8
- package/frontend-vue/app/build/data/useStagedSave.ts +7 -1
- package/frontend-vue/app/components/DataBrowser.vue +17 -14
- package/frontend-vue/app/components/DataBrowserSidebar.vue +24 -13
- package/frontend-vue/app/components/DataGrid.vue +22 -18
- package/frontend-vue/app/components/DataGridCell.vue +5 -2
- package/frontend-vue/app/components/DatabaseSwitcher.vue +101 -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 +5 -5
- 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 +19 -10
- 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 +43 -1
- package/frontend-vue/i18n/locales/database-fr-FR.json +43 -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/dataBrowserDatabase.test.ts +89 -0
- package/frontend-vue/tests/databaseSwitcher.test.ts +343 -0
- package/frontend-vue/tests/editRequest.test.ts +95 -0
- package/frontend-vue/tests/externalBrowser.test.ts +318 -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/persistence.test.ts +254 -4
- package/frontend-vue/tests/recentTables.test.ts +70 -0
- package/frontend-vue/tests/registration.test.ts +15 -1
- package/frontend-vue/tests/serverRender.test.ts +80 -4
- package/frontend-vue/vitest.config.ts +11 -1
- package/package.json +19 -15
- 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,318 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { defineComponent, h } from 'vue'
|
|
3
|
+
import { provideReadOnlyReason } from '../app/build/data/readOnlyReason'
|
|
4
|
+
import {
|
|
5
|
+
browserMount,
|
|
6
|
+
drawers,
|
|
7
|
+
type BackendRead,
|
|
8
|
+
} from './fixtures/serverRender'
|
|
9
|
+
import {
|
|
10
|
+
CONNECTIONS_URL,
|
|
11
|
+
OWN,
|
|
12
|
+
WAREHOUSE,
|
|
13
|
+
connectionsBackend,
|
|
14
|
+
connectionsState,
|
|
15
|
+
} from './fixtures/connections'
|
|
16
|
+
import type { DatabaseConnection } from '../app/build/composables/useDatabaseConnections'
|
|
17
|
+
import DataBrowserSidebar from '../app/components/DataBrowserSidebar.vue'
|
|
18
|
+
import DataGrid from '../app/components/DataGrid.vue'
|
|
19
|
+
import TableInspector from '../app/components/TableInspector.vue'
|
|
20
|
+
|
|
21
|
+
const PICKER = 'data-dms-database-instance-picker'
|
|
22
|
+
const TAB = {
|
|
23
|
+
id: 'public::__DEFAULT__::orders',
|
|
24
|
+
schema: 'public',
|
|
25
|
+
instance: '__DEFAULT__',
|
|
26
|
+
table: 'orders',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function others({ url }: BackendRead): unknown {
|
|
30
|
+
if (url === '/api/database/browse/list')
|
|
31
|
+
return { results: [{ _id: '1', total: 5 }], total: 1, primaryKey: '_id' }
|
|
32
|
+
if (url === '/api/database/browse/columns')
|
|
33
|
+
return {
|
|
34
|
+
columns: ['_id', 'total'],
|
|
35
|
+
types: { _id: 'string', total: 'number' },
|
|
36
|
+
primaryKey: '_id',
|
|
37
|
+
}
|
|
38
|
+
return { items: [] }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function openFirstRow(connection: DatabaseConnection | null) {
|
|
42
|
+
const page = browserMount(
|
|
43
|
+
DataGrid,
|
|
44
|
+
connection
|
|
45
|
+
? connectionsBackend(connectionsState(connection), { others })
|
|
46
|
+
: (read) => {
|
|
47
|
+
if (read.url === CONNECTIONS_URL) throw new Error('unreachable')
|
|
48
|
+
return others(read)
|
|
49
|
+
},
|
|
50
|
+
{ tab: TAB },
|
|
51
|
+
)
|
|
52
|
+
await page.shown
|
|
53
|
+
const openRow = () =>
|
|
54
|
+
page.find((props) =>
|
|
55
|
+
Boolean(props['aria-label']?.toString().endsWith('open_row')),
|
|
56
|
+
)?.onClick
|
|
57
|
+
await vi.waitFor(() => expect(openRow()).toBeTypeOf('function'))
|
|
58
|
+
await vi.waitFor(() =>
|
|
59
|
+
expect(page.reads.map((read) => read.url)).toContain(CONNECTIONS_URL),
|
|
60
|
+
)
|
|
61
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
62
|
+
const open = openRow()
|
|
63
|
+
if (typeof open === 'function') open()
|
|
64
|
+
expect(drawers).toHaveLength(1)
|
|
65
|
+
return drawers[0]?.componentOptions
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('data grid on an external database', () => {
|
|
69
|
+
it('opens a row read-only while the access is read, which an implementation that only reads the tab gets wrong', async () => {
|
|
70
|
+
const options = await openFirstRow(WAREHOUSE)
|
|
71
|
+
expect(options?.readOnly).toBe(true)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('opens a row editable once read and write is allowed', async () => {
|
|
75
|
+
const options = await openFirstRow({ ...WAREHOUSE, access: 'read-write' })
|
|
76
|
+
expect(options?.readOnly).toBe(false)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('opens a row read-only when the connections could not be read, which an implementation that falls back to the project database gets wrong', async () => {
|
|
80
|
+
const options = await openFirstRow(null)
|
|
81
|
+
expect(options?.readOnly).toBe(true)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('opens a row of the project database editable', async () => {
|
|
85
|
+
const options = await openFirstRow(OWN)
|
|
86
|
+
expect(options?.readOnly).toBe(false)
|
|
87
|
+
expect(options?.showReferences).toBe(true)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('offers the rows that point at this one only where the connection supports them', async () => {
|
|
91
|
+
expect((await openFirstRow(WAREHOUSE))?.showReferences).toBe(false)
|
|
92
|
+
drawers.length = 0
|
|
93
|
+
const supported = await openFirstRow({ ...WAREHOUSE, unsupported: [] })
|
|
94
|
+
expect(supported?.showReferences).toBe(true)
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe('data grid toolbar', () => {
|
|
99
|
+
async function toolbar(connection: DatabaseConnection) {
|
|
100
|
+
const page = browserMount(
|
|
101
|
+
DataGrid,
|
|
102
|
+
connectionsBackend(connectionsState(connection), { others }),
|
|
103
|
+
{ tab: TAB },
|
|
104
|
+
)
|
|
105
|
+
await page.shown
|
|
106
|
+
await vi.waitFor(() =>
|
|
107
|
+
expect(page.reads.map((read) => read.url)).toContain(CONNECTIONS_URL),
|
|
108
|
+
)
|
|
109
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
110
|
+
return page.text()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
it('links to the query console where it exists', async () => {
|
|
114
|
+
expect(await toolbar(OWN)).toContain('dms_database.data.grid.open_query')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('drops the link on an external database, whose console is locked', async () => {
|
|
118
|
+
expect(await toolbar(WAREHOUSE)).not.toContain(
|
|
119
|
+
'dms_database.data.grid.open_query',
|
|
120
|
+
)
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
describe('data browser sidebar', () => {
|
|
125
|
+
async function sidebar(connection: DatabaseConnection) {
|
|
126
|
+
const page = browserMount(
|
|
127
|
+
DataBrowserSidebar,
|
|
128
|
+
connectionsBackend(connectionsState(connection)),
|
|
129
|
+
{ schemas: [], loading: false, error: false },
|
|
130
|
+
)
|
|
131
|
+
await page.shown
|
|
132
|
+
await vi.waitFor(() =>
|
|
133
|
+
expect(page.reads.map((read) => read.url)).toContain(CONNECTIONS_URL),
|
|
134
|
+
)
|
|
135
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
136
|
+
return page
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
it('offers the instance picker on the project database', async () => {
|
|
140
|
+
expect((await sidebar(OWN)).text()).toContain(PICKER)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('hides the instance picker on an external database, which has no instances', async () => {
|
|
144
|
+
const page = await sidebar(WAREHOUSE)
|
|
145
|
+
expect(page.text()).not.toContain(PICKER)
|
|
146
|
+
expect(page.text()).not.toContain('dms_database.data.scope.instance')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('names the instance its counts are for on the project database only, which an external database without instances would otherwise read as default', async () => {
|
|
150
|
+
const COUNTS_FOR = 'dms_database.data.scope.counts_for'
|
|
151
|
+
expect((await sidebar(OWN)).text()).toContain(COUNTS_FOR)
|
|
152
|
+
expect((await sidebar(WAREHOUSE)).text()).not.toContain(COUNTS_FOR)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('still warns that the counts failed on an external database, which a footer hidden for every external database gets wrong', async () => {
|
|
156
|
+
const page = browserMount(
|
|
157
|
+
DataBrowserSidebar,
|
|
158
|
+
connectionsBackend(connectionsState(WAREHOUSE), {
|
|
159
|
+
others: (read) => {
|
|
160
|
+
if (read.url === '/api/database/browse/tables')
|
|
161
|
+
throw Object.assign(new Error('down'), { statusCode: 500 })
|
|
162
|
+
return { items: [] }
|
|
163
|
+
},
|
|
164
|
+
}),
|
|
165
|
+
{ schemas: [{ id: 'erp', tables: [] }], loading: false, error: false },
|
|
166
|
+
)
|
|
167
|
+
await page.shown
|
|
168
|
+
await vi.waitFor(() =>
|
|
169
|
+
expect(page.text()).toContain('dms_database.data.scope.counts_failed'),
|
|
170
|
+
)
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
describe('a read-only external database in the data grid', () => {
|
|
175
|
+
const REASON = 'dms_database.data.save.read_only_access Warehouse'
|
|
176
|
+
const Browser = defineComponent({
|
|
177
|
+
setup() {
|
|
178
|
+
provideReadOnlyReason()
|
|
179
|
+
return () => h(DataGrid, { tab: TAB })
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
async function cellTitles(connection: DatabaseConnection) {
|
|
184
|
+
const page = browserMount(
|
|
185
|
+
Browser,
|
|
186
|
+
connectionsBackend(connectionsState(connection), { others }),
|
|
187
|
+
)
|
|
188
|
+
await page.shown
|
|
189
|
+
await vi.waitFor(() =>
|
|
190
|
+
expect(page.reads.map((read) => read.url)).toContain(
|
|
191
|
+
'/api/database/browse/list',
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
195
|
+
const cell = page.find(
|
|
196
|
+
(props) =>
|
|
197
|
+
props.class !== undefined &&
|
|
198
|
+
'title' in props &&
|
|
199
|
+
String(props.class).includes('align-middle'),
|
|
200
|
+
)
|
|
201
|
+
return { title: cell?.title, cursor: String(cell?.class) }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
it('names why a cell takes no edit where the user tries one, which a grid saying nothing past the access bar gets wrong', async () => {
|
|
205
|
+
const { title, cursor } = await cellTitles(WAREHOUSE)
|
|
206
|
+
expect(title).toBe(REASON)
|
|
207
|
+
expect(cursor).toContain('cursor-not-allowed')
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it('gives no such reason once read and write is allowed', async () => {
|
|
211
|
+
const { title, cursor } = await cellTitles({
|
|
212
|
+
...WAREHOUSE,
|
|
213
|
+
access: 'read-write',
|
|
214
|
+
})
|
|
215
|
+
expect(title).toBeUndefined()
|
|
216
|
+
expect(cursor).not.toContain('cursor-not-allowed')
|
|
217
|
+
})
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
describe('a capped page of an external database in the data grid', () => {
|
|
221
|
+
async function gridText(capped: boolean, search = '') {
|
|
222
|
+
const page = browserMount(
|
|
223
|
+
DataGrid,
|
|
224
|
+
connectionsBackend(connectionsState(WAREHOUSE), {
|
|
225
|
+
others: (read) =>
|
|
226
|
+
read.url === '/api/database/browse/list'
|
|
227
|
+
? { results: [{ _id: '1' }], total: 1, primaryKey: '_id', capped }
|
|
228
|
+
: others(read),
|
|
229
|
+
}),
|
|
230
|
+
{ tab: TAB },
|
|
231
|
+
)
|
|
232
|
+
await page.shown
|
|
233
|
+
await vi.waitFor(() =>
|
|
234
|
+
expect(page.text()).toContain('dms_database.data.grid.rows 1'),
|
|
235
|
+
)
|
|
236
|
+
if (search) {
|
|
237
|
+
const input = page.find(
|
|
238
|
+
(props) => props.placeholder === 'dms_database.data.grid.search',
|
|
239
|
+
)?.['onUpdate:modelValue']
|
|
240
|
+
if (typeof input === 'function') input(search)
|
|
241
|
+
await vi.waitFor(
|
|
242
|
+
() =>
|
|
243
|
+
expect(page.reads.map((read) => read.query.search)).toContain(search),
|
|
244
|
+
{ timeout: 2000 },
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
return page.text()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
it('says a search matches among the first rows only, which a grid that drops the API cap gets wrong', async () => {
|
|
251
|
+
expect(await gridText(true, 'retail')).toContain(
|
|
252
|
+
'dms_database.data.grid.capped 10000',
|
|
253
|
+
)
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
it('says the count stops at the cap on a page with no search, where nothing is matched', async () => {
|
|
257
|
+
const text = await gridText(true)
|
|
258
|
+
expect(text).toContain('dms_database.data.grid.count_capped 10000')
|
|
259
|
+
expect(text).not.toContain('dms_database.data.grid.capped')
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('says nothing of a cap on a page that read every row', async () => {
|
|
263
|
+
expect(await gridText(false)).not.toMatch(/grid\.(count_)?capped/)
|
|
264
|
+
})
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
const SAMPLE_POSITION = 'dms_database.inspector.sample.position'
|
|
268
|
+
|
|
269
|
+
async function samplePosition(connection: DatabaseConnection) {
|
|
270
|
+
const page = browserMount(
|
|
271
|
+
TableInspector,
|
|
272
|
+
connectionsBackend(connectionsState(connection), {
|
|
273
|
+
others: ({ url }) => {
|
|
274
|
+
if (url === '/api/database/schemas')
|
|
275
|
+
return {
|
|
276
|
+
schemas: [
|
|
277
|
+
{
|
|
278
|
+
id: 'shop',
|
|
279
|
+
options: {},
|
|
280
|
+
tables: [
|
|
281
|
+
{
|
|
282
|
+
name: 'orders',
|
|
283
|
+
fields: { _id: { kind: 'string' } },
|
|
284
|
+
indexes: {},
|
|
285
|
+
relations: [],
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
stats: { tableCount: 1, elementCount: 3, instanceCount: 0 },
|
|
289
|
+
instances: [],
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
}
|
|
293
|
+
if (url === '/api/database/browse/count') return { total: 3 }
|
|
294
|
+
if (url === '/api/database/browse/list')
|
|
295
|
+
return { results: [{ _id: '1' }], total: 3, primaryKey: '_id' }
|
|
296
|
+
return { items: [] }
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
{ rowData: { schema: 'shop', name: 'orders' } },
|
|
300
|
+
)
|
|
301
|
+
await page.shown
|
|
302
|
+
await vi.waitFor(() => {
|
|
303
|
+
const tabs = page.find((props) => Array.isArray(props.items))
|
|
304
|
+
;(tabs?.['onUpdate:modelValue'] as (value: string) => void)('sample')
|
|
305
|
+
expect(page.text()).toContain(SAMPLE_POSITION)
|
|
306
|
+
})
|
|
307
|
+
return page.text()
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
describe('the Schemas drawer sample row', () => {
|
|
311
|
+
it('names the instance on the project database only, which a position reading default instance on an external database gets wrong', async () => {
|
|
312
|
+
const own = await samplePosition(OWN)
|
|
313
|
+
expect(own).toContain(`${SAMPLE_POSITION} `)
|
|
314
|
+
const external = await samplePosition(WAREHOUSE)
|
|
315
|
+
expect(external).toContain(`${SAMPLE_POSITION}_uninstanced`)
|
|
316
|
+
expect(external).not.toContain(`${SAMPLE_POSITION} `)
|
|
317
|
+
})
|
|
318
|
+
})
|
|
@@ -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
|
+
})
|