@antelopejs/dms-database 0.4.4 → 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.
Files changed (162) hide show
  1. package/README.md +12 -10
  2. package/dist/automation/tableWatch.d.ts +2 -2
  3. package/dist/automation/tableWatch.js +3 -3
  4. package/dist/automation/tableWatch.js.map +1 -1
  5. package/dist/config.d.ts +11 -0
  6. package/dist/config.js +12 -0
  7. package/dist/config.js.map +1 -1
  8. package/dist/connectionAccess.d.ts +3 -0
  9. package/dist/connectionAccess.js +20 -0
  10. package/dist/connectionAccess.js.map +1 -0
  11. package/dist/db/models/connection_selections.model.d.ts +27 -0
  12. package/dist/db/models/connection_selections.model.js +17 -0
  13. package/dist/db/models/connection_selections.model.js.map +1 -0
  14. package/dist/db/models/diagram_layouts.model.d.ts +4 -4
  15. package/dist/db/models/diagram_layouts.model.js +14 -12
  16. package/dist/db/models/diagram_layouts.model.js.map +1 -1
  17. package/dist/db/models/diagram_notes.model.d.ts +3 -3
  18. package/dist/db/models/index.d.ts +1 -0
  19. package/dist/db/models/index.js +1 -0
  20. package/dist/db/models/index.js.map +1 -1
  21. package/dist/db/models/query_history.model.d.ts +3 -3
  22. package/dist/db/models/saved_queries.model.d.ts +3 -3
  23. package/dist/db/tables/connection_selections.table.d.ts +6 -0
  24. package/dist/db/tables/connection_selections.table.js +30 -0
  25. package/dist/db/tables/connection_selections.table.js.map +1 -0
  26. package/dist/db/tables/index.d.ts +1 -0
  27. package/dist/db/tables/index.js +1 -0
  28. package/dist/db/tables/index.js.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +4 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/pages/externalLock.d.ts +8 -0
  33. package/dist/pages/externalLock.js +32 -0
  34. package/dist/pages/externalLock.js.map +1 -0
  35. package/dist/pages/overview.js +6 -3
  36. package/dist/pages/overview.js.map +1 -1
  37. package/dist/pages/schemas.js +6 -2
  38. package/dist/pages/schemas.js.map +1 -1
  39. package/dist/routes/connections.d.ts +14 -0
  40. package/dist/routes/connections.js +116 -0
  41. package/dist/routes/connections.js.map +1 -0
  42. package/dist/routes/data.d.ts +10 -9
  43. package/dist/routes/data.js +43 -62
  44. package/dist/routes/data.js.map +1 -1
  45. package/dist/routes/diagram.d.ts +6 -6
  46. package/dist/routes/diagram.js +16 -6
  47. package/dist/routes/diagram.js.map +1 -1
  48. package/dist/routes/health.d.ts +1 -1
  49. package/dist/routes/health.js +3 -2
  50. package/dist/routes/health.js.map +1 -1
  51. package/dist/routes/index.d.ts +1 -0
  52. package/dist/routes/index.js +1 -0
  53. package/dist/routes/index.js.map +1 -1
  54. package/dist/routes/overview.d.ts +2 -2
  55. package/dist/routes/overview.js +11 -4
  56. package/dist/routes/overview.js.map +1 -1
  57. package/dist/routes/query.d.ts +1 -1
  58. package/dist/routes/query.js +26 -10
  59. package/dist/routes/query.js.map +1 -1
  60. package/dist/routes/schemas.d.ts +1 -1
  61. package/dist/routes/schemas.js +4 -2
  62. package/dist/routes/schemas.js.map +1 -1
  63. package/dist/routes/tables.d.ts +2 -1
  64. package/dist/routes/tables.js +29 -21
  65. package/dist/routes/tables.js.map +1 -1
  66. package/dist/service/browse.d.ts +14 -6
  67. package/dist/service/browse.js +120 -18
  68. package/dist/service/browse.js.map +1 -1
  69. package/dist/service/catalog.js +2 -1
  70. package/dist/service/catalog.js.map +1 -1
  71. package/dist/service/connectionState.d.ts +29 -0
  72. package/dist/service/connectionState.js +157 -0
  73. package/dist/service/connectionState.js.map +1 -0
  74. package/dist/service/connections.d.ts +12 -0
  75. package/dist/service/connections.js +72 -0
  76. package/dist/service/connections.js.map +1 -0
  77. package/dist/service/database.d.ts +12 -0
  78. package/dist/service/database.js +30 -0
  79. package/dist/service/database.js.map +1 -0
  80. package/dist/service/declaredFields.d.ts +3 -2
  81. package/dist/service/declaredFields.js +6 -7
  82. package/dist/service/declaredFields.js.map +1 -1
  83. package/dist/service/health.d.ts +2 -1
  84. package/dist/service/health.js +48 -21
  85. package/dist/service/health.js.map +1 -1
  86. package/dist/service/introspect.d.ts +7 -5
  87. package/dist/service/introspect.js +49 -41
  88. package/dist/service/introspect.js.map +1 -1
  89. package/dist/service/overview.d.ts +3 -2
  90. package/dist/service/overview.js +4 -4
  91. package/dist/service/overview.js.map +1 -1
  92. package/dist/service/queryInspection.js +6 -3
  93. package/dist/service/queryInspection.js.map +1 -1
  94. package/dist/service/references.d.ts +3 -2
  95. package/dist/service/references.js +9 -8
  96. package/dist/service/references.js.map +1 -1
  97. package/dist/service/rowEdit.d.ts +3 -0
  98. package/dist/service/rowEdit.js +36 -3
  99. package/dist/service/rowEdit.js.map +1 -1
  100. package/dist/service/types.d.ts +1 -1
  101. package/dist/utils/deadline.d.ts +2 -0
  102. package/dist/utils/deadline.js +18 -0
  103. package/dist/utils/deadline.js.map +1 -0
  104. package/dist/utils/guards.d.ts +2 -0
  105. package/dist/utils/guards.js +8 -0
  106. package/dist/utils/guards.js.map +1 -1
  107. package/dist/utils/query.js +5 -4
  108. package/dist/utils/query.js.map +1 -1
  109. package/frontend-vue/app/build/components/DataBrowserAccessBar.vue +88 -0
  110. package/frontend-vue/app/build/components/DataGridToolbar.vue +10 -5
  111. package/frontend-vue/app/build/components/FeatureLocked.vue +16 -0
  112. package/frontend-vue/app/build/components/QueryConsoleBoard.vue +601 -0
  113. package/frontend-vue/app/build/components/SchemaDiagramBoard.vue +691 -0
  114. package/frontend-vue/app/build/composables/registerDatabaseSwitcher.ts +16 -0
  115. package/frontend-vue/app/build/composables/reloadForSelection.ts +13 -0
  116. package/frontend-vue/app/build/composables/useDataBrowserTabs.ts +9 -0
  117. package/frontend-vue/app/build/composables/useDatabaseConnections.ts +164 -0
  118. package/frontend-vue/app/build/composables/useGridAccess.ts +25 -0
  119. package/frontend-vue/app/build/composables/useLockedPages.ts +53 -0
  120. package/frontend-vue/app/build/composables/useQueryRuntime.ts +4 -4
  121. package/frontend-vue/app/build/composables/useSelectionRecheck.ts +23 -0
  122. package/frontend-vue/app/build/data/assistantOnboarding.ts +12 -0
  123. package/frontend-vue/app/build/data/readOnlyReason.ts +30 -0
  124. package/frontend-vue/app/build/data/recentTables.ts +6 -0
  125. package/frontend-vue/app/build/data/staleDatabase.ts +58 -0
  126. package/frontend-vue/app/build/data/useStagedSave.ts +10 -1
  127. package/frontend-vue/app/components/DataBrowser.vue +9 -1
  128. package/frontend-vue/app/components/DataBrowserSidebar.vue +23 -13
  129. package/frontend-vue/app/components/DataGrid.vue +17 -6
  130. package/frontend-vue/app/components/DataGridCell.vue +5 -2
  131. package/frontend-vue/app/components/DatabaseSwitcher.vue +103 -0
  132. package/frontend-vue/app/components/QueryBuilderPanel.vue +4 -4
  133. package/frontend-vue/app/components/QueryConsole.vue +11 -592
  134. package/frontend-vue/app/components/QueryLibrary.vue +3 -3
  135. package/frontend-vue/app/components/QueryResultPanel.vue +5 -5
  136. package/frontend-vue/app/components/RowDrawer.vue +21 -14
  137. package/frontend-vue/app/components/SchemaDiagram.vue +10 -683
  138. package/frontend-vue/app/components/SchemasFilterBar.vue +3 -0
  139. package/frontend-vue/app/components/TableInspector.vue +8 -4
  140. package/frontend-vue/build/backend-boundary.ts +8 -3
  141. package/frontend-vue/dms.frontend.ts +2 -0
  142. package/frontend-vue/eslint.config.mjs +0 -1
  143. package/frontend-vue/i18n/locales/database-en-GB.json +31 -1
  144. package/frontend-vue/i18n/locales/database-fr-FR.json +31 -1
  145. package/frontend-vue/package.json +3 -3
  146. package/frontend-vue/pnpm-lock.yaml +14 -11
  147. package/frontend-vue/tests/accessBar.test.ts +196 -0
  148. package/frontend-vue/tests/backend-boundary.test.ts +15 -7
  149. package/frontend-vue/tests/databaseSwitcher.test.ts +339 -0
  150. package/frontend-vue/tests/editRequest.test.ts +146 -0
  151. package/frontend-vue/tests/externalBrowser.test.ts +193 -0
  152. package/frontend-vue/tests/fixtures/connections.ts +73 -0
  153. package/frontend-vue/tests/fixtures/serverRender.ts +135 -12
  154. package/frontend-vue/tests/lockedPages.test.ts +68 -0
  155. package/frontend-vue/tests/onDemandReads.test.ts +1 -1
  156. package/frontend-vue/tests/registration.test.ts +15 -1
  157. package/frontend-vue/tests/serverRender.test.ts +58 -4
  158. package/frontend-vue/vitest.config.ts +11 -1
  159. package/package.json +19 -15
  160. package/dist/service/schemaRegistry.d.ts +0 -2
  161. package/dist/service/schemaRegistry.js +0 -8
  162. 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
