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