@antelopejs/dms-database 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +17 -10
  2. package/dist/automation/index.js.map +1 -1
  3. package/dist/automation/tableWatch.d.ts +8 -4
  4. package/dist/automation/tableWatch.js +35 -8
  5. package/dist/automation/tableWatch.js.map +1 -1
  6. package/dist/db/models/diagram_layouts.model.d.ts +7 -5
  7. package/dist/db/models/diagram_notes.model.d.ts +7 -5
  8. package/dist/db/models/query_history.model.d.ts +7 -5
  9. package/dist/db/models/saved_queries.model.d.ts +7 -5
  10. package/dist/db/tables/query_history.table.d.ts +2 -1
  11. package/dist/db/tables/query_history.table.js.map +1 -1
  12. package/dist/db/tables/saved_queries.table.d.ts +2 -1
  13. package/dist/db/tables/saved_queries.table.js.map +1 -1
  14. package/dist/i18n/messages.js +5 -2
  15. package/dist/i18n/messages.js.map +1 -1
  16. package/dist/module.js +5 -1
  17. package/dist/module.js.map +1 -1
  18. package/dist/pages/schemas.js.map +1 -1
  19. package/dist/routes/data.d.ts +4 -3
  20. package/dist/routes/data.js +37 -238
  21. package/dist/routes/data.js.map +1 -1
  22. package/dist/routes/diagram.js +64 -43
  23. package/dist/routes/diagram.js.map +1 -1
  24. package/dist/routes/query.js +51 -53
  25. package/dist/routes/query.js.map +1 -1
  26. package/dist/routes/tables.js +13 -7
  27. package/dist/routes/tables.js.map +1 -1
  28. package/dist/service/browse.d.ts +37 -0
  29. package/dist/service/browse.js +135 -0
  30. package/dist/service/browse.js.map +1 -0
  31. package/dist/service/fieldDescriptor.d.ts +6 -6
  32. package/dist/service/fieldDescriptor.js +56 -50
  33. package/dist/service/fieldDescriptor.js.map +1 -1
  34. package/dist/service/health.js.map +1 -1
  35. package/dist/service/introspect.js +45 -40
  36. package/dist/service/introspect.js.map +1 -1
  37. package/dist/service/overview.js.map +1 -1
  38. package/dist/service/queryInspection.d.ts +5 -4
  39. package/dist/service/queryInspection.js +28 -26
  40. package/dist/service/queryInspection.js.map +1 -1
  41. package/dist/service/references.d.ts +1 -1
  42. package/dist/service/references.js +3 -7
  43. package/dist/service/references.js.map +1 -1
  44. package/dist/service/rowEdit.d.ts +4 -0
  45. package/dist/service/rowEdit.js +80 -0
  46. package/dist/service/rowEdit.js.map +1 -0
  47. package/dist/service/schemaFilters.d.ts +1 -1
  48. package/dist/service/schemaFilters.js.map +1 -1
  49. package/dist/service/schemaLabels.js +1 -1
  50. package/dist/service/schemaLabels.js.map +1 -1
  51. package/dist/service/schemaRegistry.d.ts +1 -1
  52. package/dist/service/schemaRegistry.js +1 -1
  53. package/dist/service/schemaRegistry.js.map +1 -1
  54. package/dist/service/stagedSerialization.d.ts +7 -6
  55. package/dist/service/stagedSerialization.js +40 -32
  56. package/dist/service/stagedSerialization.js.map +1 -1
  57. package/dist/service/types.d.ts +3 -2
  58. package/dist/types/json.d.ts +8 -0
  59. package/dist/types/json.js +53 -0
  60. package/dist/types/json.js.map +1 -0
  61. package/dist/utils/guards.d.ts +8 -0
  62. package/dist/utils/guards.js +35 -0
  63. package/dist/utils/guards.js.map +1 -0
  64. package/dist/utils/query.d.ts +6 -7
  65. package/dist/utils/query.js +22 -30
  66. package/dist/utils/query.js.map +1 -1
  67. package/dist/utils/requestValidation.d.ts +1 -2
  68. package/dist/utils/requestValidation.js +4 -9
  69. package/dist/utils/requestValidation.js.map +1 -1
  70. package/frontend-vue/app/build/components/DataGridEmpty.vue +89 -0
  71. package/frontend-vue/app/build/components/DataGridFooter.vue +113 -0
  72. package/frontend-vue/app/build/components/DataGridReadOnlyBanner.vue +50 -0
  73. package/frontend-vue/app/build/components/DataGridSaveStatus.vue +73 -0
  74. package/frontend-vue/app/build/components/DataGridToolbar.vue +72 -0
  75. package/frontend-vue/app/build/components/DiagramLegend.vue +48 -0
  76. package/frontend-vue/app/build/components/DiagramSearchBar.vue +82 -0
  77. package/frontend-vue/app/build/components/DiagramStatusBar.vue +89 -0
  78. package/frontend-vue/app/build/components/DiagramToolbar.vue +102 -0
  79. package/frontend-vue/app/build/components/DiagramViewBar.vue +103 -0
  80. package/frontend-vue/app/build/components/diagramFloat.css +21 -0
  81. package/frontend-vue/app/build/composables/useDiagramDrag.ts +84 -0
  82. package/frontend-vue/app/build/composables/useDiagramNotes.ts +146 -0
  83. package/frontend-vue/app/build/composables/useDiagramSaveStatus.ts +50 -0
  84. package/frontend-vue/app/build/composables/useDiagramSearch.ts +77 -0
  85. package/frontend-vue/app/build/composables/useDiagramView.ts +125 -0
  86. package/frontend-vue/app/build/composables/useElsewhereInstances.ts +94 -0
  87. package/frontend-vue/app/build/composables/useTableSample.ts +176 -0
  88. package/frontend-vue/app/build/data/gridData.ts +66 -0
  89. package/frontend-vue/app/build/data/useStagedSave.ts +13 -20
  90. package/frontend-vue/app/build/diagram/autosave.ts +3 -3
  91. package/frontend-vue/app/build/diagram/graph.ts +67 -485
  92. package/frontend-vue/app/build/diagram/graphModel.ts +368 -0
  93. package/frontend-vue/app/build/diagram/layout.ts +135 -0
  94. package/frontend-vue/app/build/query/failures.ts +17 -0
  95. package/frontend-vue/app/components/DataGrid.vue +64 -358
  96. package/frontend-vue/app/components/QueryConsole.vue +27 -116
  97. package/frontend-vue/app/components/SchemaDiagram.vue +118 -678
  98. package/frontend-vue/app/components/TableInspector.vue +12 -136
  99. package/frontend-vue/build/backend-boundary.ts +122 -0
  100. package/frontend-vue/dms.frontend.build.ts +6 -0
  101. package/frontend-vue/package.json +46 -45
  102. package/frontend-vue/pnpm-lock.yaml +51 -16
  103. package/frontend-vue/tests/apiErrorPresentation.test.ts +83 -0
  104. package/frontend-vue/tests/backend-boundary.test.ts +134 -0
  105. package/frontend-vue/tests/clientNavigation.test.ts +5 -7
  106. package/frontend-vue/tests/fixtures/serverRender.ts +13 -1
  107. package/frontend-vue/tests/locales.test.ts +16 -89
  108. package/frontend-vue/tests/queryConsole.test.ts +20 -0
  109. package/frontend-vue/tests/registration.test.ts +0 -18
  110. package/frontend-vue/vitest.config.ts +5 -2
  111. package/package.json +28 -17
  112. package/skills/dms-database/cases.json +48 -0
