@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
|
@@ -1,599 +1,18 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { useSessionStorage } from '@vueuse/core'
|
|
6
|
-
import { h } from 'vue'
|
|
7
|
-
import { replaceName, type UnknownKind } from '../build/query/runs'
|
|
8
|
-
import { sqlFailure } from '../build/query/failures'
|
|
9
|
-
import {
|
|
10
|
-
describeTarget,
|
|
11
|
-
instanceArgument,
|
|
12
|
-
readQueryTarget,
|
|
13
|
-
targetFromSource,
|
|
14
|
-
withInstance,
|
|
15
|
-
type QueryTarget,
|
|
16
|
-
} from '../build/query/target'
|
|
17
|
-
import {
|
|
18
|
-
prepareQueryPayload,
|
|
19
|
-
QueryInputError,
|
|
20
|
-
} from '../build/composables/useQueryRuntime'
|
|
21
|
-
import type {
|
|
22
|
-
DryRunResult,
|
|
23
|
-
HistoryEntry,
|
|
24
|
-
SavedQuery,
|
|
25
|
-
} from '../build/composables/useQueryStore'
|
|
26
|
-
import { schemaAccess } from '../build/utils/databaseLinks'
|
|
27
|
-
import QueryBuilderPanel from './QueryBuilderPanel.vue'
|
|
28
|
-
import QueryLibrary from './QueryLibrary.vue'
|
|
29
|
-
import QueryResultPanel, { type QueryFailure } from './QueryResultPanel.vue'
|
|
2
|
+
import FeatureLocked from '../build/components/FeatureLocked.vue'
|
|
3
|
+
import QueryConsoleBoard from '../build/components/QueryConsoleBoard.vue'
|
|
4
|
+
import { useDatabaseConnections } from '../build/composables/useDatabaseConnections'
|
|
30
5
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// every write asks for the table name, as the docs say.
|
|
6
|
+
const { t } = useI18n()
|
|
7
|
+
const { lacks, ready } = useDatabaseConnections()
|
|
34
8
|
|
|
35
|
-
|
|
36
|
-
// followed by Back, brings it back (Q-9). A link that names a query wins.
|
|
37
|
-
const DRAFT_KEY = 'dms-database:query:draft'
|
|
38
|
-
const PREFILL_ROWS = 50
|
|
39
|
-
const OPERATION_ICONS: Record<string, string> = {
|
|
40
|
-
insert: 'i-ph-plus-circle',
|
|
41
|
-
update: 'i-ph-pencil-simple',
|
|
42
|
-
replace: 'i-ph-swap',
|
|
43
|
-
delete: 'i-ph-trash',
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const { t, n } = useI18n()
|
|
47
|
-
const route = useDmsRoute()
|
|
48
|
-
const router = useDmsRouter()
|
|
49
|
-
const { confirm } = useConfirm()
|
|
50
|
-
const toast = useToast()
|
|
51
|
-
const { presentError } = useApiErrorPresenter()
|
|
52
|
-
const { user } = useDmsUserSession()
|
|
53
|
-
const store = useQueryStore()
|
|
54
|
-
const { schemas, ready: schemasRead } = useDatabaseSchemas()
|
|
55
|
-
|
|
56
|
-
const source = ref('')
|
|
57
|
-
const executing = ref(false)
|
|
58
|
-
const result = ref<Awaited<ReturnType<typeof store.executeQuery>> | null>(null)
|
|
59
|
-
const failure = ref<QueryFailure | null>(null)
|
|
60
|
-
const target = ref<QueryTarget>({})
|
|
61
|
-
const loadedSaved = ref<SavedQuery | null>(null)
|
|
62
|
-
const activeHistoryId = ref<string | null>(null)
|
|
63
|
-
const { elsewhere, findElsewhere } = useElsewhereInstances(schemas)
|
|
64
|
-
const editor = useTemplateRef<InstanceType<typeof QueryBuilderPanel>>('editor')
|
|
65
|
-
|
|
66
|
-
const edited = computed(
|
|
67
|
-
() =>
|
|
68
|
-
Boolean(loadedSaved.value) && loadedSaved.value?.source !== source.value,
|
|
69
|
-
)
|
|
70
|
-
const ownId = computed(
|
|
71
|
-
() => (user.value as { _id?: string } | null)?._id ?? null,
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
// --- library ---
|
|
75
|
-
// The team's queries: the shared ones the caller did not write.
|
|
76
|
-
const team = computed(() =>
|
|
77
|
-
store.sharedQueries.value.filter((query) => query.userId !== ownId.value),
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
function openSaved(query: SavedQuery) {
|
|
81
|
-
loadedSaved.value = query
|
|
82
|
-
activeHistoryId.value = null
|
|
83
|
-
source.value = query.source
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function openHistory(entry: HistoryEntry) {
|
|
87
|
-
loadedSaved.value = null
|
|
88
|
-
activeHistoryId.value = entry.id
|
|
89
|
-
source.value = entry.source
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function newQuery() {
|
|
93
|
-
loadedSaved.value = null
|
|
94
|
-
activeHistoryId.value = null
|
|
95
|
-
source.value = ''
|
|
96
|
-
result.value = null
|
|
97
|
-
failure.value = null
|
|
98
|
-
nextTick(() => editor.value?.focus())
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const draft = useSessionStorage<{ source: string; savedId: string | null }>(
|
|
102
|
-
DRAFT_KEY,
|
|
103
|
-
{ source: '', savedId: null },
|
|
104
|
-
)
|
|
105
|
-
watch([source, () => loadedSaved.value?.id ?? null], ([text, savedId]) => {
|
|
106
|
-
draft.value = { source: text, savedId }
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
function restoreDraft() {
|
|
110
|
-
const { source: text, savedId } = draft.value
|
|
111
|
-
if (!text) return
|
|
112
|
-
const saved = savedId
|
|
113
|
-
? store.savedQueries.value.find((query) => query.id === savedId)
|
|
114
|
-
: undefined
|
|
115
|
-
loadedSaved.value = saved ?? null
|
|
116
|
-
source.value = text
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function deleteSaved(query: SavedQuery) {
|
|
120
|
-
const confirmed = await confirm({
|
|
121
|
-
title: t('dms_database.query.delete.title', { name: query.name }),
|
|
122
|
-
description: query.shared
|
|
123
|
-
? t('dms_database.query.delete.shared')
|
|
124
|
-
: undefined,
|
|
125
|
-
confirmLabel: t('dms_database.query.delete.confirm'),
|
|
126
|
-
color: 'error',
|
|
127
|
-
icon: 'i-ph-trash',
|
|
128
|
-
})
|
|
129
|
-
if (!confirmed) return
|
|
130
|
-
try {
|
|
131
|
-
await store.deleteSaved(query.id)
|
|
132
|
-
} catch (error) {
|
|
133
|
-
presentError(error, { fallbackKey: 'dms.action_error.generic' })
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
if (loadedSaved.value?.id === query.id) loadedSaved.value = null
|
|
137
|
-
await store.refreshSaved()
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function clearHistory() {
|
|
141
|
-
const confirmed = await confirm({
|
|
142
|
-
title: t('dms_database.query.clear.title'),
|
|
143
|
-
description: t('dms_database.query.clear.description'),
|
|
144
|
-
confirmLabel: t('dms_database.query.clear.confirm'),
|
|
145
|
-
color: 'warning',
|
|
146
|
-
})
|
|
147
|
-
if (confirmed)
|
|
148
|
-
await store.clearHistory().catch((error: unknown) => {
|
|
149
|
-
presentError(error, { fallbackKey: 'dms.action_error.generic' })
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// The result keeps naming the previous run's target until the new one lands.
|
|
154
|
-
async function execute(query: Record<string, unknown>, text: string) {
|
|
155
|
-
executing.value = true
|
|
156
|
-
const next = readQueryTarget(query)
|
|
157
|
-
try {
|
|
158
|
-
const answer = await store.executeQuery(query, text, 'aql')
|
|
159
|
-
failure.value = null
|
|
160
|
-
result.value = answer
|
|
161
|
-
void findElsewhere(answer, next)
|
|
162
|
-
} catch (error) {
|
|
163
|
-
result.value = null
|
|
164
|
-
failure.value = sqlFailure(error)
|
|
165
|
-
if (!failure.value)
|
|
166
|
-
presentError(error, {
|
|
167
|
-
fallbackKey: 'dms_database.query.result.failed_title',
|
|
168
|
-
})
|
|
169
|
-
} finally {
|
|
170
|
-
target.value = next
|
|
171
|
-
executing.value = false
|
|
172
|
-
activeHistoryId.value = null
|
|
173
|
-
await store.refreshHistory()
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** A run that failed before the server ran it, worded for the reader. */
|
|
178
|
-
function describeInputError(error: unknown): QueryFailure {
|
|
179
|
-
if (!(error instanceof QueryInputError))
|
|
180
|
-
return {
|
|
181
|
-
message:
|
|
182
|
-
error instanceof Error && error.message
|
|
183
|
-
? error.message
|
|
184
|
-
: t('dms_database.query.result.failed_title'),
|
|
185
|
-
durationMs: null,
|
|
186
|
-
}
|
|
187
|
-
const { problem } = error
|
|
188
|
-
if (problem.kind === 'unknown_schema')
|
|
189
|
-
return {
|
|
190
|
-
message: t('dms_database.query.errors.unknown_schema', {
|
|
191
|
-
schema: problem.schema,
|
|
192
|
-
}),
|
|
193
|
-
durationMs: null,
|
|
194
|
-
unknown: { kind: 'schema', name: problem.schema },
|
|
195
|
-
}
|
|
196
|
-
const { place, detail } = problem
|
|
197
|
-
return {
|
|
198
|
-
message: place
|
|
199
|
-
? t('dms_database.query.errors.syntax_at', { ...place })
|
|
200
|
-
: t('dms_database.query.errors.syntax', { detail }),
|
|
201
|
-
durationMs: null,
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// A run that never reached the server is not kept in History (decision 9).
|
|
206
|
-
function failBeforeRun(text: string, problem: QueryFailure) {
|
|
207
|
-
result.value = null
|
|
208
|
-
elsewhere.value = []
|
|
209
|
-
failure.value = problem
|
|
210
|
-
target.value = targetFromSource(text)
|
|
211
|
-
activeHistoryId.value = null
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function guardTexts(dry: DryRunResult) {
|
|
215
|
-
const rows = dry.rows ?? 0
|
|
216
|
-
// The whole target, schema and instance included: `demo.tags @eu`.
|
|
217
|
-
const table = describeTarget(dry) || (dry.table ?? '')
|
|
218
|
-
const unknown = dry.rows === null
|
|
219
|
-
return {
|
|
220
|
-
title: unknown
|
|
221
|
-
? t('dms_database.query.guard.title_unknown', { table })
|
|
222
|
-
: t(
|
|
223
|
-
`dms_database.query.guard.title_${dry.operation}`,
|
|
224
|
-
{ table, count: n(rows) },
|
|
225
|
-
rows,
|
|
226
|
-
),
|
|
227
|
-
confirmLabel: unknown
|
|
228
|
-
? t('dms_database.query.guard.confirm_unknown')
|
|
229
|
-
: t(
|
|
230
|
-
`dms_database.query.guard.confirm_${dry.operation}`,
|
|
231
|
-
{ count: n(rows) },
|
|
232
|
-
rows,
|
|
233
|
-
),
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
async function guard(query: Record<string, unknown>, text: string) {
|
|
238
|
-
let dry: DryRunResult
|
|
239
|
-
try {
|
|
240
|
-
dry = await store.dryRun(query)
|
|
241
|
-
} catch (error) {
|
|
242
|
-
const diagnostic = sqlFailure(error)
|
|
243
|
-
if (diagnostic) return failBeforeRun(text, diagnostic)
|
|
244
|
-
presentError(error, {
|
|
245
|
-
fallbackKey: 'dms_database.query.result.failed_title',
|
|
246
|
-
})
|
|
247
|
-
return
|
|
248
|
-
}
|
|
249
|
-
if (dry.operation === 'read') return execute(query, text)
|
|
250
|
-
const targetLabel = describeTarget(dry)
|
|
251
|
-
const texts = guardTexts(dry)
|
|
252
|
-
await confirm({
|
|
253
|
-
...texts,
|
|
254
|
-
description: t('dms_database.query.guard.description'),
|
|
255
|
-
color: dry.operation === 'delete' ? 'error' : 'warning',
|
|
256
|
-
icon: OPERATION_ICONS[dry.operation] ?? 'i-ph-warning',
|
|
257
|
-
initialFocus: 'cancel',
|
|
258
|
-
confirmText: dry.table ?? dry.schema,
|
|
259
|
-
impact: [
|
|
260
|
-
{
|
|
261
|
-
icon: OPERATION_ICONS[dry.operation] ?? 'i-ph-lightning',
|
|
262
|
-
label: t('dms_database.query.guard.operation'),
|
|
263
|
-
count: t(`dms_database.query.guard.op_${dry.operation}`),
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
icon: 'i-ph-table',
|
|
267
|
-
label: t('dms_database.query.guard.target'),
|
|
268
|
-
count: targetLabel,
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
icon: 'i-ph-rows',
|
|
272
|
-
label: t('dms_database.query.guard.rows'),
|
|
273
|
-
count: dry.rows === null ? '?' : n(dry.rows),
|
|
274
|
-
},
|
|
275
|
-
],
|
|
276
|
-
body: () =>
|
|
277
|
-
h(
|
|
278
|
-
'pre',
|
|
279
|
-
{
|
|
280
|
-
class:
|
|
281
|
-
'border-default bg-elevated/50 max-h-40 overflow-auto rounded-md border p-3 font-mono text-xs whitespace-pre-wrap [overflow-wrap:anywhere]',
|
|
282
|
-
},
|
|
283
|
-
text,
|
|
284
|
-
),
|
|
285
|
-
onConfirm: () => execute(query, text),
|
|
286
|
-
})
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
async function run() {
|
|
290
|
-
if (!source.value.trim() || executing.value) return
|
|
291
|
-
let prepared: ReturnType<typeof prepareQueryPayload>
|
|
292
|
-
try {
|
|
293
|
-
prepared = prepareQueryPayload(source.value, schemas.value)
|
|
294
|
-
} catch (error) {
|
|
295
|
-
return failBeforeRun(source.value.trim(), describeInputError(error))
|
|
296
|
-
}
|
|
297
|
-
if (prepared.hasMutations) await guard(prepared.query, prepared.source)
|
|
298
|
-
else await execute(prepared.query, prepared.source)
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function replaceUnknown(kind: UnknownKind, from: string, to: string) {
|
|
302
|
-
source.value = replaceName(source.value, kind, from, to)
|
|
303
|
-
failure.value = null
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// The empty read again, in a named instance that has rows.
|
|
307
|
-
async function runInInstance(instance: string) {
|
|
308
|
-
if (!target.value.schema) return
|
|
309
|
-
const next = withInstance(source.value, target.value.schema, instance)
|
|
310
|
-
if (next === source.value) return
|
|
311
|
-
source.value = next
|
|
312
|
-
await run()
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// --- saving ---
|
|
316
|
-
const saveOpen = ref(false)
|
|
317
|
-
const saveName = ref('')
|
|
318
|
-
const saveDescription = ref('')
|
|
319
|
-
const saveShared = ref(false)
|
|
320
|
-
const saveError = ref<string | null>(null)
|
|
321
|
-
// The name says it is missing once left empty, as a DMS form's required field.
|
|
322
|
-
const nameTouched = ref(false)
|
|
323
|
-
const nameError = computed(() =>
|
|
324
|
-
nameTouched.value && !saveName.value.trim()
|
|
325
|
-
? t('dms_database.query.save.name_required')
|
|
326
|
-
: null,
|
|
327
|
-
)
|
|
328
|
-
// A DMS form's rows in a modal: label column, hairline between rows.
|
|
329
|
-
const SAVE_ROW = { layout: 'form', inset: false, spacing: 'row' } as const
|
|
330
|
-
const saving = ref(false)
|
|
331
|
-
const editing = ref<SavedQuery | null>(null)
|
|
332
|
-
// A past run being saved: the editor takes its text once it is saved.
|
|
333
|
-
const savingRun = ref<HistoryEntry | null>(null)
|
|
334
|
-
|
|
335
|
-
function openSaveModal(from?: SavedQuery | HistoryEntry) {
|
|
336
|
-
const saved = from && 'name' in from ? from : null
|
|
337
|
-
editing.value = saved
|
|
338
|
-
savingRun.value = from && !saved ? (from as HistoryEntry) : null
|
|
339
|
-
saveName.value = saved?.name ?? ''
|
|
340
|
-
saveDescription.value = saved?.description ?? ''
|
|
341
|
-
saveShared.value = saved?.shared ?? false
|
|
342
|
-
saveError.value = null
|
|
343
|
-
nameTouched.value = false
|
|
344
|
-
saveOpen.value = true
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
async function persist(text: string) {
|
|
348
|
-
const payload = prepareQueryPayload(text, schemas.value)
|
|
349
|
-
const input = {
|
|
350
|
-
name: saveName.value.trim(),
|
|
351
|
-
description: saveDescription.value.trim(),
|
|
352
|
-
query: payload.query,
|
|
353
|
-
source: payload.source,
|
|
354
|
-
language: 'aql' as const,
|
|
355
|
-
shared: saveShared.value,
|
|
356
|
-
}
|
|
357
|
-
return editing.value
|
|
358
|
-
? store.updateSaved(editing.value.id, input)
|
|
359
|
-
: store.saveQuery(input)
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
async function confirmSave() {
|
|
363
|
-
if (!saveName.value.trim()) {
|
|
364
|
-
nameTouched.value = true
|
|
365
|
-
return
|
|
366
|
-
}
|
|
367
|
-
saving.value = true
|
|
368
|
-
saveError.value = null
|
|
369
|
-
try {
|
|
370
|
-
const run = savingRun.value
|
|
371
|
-
const text = run
|
|
372
|
-
? run.source
|
|
373
|
-
: editing.value && editing.value.id !== loadedSaved.value?.id
|
|
374
|
-
? editing.value.source
|
|
375
|
-
: source.value
|
|
376
|
-
const saved = await persist(text)
|
|
377
|
-
if (run || !editing.value || editing.value.id === loadedSaved.value?.id) {
|
|
378
|
-
loadedSaved.value = saved
|
|
379
|
-
activeHistoryId.value = null
|
|
380
|
-
source.value = saved.source
|
|
381
|
-
}
|
|
382
|
-
savingRun.value = null
|
|
383
|
-
saveOpen.value = false
|
|
384
|
-
toast.add({
|
|
385
|
-
title: t('dms_database.query.save.saved', { name: saved.name }),
|
|
386
|
-
color: 'success',
|
|
387
|
-
icon: 'i-ph-check',
|
|
388
|
-
})
|
|
389
|
-
await store.refreshSaved()
|
|
390
|
-
} catch (error) {
|
|
391
|
-
if (error instanceof QueryInputError) saveError.value = error.message
|
|
392
|
-
else presentError(error, { fallbackKey: 'dms_database.query.save.failed' })
|
|
393
|
-
} finally {
|
|
394
|
-
saving.value = false
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// ⌘S on a query of the caller's own saves it in place; anything else asks a name.
|
|
399
|
-
async function save() {
|
|
400
|
-
const own = loadedSaved.value
|
|
401
|
-
if (!own || own.userId !== ownId.value) return openSaveModal()
|
|
402
|
-
editing.value = own
|
|
403
|
-
savingRun.value = null
|
|
404
|
-
saveName.value = own.name
|
|
405
|
-
saveDescription.value = own.description
|
|
406
|
-
saveShared.value = own.shared
|
|
407
|
-
await confirmSave()
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// --- links into the console ---
|
|
411
|
-
/** Opens what the URL names; false when it names nothing to open. */
|
|
412
|
-
async function openFromRoute(): Promise<boolean> {
|
|
413
|
-
const { q, source: linked, history, schema, table, instance } = route.query
|
|
414
|
-
let opened = false
|
|
415
|
-
if (typeof q === 'string') {
|
|
416
|
-
const match =
|
|
417
|
-
store.savedQueries.value.find((query) => query.id === q) ??
|
|
418
|
-
team.value.find((query) => query.id === q)
|
|
419
|
-
if (match) openSaved(match)
|
|
420
|
-
opened = Boolean(match)
|
|
421
|
-
} else if (typeof history === 'string') {
|
|
422
|
-
const entry = await store.fetchHistoryEntry(history).catch(() => null)
|
|
423
|
-
if (entry) openHistory(entry)
|
|
424
|
-
opened = Boolean(entry)
|
|
425
|
-
} else if (typeof linked === 'string') {
|
|
426
|
-
newQuery()
|
|
427
|
-
source.value = linked
|
|
428
|
-
opened = true
|
|
429
|
-
} else if (typeof schema === 'string' && typeof table === 'string') {
|
|
430
|
-
newQuery()
|
|
431
|
-
// The instance the link names: a named one, the default, or every one.
|
|
432
|
-
source.value = `${schemaAccess(schema)}.instance(${instanceArgument(instance)}).table(${JSON.stringify(table)}).slice(0, ${PREFILL_ROWS})`
|
|
433
|
-
opened = true
|
|
434
|
-
} else {
|
|
435
|
-
return false
|
|
436
|
-
}
|
|
437
|
-
router.replace({ query: {} })
|
|
438
|
-
return opened
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// The link and the draft name queries of the library: once it is read.
|
|
442
|
-
onMounted(async () => {
|
|
443
|
-
await store.libraryRead
|
|
444
|
-
if (!(await openFromRoute())) restoreDraft()
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
// The page shows once the schemas (the first run's examples) and the library
|
|
448
|
-
// are read: a client navigation waits for them, as a server render does,
|
|
449
|
-
// instead of growing the result panel and filling the sidebar after it.
|
|
450
|
-
await Promise.all([schemasRead, store.libraryRead])
|
|
9
|
+
await ready
|
|
451
10
|
</script>
|
|
452
11
|
|
|
453
12
|
<template>
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
<QueryLibrary
|
|
460
|
-
class="max-lg:max-h-80 max-lg:shrink-0 lg:min-h-0"
|
|
461
|
-
:history="store.historyItems.value"
|
|
462
|
-
:saved="store.savedQueries.value"
|
|
463
|
-
:team="team"
|
|
464
|
-
:active-saved-id="loadedSaved?.id ?? null"
|
|
465
|
-
:active-history-id="activeHistoryId"
|
|
466
|
-
:loading="store.libraryLoading.value"
|
|
467
|
-
@open-history="openHistory"
|
|
468
|
-
@save-history="openSaveModal"
|
|
469
|
-
@open-saved="openSaved"
|
|
470
|
-
@edit-saved="openSaveModal"
|
|
471
|
-
@delete-saved="deleteSaved"
|
|
472
|
-
@clear-history="clearHistory"
|
|
473
|
-
/>
|
|
474
|
-
|
|
475
|
-
<div
|
|
476
|
-
class="flex min-w-0 flex-col gap-4 max-lg:shrink-0 lg:min-h-0 lg:overflow-y-auto"
|
|
477
|
-
>
|
|
478
|
-
<QueryBuilderPanel
|
|
479
|
-
ref="editor"
|
|
480
|
-
v-model="source"
|
|
481
|
-
class="shrink-0"
|
|
482
|
-
:executing="executing"
|
|
483
|
-
:schemas="schemas"
|
|
484
|
-
:saved-name="loadedSaved?.name"
|
|
485
|
-
:saved-shared="loadedSaved?.shared"
|
|
486
|
-
:edited="edited"
|
|
487
|
-
@execute="run"
|
|
488
|
-
@save="save"
|
|
489
|
-
@new="newQuery"
|
|
490
|
-
/>
|
|
491
|
-
<QueryResultPanel
|
|
492
|
-
class="shrink-0"
|
|
493
|
-
:result="result"
|
|
494
|
-
:failure="failure"
|
|
495
|
-
:target="target"
|
|
496
|
-
:schemas="schemas"
|
|
497
|
-
:running="executing"
|
|
498
|
-
:elsewhere="elsewhere"
|
|
499
|
-
@use-source="source = $event"
|
|
500
|
-
@replace-name="replaceUnknown"
|
|
501
|
-
@use-instance="runInInstance"
|
|
502
|
-
/>
|
|
503
|
-
</div>
|
|
504
|
-
|
|
505
|
-
<UModal
|
|
506
|
-
v-model:open="saveOpen"
|
|
507
|
-
:title="
|
|
508
|
-
editing
|
|
509
|
-
? t('dms_database.query.save.edit_title')
|
|
510
|
-
: t('dms_database.query.save.title')
|
|
511
|
-
"
|
|
512
|
-
:description="t('dms_database.query.save.description')"
|
|
513
|
-
>
|
|
514
|
-
<template #body>
|
|
515
|
-
<!-- Drawn as a DMS form in a modal: FieldRow rows, errors under
|
|
516
|
-
their control, the required legend under the rows. -->
|
|
517
|
-
<form
|
|
518
|
-
id="dms-database-save-query"
|
|
519
|
-
class="flex flex-col py-1"
|
|
520
|
-
novalidate
|
|
521
|
-
@submit.prevent="confirmSave"
|
|
522
|
-
>
|
|
523
|
-
<DmsFieldRow
|
|
524
|
-
v-bind="SAVE_ROW"
|
|
525
|
-
:label="t('dms_database.query.save.name')"
|
|
526
|
-
label-for="dms-database-save-query-name"
|
|
527
|
-
required
|
|
528
|
-
>
|
|
529
|
-
<div class="grid min-w-0 gap-1.5">
|
|
530
|
-
<UFormField name="name" :error="nameError ?? false">
|
|
531
|
-
<DmsInputText
|
|
532
|
-
id="dms-database-save-query-name"
|
|
533
|
-
v-model="saveName"
|
|
534
|
-
autofocus
|
|
535
|
-
class="w-full"
|
|
536
|
-
:placeholder="t('dms_database.query.save.name_placeholder')"
|
|
537
|
-
@blur="nameTouched = true"
|
|
538
|
-
/>
|
|
539
|
-
<template v-if="nameError" #error="{ error }">
|
|
540
|
-
<DmsFormErrorText :error />
|
|
541
|
-
</template>
|
|
542
|
-
</UFormField>
|
|
543
|
-
</div>
|
|
544
|
-
</DmsFieldRow>
|
|
545
|
-
<DmsFieldRow
|
|
546
|
-
v-bind="SAVE_ROW"
|
|
547
|
-
:label="t('dms_database.query.save.notes')"
|
|
548
|
-
label-for="dms-database-save-query-description"
|
|
549
|
-
>
|
|
550
|
-
<DmsTextarea
|
|
551
|
-
id="dms-database-save-query-description"
|
|
552
|
-
v-model="saveDescription"
|
|
553
|
-
class="w-full"
|
|
554
|
-
:rows="3"
|
|
555
|
-
/>
|
|
556
|
-
</DmsFieldRow>
|
|
557
|
-
<DmsFieldRow
|
|
558
|
-
v-bind="SAVE_ROW"
|
|
559
|
-
:label="t('dms_database.query.save.share')"
|
|
560
|
-
:description="t('dms_database.query.save.share_description')"
|
|
561
|
-
label-for="dms-database-save-query-shared"
|
|
562
|
-
>
|
|
563
|
-
<DmsSwitch
|
|
564
|
-
id="dms-database-save-query-shared"
|
|
565
|
-
v-model="saveShared"
|
|
566
|
-
/>
|
|
567
|
-
</DmsFieldRow>
|
|
568
|
-
<DmsFormRequiredLegend class="pb-2" />
|
|
569
|
-
<UAlert
|
|
570
|
-
v-if="saveError"
|
|
571
|
-
color="error"
|
|
572
|
-
variant="subtle"
|
|
573
|
-
icon="i-ph-warning"
|
|
574
|
-
:title="t('dms_database.query.save.failed')"
|
|
575
|
-
:description="saveError"
|
|
576
|
-
/>
|
|
577
|
-
</form>
|
|
578
|
-
</template>
|
|
579
|
-
<template #footer>
|
|
580
|
-
<div class="flex w-full justify-end gap-2">
|
|
581
|
-
<UButton
|
|
582
|
-
color="neutral"
|
|
583
|
-
variant="outline"
|
|
584
|
-
:disabled="saving"
|
|
585
|
-
:label="t('dms_database.common.cancel')"
|
|
586
|
-
@click="saveOpen = false"
|
|
587
|
-
/>
|
|
588
|
-
<UButton
|
|
589
|
-
type="submit"
|
|
590
|
-
form="dms-database-save-query"
|
|
591
|
-
:loading="saving"
|
|
592
|
-
:disabled="!saveName.trim()"
|
|
593
|
-
:label="t('dms_database.query.save.confirm')"
|
|
594
|
-
/>
|
|
595
|
-
</div>
|
|
596
|
-
</template>
|
|
597
|
-
</UModal>
|
|
598
|
-
</div>
|
|
13
|
+
<FeatureLocked
|
|
14
|
+
v-if="lacks('queryConsole')"
|
|
15
|
+
:title="t('dms_database.query.title')"
|
|
16
|
+
/>
|
|
17
|
+
<QueryConsoleBoard v-else />
|
|
599
18
|
</template>
|
|
@@ -137,7 +137,7 @@ function initials(name?: string): string {
|
|
|
137
137
|
</script>
|
|
138
138
|
|
|
139
139
|
<template>
|
|
140
|
-
<
|
|
140
|
+
<DmsCardPanel :padded="false" class="flex min-h-0 flex-col overflow-hidden">
|
|
141
141
|
<div class="border-default border-b px-3 pt-2">
|
|
142
142
|
<UTabs
|
|
143
143
|
v-model="tab"
|
|
@@ -160,7 +160,7 @@ function initials(name?: string): string {
|
|
|
160
160
|
<div class="min-h-0 flex-1 overflow-y-auto px-2 pb-2">
|
|
161
161
|
<template v-if="tab === 'history'">
|
|
162
162
|
<section v-for="group in historyGroups" :key="group.key" class="mb-2">
|
|
163
|
-
<
|
|
163
|
+
<DmsEyebrowLabel :label="group.label" class="px-2 pb-1 pt-2" />
|
|
164
164
|
<div
|
|
165
165
|
v-for="{ entry, target } in group.items"
|
|
166
166
|
:key="entry.id"
|
|
@@ -313,5 +313,5 @@ function initials(name?: string): string {
|
|
|
313
313
|
@click="emit('clear-history')"
|
|
314
314
|
/>
|
|
315
315
|
</footer>
|
|
316
|
-
</
|
|
316
|
+
</DmsCardPanel>
|
|
317
317
|
</template>
|
|
@@ -284,7 +284,7 @@ const suggestion = computed(() => {
|
|
|
284
284
|
</script>
|
|
285
285
|
|
|
286
286
|
<template>
|
|
287
|
-
<
|
|
287
|
+
<DmsCardPanel :padded="false" class="overflow-hidden">
|
|
288
288
|
<div
|
|
289
289
|
class="border-default flex flex-wrap items-center gap-2.5 border-b px-4 py-2.5"
|
|
290
290
|
>
|
|
@@ -348,7 +348,7 @@ const suggestion = computed(() => {
|
|
|
348
348
|
v-if="result && rows.length > 0 && !running"
|
|
349
349
|
class="ml-auto flex flex-wrap items-center gap-1.5"
|
|
350
350
|
>
|
|
351
|
-
<
|
|
351
|
+
<DmsSegmentedControl
|
|
352
352
|
v-model="mode"
|
|
353
353
|
:items="modeItems"
|
|
354
354
|
size="sm"
|
|
@@ -497,17 +497,19 @@ const suggestion = computed(() => {
|
|
|
497
497
|
{{ renderCell(row[column]) }}
|
|
498
498
|
</td>
|
|
499
499
|
<td v-if="browsable" class="px-1">
|
|
500
|
-
<
|
|
500
|
+
<ULink
|
|
501
501
|
v-if="rowLink(row)"
|
|
502
502
|
:to="rowLink(row) ?? undefined"
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
variant="ghost"
|
|
506
|
-
size="xs"
|
|
507
|
-
class="opacity-0 focus-visible:opacity-100 group-hover/result:opacity-100"
|
|
503
|
+
raw
|
|
504
|
+
class="text-default hover:bg-elevated hover:text-highlighted outline-inverted/25 focus-visible:outline-3 inline-flex size-6 items-center justify-center rounded-[6px] text-xs opacity-0 transition focus-visible:opacity-100 active:scale-[0.98] group-hover/result:opacity-100"
|
|
508
505
|
:aria-label="t('dms_database.query.result.open_row')"
|
|
509
506
|
:title="t('dms_database.query.result.open_row')"
|
|
510
|
-
|
|
507
|
+
>
|
|
508
|
+
<UIcon
|
|
509
|
+
name="i-ph-arrow-square-out"
|
|
510
|
+
class="size-3.5 shrink-0"
|
|
511
|
+
/>
|
|
512
|
+
</ULink>
|
|
511
513
|
</td>
|
|
512
514
|
</tr>
|
|
513
515
|
</tbody>
|
|
@@ -522,7 +524,7 @@ const suggestion = computed(() => {
|
|
|
522
524
|
|
|
523
525
|
<div v-else class="grid gap-3 p-4">
|
|
524
526
|
<div class="flex flex-wrap items-center gap-2">
|
|
525
|
-
<
|
|
527
|
+
<DmsEyebrowLabel :label="t('dms_database.query.result.bars')" />
|
|
526
528
|
<USelect
|
|
527
529
|
v-model="xColumn"
|
|
528
530
|
:items="columns"
|
|
@@ -554,7 +556,7 @@ const suggestion = computed(() => {
|
|
|
554
556
|
}}
|
|
555
557
|
</span>
|
|
556
558
|
</div>
|
|
557
|
-
<
|
|
559
|
+
<DmsChartBlock
|
|
558
560
|
v-if="yColumn"
|
|
559
561
|
:key="sideways ? 'sideways' : 'upright'"
|
|
560
562
|
page-id="query"
|
|
@@ -615,5 +617,5 @@ const suggestion = computed(() => {
|
|
|
615
617
|
"
|
|
616
618
|
/>
|
|
617
619
|
</div>
|
|
618
|
-
</
|
|
620
|
+
</DmsCardPanel>
|
|
619
621
|
</template>
|