@antelopejs/dms-database 0.2.3 → 0.3.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 (40) hide show
  1. package/dist/frontend-module.d.ts +2 -0
  2. package/dist/frontend-module.js +17 -0
  3. package/dist/frontend-module.js.map +1 -0
  4. package/dist/index.js +2 -11
  5. package/dist/index.js.map +1 -1
  6. package/dist/pages/overview.d.ts +0 -1
  7. package/dist/pages/overview.js +0 -14
  8. package/dist/pages/overview.js.map +1 -1
  9. package/dist/pages/schemas.js +3 -0
  10. package/dist/pages/schemas.js.map +1 -1
  11. package/frontend-vue/app/build/composables/useDatabaseHealth.ts +11 -7
  12. package/frontend-vue/app/build/composables/useDatabaseSchemas.ts +8 -1
  13. package/frontend-vue/app/build/data/cellValues.ts +50 -0
  14. package/frontend-vue/app/build/diagram/graph.ts +211 -47
  15. package/frontend-vue/app/build/diagram/packing.ts +283 -0
  16. package/frontend-vue/app/build/utils/fieldTypes.ts +16 -1
  17. package/frontend-vue/app/components/ConnectionStatus.vue +5 -1
  18. package/frontend-vue/app/components/DataBrowser.vue +2 -2
  19. package/frontend-vue/app/components/DataBrowserSidebar.vue +1 -1
  20. package/frontend-vue/app/components/DataGrid.vue +44 -34
  21. package/frontend-vue/app/components/DiagramTableNode.vue +25 -1
  22. package/frontend-vue/app/components/DrawerTabs.vue +57 -0
  23. package/frontend-vue/app/components/JsonCellPanel.vue +81 -85
  24. package/frontend-vue/app/components/QueryConsole.vue +6 -1
  25. package/frontend-vue/app/components/RowDrawer.vue +98 -124
  26. package/frontend-vue/app/components/SchemaDiagram.vue +134 -17
  27. package/frontend-vue/app/components/TableInspector.vue +122 -149
  28. package/frontend-vue/i18n/locales/database-en-GB.json +8 -12
  29. package/frontend-vue/i18n/locales/database-fr-FR.json +8 -12
  30. package/frontend-vue/package.json +1 -1
  31. package/frontend-vue/tests/clientNavigation.test.ts +93 -0
  32. package/frontend-vue/tests/dataBrowser.test.ts +91 -1
  33. package/frontend-vue/tests/diagramLayout.test.ts +383 -0
  34. package/frontend-vue/tests/fixtures/serverRender.ts +114 -0
  35. package/frontend-vue/tests/locales.test.ts +48 -0
  36. package/frontend-vue/tests/onDemandReads.test.ts +81 -0
  37. package/frontend-vue/tests/serverRender.test.ts +83 -1
  38. package/frontend-vue/vitest.config.ts +8 -1
  39. package/package.json +7 -6
  40. package/skills/dms-database/SKILL.md +1 -0
@@ -1,107 +1,103 @@
1
1
  <script setup lang="ts">
2
+ import { jsonDraftText, parseJsonDraft } from '../build/data/cellValues'
3
+
4
+ // Edits a structured cell (an object or a list) as JSON in a DMS drawer;
5
+ // applying stages the value like any other cell. null empties the cell.
6
+ // Opened through `useDrawer`, it mounts anew for each cell. The editor fills
7
+ // the drawer's height, whatever its size (`fill`, never fewer than
8
+ // MIN_LINES), the DMS footer at the drawer's end.
9
+
2
10
  const props = defineProps<{
3
- open: boolean
4
11
  column: string
5
12
  value: unknown
6
13
  readOnly: boolean
7
14
  }>()
8
15
 
9
- const emit = defineEmits<{
10
- 'update:open': [open: boolean]
11
- save: [value: unknown]
12
- }>()
16
+ // Applying settles the drawer with the value, cancelling with nothing (null
17
+ // is a value: it empties the cell).
18
+ const emit = defineEmits<{ success: [result?: { value: unknown }] }>()
13
19
 
