@antelopejs/dms-database 0.3.0 → 0.4.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 +19 -7
- package/dist/automation/index.js.map +1 -1
- package/dist/automation/tableWatch.d.ts +3 -2
- package/dist/automation/tableWatch.js +9 -6
- package/dist/automation/tableWatch.js.map +1 -1
- package/dist/db/tables/query_history.table.d.ts +2 -1
- package/dist/db/tables/query_history.table.js.map +1 -1
- package/dist/db/tables/saved_queries.table.d.ts +2 -1
- package/dist/db/tables/saved_queries.table.js.map +1 -1
- package/dist/i18n/messages.js.map +1 -1
- package/dist/module.js +5 -1
- package/dist/module.js.map +1 -1
- package/dist/pages/schemas.js.map +1 -1
- package/dist/routes/data.d.ts +1 -1
- package/dist/routes/data.js +36 -237
- package/dist/routes/data.js.map +1 -1
- package/dist/routes/diagram.js +61 -42
- package/dist/routes/diagram.js.map +1 -1
- package/dist/routes/query.js +44 -46
- package/dist/routes/query.js.map +1 -1
- package/dist/routes/tables.js +13 -7
- package/dist/routes/tables.js.map +1 -1
- package/dist/service/browse.d.ts +37 -0
- package/dist/service/browse.js +135 -0
- package/dist/service/browse.js.map +1 -0
- package/dist/service/fieldDescriptor.d.ts +6 -6
- package/dist/service/fieldDescriptor.js +9 -13
- package/dist/service/fieldDescriptor.js.map +1 -1
- package/dist/service/health.js.map +1 -1
- package/dist/service/introspect.js +13 -12
- package/dist/service/introspect.js.map +1 -1
- package/dist/service/overview.js.map +1 -1
- package/dist/service/queryInspection.d.ts +4 -3
- package/dist/service/queryInspection.js +25 -24
- package/dist/service/queryInspection.js.map +1 -1
- package/dist/service/references.js +2 -6
- package/dist/service/references.js.map +1 -1
- package/dist/service/rowEdit.d.ts +2 -0
- package/dist/service/rowEdit.js +81 -0
- package/dist/service/rowEdit.js.map +1 -0
- package/dist/service/schemaFilters.d.ts +1 -1
- package/dist/service/schemaFilters.js.map +1 -1
- package/dist/service/schemaRegistry.js.map +1 -1
- package/dist/service/stagedSerialization.d.ts +7 -6
- package/dist/service/stagedSerialization.js +29 -21
- package/dist/service/stagedSerialization.js.map +1 -1
- package/dist/types/json.d.ts +8 -0
- package/dist/types/json.js +32 -0
- package/dist/types/json.js.map +1 -0
- package/dist/utils/guards.d.ts +7 -0
- package/dist/utils/guards.js +31 -0
- package/dist/utils/guards.js.map +1 -0
- package/dist/utils/query.d.ts +6 -7
- package/dist/utils/query.js +13 -24
- package/dist/utils/query.js.map +1 -1
- package/dist/utils/requestValidation.d.ts +1 -2
- package/dist/utils/requestValidation.js +4 -9
- package/dist/utils/requestValidation.js.map +1 -1
- package/frontend-vue/app/build/components/DataGridEmpty.vue +89 -0
- package/frontend-vue/app/build/components/DataGridFooter.vue +113 -0
- package/frontend-vue/app/build/components/DataGridReadOnlyBanner.vue +50 -0
- package/frontend-vue/app/build/components/DataGridSaveStatus.vue +73 -0
- package/frontend-vue/app/build/components/DataGridToolbar.vue +72 -0
- package/frontend-vue/app/build/components/DiagramLegend.vue +48 -0
- package/frontend-vue/app/build/components/DiagramSearchBar.vue +82 -0
- package/frontend-vue/app/build/components/DiagramStatusBar.vue +89 -0
- package/frontend-vue/app/build/components/DiagramToolbar.vue +102 -0
- package/frontend-vue/app/build/components/DiagramViewBar.vue +103 -0
- package/frontend-vue/app/build/components/diagramFloat.css +21 -0
- package/frontend-vue/app/build/composables/useDiagramDrag.ts +84 -0
- package/frontend-vue/app/build/composables/useDiagramNotes.ts +146 -0
- package/frontend-vue/app/build/composables/useDiagramSaveStatus.ts +50 -0
- package/frontend-vue/app/build/composables/useDiagramSearch.ts +77 -0
- package/frontend-vue/app/build/composables/useDiagramView.ts +125 -0
- package/frontend-vue/app/build/composables/useElsewhereInstances.ts +94 -0
- package/frontend-vue/app/build/composables/useTableSample.ts +176 -0
- package/frontend-vue/app/build/data/gridData.ts +66 -0
- package/frontend-vue/app/build/data/useStagedSave.ts +13 -20
- package/frontend-vue/app/build/diagram/autosave.ts +3 -3
- package/frontend-vue/app/build/diagram/graph.ts +67 -485
- package/frontend-vue/app/build/diagram/graphModel.ts +368 -0
- package/frontend-vue/app/build/diagram/layout.ts +135 -0
- package/frontend-vue/app/build/query/failures.ts +17 -0
- package/frontend-vue/app/components/DataGrid.vue +64 -358
- package/frontend-vue/app/components/QueryConsole.vue +27 -116
- package/frontend-vue/app/components/SchemaDiagram.vue +118 -678
- package/frontend-vue/app/components/TableInspector.vue +12 -136
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +6 -0
- package/frontend-vue/package.json +3 -2
- package/frontend-vue/pnpm-lock.yaml +8 -5
- package/frontend-vue/tests/apiErrorPresentation.test.ts +83 -0
- package/frontend-vue/tests/backend-boundary.test.ts +134 -0
- package/frontend-vue/tests/clientNavigation.test.ts +5 -7
- package/frontend-vue/tests/fixtures/serverRender.ts +13 -1
- package/frontend-vue/tests/locales.test.ts +16 -89
- package/frontend-vue/tests/queryConsole.test.ts +20 -0
- package/frontend-vue/tests/registration.test.ts +0 -18
- package/frontend-vue/vitest.config.ts +5 -2
- package/package.json +23 -12
- package/skills/dms-database/SKILL.md +1 -1
- package/skills/dms-database/cases.json +48 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from 'vue'
|
|
2
|
+
import type { SchemaSummary } from './useDatabaseSchemas'
|
|
3
|
+
|
|
4
|
+
const BROWSE_LIST = '/api/database/browse/list'
|
|
5
|
+
|
|
6
|
+
interface SamplePage {
|
|
7
|
+
results: Record<string, unknown>[]
|
|
8
|
+
total: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The row asked for: its offset in an instance. No instance at offset 0 reads
|
|
13
|
+
* the default one, or the first named instance holding rows when the default
|
|
14
|
+
* one holds none.
|
|
15
|
+
*/
|
|
16
|
+
interface SampleRequest {
|
|
17
|
+
instance: string | null
|
|
18
|
+
offset: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A sample read, with the table and the instance it was read from. */
|
|
22
|
+
interface SampleRead {
|
|
23
|
+
table: string
|
|
24
|
+
instance: string | null
|
|
25
|
+
page: SamplePage
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** What the sample reads from: the inspected table, and where it is shown. */
|
|
29
|
+
interface SampleSource {
|
|
30
|
+
schemaId: ComputedRef<string>
|
|
31
|
+
tableName: ComputedRef<string>
|
|
32
|
+
tableKey: ComputedRef<string>
|
|
33
|
+
schema: ComputedRef<SchemaSummary | undefined>
|
|
34
|
+
tab: Ref<string>
|
|
35
|
+
loading: ComputedRef<boolean>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The inspector's Sample tab: the latest row of the table, or the next one on
|
|
40
|
+
* demand.
|
|
41
|
+
*/
|
|
42
|
+
export function useTableSample({
|
|
43
|
+
schemaId,
|
|
44
|
+
tableName,
|
|
45
|
+
tableKey,
|
|
46
|
+
schema,
|
|
47
|
+
tab,
|
|
48
|
+
loading,
|
|
49
|
+
}: SampleSource) {
|
|
50
|
+
const { t } = useI18n()
|
|
51
|
+
|
|
52
|
+
const requested = shallowRef<SampleRequest>({ instance: null, offset: 0 })
|
|
53
|
+
|
|
54
|
+
type ReadSample = (instance: string | null) => Promise<SamplePage>
|
|
55
|
+
|
|
56
|
+
async function firstFilledInstance(
|
|
57
|
+
read: ReadSample,
|
|
58
|
+
): Promise<{ instance: string | null; page: SamplePage }> {
|
|
59
|
+
const page = await read(null)
|
|
60
|
+
if (page.total > 0) return { instance: null, page }
|
|
61
|
+
for (const instance of schema.value?.instances ?? []) {
|
|
62
|
+
const named = await read(instance)
|
|
63
|
+
if (named.total > 0) return { instance, page: named }
|
|
64
|
+
}
|
|
65
|
+
return { instance: null, page }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Read once the Sample tab shows, in the browser only.
|
|
69
|
+
const sampleRead = useApiData<SampleRead>(
|
|
70
|
+
() =>
|
|
71
|
+
schemaId.value && tableName.value
|
|
72
|
+
? `dms-database:sample:${JSON.stringify([
|
|
73
|
+
tableKey.value,
|
|
74
|
+
requested.value.instance,
|
|
75
|
+
requested.value.offset,
|
|
76
|
+
])}`
|
|
77
|
+
: null,
|
|
78
|
+
async ({ $authFetch, signal }) => {
|
|
79
|
+
const table = tableKey.value
|
|
80
|
+
const { instance, offset } = requested.value
|
|
81
|
+
const read: ReadSample = (from) =>
|
|
82
|
+
$authFetch<SamplePage>(BROWSE_LIST, {
|
|
83
|
+
query: {
|
|
84
|
+
filter_schema: `is:${schemaId.value}`,
|
|
85
|
+
filter_table: `is:${tableName.value}`,
|
|
86
|
+
offset,
|
|
87
|
+
limit: 1,
|
|
88
|
+
...(from ? { filter_instance: `is:${from}` } : {}),
|
|
89
|
+
},
|
|
90
|
+
signal,
|
|
91
|
+
})
|
|
92
|
+
const found =
|
|
93
|
+
instance === null && offset === 0
|
|
94
|
+
? await firstFilledInstance(read)
|
|
95
|
+
: { instance, page: await read(instance) }
|
|
96
|
+
return { table, ...found }
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
immediate: false,
|
|
100
|
+
server: false,
|
|
101
|
+
watch: false,
|
|
102
|
+
refreshOnPageRefresh: false,
|
|
103
|
+
},
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
// Another table (a relation followed) shows none of the previous one's row.
|
|
107
|
+
const sampleShown = computed(() => {
|
|
108
|
+
const value = sampleRead.data.value
|
|
109
|
+
return value?.table === tableKey.value ? value : null
|
|
110
|
+
})
|
|
111
|
+
const sample = computed(() => sampleShown.value?.page.results?.[0] ?? null)
|
|
112
|
+
const sampleTotal = computed(() => sampleShown.value?.page.total ?? 0)
|
|
113
|
+
const sampleOffset = computed(() => requested.value.offset)
|
|
114
|
+
const sampleLoading = computed(() => sampleRead.pending.value)
|
|
115
|
+
const sampleFailed = computed(() => sampleRead.status.value === 'error')
|
|
116
|
+
// The instance the sample is read from.
|
|
117
|
+
const sampleInstance = computed(() => sampleShown.value?.instance ?? null)
|
|
118
|
+
|
|
119
|
+
const sampleInstanceLabel = computed(() =>
|
|
120
|
+
sampleInstance.value === null
|
|
121
|
+
? t('dms_database.inspector.sample.default_instance')
|
|
122
|
+
: t('dms_database.inspector.sample.named_instance', {
|
|
123
|
+
name: sampleInstance.value,
|
|
124
|
+
}),
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
function loadSample() {
|
|
128
|
+
if (schemaId.value && tableName.value) void sampleRead.execute()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function nextSample() {
|
|
132
|
+
const total = sampleTotal.value
|
|
133
|
+
requested.value = {
|
|
134
|
+
instance: sampleInstance.value,
|
|
135
|
+
offset: total > 0 ? (requested.value.offset + 1) % total : 0,
|
|
136
|
+
}
|
|
137
|
+
loadSample()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Another table (a relation followed) starts over from its latest row.
|
|
141
|
+
watch(tableKey, () => {
|
|
142
|
+
requested.value = { instance: null, offset: 0 }
|
|
143
|
+
if (tab.value === 'sample' && !loading.value) loadSample()
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// The sample waits for the schemas: they name the instances to look in.
|
|
147
|
+
onMounted(() =>
|
|
148
|
+
watch(
|
|
149
|
+
() => tab.value === 'sample' && !loading.value,
|
|
150
|
+
(ready) => {
|
|
151
|
+
if (ready && !sample.value && !sampleLoading.value) loadSample()
|
|
152
|
+
},
|
|
153
|
+
{ immediate: true },
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
// The `_instance` tag the store adds to rows of named instances is not a
|
|
158
|
+
// column of the table.
|
|
159
|
+
const sampleJson = computed(() => {
|
|
160
|
+
if (!sample.value) return ''
|
|
161
|
+
const { _instance: _tag, ...row } = sample.value
|
|
162
|
+
return JSON.stringify(row, null, 2)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
sample,
|
|
167
|
+
sampleTotal,
|
|
168
|
+
sampleOffset,
|
|
169
|
+
sampleLoading,
|
|
170
|
+
sampleFailed,
|
|
171
|
+
sampleInstanceLabel,
|
|
172
|
+
sampleJson,
|
|
173
|
+
loadSample,
|
|
174
|
+
nextSample,
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { GridColumn } from '../composables/useDataBrowserGrid'
|
|
2
|
+
import type { TableSummary } from '../composables/useDatabaseSchemas'
|
|
3
|
+
|
|
4
|
+
/** Primary key assumed when the backend reports none (MongoDB's implicit id). */
|
|
5
|
+
export const DEFAULT_PRIMARY_KEY = '_id'
|
|
6
|
+
|
|
7
|
+
export interface ColumnsResponse {
|
|
8
|
+
columns: string[]
|
|
9
|
+
types: Record<string, string>
|
|
10
|
+
primaryKey: string | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ListResponse {
|
|
14
|
+
results: Record<string, unknown>[]
|
|
15
|
+
total: number
|
|
16
|
+
primaryKey: string | null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The grid's columns: the sampled ones, or the introspected fields when the
|
|
21
|
+
* sample is empty or failed.
|
|
22
|
+
*/
|
|
23
|
+
export function columnsOf(
|
|
24
|
+
meta: ColumnsResponse | null,
|
|
25
|
+
primaryKey: string | null,
|
|
26
|
+
table: TableSummary | undefined,
|
|
27
|
+
): GridColumn[] {
|
|
28
|
+
const sampled = meta?.columns ?? []
|
|
29
|
+
const names = sampled.length > 0 ? sampled : Object.keys(table?.fields ?? {})
|
|
30
|
+
return names.map((name) => ({
|
|
31
|
+
name,
|
|
32
|
+
type: meta?.types[name] ?? 'string',
|
|
33
|
+
isPrimaryKey: name === (primaryKey ?? DEFAULT_PRIMARY_KEY),
|
|
34
|
+
}))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface GridCell {
|
|
38
|
+
r: number
|
|
39
|
+
c: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const MOVES: Record<string, (cell: GridCell) => GridCell> = {
|
|
43
|
+
ArrowUp: ({ r, c }) => ({ r: r - 1, c }),
|
|
44
|
+
ArrowDown: ({ r, c }) => ({ r: r + 1, c }),
|
|
45
|
+
ArrowLeft: ({ r, c }) => ({ r, c: c - 1 }),
|
|
46
|
+
ArrowRight: ({ r, c }) => ({ r, c: c + 1 }),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The cell an arrow key moves the focus to, kept inside a grid of `rows` by
|
|
51
|
+
* `columns`; null for any other key.
|
|
52
|
+
*/
|
|
53
|
+
export function moveFocus(
|
|
54
|
+
key: string,
|
|
55
|
+
from: GridCell,
|
|
56
|
+
rows: number,
|
|
57
|
+
columns: number,
|
|
58
|
+
): GridCell | null {
|
|
59
|
+
const move = MOVES[key]
|
|
60
|
+
if (!move) return null
|
|
61
|
+
const next = move(from)
|
|
62
|
+
return {
|
|
63
|
+
r: Math.max(0, Math.min(rows - 1, next.r)),
|
|
64
|
+
c: Math.max(0, Math.min(columns - 1, next.c)),
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -22,7 +22,7 @@ const UNDO_WINDOW_MS = 10_000
|
|
|
22
22
|
const UNDONE_NOTICE_MS = 3_000
|
|
23
23
|
|
|
24
24
|
/** What the save bar says once a save is written, then once it is undone. */
|
|
25
|
-
interface SaveNotice {
|
|
25
|
+
export interface SaveNotice {
|
|
26
26
|
state: 'saved' | 'undoing' | 'undone'
|
|
27
27
|
changes: StagedChange[]
|
|
28
28
|
scope: string
|
|
@@ -43,15 +43,6 @@ interface StagedSaveOptions {
|
|
|
43
43
|
onSaved: (saved: SavedChanges) => void
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/** The server's reason when it gave one, else the error's own message. */
|
|
47
|
-
function messageOf(error: unknown): string {
|
|
48
|
-
const data = (error as { data?: unknown } | null)?.data
|
|
49
|
-
if (typeof data === 'string' && data) return data
|
|
50
|
-
const message = (data as { message?: unknown } | null)?.message
|
|
51
|
-
if (typeof message === 'string' && message) return message
|
|
52
|
-
return error instanceof Error ? error.message : String(error)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
46
|
function fieldsOf(changes: StagedChange[]): string[] {
|
|
56
47
|
return [...new Set(changes.map((change) => change.field))]
|
|
57
48
|
}
|
|
@@ -61,6 +52,7 @@ export function useStagedSave(options: StagedSaveOptions) {
|
|
|
61
52
|
const { $authFetch } = useAuthFetch()
|
|
62
53
|
const { confirm } = useConfirm()
|
|
63
54
|
const toast = useToast()
|
|
55
|
+
const { presentError, resolveError } = useApiErrorPresenter()
|
|
64
56
|
const staged = useStagedEdits()
|
|
65
57
|
const saving = ref(false)
|
|
66
58
|
const notice = ref<SaveNotice | null>(null)
|
|
@@ -152,7 +144,10 @@ export function useStagedSave(options: StagedSaveOptions) {
|
|
|
152
144
|
}
|
|
153
145
|
|
|
154
146
|
/** Shows a row written as the server answered it. */
|
|
155
|
-
function showWritten(
|
|
147
|
+
function showWritten(
|
|
148
|
+
tab: BrowserTab,
|
|
149
|
+
row: Record<string, unknown> | undefined,
|
|
150
|
+
) {
|
|
156
151
|
if (row) options.onWritten(tab, row)
|
|
157
152
|
}
|
|
158
153
|
|
|
@@ -197,10 +192,13 @@ export function useStagedSave(options: StagedSaveOptions) {
|
|
|
197
192
|
)
|
|
198
193
|
if (outcome.error !== null) {
|
|
199
194
|
const left = changesOf(changes, outcome.left).length
|
|
195
|
+
const notice = resolveError(outcome.error, {
|
|
196
|
+
fallbackKey: 'error.500.description',
|
|
197
|
+
})
|
|
200
198
|
details.push(
|
|
201
199
|
t(
|
|
202
200
|
'dms_database.data.save.not_written',
|
|
203
|
-
{ count: n(left), error:
|
|
201
|
+
{ count: n(left), error: notice?.message ?? '' },
|
|
204
202
|
left,
|
|
205
203
|
),
|
|
206
204
|
)
|
|
@@ -237,14 +235,9 @@ export function useStagedSave(options: StagedSaveOptions) {
|
|
|
237
235
|
// The rows the failure left keep their undo, for a retry.
|
|
238
236
|
if (here)
|
|
239
237
|
show({ ...current, state: 'saved', changes: left }, UNDO_WINDOW_MS)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
{ count: n(left.length + gone.length) },
|
|
244
|
-
left.length + gone.length,
|
|
245
|
-
),
|
|
246
|
-
description: messageOf(outcome.error),
|
|
247
|
-
color: 'error',
|
|
238
|
+
presentError(outcome.error, {
|
|
239
|
+
fallbackKey: 'dms_database.data.save.undo_partial',
|
|
240
|
+
params: { count: left.length + gone.length },
|
|
248
241
|
})
|
|
249
242
|
} else if (here) {
|
|
250
243
|
show(
|
|
@@ -29,7 +29,7 @@ export class DiagramAutosave {
|
|
|
29
29
|
/** The state to write, read when the write is asked for. */
|
|
30
30
|
private readonly read: () => DiagramState,
|
|
31
31
|
private readonly delayMs: number,
|
|
32
|
-
private readonly onStatus: (status: SaveStatus) => void,
|
|
32
|
+
private readonly onStatus: (status: SaveStatus, error?: unknown) => void,
|
|
33
33
|
) {}
|
|
34
34
|
|
|
35
35
|
/** Saves once edits pause. */
|
|
@@ -65,8 +65,8 @@ export class DiagramAutosave {
|
|
|
65
65
|
try {
|
|
66
66
|
await this.writer.save(state)
|
|
67
67
|
this.onStatus('saved')
|
|
68
|
-
} catch {
|
|
69
|
-
this.onStatus('error')
|
|
68
|
+
} catch (error) {
|
|
69
|
+
this.onStatus('error', error)
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|