@@ -1,9 +1,11 @@
1
1
  <script setup lang="ts">
2
2
  import { useQueryStore } from '../build/composables/useQueryStore'
3
3
  import { useDatabaseSchemas } from '../build/composables/useDatabaseSchemas'
4
+ import { useElsewhereInstances } from '../build/composables/useElsewhereInstances'
4
5
  import { useSessionStorage } from '@vueuse/core'
5
6
  import { h } from 'vue'
6
7
  import { replaceName, type UnknownKind } from '../build/query/runs'
8
+ import { sqlFailure } from '../build/query/failures'
7
9
  import {
8
10
  describeTarget,
9
11
  instanceArgument,
@@ -24,17 +26,13 @@ import type {
24
26
  import { schemaAccess } from '../build/utils/databaseLinks'
25
27
  import QueryBuilderPanel from './QueryBuilderPanel.vue'
26
28
  import QueryLibrary from './QueryLibrary.vue'
27
- import QueryResultPanel, {
28
- type InstanceRows,
29
- type QueryFailure,
30
- } from './QueryResultPanel.vue'
29
+ import QueryResultPanel, { type QueryFailure } from './QueryResultPanel.vue'
31
30
 
32
31
  // The query console: the library rail, the editor and the result. A query
33
32
  // that changes data runs only after a dry run told what it touches (D-03):
34
33
  // deletes and multi-row writes ask for the table name; a single-row update
35
34
  // can be let through without asking until the browser tab is closed.
36
35
 
37
- const BROWSE_COUNT = '/api/database/browse/count'
38
36
  // The query being written, kept for the browser tab: a reload, or a row link
39
37
  // followed by Back, brings it back (Q-9). A link that names a query wins.
40
38
  const DRAFT_KEY = 'dms-database:query:draft'
@@ -52,6 +50,7 @@ const route = useDmsRoute()
52
50
  const router = useDmsRouter()
53
51
  const { confirm } = useConfirm()
54
52
  const toast = useToast()
53
+ const { presentError } = useApiErrorPresenter()
55
54
  const { user } = useDmsUserSession()
56
55
  const store = useQueryStore()
57
56
  const { schemas, ready: schemasRead } = useDatabaseSchemas()
@@ -63,9 +62,7 @@ const failure = ref<QueryFailure | null>(null)
63
62
  const target = ref<QueryTarget>({})
64
63
  const loadedSaved = ref<SavedQuery | null>(null)
65
64
  const activeHistoryId = ref<string | null>(null)
66
- // Named instances holding rows of a table the last read found empty in the
67
- // default instance.
68
- const elsewhere = ref<InstanceRows[]>([])
65
+ const { elsewhere, findElsewhere } = useElsewhereInstances(schemas)
69
66
  const editor = useTemplateRef<InstanceType<typeof QueryBuilderPanel>>('editor')
70
67
 
71
68
  const edited = computed(
@@ -132,7 +129,12 @@ async function deleteSaved(query: SavedQuery) {
132
129
  icon: 'i-ph-trash',
133
130
  })
134
131
  if (!confirmed) return
135
- await store.deleteSaved(query.id).catch(() => undefined)
132
+ try {
133
+ await store.deleteSaved(query.id)
134
+ } catch (error) {
135
+ presentError(error, { fallbackKey: 'dms.action_error.generic' })
136
+ return
137
+ }
136
138
  if (loadedSaved.value?.id === query.id) loadedSaved.value = null
137
139
  await store.refreshSaved()
138
140
  }
@@ -144,102 +146,10 @@ async function clearHistory() {
144
146
  confirmLabel: t('dms_database.query.clear.confirm'),
145
147
  color: 'warning',
146
148
  })