14
- // Edits a structured cell (an object or a list) as JSON; applying stages the
15
- // value like any other cell. null empties the cell.
16
20
  const { t } = useI18n()
17
21
 
18
- const draft = ref('')
22
+ const MIN_LINES = 12
23
+ // The form field hands the drawer's height down to the editor.
24
+ const FILL = { root: 'flex flex-1 flex-col', container: 'flex flex-1 flex-col' }
19
25
 
20
- watch(
21
- () => props.open,
22
- (open) => {
23
- if (!open) return
24
- try {
25
- draft.value = JSON.stringify(props.value, null, 2) ?? ''
26
- } catch {
27
- draft.value = ''
28
- }
29
- },
30
- { immediate: true },
31
- )
26
+ const draft = ref(jsonDraftText(props.value))
27
+
28
+ const parsed = computed(() => parseJsonDraft(draft.value))
32
29
 
33
30
  const parseError = computed(() => {
34
- try {
35
- const parsed = JSON.parse(draft.value)
36
- if (parsed !== null && typeof parsed !== 'object') {
37
- return t('dms_database.data.json.not_structured')
38
- }
39
- return null
40
- } catch (error) {
41
- // Localized prefix + the engine's parse detail (position, token…).
42
- return error instanceof Error
43
- ? `${t('dms_database.data.json.invalid')} — ${error.message}`
44
- : t('dms_database.data.json.invalid')
45
- }
31
+ const result = parsed.value
32
+ if (result.ok) return null
33
+ if (result.reason === 'not_structured')
34
+ return t('dms_database.data.json.not_structured')
35
+ // Localized prefix + the engine's parse detail (position, token…).
36
+ return result.detail
37
+ ? `${t('dms_database.data.json.invalid')} — ${result.detail}`
38
+ : t('dms_database.data.json.invalid')
46
39
  })
47
40
 
48
41
  function save() {
49
- if (parseError.value || props.readOnly) return
50
- emit('save', JSON.parse(draft.value))
42
+ const result = parsed.value
43
+ if (!result.ok || props.readOnly) return
44
+ emit('success', { value: result.value })
51
45
  }
52
46
  </script>
53
47
 
54
48
  <template>
55
- <USlideover
56
- :open="open"
57
- :title="t('dms_database.data.json.title', { column })"
58
- @update:open="emit('update:open', $event)"
59
- >
60
- <template #body>
61
- <!-- A DMS form of one field: the column as its label, the JSON in the
62
- DMS code input, the parse error in DMS error style, the required legend. -->
63
- <div class="grid gap-2">
64
- <DmsFieldRow
65
- layout="form"
66
- :inset="false"
67
- spacing="row"
68
- :label="column"
69
- label-for="dms-database-json-cell"
70
- :description="t('dms_database.data.json.help')"
71
- required
49
+ <div class="flex w-full min-w-0 flex-1 flex-col gap-4">
50
+ <!-- A DMS form of one field, stacked for the drawer: the column as its
51
+ label and the help above, the JSON in the DMS code input across the
52
+ drawer and down to the footer, the parse error under it in DMS error
53
+ style, the legend. -->
54
+ <div class="flex flex-1 flex-col gap-2">
55
+ <DmsFieldRow
56
+ layout="stack"
57
+ fill
58
+ :inset="false"
59
+ spacing="list"
60
+ :label="column"
61
+ label-for="dms-database-json-cell"
62
+ :description="t('dms_database.data.json.help')"
63
+ required
64
+ >
65
+ <UFormField
66
+ name="json"
67
+ :error="(!readOnly && parseError) || false"
68
+ :ui="FILL"
72
69
  >