- return backend(read)
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: noop }))
82
- vi.stubGlobal('useConfirm', () => ({ confirm: async () => false }))
83
- vi.stubGlobal('useDrawer', () => ({ open: noop }))
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
- 'DmsCard',
106
- 'DmsChart',
186
+ 'DmsCardPanel',
187
+ 'DmsChartBlock',
107
188
  'DmsCodeSnippet',
108
189
  'DmsContainerFooter',
109
190
  'DmsEmptyState',
110
- 'DmsEyebrow',
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
- 'DmsSegmented',
200
+ 'DmsSegmentedControl',
120
201
  'DmsStatusSummary',
121
- 'DmsSwitch',
122
- 'DmsTextarea',
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
- for (const name of UI_COMPONENTS) app.component(name, uiStub(name))
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 { shown, text: () => mountText(root), reads, errors }
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="DmsTextarea"/g)).toHaveLength(2)
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: vi.fn(),
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 { serverRender, type BackendRead } from './fixtures/serverRender'
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
- expect(page.reads.map((read) => read.url)).toEqual([
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(page.reads[1]!.query).toEqual({ filter_schema: 'is:audit' })
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
- expect(page.reads[1]!.query).toEqual({
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(/[\\*?[\]{}()!+@|]/g, '\\$&')
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
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms-database",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Database console for the AntelopeJS DMS: schemas, relation diagrams, a data browser and an AQL query console.",
5
5
  "keywords": [
6
6
  "admin",
@@ -46,7 +46,7 @@
46
46
  "dev": "ajs project run -w -p playground",
47
47
  "generate": "ajs module exports generate",
48
48
  "lint:fix": "oxlint --fix && oxfmt . && pnpm --dir frontend-vue lint:fix",
49
- "lint": "oxlint && pnpm --dir frontend-vue lint && node scripts/check-sources.mts && antelopejs-check-interface-ranges && node node_modules/@antelopejs/dms/frontend-vue/scripts/check-api-error-presentation.mjs frontend-vue/app",
49
+ "lint": "oxlint && pnpm --dir frontend-vue lint && node scripts/check-sources.mts && node node_modules/@antelopejs/dms/frontend-vue/scripts/check-api-error-presentation.mjs frontend-vue/app",
50
50
  "typecheck": "tsc --noEmit",
51
51
  "format": "oxfmt . && pnpm --dir frontend-vue format",
52
52
  "frontend:dev": "cd playground && pnpm frontend:dev",
@@ -67,20 +67,22 @@
67
67
  "suppressions:update": "antelopejs-suppressions --update"
68
68
  },
69
69
  "dependencies": {
70
- "@antelopejs/interface-api": ">=0.3.0 <1.0.0",
71
- "@antelopejs/interface-api-util": ">=0.3.0 <1.0.0",
72
- "@antelopejs/interface-core": ">=0.4.0 <1.0.0",
73
- "@antelopejs/interface-database": ">=0.3.1 <1.0.0",
74
- "@antelopejs/interface-database-decorators": ">=0.2.1 <1.0.0",
75
- "@antelopejs/interface-dms": ">=0.12.0 <1.0.0"
70
+ "@antelopejs/interface-api": ">=0.3.3 <0.4.0",
71
+ "@antelopejs/interface-api-util": ">=0.3.2 <0.4.0",
72
+ "@antelopejs/interface-core": ">=0.5.1 <0.6.0",
73
+ "@antelopejs/interface-database": ">=0.4.0 <0.5.0",
74
+ "@antelopejs/interface-database-catalog": ">=0.0.4 <0.1.0",
75
+ "@antelopejs/interface-database-decorators": ">=0.5.2 <0.6.0",
76
+ "@antelopejs/interface-dms": ">=0.14.0 <0.15.0"
76
77
  },
77
78
  "devDependencies": {
78
- "@antelopejs/core": "^1.21.0",
79
- "@antelopejs/dms": ">=0.17.0 <1.0.0",
80
- "@antelopejs/dms-frontend": ">=0.10.0 <0.11.0",
81
- "@antelopejs/interface-data-api": ">=0.6.1 <1.0.0",
82
- "@antelopejs/mongodb": "^1.6.2",
83
- "@antelopejs/tooling-configs": "^0.5.1",
79
+ "@antelopejs/core": "~1.23.2",
80
+ "@antelopejs/dms": ">=0.20.0 <0.21.0",
81
+ "@antelopejs/dms-automation": ">=0.11.1 <0.12.0",
82
+ "@antelopejs/dms-frontend": ">=0.11.1 <0.12.0",
83
+ "@antelopejs/interface-data-api": ">=0.8.0 <0.9.0",
84
+ "@antelopejs/mongodb": "~1.8.1",
85
+ "@antelopejs/tooling-configs": ">=0.7.1 <0.8.0",
84
86
  "@types/chai": "^5.2.3",
85
87
  "@types/mocha": "^10.0.10",
86
88
  "@types/node": "^24.0.0",
@@ -89,6 +91,7 @@
89
91
  "knip": "^6.34.0",
90
92
  "lefthook": "^2.2.2",
91
93
  "mocha": "^12.0.0",
94
+ "mongodb": "^6.21.0",
92
95
  "mongodb-memory-server-core": "^11.2.0",
93
96
  "oxfmt": "^0.66.0",
94
97
  "oxlint": "1.81.0",
@@ -99,7 +102,8 @@
99
102
  "typescript": "^6.0.3"
100
103
  },
101
104
  "optionalDependencies": {
102
- "@antelopejs/interface-dms-automation": ">=0.6.1 <1.0.0"
105
+ "@antelopejs/interface-dms-automation": ">=0.7.0 <0.8.0",
106
+ "@antelopejs/interface-dms-builder": ">=0.5.1 <0.6.0"
103
107
  },
104
108
  "packageManager": "pnpm@10.33.0",
105
109
  "antelopeJs": {
@@ -1,2 +0,0 @@
1
- import { Schema } from "@antelopejs/interface-database";
2
- export declare function getRegistry(): ReadonlyMap<string, Schema>;