147
- if (confirmed) await store.clearHistory().catch(() => undefined)
148
- }
149
-
150
- // --- running ---
151
- function fetchMessage(error: unknown): string {
152
- const { data, message } = (error ?? {}) as {
153
- data?: unknown
154
- message?: unknown
155
- }
156
- const inner = (data as { message?: unknown } | null)?.message
157
- if (typeof inner === 'string' && inner) return inner
158
- if (typeof data === 'string' && data) return data
159
- return typeof message === 'string' && message
160
- ? message
161
- : t('dms_database.query.result.failed_title')
162
- }
163
-
164
- /** How long the server ran a failed query, as its error says. */
165
- function fetchDuration(error: unknown): number | null {
166
- const data = (error as { data?: unknown } | null)?.data
167
- const duration = (data as { durationMs?: unknown } | null)?.durationMs
168
- return typeof duration === 'number' ? duration : null
169
- }
170
-
171
- type CountRows = (query: Record<string, string>) => Promise<{ total: number }>
172
-
173
- /**
174
- * The named instances of a table that hold rows, each with its count: asked
175
- * only when a read found the table empty in the default instance (decision
176
- * 11). An instance whose count fails is left out.
177
- */
178
- async function instancesWithRows(
179
- target: QueryTarget,
180
- count: CountRows,
181
- ): Promise<InstanceRows[]> {
182
- const instances =
183
- schemas.value.find((schema) => schema.id === target.schema)?.instances ?? []
184
- const counts = await Promise.all(
185
- instances.map((id) =>
186
- count({
187
- filter_schema: `is:${target.schema}`,
188
- filter_table: `is:${target.table}`,
189
- filter_instance: `is:${id}`,
190
- }).then(
191
- (res) => ({ id, count: res.total }),
192
- () => ({ id, count: 0 }),
193
- ),
194
- ),
195
- )
196
- return counts.filter((entry) => entry.count > 0)
197
- }
198
-
199
- // The table the last read found empty, whose instances are counted: in the
200
- // browser, after a run.
201
- const emptyTarget = shallowRef<QueryTarget | null>(null)
202
- const elsewhereRead = useApiData<InstanceRows[]>(
203
- () =>
204
- emptyTarget.value
205
- ? `dms-database:elsewhere:${JSON.stringify([
206
- emptyTarget.value.schema,
207
- emptyTarget.value.table,
208
- ])}`
209
- : null,
210
- ({ $authFetch, signal }) =>
211
- instancesWithRows(emptyTarget.value as QueryTarget, (query) =>
212
- $authFetch<{ total: number }>(BROWSE_COUNT, { query, signal }),
213
- ),
214
- {
215
- immediate: false,
216
- server: false,
217
- watch: false,
218
- refreshOnPageRefresh: false,
219
- },
220
- )
221
-
222
- // Each run drops the instances found for the previous one; a slow answer
223
- // for an older run is ignored.
224
- let runId = 0
225
-
226
- async function findElsewhere(
227
- answer: Awaited<ReturnType<typeof store.executeQuery>>,
228
- next: QueryTarget,
229
- ) {
230
- const id = ++runId
231
- elsewhere.value = []
232
- if (
233
- answer.mutation ||
234
- answer.rows.length > 0 ||
235
- next.instance !== '' ||
236
- !next.schema ||
237
- !next.table
238
- )
239
- return
240
- emptyTarget.value = next
241
- await elsewhereRead.execute()
242
- if (id === runId) elsewhere.value = elsewhereRead.data.value ?? []
149
+ if (confirmed)
150
+ await store.clearHistory().catch((error: unknown) => {
151
+ presentError(error, { fallbackKey: 'dms.action_error.generic' })
152
+ })
243
153
  }