73
- <UFormField name="json" :error="(!readOnly && parseError) || false">
74
- <DmsInputCode
75
- id="dms-database-json-cell"
76
- v-model="draft"
77
- language="json"
78
- :min-lines="12"
79
- :max-lines="30"
80
- :disabled="readOnly"
81
- />
82
- <template #error="{ error }">
83
- <DmsFormErrorText :error />
84
- </template>
85
- </UFormField>
86
- </DmsFieldRow>
87
- <DmsFormRequiredLegend v-if="!readOnly" class="pb-2" />
88
- </div>
89
- </template>
90
- <template #footer>
91
- <div class="flex w-full justify-end gap-2">
92
- <UButton
93
- variant="ghost"
94
- color="neutral"
95
- :label="t('dms_database.common.cancel')"
96
- @click="emit('update:open', false)"
97
- />
98
- <UButton
99
- v-if="!readOnly"
100
- :label="t('dms_database.data.json.apply')"
101
- :disabled="Boolean(parseError)"
102
- @click="save"
103
- />
104
- </div>
105
- </template>
106
- </USlideover>
70
+ <DmsInputCode
71
+ id="dms-database-json-cell"
72
+ v-model="draft"
73
+ language="json"
74
+ fill
75
+ :min-lines="MIN_LINES"
76
+ :disabled="readOnly"
77
+ />
78
+ <template #error="{ error }">
79
+ <DmsFormErrorText :error />
80
+ </template>
81
+ </UFormField>
82
+ </DmsFieldRow>
83
+ <DmsFormRequiredLegend v-if="!readOnly" />
84
+ </div>
85
+
86
+ <DmsContainerFooter>
87
+ <UButton
88
+ variant="outline"
89
+ color="neutral"
90
+ size="lg"
91
+ :label="t('dms_database.common.cancel')"
92
+ @click="emit('success')"
93
+ />
94
+ <UButton
95
+ v-if="!readOnly"
96
+ size="lg"
97
+ :label="t('dms_database.data.json.apply')"
98
+ :disabled="Boolean(parseError)"
99
+ @click="save"
100
+ />
101
+ </DmsContainerFooter>
102
+ </div>
107
103
  </template>
@@ -54,7 +54,7 @@ const { confirm } = useConfirm()
54
54
  const toast = useToast()
55
55
  const { user } = useDmsUserSession()
56
56
  const store = useQueryStore()
57
- const { schemas } = useDatabaseSchemas()
57
+ const { schemas, ready: schemasRead } = useDatabaseSchemas()
58
58
 
59
59
  const source = ref('')
60
60
  const executing = ref(false)
@@ -585,6 +585,11 @@ onMounted(async () => {
585
585
  await store.libraryRead
586
586
  if (!(await openFromRoute())) restoreDraft()
587
587
  })
588
+
589
+ // The page shows once the schemas (the first run's examples) and the library
590
+ // are read: a client navigation waits for them, as a server render does,
591
+ // instead of growing the result panel and filling the sidebar after it.
592
+ await Promise.all([schemasRead, store.libraryRead])
588
593
  </script>
589
594
 
590
595
  <template>
@@ -5,12 +5,12 @@ import {
5
5
  instanceBadge,
6
6
  } from '../build/composables/useDataBrowserTabs'
7
7
  import { browseSelectionQuery } from '../build/composables/useDataBrowserGrid'
8
- import { onKeyStroke } from '@vueuse/core'
9
8
  import {
10
9
  cellLabel,
11
10
  cellText,
12
11
  draftText,
13
12
  isStructured,
13
+ isWideValue,
14
14
  parseDraft,
15
15
  } from '../build/data/cellValues'
16
16
  import { useStagedEdits } from '../build/data/stagedEdits'
@@ -19,19 +19,12 @@ import type { BrowserTab } from '../build/composables/useDataBrowserTabs'
19
19
  import type { GridColumn } from '../build/composables/useDataBrowserGrid'
20
20
  import { tableLink } from '../build/utils/databaseLinks'
21
21
  import { describeRuntimeType } from '../build/utils/fieldTypes'
22
+ import DrawerTabs from './DrawerTabs.vue'
22
23
 
23
24
  // One row of the data browser in a drawer: its fields, editable and staged
24
25
  // like the grid's cells, its JSON, and the rows of other tables pointing at
25
- // it. J and K step to the next and previous row of the page.
26
-
27
- interface RowNavigation {
28
- index: number
29
- total: number
30
- hasPrev: boolean
31
- hasNext: boolean
32
- prev: () => void
33
- next: () => void
34
- }
26
+ // it. The DMS row header (the drawer's `rowHeader`) names the row, its
27
+ // position, previous / next and J / K.
35
28
 
36
29
  interface RowReference {
37
30
  schema: string
@@ -49,7 +42,6 @@ const props = defineProps<{
49
42
  columns: GridColumn[]
50
43
  table?: TableSummary
51
44
  readOnly: boolean
52
- navigation?: RowNavigation
53
45
  onStage: (rowId: string, field: string, value: unknown) => void
54
46
  onReview: () => void
55
47
  }>()
@@ -91,6 +83,8 @@ const fields = computed(() =>
91
83
  key: column.isPrimaryKey,
92
84
  relation,
93
85
  structured: isStructured(value),
86
+ // Laid out by the value read: editing it does not move the row.
87
+ wide: isWideValue(props.row[column.name]),
94
88
  type: relation
95
89
  ? relation.toTable
96
90
  : describeRuntimeType(column.type, column.name).label,
@@ -191,23 +185,23 @@ const referenceTotal = computed(() =>
191
185
  (references.value ?? []).reduce((sum, reference) => sum + reference.count, 0),
192
186
  )
193
187
 
194
- const tabs = computed(() => [
195
- {
196
- value: 'fields',
197
- label: t('dms_database.data.row.fields'),
198
- badge: props.columns.length,
199
- },
200
- { value: 'json', label: t('dms_database.data.row.json') },
201
- ...(props.readOnly
202
- ? []
203
- : [
204
- {
205
- value: 'references',
206
- label: t('dms_database.data.row.references'),
207
- badge: referenceTotal.value,
208
- },
209
- ]),
210
- ])
188
+ const tabs = computed(() => {
189
+ const items: { value: DrawerTab; label: string; badge?: number }[] = [
190
+ {
191
+ value: 'fields',
192
+ label: t('dms_database.data.row.fields'),
193
+ badge: props.columns.length,
194
+ },
195
+ { value: 'json', label: t('dms_database.data.row.json') },
196
+ ]
197
+ if (!props.readOnly)
198
+ items.push({
199
+ value: 'references',
200
+ label: t('dms_database.data.row.references'),
201
+ badge: referenceTotal.value,
202
+ })
203
+ return items
204
+ })
211
205
 
212
206
  const scope = computed(() => {
213
207
  const badge = instanceBadge(
@@ -224,76 +218,36 @@ const scopedInstance = computed(() =>
224
218
  ? undefined
225
219
  : props.tab.instance,
226
220
  )
227
-
228
- function typing(event: KeyboardEvent): boolean {
229
- return Boolean(
230
- (event.target as HTMLElement | null)?.closest('input, textarea, select'),
231
- )
232
- }
233
-
234
- onKeyStroke('j', (event) => {
235
- if (!typing(event) && props.navigation?.hasNext) props.navigation.next()
236
- })
237
- onKeyStroke('k', (event) => {
238
- if (!typing(event) && props.navigation?.hasPrev) props.navigation.prev()
239
- })
240
221
  </script>
241
222
 
242
223
  <template>
243
- <!-- As wide as the side drawer, as the table inspector. -->
244
- <div class="flex h-full w-full min-w-0 flex-col gap-4">
245
- <header class="grid gap-2">
246
- <div class="flex items-center gap-1">
247
- <DmsEyebrow :label="t('dms_database.data.row.eyebrow', { scope })" />
248
- <span class="flex-1" />
249
- <template v-if="navigation">
250
- <span class="text-dimmed mr-1 font-mono text-[11px] tabular-nums">
251
- {{ navigation.index + 1 }} / {{ navigation.total }}
252
- </span>
253
- <UButton
254
- icon="i-ph-caret-up"
255
- color="neutral"
256
- variant="ghost"
257
- size="xs"
258
- :disabled="!navigation.hasPrev"
259
- :title="t('dms_database.data.row.previous')"
260
- :aria-label="t('dms_database.data.row.previous')"
261
- @click="navigation.prev()"
262
- />
263
- <UButton
264
- icon="i-ph-caret-down"
265
- color="neutral"
266
- variant="ghost"
267
- size="xs"
268
- :disabled="!navigation.hasNext"
269
- :title="t('dms_database.data.row.next')"
270
- :aria-label="t('dms_database.data.row.next')"
271
- @click="navigation.next()"
272
- />
273
- </template>
274
- </div>
275
- <h3 class="text-highlighted font-mono text-lg font-semibold">
276
- {{ rowId ?? t('dms_database.data.row.no_id') }}
277
- </h3>
278
- <UTabs
279
- v-model="active"
280
- :items="tabs"
281
- variant="link"
282
- size="sm"
283
- :content="false"
284
- />
224
+ <!-- As wide as the side drawer, as the table inspector; it fills the
225
+ drawer's flex body, so the DMS footer sits at its end. -->
226
+ <div class="flex w-full min-w-0 flex-1 flex-col gap-4">
227
+ <header class="grid gap-3">
228
+ <p
229
+ class="text-muted flex min-w-0 items-start gap-1.5 font-mono text-xs"
230
+ data-row-scope
231
+ >
232
+ <UIcon name="i-ph-table" class="mt-px size-3.5 shrink-0" />
233
+ <span class="min-w-0 [overflow-wrap:anywhere]">{{ scope }}</span>
234
+ </p>
235
+ <DrawerTabs v-model="active" :items="tabs" />
285
236
  </header>
286
237
 
287
- <div class="min-h-0 flex-1 overflow-y-auto">
238
+ <div class="min-w-0">
288
239
  <!-- Each field is a DMS form row: the column's name in the label
289
240
  column, its type and staged change as help, the error under the
290
- control. The drawer is narrower than the label column's step, so
291
- the label sits above the control, as in a DMS form drawer. -->
241
+ control. A wide value (JSON, a long text) takes the row's width
242
+ under its label; the others sit beside it once the row is wide
243
+ enough (the row's container query). Every control keeps the same
244
+ end slot, "Set to null" or nothing: the column stays even. -->
292
245
  <div v-if="active === 'fields'" class="flex flex-col">
293
246
  <DmsFieldRow
294
247
  v-for="field in fields"
295
248
  :key="field.name"
296
- layout="form"
249
+ :layout="field.wide ? 'stack' : 'form'"
250
+ :data-field-row="field.name"
297
251
  :inset="false"
298
252
  spacing="row"
299
253
  :label-for="field.editable ? controlId(field.name) : undefined"
@@ -338,33 +292,46 @@ onKeyStroke('k', (event) => {
338
292
  · {{ t('dms_database.data.row.not_editable') }}
339
293
  </span>
340
294
  </p>
341
- <div v-else class="grid min-w-0 gap-1.5">
342
- <UFormField
343
- :name="field.name"
344
- :error="errors[field.name] ?? false"
345
- :data-field="field.name"
295
+ <UFormField
296
+ v-else
297
+ :name="field.name"
298
+ :error="errors[field.name] ?? false"
299
+ :data-field="field.name"
300
+ class="min-w-0"
301
+ >
302
+ <div
303
+ class="flex min-w-0 gap-2"
304
+ :class="field.wide ? 'items-start' : 'min-h-8 items-center'"
346
305
  >
347
- <DmsSwitch
348
- v-if="typeof field.value === 'boolean'"
349
- :id="controlId(field.name)"
350
- :model-value="field.value"
351
- class="pt-1.5"
352
- @update:model-value="setBoolean(field.name, Boolean($event))"
353
- />
354
- <DmsTextarea
355
- v-else-if="field.structured"
356
- :id="controlId(field.name)"
357
- :model-value="draftOf(field.name, field.value)"
358
- :rows="4"
359
- autoresize
360
- class="w-full font-mono text-xs"
361
- :color="field.staged ? 'warning' : 'primary'"
362
- :highlight="Boolean(field.staged || errors[field.name])"
363
- @update:model-value="drafts[field.name] = String($event)"
364
- @blur="commit(field)"
365
- />
366
- <div v-else class="flex min-w-0 items-center gap-2">
306
+ <div class="min-w-0 flex-1">
307
+ <DmsSwitch
308
+ v-if="typeof field.value === 'boolean'"
309
+ :id="controlId(field.name)"
310
+ :model-value="field.value"
311
+ @update:model-value="setBoolean(field.name, Boolean($event))"
312
+ />
313
+ <!-- JSON, or a text of several lines: a text area. -->
314
+ <DmsTextarea
315
+ v-else-if="field.wide"
316
+ :id="controlId(field.name)"
317
+ :model-value="draftOf(field.name, field.value)"
318
+ :rows="field.structured ? 4 : 2"
319
+ autoresize
320
+ class="w-full font-mono"
321
+ :class="{ 'text-xs': field.structured }"
322
+ :color="
323
+ errors[field.name]
324
+ ? 'error'
325
+ : field.staged
326
+ ? 'warning'
327
+ : 'primary'
328
+ "
329
+ :highlight="Boolean(field.staged || errors[field.name])"
330
+ @update:model-value="drafts[field.name] = String($event)"
331
+ @blur="commit(field)"
332
+ />
367
333
  <DmsInputText
334
+ v-else
368
335
  :id="controlId(field.name)"
369
336
  :model-value="draftOf(field.name, field.value)"
370
337
  :title="t('dms_database.data.grid.null_hint')"
@@ -373,7 +340,7 @@ onKeyStroke('k', (event) => {
373
340
  ? 'null'
374
341
  : undefined
375
342
  "
376
- class="min-w-0 flex-1 font-mono"
343
+ class="w-full font-mono"
377
344
  :color="
378
345
  errors[field.name]
379
346
  ? 'error'
@@ -386,20 +353,26 @@ onKeyStroke('k', (event) => {
386
353
  @blur="commit(field)"
387
354
  @keydown.enter.prevent="commit(field)"
388
355
  />
356
+ </div>
357
+ <!-- The end slot, as wide with its button or without. -->
358
+ <div class="flex w-8 shrink-0 justify-center" data-null-slot>
389
359
  <UButton
390
360
  v-if="field.value !== null && field.value !== undefined"
361
+ icon="i-ph-circle-dashed"
391
362
  size="sm"
392
363
  color="neutral"
393
364
  variant="ghost"
394
- :label="t('dms_database.data.row.set_null')"
365
+ square
366
+ :title="t('dms_database.data.row.set_null')"
367
+ :aria-label="t('dms_database.data.row.set_null')"
395
368
  @click="setNull(field.name)"
396
369
  />
397
370
  </div>
398
- <template v-if="errors[field.name]" #error="{ error }">
399
- <DmsFormErrorText :error />
400
- </template>
401
- </UFormField>
402
- </div>
371
+ </div>
372
+ <template v-if="errors[field.name]" #error="{ error }">
373
+ <DmsFormErrorText :error />
374
+ </template>
375
+ </UFormField>
403
376
  <DmsAutoLink
404
377
  @click="emit('success')"
405
378
  v-if="
@@ -492,9 +465,11 @@ onKeyStroke('k', (event) => {
492
465
  </div>
493
466
  </div>
494
467
 
495
- <footer
468
+ <DmsContainerFooter
496
469
  v-if="!readOnly"
497
- class="border-default flex items-center gap-2 border-t pt-3"
470
+ data-row-footer
471
+ class="min-h-14"
472
+ justify="between"
498
473
  >
499
474
  <span class="text-dimmed flex items-center gap-1.5 text-xs">
500
475
  <span v-if="pending" class="bg-warning size-1.5 rounded-full" />
@@ -506,12 +481,11 @@ onKeyStroke('k', (event) => {
506
481
  </span>
507
482
  <UButton
508
483
  v-if="tabPending > 0"
509
- class="ml-auto"
510
484
  size="sm"
511
485
  icon="i-ph-check"
512
486
  :label="t('dms_database.data.save.review', tabPending)"
513
487
  @click="onReview"
514
488
  />
515
- </footer>
489
+ </DmsContainerFooter>
516
490
  </div>
517
491
  </template>