244
154
 
245
155
  // The result keeps naming the previous run's target until the new one lands.
@@ -253,10 +163,11 @@ async function execute(query: Record<string, unknown>, text: string) {
253
163
  void findElsewhere(answer, next)
254
164
  } catch (error) {
255
165
  result.value = null
256
- failure.value = {
257
- message: fetchMessage(error),
258
- durationMs: fetchDuration(error),
259
- }
166
+ failure.value = sqlFailure(error)
167
+ if (!failure.value)
168
+ presentError(error, {
169
+ fallbackKey: 'dms_database.query.result.failed_title',
170
+ })
260
171
  } finally {
261
172
  target.value = next
262
173
  executing.value = false
@@ -344,10 +255,12 @@ async function guard(query: Record<string, unknown>, text: string) {
344
255
  try {
345
256
  dry = await store.dryRun(query)
346
257
  } catch (error) {
347
- return failBeforeRun(text, {
348
- message: fetchMessage(error),
349
- durationMs: null,
258
+ const diagnostic = sqlFailure(error)
259
+ if (diagnostic) return failBeforeRun(text, diagnostic)
260
+ presentError(error, {
261
+ fallbackKey: 'dms_database.query.result.failed_title',
350
262
  })
263
+ return
351
264
  }
352
265
  if (dry.operation === 'read') return execute(query, text)
353
266
  if (isSingleRowUpdate(dry) && skipsSingleUpdates())
@@ -528,10 +441,8 @@ async function confirmSave() {
528
441
  })
529
442
  await store.refreshSaved()
530
443
  } catch (error) {
531
- saveError.value =
532
- error instanceof Error && !('data' in error)
533
- ? error.message
534
- : fetchMessage(error)
444
+ if (error instanceof QueryInputError) saveError.value = error.message
445
+ else presentError(error, { fallbackKey: 'dms_database.query.save.failed' })
535
446
  } finally {
536
447
  saving.value = false
537
448
  }